X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=2cb8db985b82a73f5a34e3434b34224ca0b64cd0;hb=6eab3f6e6254e384397ea41c4dca23c6e3cc6712;hp=705106e7a13e603333fbeaf15c02ca5f9d26a1fa;hpb=c83e416cba6748e7a436c5df6a202349ff4d0fe2;p=yaffs2.git diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 705106e..2cb8db9 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -37,6 +37,8 @@ static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relativeDirectory, int *notDir, int *loop); static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj); +static yaffs_DIR *yaffsfs_opendir_no_lock(const YCHAR *dirname); +static int yaffsfs_closedir_no_lock(yaffs_DIR *dirent); unsigned int yaffs_wr_attempts; @@ -66,7 +68,19 @@ struct yaffsfs_Inode { struct yaffs_obj *iObj; }; + +struct yaffsfs_DirSearchContext { + struct yaffs_dirent de; /* directory entry */ + YCHAR name[NAME_MAX + 1]; /* name of directory being searched */ + struct yaffs_obj *dirObj; /* ptr to directory being searched */ + struct yaffs_obj *nextReturn; /* obj returned by next readddir */ + struct list_head others; + int offset:20; + unsigned inUse:1; +}; + struct yaffsfs_FileDes { + u8 isDir:1; /* This s a directory */ u8 reading:1; u8 writing:1; u8 append:1; @@ -74,7 +88,10 @@ struct yaffsfs_FileDes { u8 shareWrite:1; int inodeId:12; /* Index to corresponding yaffsfs_Inode */ int handleCount:10; /* Number of handles for this fd */ - Y_LOFF_T position; /* current position in file */ + union { + Y_LOFF_T position; /* current position in file */ + yaffs_DIR *dir; + } v; }; struct yaffsfs_Handle { @@ -83,17 +100,7 @@ struct yaffsfs_Handle { }; -struct yaffsfs_DirSearchContxt { - struct yaffs_dirent de; /* directory entry */ - YCHAR name[NAME_MAX + 1]; /* name of directory being searched */ - struct yaffs_obj *dirObj; /* ptr to directory being searched */ - struct yaffs_obj *nextReturn; /* obj returned by next readddir */ - struct list_head others; - int offset:20; - unsigned inUse:1; -}; - -static struct yaffsfs_DirSearchContxt yaffsfs_dsc[YAFFSFS_N_DSC]; +static struct yaffsfs_DirSearchContext yaffsfs_dsc[YAFFSFS_N_DSC]; static struct yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES]; static struct yaffsfs_FileDes yaffsfs_fd[YAFFSFS_N_HANDLES]; static struct yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES]; @@ -122,6 +129,8 @@ static void yaffsfs_InitHandles(void) if (yaffsfs_handlesInitialised) return; + yaffsfs_handlesInitialised = 1; + memset(yaffsfs_inode, 0, sizeof(yaffsfs_inode)); memset(yaffsfs_fd, 0, sizeof(yaffsfs_fd)); memset(yaffsfs_handle, 0, sizeof(yaffsfs_handle)); @@ -335,6 +344,8 @@ static int yaffsfs_PutFileDes(int fdId) fd = &yaffsfs_fd[fdId]; fd->handleCount--; if (fd->handleCount < 1) { + if (fd->isDir) + yaffsfs_closedir_no_lock(fd->v.dir); if (fd->inodeId >= 0) { yaffsfs_PutInode(fd->inodeId); fd->inodeId = -1; @@ -501,6 +512,9 @@ static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path, thisMatchLength = 0; matching = 1; + if(!p) + continue; + while (matching && *p && *leftOver) { /* Skip over any /s */ while (yaffsfs_IsPathDivider(*p)) @@ -792,8 +806,10 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) u8 writeRequested; int notDir = 0; int loop = 0; + int is_dir = 0; + yaffs_DIR *dsc; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0)< 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -842,14 +858,27 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) if (obj) { /* The file already exists or it might be a directory */ + is_dir = (obj->variant_type == + YAFFS_OBJECT_TYPE_DIRECTORY); - /* A directory can't be opened as a file */ - if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) { + /* A directory can't be opened except for read */ + if ( is_dir && + (writeRequested || !readRequested || + (oflag & ~O_RDONLY))) { openDenied = 1; yaffsfs_SetError(-EISDIR); errorReported = 1; } + if(is_dir) { + dsc = yaffsfs_opendir_no_lock(path); + if (!dsc) { + openDenied = 1; + yaffsfs_SetError(-ENFILE); + errorReported = 1; + } + } + /* Open should fail if O_CREAT and O_EXCL are specified * for a file that exists. */ @@ -972,14 +1001,19 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) fd->reading = readRequested; fd->writing = writeRequested; fd->append = (oflag & O_APPEND) ? 1 : 0; - fd->position = 0; fd->shareRead = shareRead; fd->shareWrite = shareWrite; + fd->isDir = is_dir; + + if(is_dir) + fd->v.dir = dsc; + else + fd->v.position = 0; /* Hook inode to object */ obj->my_inode = (void *)&yaffsfs_inode[inodeId]; - if ((oflag & O_TRUNC) && fd->writing) + if (!is_dir && (oflag & O_TRUNC) && fd->writing) yaffs_resize_file(obj, 0); } else { yaffsfs_PutHandle(handle); @@ -1041,19 +1075,22 @@ int yaffs_fdatasync(int handle) int yaffs_close(int handle) { struct yaffsfs_Handle *h = NULL; + struct yaffsfs_FileDes *f; struct yaffs_obj *obj = NULL; int retVal = -1; yaffsfs_Lock(); h = yaffsfs_HandleToPointer(handle); + f = yaffsfs_HandleToFileDes(handle); obj = yaffsfs_HandleToObject(handle); - if (!h || !obj) + if (!h || !obj || !f) yaffsfs_SetError(-EBADF); else { /* clean up */ - yaffs_flush_file(obj, 1, 0); + if(!f->isDir) + yaffs_flush_file(obj, 1, 0); yaffsfs_PutHandle(handle); retVal = 0; } @@ -1077,7 +1114,7 @@ static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, Y_LOFF_T maxRead; u8 *buf = (u8 *) vbuf; - if (!vbuf) { + if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1101,7 +1138,7 @@ static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, if (isPread) startPos = offset; else - startPos = fd->position; + startPos = fd->v.position; pos = startPos; @@ -1162,7 +1199,7 @@ static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, if (!isPread) { if (totalRead >= 0) - fd->position = startPos + totalRead; + fd->v.position = startPos + totalRead; else yaffsfs_SetError(-EINVAL); } @@ -1199,7 +1236,7 @@ static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, int nToWrite = 0; const u8 *buf = (const u8 *)vbuf; - if (!vbuf) { + if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1224,7 +1261,7 @@ static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, else if (isPwrite) startPos = offset; else - startPos = fd->position; + startPos = fd->v.position; yaffsfs_GetHandle(handle); pos = startPos; @@ -1281,7 +1318,7 @@ static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, if (!isPwrite) { if (totalWritten > 0) - fd->position = startPos + totalWritten; + fd->v.position = startPos + totalWritten; else yaffsfs_SetError(-EINVAL); } @@ -1310,7 +1347,7 @@ int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size) int notDir = 0; int loop = 0; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1395,8 +1432,8 @@ Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence) if (offset >= 0) pos = offset; } else if (whence == SEEK_CUR) { - if ((fd->position + offset) >= 0) - pos = (fd->position + offset); + if ((fd->v.position + offset) >= 0) + pos = (fd->v.position + offset); } else if (whence == SEEK_END) { fSize = yaffs_get_obj_length(obj); if (fSize >= 0 && (fSize + offset) >= 0) @@ -1404,7 +1441,7 @@ Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence) } if (pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE) - fd->position = pos; + fd->v.position = pos; else { yaffsfs_SetError(-EINVAL); pos = -1; @@ -1425,7 +1462,7 @@ static int yaffsfs_DoUnlink(const YCHAR *path, int isDirectory) int notDir = 0; int loop = 0; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1477,6 +1514,24 @@ int yaffs_unlink(const YCHAR *path) return yaffsfs_DoUnlink(path, 0); } +static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj) +{ + if (obj && obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY && + newobj && newobj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) + return 1; + else + return 0; +} + +static int rename_dir_over_file(struct yaffs_obj *obj, struct yaffs_obj *newobj) +{ + if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY && + newobj && newobj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY) + return 1; + else + return 0; +} + int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) { struct yaffs_obj *olddir = NULL; @@ -1494,7 +1549,8 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) YCHAR *alt_newpath = NULL; - if (!oldPath || !newPath) { + if (yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 || + yaffsfs_CheckMemRegion(newPath, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1545,6 +1601,12 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) } else if (obj->my_dev->read_only) { yaffsfs_SetError(-EROFS); rename_allowed = 0; + } else if (rename_file_over_dir(obj, newobj)) { + yaffsfs_SetError(-EISDIR); + rename_allowed = 0; + } else if (rename_dir_over_file(obj, newobj)) { + yaffsfs_SetError(-ENOTDIR); + rename_allowed = 0; } else if (yaffs_is_non_empty_dir(newobj)) { yaffsfs_SetError(-ENOTEMPTY); rename_allowed = 0; @@ -1633,7 +1695,8 @@ static int yaffsfs_DoStatOrLStat(const YCHAR *path, int notDir = 0; int loop = 0; - if (!path || !buf) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 || + yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1681,7 +1744,7 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf) int retVal = -1; - if (!buf) { + if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1802,7 +1865,9 @@ static int yaffs_do_setxattr(const YCHAR *path, const char *name, int retVal = -1; - if (!path || !name || !data) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 || + yaffsfs_CheckMemRegion(name, 0, 0) < 0 || + yaffsfs_CheckMemRegion(data, size, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1858,7 +1923,8 @@ int yaffs_fsetxattr(int fd, const char *name, int retVal = -1; - if (!name || !data) { + if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 || + yaffsfs_CheckMemRegion(data, size, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1890,7 +1956,9 @@ static int yaffs_do_getxattr(const YCHAR *path, const char *name, int notDir = 0; int loop = 0; - if (!path || !name || !data) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 || + yaffsfs_CheckMemRegion(name, 0, 0) < 0 || + yaffsfs_CheckMemRegion(data, size, 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1942,7 +2010,8 @@ int yaffs_fgetxattr(int fd, const char *name, void *data, int size) int retVal = -1; - if (!name || !data) { + if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 || + yaffsfs_CheckMemRegion(data, size, 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -1974,7 +2043,8 @@ static int yaffs_do_listxattr(const YCHAR *path, char *data, int notDir = 0; int loop = 0; - if (!path || !data) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 || + yaffsfs_CheckMemRegion(data, size, 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2027,7 +2097,7 @@ int yaffs_flistxattr(int fd, char *data, int size) int retVal = -1; - if (!data) { + if (yaffsfs_CheckMemRegion(data, size, 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2059,7 +2129,8 @@ static int yaffs_do_removexattr(const YCHAR *path, const char *name, int loop = 0; int retVal = -1; - if (!path || !name) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 || + yaffsfs_CheckMemRegion(name, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2112,7 +2183,7 @@ int yaffs_fremovexattr(int fd, const char *name) int retVal = -1; - if (!name) { + if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2236,7 +2307,7 @@ int yaffs_access(const YCHAR *path, int amode) int loop = 0; int retval = -1; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2294,7 +2365,7 @@ int yaffs_chmod(const YCHAR *path, mode_t mode) int notDir = 0; int loop = 0; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2366,7 +2437,7 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode) int notDir = 0; int loop = 0; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2420,7 +2491,7 @@ int yaffs_rmdir(const YCHAR *path) int result; YCHAR *alt_path; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2457,7 +2528,7 @@ int yaffs_mount_common(const YCHAR *path, int read_only, int skip_checkpt) int result = YAFFS_FAIL; struct yaffs_dev *dev = NULL; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2516,7 +2587,7 @@ int yaffs_sync(const YCHAR *path) struct yaffs_dev *dev = NULL; YCHAR *dummy; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2565,7 +2636,7 @@ int yaffs_remount(const YCHAR *path, int force, int read_only) int retVal = -1; struct yaffs_dev *dev = NULL; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2605,7 +2676,7 @@ int yaffs_unmount2(const YCHAR *path, int force) int retVal = -1; struct yaffs_dev *dev = NULL; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2715,7 +2786,7 @@ Y_LOFF_T yaffs_freespace(const YCHAR *path) struct yaffs_dev *dev = NULL; YCHAR *dummy; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2744,7 +2815,7 @@ Y_LOFF_T yaffs_totalspace(const YCHAR *path) struct yaffs_dev *dev = NULL; YCHAR *dummy; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2775,7 +2846,7 @@ int yaffs_inodecount(const YCHAR *path) struct yaffs_dev *dev = NULL; YCHAR *dummy; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -2850,7 +2921,7 @@ struct yaffs_dev *yaffs_next_dev(void) static struct list_head search_contexts; -static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContxt *dsc) +static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContext *dsc) { if (dsc && dsc->dirObj && @@ -2870,7 +2941,7 @@ static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContxt *dsc) } } -static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContxt *dsc) +static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContext *dsc) { if (dsc && dsc->dirObj && @@ -2898,7 +2969,7 @@ static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj) { struct list_head *i; - struct yaffsfs_DirSearchContxt *dsc; + struct yaffsfs_DirSearchContext *dsc; /* if search contexts not initilised then skip */ if (!search_contexts.next) @@ -2910,7 +2981,7 @@ static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj) */ list_for_each(i, &search_contexts) { if (i) { - dsc = list_entry(i, struct yaffsfs_DirSearchContxt, + dsc = list_entry(i, struct yaffsfs_DirSearchContext, others); if (dsc->nextReturn == obj) yaffsfs_DirAdvance(dsc); @@ -2919,15 +2990,15 @@ static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj) } -yaffs_DIR *yaffs_opendir(const YCHAR *dirname) +static yaffs_DIR *yaffsfs_opendir_no_lock(const YCHAR *dirname) { yaffs_DIR *dir = NULL; struct yaffs_obj *obj = NULL; - struct yaffsfs_DirSearchContxt *dsc = NULL; + struct yaffsfs_DirSearchContext *dsc = NULL; int notDir = 0; int loop = 0; - if (!dirname) { + if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return NULL; } @@ -2937,8 +3008,6 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname) return NULL; } - yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL, dirname, 0, 1, NULL, ¬Dir, &loop); if (!obj && notDir) @@ -2960,7 +3029,7 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname) dir = (yaffs_DIR *) dsc; if (dsc) { - memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContxt)); + memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContext)); dsc->inUse = 1; dsc->dirObj = obj; yaffs_strncpy(dsc->name, dirname, NAME_MAX); @@ -2972,21 +3041,27 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname) list_add(&dsc->others, &search_contexts); yaffsfs_SetDirRewound(dsc); } - } + return dir; +} - yaffsfs_Unlock(); +yaffs_DIR *yaffs_opendir(const YCHAR *dirname) +{ + yaffs_DIR *ret; - return dir; + yaffsfs_Lock(); + ret = yaffsfs_opendir_no_lock(dirname); + yaffsfs_Unlock(); + return ret; } -struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp) +struct yaffs_dirent *yaffsfs_readdir_no_lock(yaffs_DIR * dirp) { - struct yaffsfs_DirSearchContxt *dsc; + struct yaffsfs_DirSearchContext *dsc; struct yaffs_dirent *retVal = NULL; - dsc = (struct yaffsfs_DirSearchContxt *) dirp; - yaffsfs_Lock(); + dsc = (struct yaffsfs_DirSearchContext *) dirp; + if (dsc && dsc->inUse) { yaffsfs_SetError(0); @@ -3009,42 +3084,89 @@ struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp) } else yaffsfs_SetError(-EBADF); + return retVal; + +} +struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp) +{ + struct yaffs_dirent *ret; + + yaffsfs_Lock(); + ret = yaffsfs_readdir_no_lock(dirp); yaffsfs_Unlock(); + return ret; +} - return retVal; +static void yaffsfs_rewinddir_no_lock(yaffs_DIR *dirp) +{ + struct yaffsfs_DirSearchContext *dsc; + + dsc = (struct yaffsfs_DirSearchContext *) dirp; + + if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) + return; + + yaffsfs_SetDirRewound(dsc); } void yaffs_rewinddir(yaffs_DIR *dirp) { - struct yaffsfs_DirSearchContxt *dsc; + yaffsfs_Lock(); + yaffsfs_rewinddir_no_lock(dirp); + yaffsfs_Unlock(); +} - dsc = (struct yaffsfs_DirSearchContxt *) dirp; +struct yaffs_dirent *yaffs_readdir_fd(int fd) +{ + struct yaffs_dirent *ret = NULL; + struct yaffsfs_FileDes *f; yaffsfs_Lock(); + f = yaffsfs_HandleToFileDes(fd); + if(f && f->isDir) + ret = yaffsfs_readdir_no_lock(f->v.dir); + yaffsfs_Unlock(); + return ret; +} - yaffsfs_SetDirRewound(dsc); +void yaffs_rewinddir_fd(int fd) +{ + struct yaffsfs_FileDes *f; + yaffsfs_Lock(); + f = yaffsfs_HandleToFileDes(fd); + if(f && f->isDir) + yaffsfs_rewinddir_no_lock(f->v.dir); yaffsfs_Unlock(); } -int yaffs_closedir(yaffs_DIR *dirp) + +static int yaffsfs_closedir_no_lock(yaffs_DIR *dirp) { - struct yaffsfs_DirSearchContxt *dsc; + struct yaffsfs_DirSearchContext *dsc; - dsc = (struct yaffsfs_DirSearchContxt *) dirp; + dsc = (struct yaffsfs_DirSearchContext *) dirp; - if (!dsc) { + if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } - yaffsfs_Lock(); dsc->inUse = 0; list_del(&dsc->others); /* unhook from list */ - yaffsfs_Unlock(); + return 0; } +int yaffs_closedir(yaffs_DIR *dirp) +{ + int ret; + + yaffsfs_Lock(); + ret = yaffsfs_closedir_no_lock(dirp); + yaffsfs_Unlock(); + return ret; +} /* End of directory stuff */ @@ -3058,7 +3180,8 @@ int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath) int notDir = 0; int loop = 0; - if (!oldpath || !newpath) { + if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 || + yaffsfs_CheckMemRegion(newpath, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -3105,7 +3228,8 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz) int notDir = 0; int loop = 0; - if (!path || !buf) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 || + yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -3146,7 +3270,8 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath) int lnkLoop = 0; YCHAR *newname; - if (!oldpath || !linkpath) { + if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 || + yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; } @@ -3218,7 +3343,7 @@ int yaffs_n_handles(const YCHAR *path) { struct yaffs_obj *obj; - if (!path) { + if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) { yaffsfs_SetError(-EFAULT); return -1; }