2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
3 * yaffsfs.c The interface functions for using YAFFS via a "direct" interface.
5 * Copyright (C) 2002 Aleph One Ltd.
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
16 #include "yaffs_guts.h"
18 #include <string.h> // for memset
21 #define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5
24 #define NULL ((void *)0)
28 const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.14 2006-11-07 23:37:43 charles Exp $";
30 // configurationList is the list of devices that are supported
31 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
34 /* Some forward references */
35 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const char *path, int symDepth);
36 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj);
44 __u8 inUse:1; // this handle is in use
45 __u8 readOnly:1; // this handle is read only
46 __u8 append:1; // append only
47 __u8 exclusive:1; // exclusive
48 __u32 position; // current position in file
49 yaffs_Object *obj; // the object
53 static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
56 /// Inilitalise handles on start-up.
58 static int yaffsfs_InitHandles(void)
61 for(i = 0; i < YAFFSFS_N_HANDLES; i++)
63 yaffsfs_handle[i].inUse = 0;
64 yaffsfs_handle[i].obj = NULL;
69 yaffsfs_Handle *yaffsfs_GetHandlePointer(int h)
71 if(h < 0 || h >= YAFFSFS_N_HANDLES)
76 return &yaffsfs_handle[h];
79 yaffs_Object *yaffsfs_GetHandleObject(int handle)
81 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle);
93 // Grab a handle (when opening a file)
96 static int yaffsfs_GetHandle(void)
101 for(i = 0; i < YAFFSFS_N_HANDLES; i++)
103 h = yaffsfs_GetHandlePointer(i);
106 // todo bug: should never happen
110 memset(h,0,sizeof(yaffsfs_Handle));
119 // Let go of a handle (when closing a file)
121 static int yaffsfs_PutHandle(int handle)
123 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle);
135 // Stuff to search for a directory from a path
138 int yaffsfs_Match(char a, char b)
144 // yaffsfs_FindDevice
146 // Scan the configuration list to find the root.
147 // Curveballs: Should match paths that end in '/' too
148 // Curveball2 Might have "/x/ and "/x/y". Need to return the longest match
149 static yaffs_Device *yaffsfs_FindDevice(const char *path, char **restOfPath)
151 yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList;
152 const char *leftOver;
154 yaffs_Device *retval = NULL;
156 int longestMatch = -1;
158 // Check all configs, choose the one that:
159 // 1) Actually matches a prefix (ie /a amd /abc will not match
160 // 2) Matches the longest.
161 while(cfg && cfg->prefix && cfg->dev)
167 while(*p && //unmatched part of prefix
168 strcmp(p,"/") && // the rest of the prefix is not / (to catch / at end)
170 yaffsfs_Match(*p,*leftOver))
176 if((!*p || strcmp(p,"/") == 0) && // end of prefix
177 (!*leftOver || *leftOver == '/') && // no more in this path name part
178 (thisMatchLength > longestMatch))
181 *restOfPath = (char *)leftOver;
183 longestMatch = thisMatchLength;
190 static yaffs_Object *yaffsfs_FindRoot(const char *path, char **restOfPath)
195 dev= yaffsfs_FindDevice(path,restOfPath);
196 if(dev && dev->isMounted)
203 static yaffs_Object *yaffsfs_FollowLink(yaffs_Object *obj,int symDepth)
206 while(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
208 char *alias = obj->variant.symLinkVariant.alias;
212 // Starts with a /, need to scan from root up
213 obj = yaffsfs_FindObject(NULL,alias,symDepth++);
217 // Relative to here, so use the parent of the symlink as a start
218 obj = yaffsfs_FindObject(obj->parent,alias,symDepth++);
225 // yaffsfs_FindDirectory
226 // Parse a path to determine the directory and the name within the directory.
228 // eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
229 static yaffs_Object *yaffsfs_DoFindDirectory(yaffs_Object *startDir,const char *path,char **name,int symDepth)
233 char str[YAFFS_MAX_NAME_LENGTH+1];
236 if(symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES)
244 restOfPath = (char *)path;
248 dir = yaffsfs_FindRoot(path,&restOfPath);
254 // curve ball: also throw away surplus '/'
255 // eg. "/ram/x////ff" gets treated the same as "/ram/x/ff"
256 while(*restOfPath == '/')
258 restOfPath++; // get rid of '/'
264 while(*restOfPath && *restOfPath != '/')
266 if (i < YAFFS_MAX_NAME_LENGTH)
268 str[i] = *restOfPath;
277 // got to the end of the string
282 if(strcmp(str,".") == 0)
286 else if(strcmp(str,"..") == 0)
292 dir = yaffs_FindObjectByName(dir,str);
294 while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
297 dir = yaffsfs_FollowLink(dir,symDepth);
301 if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
308 // directory did not exist.
312 static yaffs_Object *yaffsfs_FindDirectory(yaffs_Object *relativeDirectory,const char *path,char **name,int symDepth)
314 return yaffsfs_DoFindDirectory(relativeDirectory,path,name,symDepth);
317 // yaffsfs_FindObject turns a path for an existing object into the object
319 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const char *path,int symDepth)
324 dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
328 return yaffs_FindObjectByName(dir,name);
336 int yaffs_open(const char *path, int oflag, int mode)
338 yaffs_Object *obj = NULL;
339 yaffs_Object *dir = NULL;
342 yaffsfs_Handle *h = NULL;
344 int alreadyExclusive = 0;
347 int errorReported = 0;
352 // todo sanity check oflag (eg. can't have O_TRUNC without WRONLY or RDWR
357 handle = yaffsfs_GetHandle();
362 h = yaffsfs_GetHandlePointer(handle);
365 // try to find the exisiting object
366 obj = yaffsfs_FindObject(NULL,path,0);
368 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
371 obj = yaffsfs_FollowLink(obj,symDepth++);
376 // Check if the object is already in use
377 alreadyOpen = alreadyExclusive = 0;
379 for(i = 0; i <= YAFFSFS_N_HANDLES; i++)
383 yaffsfs_handle[i].inUse &&
384 obj == yaffsfs_handle[i].obj)
387 if(yaffsfs_handle[i].exclusive)
389 alreadyExclusive = 1;
394 if(((oflag & O_EXCL) && alreadyOpen) || alreadyExclusive)
399 // Open should fail if O_CREAT and O_EXCL are specified
400 if((oflag & O_EXCL) && (oflag & O_CREAT))
403 yaffsfs_SetError(-EEXIST);
407 // Check file permissions
408 if( (oflag & (O_RDWR | O_WRONLY)) == 0 && // ie O_RDONLY
409 !(obj->yst_mode & S_IREAD))
414 if( (oflag & O_RDWR) &&
415 !(obj->yst_mode & S_IREAD))
420 if( (oflag & (O_RDWR | O_WRONLY)) &&
421 !(obj->yst_mode & S_IWRITE))
428 else if((oflag & O_CREAT))
430 // Let's see if we can create this file
431 dir = yaffsfs_FindDirectory(NULL,path,&name,0);
434 obj = yaffs_MknodFile(dir,name,mode,0,0);
438 yaffsfs_SetError(-ENOTDIR);
442 if(obj && !openDenied)
446 h->readOnly = (oflag & (O_WRONLY | O_RDWR)) ? 0 : 1;
447 h->append = (oflag & O_APPEND) ? 1 : 0;
448 h->exclusive = (oflag & O_EXCL) ? 1 : 0;
452 if((oflag & O_TRUNC) && !h->readOnly)
455 yaffs_ResizeFile(obj,0);
461 yaffsfs_PutHandle(handle);
464 yaffsfs_SetError(-EACCESS);
477 int yaffs_close(int fd)
479 yaffsfs_Handle *h = NULL;
484 h = yaffsfs_GetHandlePointer(fd);
489 yaffs_FlushFile(h->obj,1);
491 if(h->obj->inUse <= 0 && h->obj->unlinked)
493 yaffs_DeleteFile(h->obj);
495 yaffsfs_PutHandle(fd);
501 yaffsfs_SetError(-EBADF);
510 int yaffs_read(int fd, void *buf, unsigned int nbyte)
512 yaffsfs_Handle *h = NULL;
513 yaffs_Object *obj = NULL;
519 h = yaffsfs_GetHandlePointer(fd);
520 obj = yaffsfs_GetHandleObject(fd);
525 yaffsfs_SetError(-EBADF);
530 if(yaffs_GetObjectFileLength(obj) > pos)
532 maxRead = yaffs_GetObjectFileLength(obj) - pos;
547 nRead = yaffs_ReadDataFromFile(obj,buf,pos,nbyte);
550 h->position = pos + nRead;
567 return (nRead >= 0) ? nRead : -1;
571 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
573 yaffsfs_Handle *h = NULL;
574 yaffs_Object *obj = NULL;
577 int writeThrough = 0;
580 h = yaffsfs_GetHandlePointer(fd);
581 obj = yaffsfs_GetHandleObject(fd);
586 yaffsfs_SetError(-EBADF);
588 else if( h && obj && h->readOnly)
596 pos = yaffs_GetObjectFileLength(obj);
603 nWritten = yaffs_WriteDataToFile(obj,buf,pos,nbyte,writeThrough);
607 h->position = pos + nWritten;
619 return (nWritten >= 0) ? nWritten : -1;
623 int yaffs_truncate(int fd, off_t newSize)
625 yaffsfs_Handle *h = NULL;
626 yaffs_Object *obj = NULL;
630 h = yaffsfs_GetHandlePointer(fd);
631 obj = yaffsfs_GetHandleObject(fd);
636 yaffsfs_SetError(-EBADF);
641 result = yaffs_ResizeFile(obj,newSize);
646 return (result) ? 0 : -1;
650 off_t yaffs_lseek(int fd, off_t offset, int whence)
652 yaffsfs_Handle *h = NULL;
653 yaffs_Object *obj = NULL;
658 h = yaffsfs_GetHandlePointer(fd);
659 obj = yaffsfs_GetHandleObject(fd);
664 yaffsfs_SetError(-EBADF);
666 else if(whence == SEEK_SET)
673 else if(whence == SEEK_CUR)
675 if( (h->position + offset) >= 0)
677 pos = (h->position + offset);
680 else if(whence == SEEK_END)
682 fSize = yaffs_GetObjectFileLength(obj);
683 if(fSize >= 0 && (fSize + offset) >= 0)
685 pos = fSize + offset;
705 int yaffsfs_DoUnlink(const char *path,int isDirectory)
707 yaffs_Object *dir = NULL;
708 yaffs_Object *obj = NULL;
710 int result = YAFFS_FAIL;
714 obj = yaffsfs_FindObject(NULL,path,0);
715 dir = yaffsfs_FindDirectory(NULL,path,&name,0);
718 yaffsfs_SetError(-ENOTDIR);
722 yaffsfs_SetError(-ENOENT);
724 else if(!isDirectory && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
726 yaffsfs_SetError(-EISDIR);
728 else if(isDirectory && obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
730 yaffsfs_SetError(-ENOTDIR);
732 else if(isDirectory && obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
734 yaffsfs_SetError(-ENOTDIR);
738 result = yaffs_Unlink(dir,name);
740 if(result == YAFFS_FAIL && isDirectory)
742 yaffsfs_SetError(-ENOTEMPTY);
750 return (result == YAFFS_FAIL) ? -1 : 0;
752 int yaffs_rmdir(const char *path)
754 return yaffsfs_DoUnlink(path,1);
757 int yaffs_unlink(const char *path)
759 return yaffsfs_DoUnlink(path,0);
762 int yaffs_rename(const char *oldPath, const char *newPath)
764 yaffs_Object *olddir = NULL;
765 yaffs_Object *newdir = NULL;
766 yaffs_Object *obj = NULL;
769 int result= YAFFS_FAIL;
770 int renameAllowed = 1;
774 olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
775 newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
776 obj = yaffsfs_FindObject(NULL,oldPath,0);
778 if(!olddir || !newdir || !obj)
781 yaffsfs_SetError(-EBADF);
784 else if(olddir->myDev != newdir->myDev)
786 // oops must be on same device
788 yaffsfs_SetError(-EXDEV);
791 else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
793 // It is a directory, check that it is not being renamed to
794 // being its own decendent.
795 // Do this by tracing from the new directory back to the root, checking for obj
797 yaffs_Object *xx = newdir;
799 while( renameAllowed && xx)
807 if(!renameAllowed) yaffsfs_SetError(-EACCESS);
812 result = yaffs_RenameObject(olddir,oldname,newdir,newname);
817 return (result == YAFFS_FAIL) ? -1 : 0;
821 static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
827 obj = yaffs_GetEquivalentObject(obj);
832 buf->st_dev = (int)obj->myDev->genericDevice;
833 buf->st_ino = obj->objectId;
834 buf->st_mode = obj->yst_mode & ~S_IFMT; // clear out file type bits
836 if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
838 buf->st_mode |= S_IFDIR;
840 else if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
842 buf->st_mode |= S_IFLNK;
844 else if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
846 buf->st_mode |= S_IFREG;
849 buf->st_nlink = yaffs_GetObjectLinkCount(obj);
852 buf->st_rdev = obj->yst_rdev;
853 buf->st_size = yaffs_GetObjectFileLength(obj);
854 buf->st_blksize = obj->myDev->nDataBytesPerChunk;
855 buf->st_blocks = (buf->st_size + buf->st_blksize -1)/buf->st_blksize;
856 buf->yst_atime = obj->yst_atime;
857 buf->yst_ctime = obj->yst_ctime;
858 buf->yst_mtime = obj->yst_mtime;
864 static int yaffsfs_DoStatOrLStat(const char *path, struct yaffs_stat *buf,int doLStat)
871 obj = yaffsfs_FindObject(NULL,path,0);
875 obj = yaffsfs_FollowLink(obj,0);
880 retVal = yaffsfs_DoStat(obj,buf);
884 // todo error not found
885 yaffsfs_SetError(-ENOENT);
894 int yaffs_stat(const char *path, struct yaffs_stat *buf)
896 return yaffsfs_DoStatOrLStat(path,buf,0);
899 int yaffs_lstat(const char *path, struct yaffs_stat *buf)
901 return yaffsfs_DoStatOrLStat(path,buf,1);
904 int yaffs_fstat(int fd, struct yaffs_stat *buf)
911 obj = yaffsfs_GetHandleObject(fd);
915 retVal = yaffsfs_DoStat(obj,buf);
920 yaffsfs_SetError(-EBADF);
928 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
934 obj = yaffs_GetEquivalentObject(obj);
939 obj->yst_mode = mode;
941 result = yaffs_FlushFile(obj,0);
944 return result == YAFFS_OK ? 0 : -1;
948 int yaffs_chmod(const char *path, mode_t mode)
955 obj = yaffsfs_FindObject(NULL,path,0);
959 retVal = yaffsfs_DoChMod(obj,mode);
963 // todo error not found
964 yaffsfs_SetError(-ENOENT);
974 int yaffs_fchmod(int fd, mode_t mode)
981 obj = yaffsfs_GetHandleObject(fd);
985 retVal = yaffsfs_DoChMod(obj,mode);
990 yaffsfs_SetError(-EBADF);
999 int yaffs_mkdir(const char *path, mode_t mode)
1001 yaffs_Object *parent = NULL;
1002 yaffs_Object *dir = NULL;
1007 parent = yaffsfs_FindDirectory(NULL,path,&name,0);
1009 dir = yaffs_MknodDirectory(parent,name,mode,0,0);
1016 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1025 int yaffs_mount(const char *path)
1028 int result=YAFFS_FAIL;
1029 yaffs_Device *dev=NULL;
1032 T(YAFFS_TRACE_ALWAYS,("yaffs: Mounting %s\n",path));
1035 dev = yaffsfs_FindDevice(path,&dummy);
1040 result = yaffs_GutsInitialise(dev);
1041 if(result == YAFFS_FAIL)
1043 // todo error - mount failed
1044 yaffsfs_SetError(-ENOMEM);
1046 retVal = result ? 0 : -1;
1051 //todo error - already mounted.
1052 yaffsfs_SetError(-EBUSY);
1057 // todo error - no device
1058 yaffsfs_SetError(-ENODEV);
1065 int yaffs_unmount(const char *path)
1068 yaffs_Device *dev=NULL;
1072 dev = yaffsfs_FindDevice(path,&dummy);
1080 yaffs_FlushEntireDeviceCache(dev);
1081 yaffs_CheckpointSave(dev);
1083 for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++)
1085 if(yaffsfs_handle[i].inUse && yaffsfs_handle[i].obj->myDev == dev)
1087 inUse = 1; // the device is in use, can't unmount
1093 yaffs_Deinitialise(dev);
1099 // todo error can't unmount as files are open
1100 yaffsfs_SetError(-EBUSY);
1106 //todo error - not mounted.
1107 yaffsfs_SetError(-EINVAL);
1113 // todo error - no device
1114 yaffsfs_SetError(-ENODEV);
1121 loff_t yaffs_freespace(const char *path)
1124 yaffs_Device *dev=NULL;
1128 dev = yaffsfs_FindDevice(path,&dummy);
1129 if(dev && dev->isMounted)
1131 retVal = yaffs_GetNumberOfFreeChunks(dev);
1132 retVal *= dev->nDataBytesPerChunk;
1137 yaffsfs_SetError(-EINVAL);
1146 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)
1149 yaffsfs_DeviceConfiguration *cfg;
1151 yaffsfs_configurationList = cfgList;
1153 yaffsfs_InitHandles();
1155 cfg = yaffsfs_configurationList;
1157 while(cfg && cfg->prefix && cfg->dev)
1159 cfg->dev->isMounted = 0;
1160 cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback;
1169 // Directory search stuff.
1172 // Directory search context
1174 // NB this is an opaque structure.
1180 yaffs_dirent de; /* directory entry being used by this dsc */
1181 char name[NAME_MAX+1]; /* name of directory being searched */
1182 yaffs_Object *dirObj; /* ptr to directory being searched */
1183 yaffs_Object *nextReturn; /* obj to be returned by next readddir */
1185 struct list_head others;
1186 } yaffsfs_DirectorySearchContext;
1190 static struct list_head search_contexts;
1193 static void yaffsfs_SetDirRewound(yaffsfs_DirectorySearchContext *dsc)
1197 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1201 if( list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1202 dsc->nextReturn = NULL;
1204 dsc->nextReturn = list_entry(dsc->dirObj->variant.directoryVariant.children.next,
1205 yaffs_Object,siblings);
1208 /* Hey someone isn't playing nice! */
1212 static void yaffsfs_DirAdvance(yaffsfs_DirectorySearchContext *dsc)
1216 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1218 if( dsc->nextReturn == NULL ||
1219 list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1220 dsc->nextReturn = NULL;
1222 struct list_head *next = dsc->nextReturn->siblings.next;
1224 if( next == &dsc->dirObj->variant.directoryVariant.children)
1225 dsc->nextReturn = NULL; /* end of list */
1227 dsc->nextReturn = list_entry(next,yaffs_Object,siblings);
1230 /* Hey someone isn't playing nice! */
1234 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj)
1237 struct list_head *i;
1238 yaffsfs_DirectorySearchContext *dsc;
1240 /* if search contexts not initilised then skip */
1241 if(!search_contexts.next)
1244 /* Iteratethrough the directory search contexts.
1245 * If any are the one being removed, then advance the dsc to
1246 * the next one to prevent a hanging ptr.
1248 list_for_each(i, &search_contexts) {
1250 dsc = list_entry(i, yaffsfs_DirectorySearchContext,others);
1251 if(dsc->nextReturn == obj)
1252 yaffsfs_DirAdvance(dsc);
1258 yaffs_DIR *yaffs_opendir(const char *dirname)
1260 yaffs_DIR *dir = NULL;
1261 yaffs_Object *obj = NULL;
1262 yaffsfs_DirectorySearchContext *dsc = NULL;
1266 obj = yaffsfs_FindObject(NULL,dirname,0);
1268 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
1271 dsc = YMALLOC(sizeof(yaffsfs_DirectorySearchContext));
1272 dir = (yaffs_DIR *)dsc;
1275 memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
1276 dsc->magic = YAFFS_MAGIC;
1278 strncpy(dsc->name,dirname,NAME_MAX);
1279 INIT_LIST_HEAD(&dsc->others);
1281 if(!search_contexts.next)
1282 INIT_LIST_HEAD(&search_contexts);
1284 list_add(&dsc->others,&search_contexts);
1285 yaffsfs_SetDirRewound(dsc); }
1294 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp)
1296 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1297 struct yaffs_dirent *retVal = NULL;
1301 if(dsc && dsc->magic == YAFFS_MAGIC){
1302 yaffsfs_SetError(0);
1303 if(dsc->nextReturn){
1304 dsc->de.d_ino = yaffs_GetEquivalentObject(dsc->nextReturn)->objectId;
1305 dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
1306 dsc->de.d_off = dsc->offset++;
1307 yaffs_GetObjectName(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
1308 if(strlen(dsc->de.d_name) == 0)
1310 // this should not happen!
1311 strcpy(dsc->de.d_name,"zz");
1313 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
1315 yaffsfs_DirAdvance(dsc);
1321 yaffsfs_SetError(-EBADF);
1331 void yaffs_rewinddir(yaffs_DIR *dirp)
1333 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1337 yaffsfs_SetDirRewound(dsc);
1343 int yaffs_closedir(yaffs_DIR *dirp)
1345 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1349 list_del(&dsc->others); /* unhook from list */
1355 // end of directory stuff
1358 int yaffs_symlink(const char *oldpath, const char *newpath)
1360 yaffs_Object *parent = NULL;
1364 int mode = 0; // ignore for now
1367 parent = yaffsfs_FindDirectory(NULL,newpath,&name,0);
1368 obj = yaffs_MknodSymLink(parent,name,mode,0,0,oldpath);
1375 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1385 int yaffs_readlink(const char *path, char *buf, int bufsiz)
1387 yaffs_Object *obj = NULL;
1393 obj = yaffsfs_FindObject(NULL,path,0);
1397 yaffsfs_SetError(-ENOENT);
1400 else if(obj->variantType != YAFFS_OBJECT_TYPE_SYMLINK)
1402 yaffsfs_SetError(-EINVAL);
1407 char *alias = obj->variant.symLinkVariant.alias;
1408 memset(buf,0,bufsiz);
1409 strncpy(buf,alias,bufsiz - 1);
1416 int yaffs_link(const char *oldpath, const char *newpath)
1418 // Creates a link called newpath to existing oldpath
1419 yaffs_Object *obj = NULL;
1420 yaffs_Object *target = NULL;
1426 obj = yaffsfs_FindObject(NULL,oldpath,0);
1427 target = yaffsfs_FindObject(NULL,newpath,0);
1431 yaffsfs_SetError(-ENOENT);
1436 yaffsfs_SetError(-EEXIST);
1441 yaffs_Object *newdir = NULL;
1442 yaffs_Object *link = NULL;
1446 newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0);
1450 yaffsfs_SetError(-ENOTDIR);
1453 else if(newdir->myDev != obj->myDev)
1455 yaffsfs_SetError(-EXDEV);
1458 if(newdir && strlen(newname) > 0)
1460 link = yaffs_Link(newdir,newname,obj);
1465 yaffsfs_SetError(-ENOSPC);
1476 int yaffs_mknod(const char *pathname, mode_t mode, dev_t dev);
1478 int yaffs_DumpDevStruct(const char *path)
1482 yaffs_Object *obj = yaffsfs_FindRoot(path,&rest);
1486 yaffs_Device *dev = obj->myDev;
1489 "nPageWrites.......... %d\n"
1490 "nPageReads........... %d\n"
1491 "nBlockErasures....... %d\n"
1492 "nGCCopies............ %d\n"
1493 "garbageCollections... %d\n"
1494 "passiveGarbageColl'ns %d\n"
1498 dev->nBlockErasures,
1500 dev->garbageCollections,
1501 dev->passiveGarbageCollections