Hi Ju Hyung,
On 2019/4/17 17:54, Ju Hyung Park wrote:
> Hi Chao,
>
> On Wed, Apr 17, 2019 at 6:41 PM Chao Yu <[email protected]> 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.
Thanks for your confirmation.
Sorry for my mistake, I just recall that we added .db in hot file extension list
so that .db-journal, .db-wal, .db-shm can also be covered.
Maybe we have faced some risk that there is cold extension which is the prefix
of hot file's extension, but I guess this is really rare or even not exist.
Anyway I think we can afford that risk since extension itself is rough method
for judging the hot/cold type of file, it may not always be 100% correct.
So, it looks okay to me to use their common prefix. ;)
Thanks,
>
> 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]);
> }
> }
> .
>
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel