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.
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