+int yaffs_rmdir(const YCHAR *path)
+{
+ return yaffsfs_DoUnlink(path,1);
+}
+
+int yaffs_unlink(const YCHAR *path)
+{
+ return yaffsfs_DoUnlink(path,0);
+}
+
+int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
+{
+ yaffs_Object *olddir = NULL;
+ yaffs_Object *newdir = NULL;
+ yaffs_Object *obj = NULL;
+ YCHAR *oldname;
+ YCHAR *newname;
+ int result= YAFFS_FAIL;
+ int renameAllowed = 1;
+
+ yaffsfs_Lock();
+
+ olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
+ newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
+ obj = yaffsfs_FindObject(NULL,oldPath,0);
+
+ if(!olddir || !newdir || !obj) {
+ /* bad file */
+ yaffsfs_SetError(-EBADF);
+ renameAllowed = 0;
+ } else if(obj->myDev->readOnly){
+ yaffsfs_SetError(-EINVAL);
+ renameAllowed = 0;
+ } else if(olddir->myDev != newdir->myDev) {
+ /* oops must be on same device */
+ /* todo error */
+ yaffsfs_SetError(-EXDEV);
+ renameAllowed = 0;
+ } else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) {
+ /*
+ * It is a directory, check that it is not being renamed to
+ * being its own decendent.
+ * Do this by tracing from the new directory back to the root, checking for obj
+ */
+
+ yaffs_Object *xx = newdir;
+
+ while( renameAllowed && xx){
+ if(xx == obj)
+ renameAllowed = 0;
+ xx = xx->parent;
+ }
+ if(!renameAllowed)
+ yaffsfs_SetError(-EACCES);
+ }
+
+ if(renameAllowed)
+ result = yaffs_RenameObject(olddir,oldname,newdir,newname);
+
+ yaffsfs_Unlock();
+
+ return (result == YAFFS_FAIL) ? -1 : 0;
+}
+
+
+static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
+{
+ int retVal = -1;
+
+ if(obj)
+ obj = yaffs_GetEquivalentObject(obj);
+
+ if(obj && buf){
+ buf->st_dev = (int)obj->myDev->context;
+ buf->st_ino = obj->objectId;
+ buf->st_mode = obj->yst_mode & ~S_IFMT; /* clear out file type bits */
+
+ if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
+ buf->st_mode |= S_IFDIR;
+ else if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
+ buf->st_mode |= S_IFLNK;
+ else if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
+ buf->st_mode |= S_IFREG;
+
+ buf->st_nlink = yaffs_GetObjectLinkCount(obj);
+ buf->st_uid = 0;
+ buf->st_gid = 0;;
+ buf->st_rdev = obj->yst_rdev;
+ buf->st_size = yaffs_GetObjectFileLength(obj);
+ buf->st_blksize = obj->myDev->nDataBytesPerChunk;
+ buf->st_blocks = (buf->st_size + buf->st_blksize -1)/buf->st_blksize;
+#if CONFIG_YAFFS_WINCE
+ buf->yst_wince_atime[0] = obj->win_atime[0];
+ buf->yst_wince_atime[1] = obj->win_atime[1];
+ buf->yst_wince_ctime[0] = obj->win_ctime[0];
+ buf->yst_wince_ctime[1] = obj->win_ctime[1];
+ buf->yst_wince_mtime[0] = obj->win_mtime[0];
+ buf->yst_wince_mtime[1] = obj->win_mtime[1];
+#else
+ buf->yst_atime = obj->yst_atime;
+ buf->yst_ctime = obj->yst_ctime;
+ buf->yst_mtime = obj->yst_mtime;
+#endif
+ retVal = 0;
+ }
+ return retVal;
+}
+
+static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int doLStat)
+{
+ yaffs_Object *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_FindObject(NULL,path,0);
+
+ if(!doLStat && obj)
+ obj = yaffsfs_FollowLink(obj,0);
+
+ if(obj)
+ retVal = yaffsfs_DoStat(obj,buf);
+ else
+ /* todo error not found */
+ yaffsfs_SetError(-ENOENT);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+
+int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf)
+{
+ return yaffsfs_DoStatOrLStat(path,buf,0);
+}
+
+int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf)
+{
+ return yaffsfs_DoStatOrLStat(path,buf,1);
+}
+
+int yaffs_fstat(int fd, struct yaffs_stat *buf)
+{
+ yaffs_Object *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_GetHandleObject(fd);
+
+ if(obj)
+ retVal = yaffsfs_DoStat(obj,buf);
+ else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+
+/* xattrib functions */
+
+
+static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *data, int size, int flags, int follow)
+{
+ yaffs_Object *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_FindObject(NULL,path,0);
+
+ if(follow)
+ obj = yaffsfs_FollowLink(obj,0);
+
+ if(obj) {
+ retVal = yaffs_SetXAttribute(obj,name,data,size,flags);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ } else
+ /* todo error not found */
+ yaffsfs_SetError(-ENOENT);
+
+ 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)
+{
+ yaffs_Object *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_GetHandleObject(fd);
+
+ if(obj) {
+ retVal = yaffs_SetXAttribute(obj,name,data,size,flags);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ } else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, int size, int follow)
+{
+ yaffs_Object *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_FindObject(NULL,path,0);
+
+ if(follow)
+ obj = yaffsfs_FollowLink(obj,0);
+
+ if(obj) {
+ retVal = yaffs_GetXAttribute(obj,name,data,size);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ } else
+ /* todo error not found */
+ yaffsfs_SetError(-ENOENT);
+
+ 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)
+{
+ yaffs_Object *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_GetHandleObject(fd);
+
+ if(obj) {
+ retVal = yaffs_GetXAttribute(obj,name,data,size);
+ if(retVal< 0){
+ yaffsfs_SetError(retVal);
+ retVal = -1;
+ }
+ } else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;