All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ju Hyung Park <qkrwngud825@gmail.com>
To: Chao Yu <yuchao0@huawei.com>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH 2/2] mkfs.f2fs: make the default extensions list much more sensical
Date: Wed, 17 Apr 2019 18:54:11 +0900	[thread overview]
Message-ID: <CAD14+f2_dp8+KScRi4uyGG1KgQkqpdxGTZGvm5h3w++EYNvQnA@mail.gmail.com> (raw)
In-Reply-To: <c91943d3-8dbb-ca08-97c8-6e2d37392e70@huawei.com>

Hi Chao,

On Wed, Apr 17, 2019 at 6:41 PM Chao Yu <yuchao0@huawei.com> wrote:
> Actually, kernel will compare each character of extension in list with file's
> extension, rather than prefix, could you confirm that? :)

Just wrote a sample C program with namei.c's is_extension_exist() to
confirm this indeed works as intended.

Output:
Checking against "jp"
jpg: false
abc.jpg: true
abc.jpeg: true
abc.jpg.tmp: true
abc.jpeg.tmp: true
abc.jgp: false

Source:

#include <stdio.h>
#include <stddef.h>
#include <string.h>

static int is_extension_exist(const unsigned char *s, const char *sub)
{
    size_t slen = strlen(s);
    size_t sublen = strlen(sub);
    int i;

    /*
     * filename format of multimedia file should be defined as:
     * "filename + '.' + extension + (optional: '.' + temp extension)".
     */
    if (slen < sublen + 2)
        return 0;

    for (i = 1; i < slen - sublen; i++) {
        if (s[i] != '.')
            continue;
        if (!strncasecmp(s + i + 1, sub, sublen))
            return 1;
    }

    return 0;
}

static const char *list[] = {
    "jpg",
    "abc.jpg",
    "abc.jpeg",
    "abc.jpg.tmp",
    "abc.jpeg.tmp",
    "abc.jgp",
    NULL
};

#define CHECK "jp"

int main() {
    printf("Checking against \"%s\"\n", CHECK);

    for (int i = 0; list[i]; i++) {
        if (is_extension_exist(list[i], CHECK))
            printf("%s: true\n", list[i]);
        else
            printf("%s: false\n", list[i]);
    }
}

  reply	other threads:[~2019-04-17  9:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16  6:43 [PATCH 1/2] mkfs.f2fs: make extensions list easier to read Park Ju Hyung
2019-04-16  6:43 ` [PATCH 2/2] mkfs.f2fs: make the default extensions list much more sensical Park Ju Hyung
2019-04-16  6:49   ` Ju Hyung Park
2019-04-16 20:39     ` Jaegeuk Kim
2019-04-17  7:14       ` Ju Hyung Park
2019-04-17  9:41   ` Chao Yu
2019-04-17  9:54     ` Ju Hyung Park [this message]
2019-04-17 10:44       ` Chao Yu
2019-04-20  2:14   ` Chao Yu
2019-05-28 10:19   ` Chao Yu
2019-05-28 10:28     ` Ju Hyung Park
2019-05-29  1:57       ` Chao Yu
2019-04-17  9:33 ` [PATCH 1/2] mkfs.f2fs: make extensions list easier to read Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAD14+f2_dp8+KScRi4uyGG1KgQkqpdxGTZGvm5h3w++EYNvQnA@mail.gmail.com \
    --to=qkrwngud825@gmail.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.