Set up new version of case insensitive code using sed
authorCharles Manning <cdhmanning@gmail.com>
Mon, 13 Feb 2012 04:40:39 +0000 (17:40 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Tue, 14 Feb 2012 01:16:51 +0000 (14:16 +1300)
This version uses sed to change strncmp->yaffs_strncmp etc.
This emnables us to keep the core code free of yaffs_strxxx macros.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/Makefile
direct/basic-test/dtest.c
direct/tests/Makefile
direct/yaffs_attribs.c
direct/yaffsfs.c
direct/ydirectenv.h

index afe0ef0577bd687833c4906405585ec475da30c7..1761ac449d248deae0c08074347db3914594d236 100644 (file)
@@ -24,6 +24,7 @@ CFLAGS +=    -Wall -g $(EXTRA_COMPILE_FLAGS) -Werror=strict-aliasing
 #CFLAGS +=    -fno-strict-aliasing
 CFLAGS +=    -O0
 #CFLAGS +=    -DVALGRIND_TEST
+#CFLAGS +=     -DCONFIG_YAFFS_CASE_INSENSITIVE
 
 CFLAGS+=   -Wshadow -Werror=pointer-arith -Werror=write-strings
 CFLAGS+=   -Werror=strict-prototypes -Werror=missing-parameter-type
@@ -50,7 +51,7 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o \
 #               yaffs_checkptrwtest.o\
 
 
-YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \
+YAFFS_SOURCES = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \
           yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h \
           yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \
           yaffs_checkptrw.h yaffs_checkptrw.c \
@@ -72,7 +73,7 @@ YAFFSDIRECTSYMLINKS =  yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\
 
 
 
-SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS)
+COPIED_SOURCES = $(YAFFS_SOURCES) $(YAFFSDIRECTSYMLINKS)
 
 
 DIRECTTESTOBJS = $(COMMONTESTOBJS) dtest.o
@@ -89,6 +90,15 @@ $(ALLOBJS): %.o: %.c
        gcc -c $(CFLAGS) -o $@ $<
 
 
+$(YAFFS_SOURCES):
+       sed ../../$@ \
+       -e "s/strcat/yaffs_strcat/g" \
+       -e "s/strcpy/yaffs_strcpy/g" \
+       -e "s/strncpy/yaffs_strncpy/g" \
+       -e "s/strnlen/yaffs_strnlen/g" \
+       -e "s/strcmp/yaffs_strcmp/g" \
+       -e "s/strncmp/yaffs_strncmp/g" >$@
+                                                        
 $(YAFFSSYMLINKS):
        ln -s ../../$@ $@
 
@@ -96,16 +106,16 @@ $(YAFFSDIRECTSYMLINKS):
        ln -s ../$@ $@
 
 
-directtest2k: $(SYMLINKS) $(DIRECTTESTOBJS)
+directtest2k: $(COPIED_SOURCES) $(DIRECTTESTOBJS)
        gcc -o $@ $(DIRECTTESTOBJS)
 
-yaffs_test: $(SYMLINKS) $(YAFFSTESTOBJS)
+yaffs_test: $(COPIED_SOURCES) $(YAFFSTESTOBJS)
        gcc -o $@ $(YAFFSTESTOBJS)
 
 
-boottest: $(SYMLINKS) $(BOOTTESTOBJS)
+boottest: $(COPIED_SOURCES) $(BOOTTESTOBJS)
        gcc -o $@ $(BOOTTESTOBJS)
 
 
 clean:
-       rm -f $(TARGETS) $(ALLOBJS) core core $(SYMLINKS)
+       rm -f $(TARGETS) $(ALLOBJS) core core $(COPIED_SOURCES)
index 4953830694c40290b699c8ef0244cb1cc9739bb6..e57691903d369e416652e22db5a94ae122e32beb 100644 (file)
@@ -2796,6 +2796,58 @@ void max_files_test(const char *mountpt)
 
        h =yaffs_open(hn,O_RDWR,0);
 
+}
+void case_insensitive_test(const char *mountpt)
+{
+        char fn[100];
+        char fn2[100];
+        char buffer[100];
+        int ret;
+        struct yaffs_stat s;
+        int h;
+        char *x;
+
+       yaffs_trace_mask = 0;
+
+       yaffs_start_up();
+
+       yaffs_mount(mountpt);
+       dump_directory_tree(mountpt);
+
+       sprintf(fn,"%s/Abc.Txt",mountpt);
+       yaffs_unlink(fn);
+       h = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
+
+       ret = yaffs_write(h,fn, strlen(fn) + 1);
+
+       ret = yaffs_close(h);
+
+       dump_directory_tree(mountpt);
+
+
+       strcpy(fn2, fn);
+       x = fn2;
+       while(*x) {
+               *x = toupper(*x);
+               x++;
+        }
+
+        h = yaffs_open(fn2, O_RDONLY, 0);
+        ret = yaffs_read(h, buffer, 100);
+
+        if (ret != strlen(fn) + 1 || memcmp(buffer, fn, ret)){
+               printf("wrong file read\n");
+        } else {
+               printf("File %s is the same as file %s\n", fn, fn2);
+        }
+
+        ret = yaffs_stat(fn2, &s);
+
+       printf("renaming\n");
+
+        ret = yaffs_rename(fn, fn2);
+       dump_directory_tree(mountpt);
+
 }
 
 void start_twice(const char *mountpt)
@@ -3047,6 +3099,7 @@ int main(int argc, char *argv[])
         //large_file_test("/yaffs2");
 
         //basic_utime_test("/yaffs2");
+        //case_insensitive_test("/yaffs2");
 
         return 0;
 
index 1389552b54f55fcd46e96da7b703557d059f431e..495473b58b8a37c72bc24072752fc17f32818644 100644 (file)
@@ -51,7 +51,7 @@ YAFFSTESTOBJS  = $(COMMONTESTOBJS) yaffs_test.o
 
 ALLOBJS = $(sort $(YAFFSTESTOBJS))
 
-YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \
+YAFFSSOURCEFILES = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \
           yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h  \
           yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \
           yaffs_checkptrw.h yaffs_checkptrw.c \
@@ -78,7 +78,7 @@ DIRECTEXTRASYMLINKS =         yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\
                        yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \
                        ynorsim.h ynorsim.c yaffs_osglue.c
 
-SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS)
+COPIED_SOURCES = $(YAFFSSOURCEFILES) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS)
 #all: directtest2k boottest
 
 all: yaffs_test fuzzer
@@ -87,8 +87,14 @@ $(ALLOBJS): %.o: %.c
        gcc -c $(CFLAGS) -o $@ $<
 
 
-$(YAFFSSYMLINKS):
-       ln -s ../../$@ $@
+$(YAFFSSOURCEFILES):
+       sed ../../$@ \
+       -e "s/strcat/yaffs_strcat/g" \
+       -e "s/strcpy/yaffs_strcpy/g" \
+       -e "s/strncpy/yaffs_strncpy/g" \
+       -e "s/strnlen/yaffs_strnlen/g" \
+       -e "s/strcmp/yaffs_strcmp/g" \
+       -e "s/strncmp/yaffs_strncmp/g" >$@
 
 $(YAFFSDIRECTSYMLINKS):
        ln -s ../$@ $@
@@ -97,7 +103,7 @@ $(DIRECTEXTRASYMLINKS):
        ln -s ../basic-test/$@ $@
 
 
-yaffs_test: $(SYMLINKS) $(YAFFSTESTOBJS)
+yaffs_test: $(COPIED_SOURCES) $(YAFFSTESTOBJS)
        gcc $(CFLLAG) -o $@ $(YAFFSTESTOBJS)
 
 fuzzer: fuzzer.c
@@ -108,4 +114,4 @@ fuzzer: fuzzer.c
 
 
 clean:
-       rm -f yaffs_test fuzzer fuzzer.o $(ALLOBJS) core $(SYMLINKS)
+       rm -f yaffs_test fuzzer fuzzer.o $(ALLOBJS) core $(COPIED_SOURCES)
index 416341af4eb9a5fb19eb27592f04ccdad52b4f1f..82111c2c3979ca076f51257c80bd21f1c12dd61a 100644 (file)
@@ -92,7 +92,7 @@ loff_t yaffs_get_file_size(struct yaffs_obj *obj)
                alias = obj->variant.symlink_variant.alias;
                if(!alias)
                        return 0;
-               return strnlen(alias,YAFFS_MAX_ALIAS_LENGTH);
+               return yaffs_strnlen(alias,YAFFS_MAX_ALIAS_LENGTH);
        default:
                return 0;
        }
index b57084cb5805ca6b675d9a8287e4a69ece20ef75..9ef19bff447227f7ff6e7b535a5372d3a32cb706 100644 (file)
@@ -380,13 +380,27 @@ static void yaffsfs_BreakDeviceHandles(struct yaffs_dev *dev)
 /*
  *  Stuff to handle names.
  */
-
+#ifdef CONFIG_YAFFS_CASE_INSENSITIVE
+static int yaffs_toupper(YCHAR a)
+{
+       if(a >= 'a' && a <= 'z')
+               return (a - 'a') + 'A';
+       else
+               return a;
+}
 
+int yaffsfs_Match(YCHAR a, YCHAR b)
+{
+       return (yaffs_toupper(a) == yaffs_toupper(b));
+}
+#else
 int yaffsfs_Match(YCHAR a, YCHAR b)
 {
        /* case sensitive */
        return (a == b);
 }
+#endif
 
 int yaffsfs_IsPathDivider(YCHAR ch)
 {
@@ -405,7 +419,7 @@ int yaffsfs_CheckNameLength(const char *name)
 {
        int retVal = 0;
 
-       int nameLength = strnlen(name,YAFFS_MAX_NAME_LENGTH+1);
+       int nameLength = yaffs_strnlen(name,YAFFS_MAX_NAME_LENGTH+1);
 
        if(nameLength == 0){
                yaffsfs_SetError(-ENOENT);
@@ -430,7 +444,7 @@ static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
         * We will use 3 * max name length instead.
         */
        *ret_path = NULL;
-       path_length = strnlen(path,(YAFFS_MAX_NAME_LENGTH+1)*3 +1);
+       path_length = yaffs_strnlen(path,(YAFFS_MAX_NAME_LENGTH+1)*3 +1);
 
        /* If the last character is a path divider, then we need to
         * trim it back so that the name look-up works properly.
@@ -443,7 +457,7 @@ static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
                alt_path = kmalloc(path_length + 1, 0);
                if(!alt_path)
                        return -1;
-               strcpy(alt_path, path);
+               yaffs_strcpy(alt_path, path);
                for(i = path_length-1;
                        i >= 0 && yaffsfs_IsPathDivider(alt_path[i]);
                        i--)
@@ -650,9 +664,9 @@ static struct yaffs_obj *yaffsfs_DoFindDirectory(struct yaffs_obj *startDir,
                        /* got to the end of the string */
                        return dir;
                else{
-                       if(strcmp(str,_Y(".")) == 0){
+                       if(yaffs_strcmp(str,_Y(".")) == 0){
                                /* Do nothing */
-                       } else if(strcmp(str,_Y("..")) == 0) {
+                       } else if(yaffs_strcmp(str,_Y("..")) == 0) {
                                dir = dir->parent;
                        } else{
                                dir = yaffs_find_by_name(dir,str);
@@ -1430,7 +1444,7 @@ int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory)
                yaffsfs_SetError(-ELOOP);
        else if(!dir)
                yaffsfs_SetError(-ENOENT);
-       else if(strncmp(name,_Y("."),2) == 0)
+       else if(yaffs_strncmp(name,_Y("."),2) == 0)
                yaffsfs_SetError(-EINVAL);
        else if(!obj)
                yaffsfs_SetError(-ENOENT);
@@ -1518,7 +1532,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
        } else if(oldLoop || newLoop) {
                yaffsfs_SetError(-ELOOP);
                rename_allowed = 0;
-       } else if (olddir && oldname && strncmp(oldname, _Y("."),2) == 0){
+       } else if (olddir && oldname && yaffs_strncmp(oldname, _Y("."),2) == 0){
                yaffsfs_SetError(-EINVAL);
                rename_allowed = 0;
        }else if(!olddir || !newdir || !obj) {
@@ -2379,7 +2393,7 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode)
                yaffsfs_SetError(-ENOENT);
        else if(yaffsfs_TooManyObjects(parent->my_dev))
                yaffsfs_SetError(-ENFILE);
-       else if(strnlen(name,5) == 0){
+       else if(yaffs_strnlen(name,5) == 0){
                /* Trying to make the root itself */
                yaffsfs_SetError(-EEXIST);
        } else if(parent->my_dev->read_only)
@@ -2885,7 +2899,7 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
                        memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
                         dsc->magic = YAFFS_MAGIC;
                         dsc->dirObj = obj;
-                        strncpy(dsc->name,dirname,NAME_MAX);
+                        yaffs_strncpy(dsc->name,dirname,NAME_MAX);
                         INIT_LIST_HEAD(&dsc->others);
 
                         if(!search_contexts.next)
@@ -2916,10 +2930,10 @@ struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp)
                        dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
                        dsc->de.d_off = dsc->offset++;
                        yaffs_get_obj_name(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
-                       if(strnlen(dsc->de.d_name,NAME_MAX+1) == 0)
+                       if(yaffs_strnlen(dsc->de.d_name,NAME_MAX+1) == 0)
                        {
                                /* this should not happen! */
-                               strcpy(dsc->de.d_name,_Y("zz"));
+                               yaffs_strcpy(dsc->de.d_name,_Y("zz"));
                        }
                        dsc->de.d_reclen = sizeof(struct yaffs_dirent);
                        retVal = &dsc->de;
@@ -2995,7 +3009,7 @@ int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
                yaffsfs_SetError(-ENOTDIR);
        else if(loop)
                yaffsfs_SetError(-ELOOP);
-       else if( !parent || strnlen(name,5) < 1)
+       else if( !parent || yaffs_strnlen(name,5) < 1)
                yaffsfs_SetError(-ENOENT);
        else if(yaffsfs_TooManyObjects(parent->my_dev))
                yaffsfs_SetError(-ENFILE);
@@ -3045,7 +3059,7 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
        else {
                YCHAR *alias = obj->variant.symlink_variant.alias;
                memset(buf,0,bufsiz);
-               strncpy(buf,alias,bufsiz - 1);
+               yaffs_strncpy(buf,alias,bufsiz - 1);
                retVal = 0;
        }
        yaffsfs_Unlock();
index 7860b848f21548cc4c6f3432425e839c94893344..fbf460664229e1034cd58c80f473d360e7105c29 100644 (file)
 #define YUCHAR unsigned char
 #define _Y(x) x
 
+#define yaffs_strcat(a,b)    strcat(a,b)
+#define yaffs_strcpy(a,b)    strcpy(a,b)
+#define yaffs_strncpy(a,b,c) strncpy(a,b,c)
+#define yaffs_strnlen(s,m)           strnlen(s,m)
+#ifdef CONFIG_YAFFS_CASE_INSENSITIVE
+#define yaffs_strcmp(a,b) strcasecmp(a,b)
+#define yaffs_strncmp(a,b,c) strncasecmp(a,b,c)
+#else
+#define yaffs_strcmp(a,b) strcmp(a,b)
+#define yaffs_strncmp(a,b,c) strncmp(a,b,c)
+#endif
+
 #define hweight8(x)    yaffs_hweight8(x)
 #define hweight32(x)   yaffs_hweight32(x)