+ retVal = yaffsfs_DoUtime(obj,buf);
+ else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+
+#ifndef CONFIG_YAFFS_WINCE
+/* xattrib functions */
+
+
+static int yaffs_do_setxattr(const YCHAR *path, const char *name,
+ const void *data, int size, int flags, int follow)
+{
+ struct yaffs_obj *obj;
+ struct yaffs_obj *dir;
+ int notDir = 0;
+ int loop = 0;
+
+ int retVal = -1;
+
+ if(!path || !name || !data){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir,¬Dir,&loop);
+
+ if(follow)
+ obj = yaffsfs_FollowLink(obj,0,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
+ retVal = yaffs_set_xattrib(obj,name,data,size,flags);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ }
+
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+
+int yaffs_setxattr(const YCHAR *path, const char *name, const void *data, int size, int flags)
+{
+ return yaffs_do_setxattr(path, name, data, size, flags, 1);
+}
+
+int yaffs_lsetxattr(const YCHAR *path, const char *name, const void *data, int size, int flags)
+{
+ return yaffs_do_setxattr(path, name, data, size, flags, 0);
+}
+
+
+
+int yaffs_fsetxattr(int fd, const char *name, const void *data, int size, int flags)
+{
+ struct yaffs_obj *obj;
+
+ int retVal = -1;
+
+ if(!name || !data){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(!obj)
+ yaffsfs_SetError(-EBADF);
+ else {
+ retVal = yaffs_set_xattrib(obj,name,data,size,flags);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ }
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, int size, int follow)
+{
+ struct yaffs_obj *obj;
+ struct yaffs_obj *dir;
+ int retVal = -1;
+ int notDir = 0;
+ int loop = 0;
+
+ if(!path || !name || !data ){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir,¬Dir,&loop);
+
+ if(follow)
+ obj = yaffsfs_FollowLink(obj,0,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
+ retVal = yaffs_get_xattrib(obj,name,data,size);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ }
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+
+int yaffs_getxattr(const YCHAR *path, const char *name, void *data, int size)
+{
+ return yaffs_do_getxattr( path, name, data, size, 1);
+}
+int yaffs_lgetxattr(const YCHAR *path, const char *name, void *data, int size)
+{
+ return yaffs_do_getxattr( path, name, data, size, 0);
+}
+
+
+
+int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
+{
+ struct yaffs_obj *obj;
+
+ int retVal = -1;
+
+ if(!name || !data ){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(obj) {
+ retVal = yaffs_get_xattrib(obj,name,data,size);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ } else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+static int yaffs_do_listxattr(const YCHAR *path, char *data, int size, int follow)
+{
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
+ int retVal = -1;
+ int notDir = 0;
+ int loop = 0;
+
+ if(!path || !data ){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir,¬Dir,&loop);
+
+ if(follow)
+ obj = yaffsfs_FollowLink(obj,0,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
+ retVal = yaffs_list_xattrib(obj, data,size);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ }
+
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+
+int yaffs_listxattr(const YCHAR *path, char *data, int size)
+{
+ return yaffs_do_listxattr(path, data, size, 1);
+}
+
+int yaffs_llistxattr(const YCHAR *path, char *data, int size)
+{
+ return yaffs_do_listxattr(path, data, size, 0);
+}
+
+int yaffs_flistxattr(int fd, char *data, int size)
+{
+ struct yaffs_obj *obj;
+
+ int retVal = -1;
+
+ if(!data ){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(obj) {
+ retVal = yaffs_list_xattrib(obj,data,size);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ } else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+static int yaffs_do_removexattr(const YCHAR *path, const char *name, int follow)
+{
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
+ int notDir = 0;
+ int loop = 0;
+ int retVal = -1;
+
+ if(!path || !name){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir,¬Dir,&loop);
+
+ if(follow)
+ obj = yaffsfs_FollowLink(obj,0,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
+ retVal = yaffs_remove_xattrib(obj,name);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ }
+
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+
+int yaffs_removexattr(const YCHAR *path, const char *name)
+{
+ return yaffs_do_removexattr(path, name, 1);
+}
+
+int yaffs_lremovexattr(const YCHAR *path, const char *name)
+{
+ return yaffs_do_removexattr(path, name, 0);
+}
+
+int yaffs_fremovexattr(int fd, const char *name)
+{
+ struct yaffs_obj *obj;
+
+ int retVal = -1;
+
+ if(!name){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(obj){
+ retVal = yaffs_remove_xattrib(obj,name);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ }else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+#endif
+
+#ifdef CONFIG_YAFFS_WINCE
+int yaffs_get_wince_times(int fd, unsigned *wctime, unsigned *watime, unsigned *wmtime)
+{
+ struct yaffs_obj *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(obj){
+
+ if(wctime){
+ wctime[0] = obj->win_ctime[0];
+ wctime[1] = obj->win_ctime[1];
+ }
+ if(watime){
+ watime[0] = obj->win_atime[0];
+ watime[1] = obj->win_atime[1];
+ }
+ if(wmtime){
+ wmtime[0] = obj->win_mtime[0];
+ wmtime[1] = obj->win_mtime[1];
+ }
+
+
+ retVal = 0;
+ } else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+
+int yaffs_set_wince_times(int fd,
+ const unsigned *wctime,
+ const unsigned *watime,
+ const unsigned *wmtime)
+{
+ struct yaffs_obj *obj;
+ int result;
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(obj){
+
+ if(wctime){
+ obj->win_ctime[0] = wctime[0];
+ obj->win_ctime[1] = wctime[1];
+ }
+ if(watime){
+ obj->win_atime[0] = watime[0];
+ obj->win_atime[1] = watime[1];
+ }
+ if(wmtime){
+ obj->win_mtime[0] = wmtime[0];
+ obj->win_mtime[1] = wmtime[1];
+ }
+
+ obj->dirty = 1;
+ result = yaffs_flush_file(obj,0,0);
+ retVal = 0;
+ } else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+#endif
+
+
+static int yaffsfs_DoChMod(struct yaffs_obj *obj,mode_t mode)
+{
+ int result = -1;
+
+ if(obj)
+ obj = yaffs_get_equivalent_obj(obj);
+
+ if(obj) {
+ obj->yst_mode = mode;
+ obj->dirty = 1;
+ result = yaffs_flush_file(obj,0,0);
+ }
+
+ return result == YAFFS_OK ? 0 : -1;
+}
+
+
+int yaffs_access(const YCHAR *path, int amode)
+{
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
+ int notDir = 0;
+ int loop = 0;
+ int retval = -1;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ if(amode & ~(R_OK | W_OK | X_OK)){
+ yaffsfs_SetError(-EINVAL);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir,¬Dir,&loop);
+ obj = yaffsfs_FollowLink(obj,0,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else if((amode & W_OK) && obj->my_dev->read_only)
+ yaffsfs_SetError(-EROFS);
+ else{
+ int access_ok = 1;
+
+ if((amode & R_OK) && !(obj->yst_mode & S_IREAD))
+ access_ok = 0;
+ if((amode & W_OK) && !(obj->yst_mode & S_IWRITE))
+ access_ok = 0;
+ if((amode & X_OK) && !(obj->yst_mode & S_IEXEC))
+ access_ok = 0;
+
+ if(!access_ok)
+ yaffsfs_SetError(-EACCES);
+ else
+ retval = 0;
+ }
+
+ yaffsfs_Unlock();
+
+ return retval;
+
+}
+
+
+int yaffs_chmod(const YCHAR *path, mode_t mode)
+{
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
+ int retVal = -1;
+ int notDir = 0;
+ int loop = 0;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ if(mode & ~(0777)){
+ yaffsfs_SetError(-EINVAL);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir, ¬Dir,&loop);
+ obj = yaffsfs_FollowLink(obj,0,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else if(obj->my_dev->read_only)
+ yaffsfs_SetError(-EROFS);
+ else
+ retVal = yaffsfs_DoChMod(obj,mode);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+
+
+int yaffs_fchmod(int fd, mode_t mode)
+{
+ struct yaffs_obj *obj;
+ int retVal = -1;
+
+ if(mode & ~(0777)){
+ yaffsfs_SetError(-EINVAL);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(!obj)
+ yaffsfs_SetError(-EBADF);
+ else if(obj->my_dev->read_only)
+ yaffsfs_SetError(-EROFS);
+ else
+ retVal = yaffsfs_DoChMod(obj,mode);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+int yaffs_mkdir(const YCHAR *path, mode_t mode)
+{
+ struct yaffs_obj *parent = NULL;
+ struct yaffs_obj *dir = NULL;
+ YCHAR *name;
+ YCHAR *alt_path = NULL;
+ int retVal= -1;
+ int notDir = 0;
+ int loop = 0;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ if(yaffsfs_alt_dir_path(path, &alt_path) < 0){
+ yaffsfs_SetError(-ENOMEM);
+ return -1;
+ }
+ if(alt_path)
+ path = alt_path;
+
+ yaffsfs_Lock();
+ parent = yaffsfs_FindDirectory(NULL,path,&name,0,¬Dir,&loop);
+ if(!parent && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!parent)
+ yaffsfs_SetError(-ENOENT);
+ else if(yaffsfs_TooManyObjects(parent->my_dev))
+ yaffsfs_SetError(-ENFILE);
+ else if(yaffs_strnlen(name,5) == 0){
+ /* Trying to make the root itself */
+ yaffsfs_SetError(-EEXIST);
+ } else if(parent->my_dev->read_only)
+ yaffsfs_SetError(-EROFS);
+ else {
+ dir = yaffs_create_dir(parent,name,mode,0,0);
+ if(dir)
+ retVal = 0;
+ else if (yaffs_find_by_name(parent,name))
+ yaffsfs_SetError(-EEXIST); /* the name already exists */
+ else
+ yaffsfs_SetError(-ENOSPC); /* just assume no space */
+ }
+
+ yaffsfs_Unlock();
+
+ if(alt_path)
+ kfree(alt_path);
+
+ return retVal;
+}
+
+int yaffs_rmdir(const YCHAR *path)
+{
+ int result;
+ YCHAR *alt_path;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ if(yaffsfs_alt_dir_path(path, &alt_path) < 0){
+ yaffsfs_SetError(-ENOMEM);
+ return -1;
+ }
+ if(alt_path)
+ path = alt_path;
+ result = yaffsfs_DoUnlink(path,1);
+ if(alt_path)
+ kfree(alt_path);
+ return result;
+}
+
+
+void * yaffs_getdev(const YCHAR *path)
+{
+ struct yaffs_dev *dev=NULL;
+ YCHAR *dummy;
+ dev = yaffsfs_FindDevice(path,&dummy);
+ return (void *)dev;
+}
+
+int yaffs_mount2(const YCHAR *path,int read_only)
+{
+ int retVal=-1;
+ int result=YAFFS_FAIL;
+ struct yaffs_dev *dev=NULL;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ yaffs_trace(YAFFS_TRACE_MOUNT,"yaffs: Mounting %s",path);
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ yaffsfs_InitHandles();
+
+ dev = yaffsfs_FindMountPoint(path);
+ if(dev){
+ if(!dev->is_mounted){
+ dev->read_only = read_only ? 1 : 0;
+ result = yaffs_guts_initialise(dev);
+ if(result == YAFFS_FAIL)
+ yaffsfs_SetError(-ENOMEM);
+ retVal = result ? 0 : -1;
+
+ }
+ else
+ yaffsfs_SetError(-EBUSY);
+ } else
+ yaffsfs_SetError(-ENODEV);
+
+ yaffsfs_Unlock();
+ return retVal;
+
+}
+
+int yaffs_mount(const YCHAR *path)
+{
+ return yaffs_mount2(path,0);
+}
+
+int yaffs_sync(const YCHAR *path)
+{
+ int retVal=-1;
+ struct yaffs_dev *dev=NULL;
+ YCHAR *dummy;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ dev = yaffsfs_FindDevice(path,&dummy);
+ if(dev){
+ if(!dev->is_mounted)
+ yaffsfs_SetError(-EINVAL);
+ else if(dev->read_only)
+ yaffsfs_SetError(-EROFS);
+ else {
+
+ yaffs_flush_whole_cache(dev);
+ yaffs_checkpoint_save(dev);
+ retVal = 0;
+
+ }
+ }else
+ yaffsfs_SetError(-ENODEV);
+
+ yaffsfs_Unlock();
+ return retVal;
+}
+
+
+static int yaffsfs_IsDevBusy(struct yaffs_dev * dev)
+{
+ int i;
+ struct yaffs_obj *obj;
+
+ for(i = 0; i < YAFFSFS_N_HANDLES; i++){
+ obj = yaffsfs_HandleToObject(i);
+ if(obj && obj->my_dev == dev)
+ return 1;
+ }
+ return 0;
+}
+
+
+int yaffs_remount(const YCHAR *path, int force, int read_only)
+{
+ int retVal=-1;
+ struct yaffs_dev *dev=NULL;
+
+ 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){
+ if(dev->is_mounted){
+ yaffs_flush_whole_cache(dev);
+
+ if(force || ! yaffsfs_IsDevBusy(dev)){
+ if(read_only)
+ yaffs_checkpoint_save(dev);
+ dev->read_only = read_only ? 1 : 0;
+ retVal = 0;
+ } else
+ yaffsfs_SetError(-EBUSY);
+
+ } else
+ yaffsfs_SetError(-EINVAL);
+