Merge branch 'big-files': Merge in large file support
[yaffs2.git] / direct / yaffsfs.c
index 568fe1efbd98182ba937a786600cce2ca0ec75d9..b57084cb5805ca6b675d9a8287e4a69ece20ef75 100644 (file)
@@ -75,7 +75,7 @@ typedef struct{
        u8      shareWrite:1;
        int     inodeId:12;     /* Index to corresponding yaffsfs_Inode */
        int     handleCount:10; /* Number of handles for this fd */
-       u32 position;           /* current position in file */
+       loff_t  position;               /* current position in file */
 }yaffsfs_FileDes;
 
 typedef struct {
@@ -124,7 +124,7 @@ static void yaffsfs_InitHandles(void)
 
 static yaffsfs_Handle *yaffsfs_HandleToPointer(int h)
 {
-       if(h >= 0 && h <= YAFFSFS_N_HANDLES)
+       if(h >= 0 && h < YAFFSFS_N_HANDLES)
                return &yaffsfs_handle[h];
        return NULL;
 }
@@ -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);
 
@@ -1037,17 +1048,17 @@ int yaffs_close(int handle)
 
 
 
-int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, int isPread, int offset)
+int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, int isPread, loff_t offset)
 {
        yaffsfs_FileDes *fd = NULL;
        struct yaffs_obj *obj = NULL;
-       int pos = 0;
-       int startPos = 0;
-       int endPos = 0;
+       loff_t pos = 0;
+       loff_t startPos = 0;
+       loff_t endPos = 0;
        int nRead = 0;
        int nToRead = 0;
        int totalRead = 0;
-       unsigned int maxRead;
+       loff_t maxRead;
        u8 *buf = (u8 *)vbuf;
 
        if(!vbuf){
@@ -1154,18 +1165,18 @@ int yaffs_read(int handle, void *buf, unsigned int nbyte)
        return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
 }
 
-int yaffs_pread(int handle, void *buf, unsigned int nbyte, unsigned int offset)
+int yaffs_pread(int handle, void *buf, unsigned int nbyte, loff_t offset)
 {
        return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
 }
 
-int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, int isPwrite, int offset)
+int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, int isPwrite, loff_t offset)
 {
        yaffsfs_FileDes *fd = NULL;
        struct yaffs_obj *obj = NULL;
-       int pos = 0;
-       int startPos = 0;
-       int endPos;
+       loff_t pos = 0;
+       loff_t startPos = 0;
+       loff_t endPos;
        int nWritten = 0;
        int totalWritten = 0;
        int write_trhrough = 0;
@@ -1268,13 +1279,13 @@ int yaffs_write(int fd, const void *buf, unsigned int nbyte)
        return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
 }
 
-int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, unsigned int offset)
+int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, loff_t offset)
 {
        return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
 }
 
 
-int yaffs_truncate(const YCHAR *path,off_t new_size)
+int yaffs_truncate(const YCHAR *path,loff_t new_size)
 {
        struct yaffs_obj *obj = NULL;
        struct yaffs_obj *dir = NULL;
@@ -1312,14 +1323,14 @@ int yaffs_truncate(const YCHAR *path,off_t new_size)
        else if(new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
                yaffsfs_SetError(-EINVAL);
        else
-               result = yaffs_resize_file(obj,new_size);
+               result = yaffs_resize_file(obj, new_size);
 
        yaffsfs_Unlock();
 
        return (result) ? 0 : -1;
 }
 
-int yaffs_ftruncate(int handle, off_t new_size)
+int yaffs_ftruncate(int handle, loff_t new_size)
 {
        yaffsfs_FileDes *fd = NULL;
        struct yaffs_obj *obj = NULL;
@@ -1340,19 +1351,19 @@ int yaffs_ftruncate(int handle, off_t new_size)
                yaffsfs_SetError(-EINVAL);
        else
                /* resize the file */
-               result = yaffs_resize_file(obj,new_size);
+               result = yaffs_resize_file(obj, new_size);
        yaffsfs_Unlock();
 
        return (result) ? 0 : -1;
 
 }
 
-off_t yaffs_lseek(int handle, off_t offset, int whence)
+loff_t yaffs_lseek(int handle, loff_t offset, int whence)
 {
        yaffsfs_FileDes *fd = NULL;
        struct yaffs_obj *obj = NULL;
-       int pos = -1;
-       int fSize = -1;
+       loff_t pos = -1;
+       loff_t fSize = -1;
 
        yaffsfs_Lock();
        fd = yaffsfs_HandleToFileDes(handle);
@@ -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);
@@ -2425,7 +2438,7 @@ void * yaffs_getdev(const YCHAR *path)
        return (void *)dev;
 }
 
-int yaffs_mount2(const YCHAR *path,int read_only)
+int yaffs_mount_common(const YCHAR *path,int read_only, int skip_checkpt)
 {
        int retVal=-1;
        int result=YAFFS_FAIL;
@@ -2451,7 +2464,15 @@ int yaffs_mount2(const YCHAR *path,int read_only)
        if(dev){
                if(!dev->is_mounted){
                        dev->read_only = read_only ? 1 : 0;
-                       result = yaffs_guts_initialise(dev);
+                       if(skip_checkpt) {
+                               u8 skip = dev->param.skip_checkpt_rd;
+                               dev->param.skip_checkpt_rd = 1;
+                               result = yaffs_guts_initialise(dev);
+                               dev->param.skip_checkpt_rd = skip;
+                       } else {
+                               result = yaffs_guts_initialise(dev);
+                       }
+
                        if(result == YAFFS_FAIL)
                                yaffsfs_SetError(-ENOMEM);
                        retVal = result ? 0 : -1;
@@ -2467,9 +2488,13 @@ int yaffs_mount2(const YCHAR *path,int read_only)
 
 }
 
+int yaffs_mount2(const YCHAR *path, int readonly)
+{
+       return yaffs_mount_common(path, readonly, 0);
+}
 int yaffs_mount(const YCHAR *path)
 {
-       return yaffs_mount2(path,0);
+       return yaffs_mount_common(path, 0, 0);
 }
 
 int yaffs_sync(const YCHAR *path)
@@ -2707,6 +2732,14 @@ int yaffs_inodecount(const YCHAR *path)
 
 void yaffs_add_device(struct yaffs_dev *dev)
 {
+       struct list_head *cfg;
+       /* First check that the device is not in the list. */
+
+       list_for_each(cfg, &yaffsfs_deviceList){
+               if(dev == list_entry(cfg, struct yaffs_dev, dev_list))
+                       return;
+       }
+
        dev->is_mounted = 0;
        dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
 
@@ -2964,6 +2997,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 +3091,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)