2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
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.
15 #include "yaffs_guts.h"
17 #include <string.h> // for memset
20 #define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5
23 #define NULL ((void *)0)
27 const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.18 2007-07-18 19:40:38 charles Exp $";
29 // configurationList is the list of devices that are supported
30 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
33 /* Some forward references */
34 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const char *path, int symDepth);
35 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj);
42 unsigned int yaffs_wr_attempts;
46 __u8 inUse:1; // this handle is in use
47 __u8 readOnly:1; // this handle is read only
48 __u8 append:1; // append only
49 __u8 exclusive:1; // exclusive
50 __u32 position; // current position in file
51 yaffs_Object *obj; // the object
55 static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
58 /// Inilitalise handles on start-up.
60 static int yaffsfs_InitHandles(void)
63 for(i = 0; i < YAFFSFS_N_HANDLES; i++)
65 yaffsfs_handle[i].inUse = 0;
66 yaffsfs_handle[i].obj = NULL;
71 yaffsfs_Handle *yaffsfs_GetHandlePointer(int h)
73 if(h < 0 || h >= YAFFSFS_N_HANDLES)
78 return &yaffsfs_handle[h];
81 yaffs_Object *yaffsfs_GetHandleObject(int handle)
83 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle);
95 // Grab a handle (when opening a file)
98 static int yaffsfs_GetHandle(void)
103 for(i = 0; i < YAFFSFS_N_HANDLES; i++)
105 h = yaffsfs_GetHandlePointer(i);
108 // todo bug: should never happen
112 memset(h,0,sizeof(yaffsfs_Handle));
121 // Let go of a handle (when closing a file)
123 static int yaffsfs_PutHandle(int handle)
125 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle);
137 // Stuff to search for a directory from a path
140 int yaffsfs_Match(char a, char b)
146 // yaffsfs_FindDevice
148 // Scan the configuration list to find the root.
149 // Curveballs: Should match paths that end in '/' too
150 // Curveball2 Might have "/x/ and "/x/y". Need to return the longest match
151 static yaffs_Device *yaffsfs_FindDevice(const char *path, char **restOfPath)
153 yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList;
154 const char *leftOver;
156 yaffs_Device *retval = NULL;
158 int longestMatch = -1;
160 // Check all configs, choose the one that:
161 // 1) Actually matches a prefix (ie /a amd /abc will not match
162 // 2) Matches the longest.
163 while(cfg && cfg->prefix && cfg->dev)
169 while(*p && //unmatched part of prefix
170 strcmp(p,"/") && // the rest of the prefix is not / (to catch / at end)
172 yaffsfs_Match(*p,*leftOver))
178 if((!*p || strcmp(p,"/") == 0) && // end of prefix
179 (!*leftOver || *leftOver == '/') && // no more in this path name part
180 (thisMatchLength > longestMatch))
183 *restOfPath = (char *)leftOver;
185 longestMatch = thisMatchLength;
192 static yaffs_Object *yaffsfs_FindRoot(const char *path, char **restOfPath)
197 dev= yaffsfs_FindDevice(path,restOfPath);
198 if(dev && dev->isMounted)
205 static yaffs_Object *yaffsfs_FollowLink(yaffs_Object *obj,int symDepth)
208 while(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
210 char *alias = obj->variant.symLinkVariant.alias;
214 // Starts with a /, need to scan from root up
215 obj = yaffsfs_FindObject(NULL,alias,symDepth++);
219 // Relative to here, so use the parent of the symlink as a start
220 obj = yaffsfs_FindObject(obj->parent,alias,symDepth++);
227 // yaffsfs_FindDirectory
228 // Parse a path to determine the directory and the name within the directory.
230 // eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
231 static yaffs_Object *yaffsfs_DoFindDirectory(yaffs_Object *startDir,const char *path,char **name,int symDepth)
235 char str[YAFFS_MAX_NAME_LENGTH+1];
238 if(symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES)
246 restOfPath = (char *)path;
250 dir = yaffsfs_FindRoot(path,&restOfPath);
256 // curve ball: also throw away surplus '/'
257 // eg. "/ram/x////ff" gets treated the same as "/ram/x/ff"
258 while(*restOfPath == '/')
260 restOfPath++; // get rid of '/'
266 while(*restOfPath && *restOfPath != '/')
268 if (i < YAFFS_MAX_NAME_LENGTH)
270 str[i] = *restOfPath;
279 // got to the end of the string
284 if(strcmp(str,".") == 0)
288 else if(strcmp(str,"..") == 0)
294 dir = yaffs_FindObjectByName(dir,str);
296 while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
299 dir = yaffsfs_FollowLink(dir,symDepth);
303 if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
310 // directory did not exist.
314 static yaffs_Object *yaffsfs_FindDirectory(yaffs_Object *relativeDirectory,const char *path,char **name,int symDepth)
316 return yaffsfs_DoFindDirectory(relativeDirectory,path,name,symDepth);
319 // yaffsfs_FindObject turns a path for an existing object into the object
321 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const char *path,int symDepth)
326 dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
330 return yaffs_FindObjectByName(dir,name);
338 int yaffs_open(const char *path, int oflag, int mode)
340 yaffs_Object *obj = NULL;
341 yaffs_Object *dir = NULL;
344 yaffsfs_Handle *h = NULL;
346 int alreadyExclusive = 0;
349 int errorReported = 0;
354 // todo sanity check oflag (eg. can't have O_TRUNC without WRONLY or RDWR
359 handle = yaffsfs_GetHandle();
364 h = yaffsfs_GetHandlePointer(handle);
367 // try to find the exisiting object
368 obj = yaffsfs_FindObject(NULL,path,0);
370 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
373 obj = yaffsfs_FollowLink(obj,symDepth++);
378 // Check if the object is already in use
379 alreadyOpen = alreadyExclusive = 0;
381 for(i = 0; i <= YAFFSFS_N_HANDLES; i++)
385 yaffsfs_handle[i].inUse &&
386 obj == yaffsfs_handle[i].obj)
389 if(yaffsfs_handle[i].exclusive)
391 alreadyExclusive = 1;
396 if(((oflag & O_EXCL) && alreadyOpen) || alreadyExclusive)
401 // Open should fail if O_CREAT and O_EXCL are specified
402 if((oflag & O_EXCL) && (oflag & O_CREAT))
405 yaffsfs_SetError(-EEXIST);
409 // Check file permissions
410 if( (oflag & (O_RDWR | O_WRONLY)) == 0 && // ie O_RDONLY
411 !(obj->yst_mode & S_IREAD))
416 if( (oflag & O_RDWR) &&
417 !(obj->yst_mode & S_IREAD))
422 if( (oflag & (O_RDWR | O_WRONLY)) &&
423 !(obj->yst_mode & S_IWRITE))
430 else if((oflag & O_CREAT))
432 // Let's see if we can create this file
433 dir = yaffsfs_FindDirectory(NULL,path,&name,0);
436 obj = yaffs_MknodFile(dir,name,mode,0,0);
440 yaffsfs_SetError(-ENOTDIR);
444 if(obj && !openDenied)
448 h->readOnly = (oflag & (O_WRONLY | O_RDWR)) ? 0 : 1;
449 h->append = (oflag & O_APPEND) ? 1 : 0;
450 h->exclusive = (oflag & O_EXCL) ? 1 : 0;
454 if((oflag & O_TRUNC) && !h->readOnly)
457 yaffs_ResizeFile(obj,0);
463 yaffsfs_PutHandle(handle);
466 yaffsfs_SetError(-EACCESS);
479 int yaffs_close(int fd)
481 yaffsfs_Handle *h = NULL;
486 h = yaffsfs_GetHandlePointer(fd);
491 yaffs_FlushFile(h->obj,1);
493 if(h->obj->inUse <= 0 && h->obj->unlinked)
495 yaffs_DeleteFile(h->obj);
497 yaffsfs_PutHandle(fd);
503 yaffsfs_SetError(-EBADF);
512 int yaffs_read(int fd, void *buf, unsigned int nbyte)
514 yaffsfs_Handle *h = NULL;
515 yaffs_Object *obj = NULL;
521 h = yaffsfs_GetHandlePointer(fd);
522 obj = yaffsfs_GetHandleObject(fd);
527 yaffsfs_SetError(-EBADF);
532 if(yaffs_GetObjectFileLength(obj) > pos)
534 maxRead = yaffs_GetObjectFileLength(obj) - pos;
549 nRead = yaffs_ReadDataFromFile(obj,buf,pos,nbyte);
552 h->position = pos + nRead;
569 return (nRead >= 0) ? nRead : -1;
573 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
575 yaffsfs_Handle *h = NULL;
576 yaffs_Object *obj = NULL;
579 int writeThrough = 0;
582 h = yaffsfs_GetHandlePointer(fd);
583 obj = yaffsfs_GetHandleObject(fd);
588 yaffsfs_SetError(-EBADF);
590 else if( h && obj && h->readOnly)
598 pos = yaffs_GetObjectFileLength(obj);
605 nWritten = yaffs_WriteDataToFile(obj,buf,pos,nbyte,writeThrough);
609 h->position = pos + nWritten;
621 return (nWritten >= 0) ? nWritten : -1;
625 int yaffs_truncate(int fd, off_t newSize)
627 yaffsfs_Handle *h = NULL;
628 yaffs_Object *obj = NULL;
632 h = yaffsfs_GetHandlePointer(fd);
633 obj = yaffsfs_GetHandleObject(fd);
638 yaffsfs_SetError(-EBADF);
643 result = yaffs_ResizeFile(obj,newSize);
648 return (result) ? 0 : -1;
652 off_t yaffs_lseek(int fd, off_t offset, int whence)
654 yaffsfs_Handle *h = NULL;
655 yaffs_Object *obj = NULL;
660 h = yaffsfs_GetHandlePointer(fd);
661 obj = yaffsfs_GetHandleObject(fd);
666 yaffsfs_SetError(-EBADF);
668 else if(whence == SEEK_SET)
675 else if(whence == SEEK_CUR)
677 if( (h->position + offset) >= 0)
679 pos = (h->position + offset);
682 else if(whence == SEEK_END)
684 fSize = yaffs_GetObjectFileLength(obj);
685 if(fSize >= 0 && (fSize + offset) >= 0)
687 pos = fSize + offset;
707 int yaffsfs_DoUnlink(const char *path,int isDirectory)
709 yaffs_Object *dir = NULL;
710 yaffs_Object *obj = NULL;
712 int result = YAFFS_FAIL;
716 obj = yaffsfs_FindObject(NULL,path,0);
717 dir = yaffsfs_FindDirectory(NULL,path,&name,0);
720 yaffsfs_SetError(-ENOTDIR);
724 yaffsfs_SetError(-ENOENT);
726 else if(!isDirectory && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
728 yaffsfs_SetError(-EISDIR);
730 else if(isDirectory && obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
732 yaffsfs_SetError(-ENOTDIR);
736 result = yaffs_Unlink(dir,name);
738 if(result == YAFFS_FAIL && isDirectory)
740 yaffsfs_SetError(-ENOTEMPTY);
748 return (result == YAFFS_FAIL) ? -1 : 0;
750 int yaffs_rmdir(const char *path)
752 return yaffsfs_DoUnlink(path,1);
755 int yaffs_unlink(const char *path)
757 return yaffsfs_DoUnlink(path,0);
760 int yaffs_rename(const char *oldPath, const char *newPath)
762 yaffs_Object *olddir = NULL;
763 yaffs_Object *newdir = NULL;
764 yaffs_Object *obj = NULL;
767 int result= YAFFS_FAIL;
768 int renameAllowed = 1;
772 olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
773 newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
774 obj = yaffsfs_FindObject(NULL,oldPath,0);
776 if(!olddir || !newdir || !obj)
779 yaffsfs_SetError(-EBADF);
782 else if(olddir->myDev != newdir->myDev)
784 // oops must be on same device
786 yaffsfs_SetError(-EXDEV);
789 else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
791 // It is a directory, check that it is not being renamed to
792 // being its own decendent.
793 // Do this by tracing from the new directory back to the root, checking for obj
795 yaffs_Object *xx = newdir;
797 while( renameAllowed && xx)
805 if(!renameAllowed) yaffsfs_SetError(-EACCESS);
810 result = yaffs_RenameObject(olddir,oldname,newdir,newname);
815 return (result == YAFFS_FAIL) ? -1 : 0;
819 static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
825 obj = yaffs_GetEquivalentObject(obj);
830 buf->st_dev = (int)obj->myDev->genericDevice;
831 buf->st_ino = obj->objectId;
832 buf->st_mode = obj->yst_mode & ~S_IFMT; // clear out file type bits
834 if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
836 buf->st_mode |= S_IFDIR;
838 else if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
840 buf->st_mode |= S_IFLNK;
842 else if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
844 buf->st_mode |= S_IFREG;
847 buf->st_nlink = yaffs_GetObjectLinkCount(obj);
850 buf->st_rdev = obj->yst_rdev;
851 buf->st_size = yaffs_GetObjectFileLength(obj);
852 buf->st_blksize = obj->myDev->nDataBytesPerChunk;
853 buf->st_blocks = (buf->st_size + buf->st_blksize -1)/buf->st_blksize;
854 buf->yst_atime = obj->yst_atime;
855 buf->yst_ctime = obj->yst_ctime;
856 buf->yst_mtime = obj->yst_mtime;
862 static int yaffsfs_DoStatOrLStat(const char *path, struct yaffs_stat *buf,int doLStat)
869 obj = yaffsfs_FindObject(NULL,path,0);
873 obj = yaffsfs_FollowLink(obj,0);
878 retVal = yaffsfs_DoStat(obj,buf);
882 // todo error not found
883 yaffsfs_SetError(-ENOENT);
892 int yaffs_stat(const char *path, struct yaffs_stat *buf)
894 return yaffsfs_DoStatOrLStat(path,buf,0);
897 int yaffs_lstat(const char *path, struct yaffs_stat *buf)
899 return yaffsfs_DoStatOrLStat(path,buf,1);
902 int yaffs_fstat(int fd, struct yaffs_stat *buf)
909 obj = yaffsfs_GetHandleObject(fd);
913 retVal = yaffsfs_DoStat(obj,buf);
918 yaffsfs_SetError(-EBADF);
926 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
932 obj = yaffs_GetEquivalentObject(obj);
937 obj->yst_mode = mode;
939 result = yaffs_FlushFile(obj,0);
942 return result == YAFFS_OK ? 0 : -1;
946 int yaffs_chmod(const char *path, mode_t mode)
953 obj = yaffsfs_FindObject(NULL,path,0);
957 retVal = yaffsfs_DoChMod(obj,mode);
961 // todo error not found
962 yaffsfs_SetError(-ENOENT);
972 int yaffs_fchmod(int fd, mode_t mode)
979 obj = yaffsfs_GetHandleObject(fd);
983 retVal = yaffsfs_DoChMod(obj,mode);
988 yaffsfs_SetError(-EBADF);
997 int yaffs_mkdir(const char *path, mode_t mode)
999 yaffs_Object *parent = NULL;
1000 yaffs_Object *dir = NULL;
1005 parent = yaffsfs_FindDirectory(NULL,path,&name,0);
1007 dir = yaffs_MknodDirectory(parent,name,mode,0,0);
1014 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1023 int yaffs_mount(const char *path)
1026 int result=YAFFS_FAIL;
1027 yaffs_Device *dev=NULL;
1030 T(YAFFS_TRACE_ALWAYS,("yaffs: Mounting %s\n",path));
1033 dev = yaffsfs_FindDevice(path,&dummy);
1038 result = yaffs_GutsInitialise(dev);
1039 if(result == YAFFS_FAIL)
1041 // todo error - mount failed
1042 yaffsfs_SetError(-ENOMEM);
1044 retVal = result ? 0 : -1;
1049 //todo error - already mounted.
1050 yaffsfs_SetError(-EBUSY);
1055 // todo error - no device
1056 yaffsfs_SetError(-ENODEV);
1063 int yaffs_unmount(const char *path)
1066 yaffs_Device *dev=NULL;
1070 dev = yaffsfs_FindDevice(path,&dummy);
1078 yaffs_FlushEntireDeviceCache(dev);
1079 yaffs_CheckpointSave(dev);
1081 for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++)
1083 if(yaffsfs_handle[i].inUse && yaffsfs_handle[i].obj->myDev == dev)
1085 inUse = 1; // the device is in use, can't unmount
1091 yaffs_Deinitialise(dev);
1097 // todo error can't unmount as files are open
1098 yaffsfs_SetError(-EBUSY);
1104 //todo error - not mounted.
1105 yaffsfs_SetError(-EINVAL);
1111 // todo error - no device
1112 yaffsfs_SetError(-ENODEV);
1119 loff_t yaffs_freespace(const char *path)
1122 yaffs_Device *dev=NULL;
1126 dev = yaffsfs_FindDevice(path,&dummy);
1127 if(dev && dev->isMounted)
1129 retVal = yaffs_GetNumberOfFreeChunks(dev);
1130 retVal *= dev->nDataBytesPerChunk;
1135 yaffsfs_SetError(-EINVAL);
1144 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)
1147 yaffsfs_DeviceConfiguration *cfg;
1149 yaffsfs_configurationList = cfgList;
1151 yaffsfs_InitHandles();
1153 cfg = yaffsfs_configurationList;
1155 while(cfg && cfg->prefix && cfg->dev)
1157 cfg->dev->isMounted = 0;
1158 cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback;
1167 // Directory search stuff.
1170 // Directory search context
1172 // NB this is an opaque structure.
1178 yaffs_dirent de; /* directory entry being used by this dsc */
1179 char name[NAME_MAX+1]; /* name of directory being searched */
1180 yaffs_Object *dirObj; /* ptr to directory being searched */
1181 yaffs_Object *nextReturn; /* obj to be returned by next readddir */
1183 struct list_head others;
1184 } yaffsfs_DirectorySearchContext;
1188 static struct list_head search_contexts;
1191 static void yaffsfs_SetDirRewound(yaffsfs_DirectorySearchContext *dsc)
1195 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1199 if( list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1200 dsc->nextReturn = NULL;
1202 dsc->nextReturn = list_entry(dsc->dirObj->variant.directoryVariant.children.next,
1203 yaffs_Object,siblings);
1206 /* Hey someone isn't playing nice! */
1210 static void yaffsfs_DirAdvance(yaffsfs_DirectorySearchContext *dsc)
1214 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1216 if( dsc->nextReturn == NULL ||
1217 list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1218 dsc->nextReturn = NULL;
1220 struct list_head *next = dsc->nextReturn->siblings.next;
1222 if( next == &dsc->dirObj->variant.directoryVariant.children)
1223 dsc->nextReturn = NULL; /* end of list */
1225 dsc->nextReturn = list_entry(next,yaffs_Object,siblings);
1228 /* Hey someone isn't playing nice! */
1232 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj)
1235 struct list_head *i;
1236 yaffsfs_DirectorySearchContext *dsc;
1238 /* if search contexts not initilised then skip */
1239 if(!search_contexts.next)
1242 /* Iteratethrough the directory search contexts.
1243 * If any are the one being removed, then advance the dsc to
1244 * the next one to prevent a hanging ptr.
1246 list_for_each(i, &search_contexts) {
1248 dsc = list_entry(i, yaffsfs_DirectorySearchContext,others);
1249 if(dsc->nextReturn == obj)
1250 yaffsfs_DirAdvance(dsc);
1256 yaffs_DIR *yaffs_opendir(const char *dirname)
1258 yaffs_DIR *dir = NULL;
1259 yaffs_Object *obj = NULL;
1260 yaffsfs_DirectorySearchContext *dsc = NULL;
1264 obj = yaffsfs_FindObject(NULL,dirname,0);
1266 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
1269 dsc = YMALLOC(sizeof(yaffsfs_DirectorySearchContext));
1270 dir = (yaffs_DIR *)dsc;
1273 memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
1274 dsc->magic = YAFFS_MAGIC;
1276 strncpy(dsc->name,dirname,NAME_MAX);
1277 INIT_LIST_HEAD(&dsc->others);
1279 if(!search_contexts.next)
1280 INIT_LIST_HEAD(&search_contexts);
1282 list_add(&dsc->others,&search_contexts);
1283 yaffsfs_SetDirRewound(dsc); }
1292 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp)
1294 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1295 struct yaffs_dirent *retVal = NULL;
1299 if(dsc && dsc->magic == YAFFS_MAGIC){
1300 yaffsfs_SetError(0);
1301 if(dsc->nextReturn){
1302 dsc->de.d_ino = yaffs_GetEquivalentObject(dsc->nextReturn)->objectId;
1303 dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
1304 dsc->de.d_off = dsc->offset++;
1305 yaffs_GetObjectName(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
1306 if(strlen(dsc->de.d_name) == 0)
1308 // this should not happen!
1309 strcpy(dsc->de.d_name,"zz");
1311 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
1313 yaffsfs_DirAdvance(dsc);
1319 yaffsfs_SetError(-EBADF);
1329 void yaffs_rewinddir(yaffs_DIR *dirp)
1331 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1335 yaffsfs_SetDirRewound(dsc);
1341 int yaffs_closedir(yaffs_DIR *dirp)
1343 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1347 list_del(&dsc->others); /* unhook from list */
1353 // end of directory stuff
1356 int yaffs_symlink(const char *oldpath, const char *newpath)
1358 yaffs_Object *parent = NULL;
1362 int mode = 0; // ignore for now
1365 parent = yaffsfs_FindDirectory(NULL,newpath,&name,0);
1366 obj = yaffs_MknodSymLink(parent,name,mode,0,0,oldpath);
1373 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1383 int yaffs_readlink(const char *path, char *buf, int bufsiz)
1385 yaffs_Object *obj = NULL;
1391 obj = yaffsfs_FindObject(NULL,path,0);
1395 yaffsfs_SetError(-ENOENT);
1398 else if(obj->variantType != YAFFS_OBJECT_TYPE_SYMLINK)
1400 yaffsfs_SetError(-EINVAL);
1405 char *alias = obj->variant.symLinkVariant.alias;
1406 memset(buf,0,bufsiz);
1407 strncpy(buf,alias,bufsiz - 1);
1414 int yaffs_link(const char *oldpath, const char *newpath)
1416 // Creates a link called newpath to existing oldpath
1417 yaffs_Object *obj = NULL;
1418 yaffs_Object *target = NULL;
1424 obj = yaffsfs_FindObject(NULL,oldpath,0);
1425 target = yaffsfs_FindObject(NULL,newpath,0);
1429 yaffsfs_SetError(-ENOENT);
1434 yaffsfs_SetError(-EEXIST);
1439 yaffs_Object *newdir = NULL;
1440 yaffs_Object *link = NULL;
1444 newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0);
1448 yaffsfs_SetError(-ENOTDIR);
1451 else if(newdir->myDev != obj->myDev)
1453 yaffsfs_SetError(-EXDEV);
1456 if(newdir && strlen(newname) > 0)
1458 link = yaffs_Link(newdir,newname,obj);
1463 yaffsfs_SetError(-ENOSPC);
1474 int yaffs_mknod(const char *pathname, mode_t mode, dev_t dev);
1476 int yaffs_DumpDevStruct(const char *path)
1480 yaffs_Object *obj = yaffsfs_FindRoot(path,&rest);
1484 yaffs_Device *dev = obj->myDev;
1487 "nPageWrites.......... %d\n"
1488 "nPageReads........... %d\n"
1489 "nBlockErasures....... %d\n"
1490 "nGCCopies............ %d\n"
1491 "garbageCollections... %d\n"
1492 "passiveGarbageColl'ns %d\n"
1496 dev->nBlockErasures,
1498 dev->garbageCollections,
1499 dev->passiveGarbageCollections