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 {
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));
thisMatchLength = 0;
matching = 1;
+ if(!p)
+ continue;
+
while (matching && *p && *leftOver) {
/* Skip over any /s */
while (yaffsfs_IsPathDivider(*p))
int notDir = 0;
int loop = 0;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0)< 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
}
static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
- int isPread, loff_t offset)
+ 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) {
+ if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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);
}
static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
- int isPwrite, loff_t offset)
+ 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;
int nToWrite = 0;
const u8 *buf = (const u8 *)vbuf;
- if (!vbuf) {
+ if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
int notDir = 0;
int loop = 0;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
}
-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);
int notDir = 0;
int loop = 0;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
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;
}
} 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;
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;
}
int retVal = -1;
- if (!buf) {
+ if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
}
int retVal = -1;
- if (!name || !data) {
+ if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
+ yaffsfs_CheckMemRegion(data, size, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
}
int retVal = -1;
- if (!name || !data) {
+ if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
+ yaffsfs_CheckMemRegion(data, size, 1) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
}
int retVal = -1;
- if (!data) {
+ if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
}
int retVal = -1;
- if (!name) {
+ if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int loop = 0;
int retval = -1;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int notDir = 0;
int loop = 0;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int notDir = 0;
int loop = 0;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int result;
YCHAR *alt_path;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int result = YAFFS_FAIL;
struct yaffs_dev *dev = NULL;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
struct yaffs_dev *dev = NULL;
YCHAR *dummy;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int retVal = -1;
struct yaffs_dev *dev = NULL;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int retVal = -1;
struct yaffs_dev *dev = NULL;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
- YCHAR *dummy;
+ int result;
if (!path) {
yaffsfs_SetError(-EFAULT);
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;
+
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if (yaffsfs_CheckPath(path) < 0) {
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
yaffsfs_Lock();
dev = yaffsfs_FindDevice(path, &dummy);
if (dev && dev->is_mounted) {
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;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int yaffs_inodecount(const YCHAR *path)
{
- loff_t retVal = -1;
+ Y_LOFF_T retVal = -1;
struct yaffs_dev *dev = NULL;
YCHAR *dummy;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int notDir = 0;
int loop = 0;
- if (!dirname) {
+ if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return NULL;
}
dsc = (struct yaffsfs_DirSearchContxt *) dirp;
+ if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
+ return;
+
yaffsfs_Lock();
yaffsfs_SetDirRewound(dsc);
dsc = (struct yaffsfs_DirSearchContxt *) dirp;
- if (!dsc) {
+ if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
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;
}
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;
}
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;
}
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;
{
struct yaffs_obj *obj;
- if (!path) {
+ if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
yaffsfs_SetError(-EFAULT);
return -1;
}
int yaffs_dump_dev(const YCHAR *path)
{
#if 1
- path = path;
+ (void) path;
#else
YCHAR *rest;