yaffs Direct: Add feature to limit the number of files that may be created on a singl...
authorCharles Manning <cdhmanning@gmail.com>
Tue, 17 Jan 2012 22:49:27 +0000 (11:49 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Tue, 17 Jan 2012 22:49:27 +0000 (11:49 +1300)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/dtest.c
direct/yaffsfs.c
yaffs_guts.h

index fa48158..0a54bd4 100644 (file)
@@ -2755,6 +2755,48 @@ void link_follow_test(const char *mountpt)
 
 }
 
+void max_files_test(const char *mountpt)
+{
+       char fn[100];
+       char sn[100];
+       char hn[100];
+       int result;
+       int h;
+       int i;
+
+       yaffs_trace_mask = 0;
+
+       yaffs_start_up();
+
+       yaffs_mount(mountpt);
+
+       for(i = 0; i < 5000; i++) {
+               sprintf(fn,"%s/file%d", mountpt, i);
+               yaffs_unlink(fn);
+               h = yaffs_open(fn,O_CREAT| O_RDWR, S_IREAD | S_IWRITE);
+               if(h < 0)
+                       printf("File %s not created\n", fn);
+               yaffs_write(h,fn,100);
+               result = yaffs_close(h);
+       }
+       for(i = 0; i < 5; i++){
+               sprintf(fn,"%s/file%d",mountpt, i);
+               yaffs_unlink(fn);
+       }
+
+       for(i = 1000; i < 1010; i++){
+               sprintf(fn,"%s/file%d",mountpt, i);
+               h = yaffs_open(fn,O_CREAT| O_RDWR, S_IREAD | S_IWRITE);
+               yaffs_write(h,fn,100);
+               if(h < 0)
+                       printf("File %s not created\n", fn);
+               result = yaffs_close(h);
+       }
+
+       h =yaffs_open(hn,O_RDWR,0);
+
+}
+
 int random_seed;
 int simulate_power_failure;
 
@@ -2791,7 +2833,7 @@ int main(int argc, char *argv[])
         //checkpoint_upgrade_test("/flash/flash",20);
          //small_overwrite_test("/flash/flash",1000);
          //checkpoint_fill_test("/flash/flash",20);
-       // random_small_file_test("/flash/flash",10000);
+       //random_small_file_test("/flash/flash",10000);
         // huge_array_test("/flash/flash",10);
 
 
@@ -2820,7 +2862,10 @@ int main(int argc, char *argv[])
 
         //test_flash_traffic("yaffs2");
         // link_follow_test("/yaffs2");
-        basic_utime_test("/yaffs2");
+        //basic_utime_test("/yaffs2");
+
+        max_files_test("/yaffs2");
+
 
         return 0;
 
index 2b2b859..2668b22 100644 (file)
@@ -743,7 +743,15 @@ int yaffs_dup(int handle)
 
 }
 
+static int yaffsfs_TooManyObjects(struct yaffs_dev *dev)
+{
+       int current_objects = dev->n_obj - dev->n_deleted_files;
 
+       if(dev->param.max_objects && current_objects > dev->param.max_objects)
+               return 1;
+       else
+               return 0;
+}
 
 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
 {
@@ -915,6 +923,9 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
                        if(dir->my_dev->read_only){
                                yaffsfs_SetError(-EROFS);
                                errorReported = 1;
+                       } else if(yaffsfs_TooManyObjects(dir->my_dev)) {
+                               yaffsfs_SetError(-ENFILE);
+                               errorReported = 1;
                        } else
                                obj = yaffs_create_file(dir,name,mode,0,0);
 
@@ -2366,6 +2377,8 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode)
                yaffsfs_SetError(-ELOOP);
        else if(!parent)
                yaffsfs_SetError(-ENOENT);
+       else if(yaffsfs_TooManyObjects(parent->my_dev))
+               yaffsfs_SetError(-ENFILE);
        else if(strnlen(name,5) == 0){
                /* Trying to make the root itself */
                yaffsfs_SetError(-EEXIST);
@@ -2964,6 +2977,8 @@ int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
                yaffsfs_SetError(-ELOOP);
        else if( !parent || strnlen(name,5) < 1)
                yaffsfs_SetError(-ENOENT);
+       else if(yaffsfs_TooManyObjects(parent->my_dev))
+               yaffsfs_SetError(-ENFILE);
        else if(parent->my_dev->read_only)
                yaffsfs_SetError(-EROFS);
        else if(parent){
@@ -3056,6 +3071,8 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
                yaffsfs_SetError(-ENOENT);
        else if(obj->my_dev->read_only)
                yaffsfs_SetError(-EROFS);
+       else if(yaffsfs_TooManyObjects(obj->my_dev))
+               yaffsfs_SetError(-ENFILE);
        else if(lnk)
                yaffsfs_SetError(-EEXIST);
        else if(lnk_dir->my_dev != obj->my_dev)
index 490122a..b6d5129 100644 (file)
@@ -587,6 +587,11 @@ struct yaffs_param {
        int always_check_erased;        /* Force chunk erased check always on */
 
        int disable_summary;
+
+       int max_objects;        /*
+                                * Set to limit the number of objects created.
+                                * 0 = no limit.
+                               */
 };
 
 struct yaffs_dev {