X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=705106e7a13e603333fbeaf15c02ca5f9d26a1fa;hp=9f1397b578d365a0281dcb147ef0ce95a305745f;hb=d634851c1f36e7995726602d3af784478ccb472e;hpb=83d99930038ef56463b6551aff5aa4d8348ce240 diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 9f1397b..705106e 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -74,7 +74,7 @@ struct yaffsfs_FileDes { u8 shareWrite:1; int inodeId:12; /* Index to corresponding yaffsfs_Inode */ int handleCount:10; /* Number of handles for this fd */ - loff_t position; /* current position in file */ + Y_LOFF_T position; /* current position in file */ }; struct yaffsfs_Handle { @@ -394,19 +394,19 @@ static int yaffs_toupper(YCHAR a) return a; } -int yaffsfs_Match(YCHAR a, YCHAR b) +static int yaffsfs_Match(YCHAR a, YCHAR b) { return (yaffs_toupper(a) == yaffs_toupper(b)); } #else -int yaffsfs_Match(YCHAR a, YCHAR b) +static int yaffsfs_Match(YCHAR a, YCHAR b) { /* case sensitive */ return (a == b); } #endif -int yaffsfs_IsPathDivider(YCHAR ch) +static int yaffsfs_IsPathDivider(YCHAR ch) { const YCHAR *str = YAFFS_PATH_DIVIDERS; @@ -419,7 +419,7 @@ int yaffsfs_IsPathDivider(YCHAR ch) return 0; } -int yaffsfs_CheckNameLength(const char *name) +static int yaffsfs_CheckNameLength(const char *name) { int retVal = 0; @@ -1000,7 +1000,7 @@ int yaffs_open(const YCHAR *path, int oflag, int mode) YAFFS_SHARE_READ | YAFFS_SHARE_WRITE); } -int yaffs_Dofsync(int handle, int datasync) +static int yaffs_Dofsync(int handle, int datasync) { int retVal = -1; struct yaffs_obj *obj; @@ -1063,18 +1063,18 @@ int yaffs_close(int handle) return retVal; } -int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, - int isPread, loff_t offset) +static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, + int isPread, Y_LOFF_T offset) { struct yaffsfs_FileDes *fd = NULL; struct yaffs_obj *obj = NULL; - loff_t pos = 0; - loff_t startPos = 0; - loff_t endPos = 0; + Y_LOFF_T pos = 0; + Y_LOFF_T startPos = 0; + Y_LOFF_T endPos = 0; int nRead = 0; int nToRead = 0; int totalRead = 0; - loff_t maxRead; + Y_LOFF_T maxRead; u8 *buf = (u8 *) vbuf; if (!vbuf) { @@ -1180,19 +1180,19 @@ 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, loff_t offset) +int yaffs_pread(int handle, void *buf, unsigned int nbyte, Y_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, loff_t offset) +static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, + int isPwrite, Y_LOFF_T offset) { struct yaffsfs_FileDes *fd = NULL; struct yaffs_obj *obj = NULL; - loff_t pos = 0; - loff_t startPos = 0; - loff_t endPos; + Y_LOFF_T pos = 0; + Y_LOFF_T startPos = 0; + Y_LOFF_T endPos; int nWritten = 0; int totalWritten = 0; int write_trhrough = 0; @@ -1297,12 +1297,12 @@ 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, loff_t offset) +int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset) { return yaffsfs_do_write(fd, buf, nbyte, 1, offset); } -int yaffs_truncate(const YCHAR *path, loff_t new_size) +int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size) { struct yaffs_obj *obj = NULL; struct yaffs_obj *dir = NULL; @@ -1347,7 +1347,7 @@ int yaffs_truncate(const YCHAR *path, loff_t new_size) return (result) ? 0 : -1; } -int yaffs_ftruncate(int handle, loff_t new_size) +int yaffs_ftruncate(int handle, Y_LOFF_T new_size) { struct yaffsfs_FileDes *fd = NULL; struct yaffs_obj *obj = NULL; @@ -1375,12 +1375,12 @@ int yaffs_ftruncate(int handle, loff_t new_size) } -loff_t yaffs_lseek(int handle, loff_t offset, int whence) +Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence) { struct yaffsfs_FileDes *fd = NULL; struct yaffs_obj *obj = NULL; - loff_t pos = -1; - loff_t fSize = -1; + Y_LOFF_T pos = -1; + Y_LOFF_T fSize = -1; yaffsfs_Lock(); fd = yaffsfs_HandleToFileDes(handle); @@ -1416,7 +1416,7 @@ loff_t yaffs_lseek(int handle, loff_t offset, int whence) return pos; } -int yaffsfs_DoUnlink(const YCHAR *path, int isDirectory) +static int yaffsfs_DoUnlink(const YCHAR *path, int isDirectory) { struct yaffs_obj *dir = NULL; struct yaffs_obj *obj = NULL; @@ -2648,9 +2648,70 @@ int yaffs_unmount(const YCHAR *path) return yaffs_unmount2(path, 0); } -loff_t yaffs_freespace(const YCHAR *path) +int yaffs_format(const YCHAR *path, + int unmount_flag, + int force_unmount_flag, + int remount_flag) { - loff_t retVal = -1; + int retVal = 0; + struct yaffs_dev *dev = NULL; + int result; + + if (!path) { + yaffsfs_SetError(-EFAULT); + return -1; + } + + if (yaffsfs_CheckPath(path) < 0) { + yaffsfs_SetError(-ENAMETOOLONG); + return -1; + } + + yaffsfs_Lock(); + dev = yaffsfs_FindMountPoint(path); + + if (dev) { + int was_mounted = dev->is_mounted; + + if (dev->is_mounted && unmount_flag) { + int inUse; + yaffs_flush_whole_cache(dev); + yaffs_checkpoint_save(dev); + inUse = yaffsfs_IsDevBusy(dev); + if (!inUse || force_unmount_flag) { + if (inUse) + yaffsfs_BreakDeviceHandles(dev); + yaffs_deinitialise(dev); + } + } + + if(dev->is_mounted) { + yaffsfs_SetError(-EBUSY); + retVal = -1; + } else { + yaffs_format_dev(dev); + if(was_mounted && remount_flag) { + result = yaffs_guts_initialise(dev); + if (result == YAFFS_FAIL) { + yaffsfs_SetError(-ENOMEM); + retVal = -1; + } + } + } + } else { + yaffsfs_SetError(-ENODEV); + retVal = -1; + } + + yaffsfs_Unlock(); + return retVal; + +} + + +Y_LOFF_T yaffs_freespace(const YCHAR *path) +{ + Y_LOFF_T retVal = -1; struct yaffs_dev *dev = NULL; YCHAR *dummy; @@ -2677,9 +2738,9 @@ loff_t yaffs_freespace(const YCHAR *path) return retVal; } -loff_t yaffs_totalspace(const YCHAR *path) +Y_LOFF_T yaffs_totalspace(const YCHAR *path) { - loff_t retVal = -1; + Y_LOFF_T retVal = -1; struct yaffs_dev *dev = NULL; YCHAR *dummy; @@ -2710,7 +2771,7 @@ loff_t yaffs_totalspace(const YCHAR *path) int yaffs_inodecount(const YCHAR *path) { - loff_t retVal = -1; + Y_LOFF_T retVal = -1; struct yaffs_dev *dev = NULL; YCHAR *dummy; @@ -3137,9 +3198,9 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath) int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev) { - pathname = pathname; - mode = mode; - dev = dev; + (void) pathname; + (void) mode; + (void) dev; yaffsfs_SetError(-EINVAL); return -1; @@ -3189,7 +3250,7 @@ int yaffs_set_error(int error) int yaffs_dump_dev(const YCHAR *path) { #if 1 - path = path; + (void) path; #else YCHAR *rest;