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.15 2006-11-17 01:43:48 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);
734 result = yaffs_Unlink(dir,name);
736 if(result == YAFFS_FAIL && isDirectory)
738 yaffsfs_SetError(-ENOTEMPTY);
746 return (result == YAFFS_FAIL) ? -1 : 0;
748 int yaffs_rmdir(const char *path)
750 return yaffsfs_DoUnlink(path,1);
753 int yaffs_unlink(const char *path)
755 return yaffsfs_DoUnlink(path,0);
758 int yaffs_rename(const char *oldPath, const char *newPath)
760 yaffs_Object *olddir = NULL;
761 yaffs_Object *newdir = NULL;
762 yaffs_Object *obj = NULL;
765 int result= YAFFS_FAIL;
766 int renameAllowed = 1;
770 olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
771 newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
772 obj = yaffsfs_FindObject(NULL,oldPath,0);
774 if(!olddir || !newdir || !obj)
777 yaffsfs_SetError(-EBADF);
780 else if(olddir->myDev != newdir->myDev)
782 // oops must be on same device
784 yaffsfs_SetError(-EXDEV);
787 else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
789 // It is a directory, check that it is not being renamed to
790 // being its own decendent.
791 // Do this by tracing from the new directory back to the root, checking for obj
793 yaffs_Object *xx = newdir;
795 while( renameAllowed && xx)
803 if(!renameAllowed) yaffsfs_SetError(-EACCESS);
808 result = yaffs_RenameObject(olddir,oldname,newdir,newname);
813 return (result == YAFFS_FAIL) ? -1 : 0;
817 static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
823 obj = yaffs_GetEquivalentObject(obj);
828 buf->st_dev = (int)obj->myDev->genericDevice;
829 buf->st_ino = obj->objectId;
830 buf->st_mode = obj->yst_mode & ~S_IFMT; // clear out file type bits
832 if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
834 buf->st_mode |= S_IFDIR;
836 else if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
838 buf->st_mode |= S_IFLNK;
840 else if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
842 buf->st_mode |= S_IFREG;
845 buf->st_nlink = yaffs_GetObjectLinkCount(obj);
848 buf->st_rdev = obj->yst_rdev;
849 buf->st_size = yaffs_GetObjectFileLength(obj);
850 buf->st_blksize = obj->myDev->nDataBytesPerChunk;
851 buf->st_blocks = (buf->st_size + buf->st_blksize -1)/buf->st_blksize;
852 buf->yst_atime = obj->yst_atime;
853 buf->yst_ctime = obj->yst_ctime;
854 buf->yst_mtime = obj->yst_mtime;
860 static int yaffsfs_DoStatOrLStat(const char *path, struct yaffs_stat *buf,int doLStat)
867 obj = yaffsfs_FindObject(NULL,path,0);
871 obj = yaffsfs_FollowLink(obj,0);
876 retVal = yaffsfs_DoStat(obj,buf);
880 // todo error not found
881 yaffsfs_SetError(-ENOENT);
890 int yaffs_stat(const char *path, struct yaffs_stat *buf)
892 return yaffsfs_DoStatOrLStat(path,buf,0);
895 int yaffs_lstat(const char *path, struct yaffs_stat *buf)
897 return yaffsfs_DoStatOrLStat(path,buf,1);
900 int yaffs_fstat(int fd, struct yaffs_stat *buf)
907 obj = yaffsfs_GetHandleObject(fd);
911 retVal = yaffsfs_DoStat(obj,buf);
916 yaffsfs_SetError(-EBADF);
924 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
930 obj = yaffs_GetEquivalentObject(obj);
935 obj->yst_mode = mode;
937 result = yaffs_FlushFile(obj,0);
940 return result == YAFFS_OK ? 0 : -1;
944 int yaffs_chmod(const char *path, mode_t mode)
951 obj = yaffsfs_FindObject(NULL,path,0);
955 retVal = yaffsfs_DoChMod(obj,mode);
959 // todo error not found
960 yaffsfs_SetError(-ENOENT);
970 int yaffs_fchmod(int fd, mode_t mode)
977 obj = yaffsfs_GetHandleObject(fd);
981 retVal = yaffsfs_DoChMod(obj,mode);
986 yaffsfs_SetError(-EBADF);
995 int yaffs_mkdir(const char *path, mode_t mode)
997 yaffs_Object *parent = NULL;
998 yaffs_Object *dir = NULL;
1003 parent = yaffsfs_FindDirectory(NULL,path,&name,0);
1005 dir = yaffs_MknodDirectory(parent,name,mode,0,0);
1012 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1021 int yaffs_mount(const char *path)
1024 int result=YAFFS_FAIL;
1025 yaffs_Device *dev=NULL;
1028 T(YAFFS_TRACE_ALWAYS,("yaffs: Mounting %s\n",path));
1031 dev = yaffsfs_FindDevice(path,&dummy);
1036 result = yaffs_GutsInitialise(dev);
1037 if(result == YAFFS_FAIL)
1039 // todo error - mount failed
1040 yaffsfs_SetError(-ENOMEM);
1042 retVal = result ? 0 : -1;
1047 //todo error - already mounted.
1048 yaffsfs_SetError(-EBUSY);
1053 // todo error - no device
1054 yaffsfs_SetError(-ENODEV);
1061 int yaffs_unmount(const char *path)
1064 yaffs_Device *dev=NULL;
1068 dev = yaffsfs_FindDevice(path,&dummy);
1076 yaffs_FlushEntireDeviceCache(dev);
1077 yaffs_CheckpointSave(dev);
1079 for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++)
1081 if(yaffsfs_handle[i].inUse && yaffsfs_handle[i].obj->myDev == dev)
1083 inUse = 1; // the device is in use, can't unmount
1089 yaffs_Deinitialise(dev);
1095 // todo error can't unmount as files are open
1096 yaffsfs_SetError(-EBUSY);
1102 //todo error - not mounted.
1103 yaffsfs_SetError(-EINVAL);
1109 // todo error - no device
1110 yaffsfs_SetError(-ENODEV);
1117 loff_t yaffs_freespace(const char *path)
1120 yaffs_Device *dev=NULL;
1124 dev = yaffsfs_FindDevice(path,&dummy);
1125 if(dev && dev->isMounted)
1127 retVal = yaffs_GetNumberOfFreeChunks(dev);
1128 retVal *= dev->nDataBytesPerChunk;
1133 yaffsfs_SetError(-EINVAL);
1142 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)
1145 yaffsfs_DeviceConfiguration *cfg;
1147 yaffsfs_configurationList = cfgList;
1149 yaffsfs_InitHandles();
1151 cfg = yaffsfs_configurationList;
1153 while(cfg && cfg->prefix && cfg->dev)
1155 cfg->dev->isMounted = 0;
1156 cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback;
1165 // Directory search stuff.
1168 // Directory search context
1170 // NB this is an opaque structure.
1176 yaffs_dirent de; /* directory entry being used by this dsc */
1177 char name[NAME_MAX+1]; /* name of directory being searched */
1178 yaffs_Object *dirObj; /* ptr to directory being searched */
1179 yaffs_Object *nextReturn; /* obj to be returned by next readddir */
1181 struct list_head others;
1182 } yaffsfs_DirectorySearchContext;
1186 static struct list_head search_contexts;
1189 static void yaffsfs_SetDirRewound(yaffsfs_DirectorySearchContext *dsc)
1193 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1197 if( list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1198 dsc->nextReturn = NULL;
1200 dsc->nextReturn = list_entry(dsc->dirObj->variant.directoryVariant.children.next,
1201 yaffs_Object,siblings);
1204 /* Hey someone isn't playing nice! */
1208 static void yaffsfs_DirAdvance(yaffsfs_DirectorySearchContext *dsc)
1212 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1214 if( dsc->nextReturn == NULL ||
1215 list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1216 dsc->nextReturn = NULL;
1218 struct list_head *next = dsc->nextReturn->siblings.next;
1220 if( next == &dsc->dirObj->variant.directoryVariant.children)
1221 dsc->nextReturn = NULL; /* end of list */
1223 dsc->nextReturn = list_entry(next,yaffs_Object,siblings);
1226 /* Hey someone isn't playing nice! */
1230 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj)
1233 struct list_head *i;
1234 yaffsfs_DirectorySearchContext *dsc;
1236 /* if search contexts not initilised then skip */
1237 if(!search_contexts.next)
1240 /* Iteratethrough the directory search contexts.
1241 * If any are the one being removed, then advance the dsc to
1242 * the next one to prevent a hanging ptr.
1244 list_for_each(i, &search_contexts) {
1246 dsc = list_entry(i, yaffsfs_DirectorySearchContext,others);
1247 if(dsc->nextReturn == obj)
1248 yaffsfs_DirAdvance(dsc);
1254 yaffs_DIR *yaffs_opendir(const char *dirname)
1256 yaffs_DIR *dir = NULL;
1257 yaffs_Object *obj = NULL;
1258 yaffsfs_DirectorySearchContext *dsc = NULL;
1262 obj = yaffsfs_FindObject(NULL,dirname,0);
1264 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
1267 dsc = YMALLOC(sizeof(yaffsfs_DirectorySearchContext));
1268 dir = (yaffs_DIR *)dsc;
1271 memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
1272 dsc->magic = YAFFS_MAGIC;
1274 strncpy(dsc->name,dirname,NAME_MAX);
1275 INIT_LIST_HEAD(&dsc->others);
1277 if(!search_contexts.next)
1278 INIT_LIST_HEAD(&search_contexts);
1280 list_add(&dsc->others,&search_contexts);
1281 yaffsfs_SetDirRewound(dsc); }
1290 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp)
1292 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1293 struct yaffs_dirent *retVal = NULL;
1297 if(dsc && dsc->magic == YAFFS_MAGIC){
1298 yaffsfs_SetError(0);
1299 if(dsc->nextReturn){
1300 dsc->de.d_ino = yaffs_GetEquivalentObject(dsc->nextReturn)->objectId;
1301 dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
1302 dsc->de.d_off = dsc->offset++;
1303 yaffs_GetObjectName(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
1304 if(strlen(dsc->de.d_name) == 0)
1306 // this should not happen!
1307 strcpy(dsc->de.d_name,"zz");
1309 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
1311 yaffsfs_DirAdvance(dsc);
1317 yaffsfs_SetError(-EBADF);
1327 void yaffs_rewinddir(yaffs_DIR *dirp)
1329 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1333 yaffsfs_SetDirRewound(dsc);
1339 int yaffs_closedir(yaffs_DIR *dirp)
1341 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1345 list_del(&dsc->others); /* unhook from list */
1351 // end of directory stuff
1354 int yaffs_symlink(const char *oldpath, const char *newpath)
1356 yaffs_Object *parent = NULL;
1360 int mode = 0; // ignore for now
1363 parent = yaffsfs_FindDirectory(NULL,newpath,&name,0);
1364 obj = yaffs_MknodSymLink(parent,name,mode,0,0,oldpath);
1371 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1381 int yaffs_readlink(const char *path, char *buf, int bufsiz)
1383 yaffs_Object *obj = NULL;
1389 obj = yaffsfs_FindObject(NULL,path,0);
1393 yaffsfs_SetError(-ENOENT);
1396 else if(obj->variantType != YAFFS_OBJECT_TYPE_SYMLINK)
1398 yaffsfs_SetError(-EINVAL);
1403 char *alias = obj->variant.symLinkVariant.alias;
1404 memset(buf,0,bufsiz);
1405 strncpy(buf,alias,bufsiz - 1);
1412 int yaffs_link(const char *oldpath, const char *newpath)
1414 // Creates a link called newpath to existing oldpath
1415 yaffs_Object *obj = NULL;
1416 yaffs_Object *target = NULL;
1422 obj = yaffsfs_FindObject(NULL,oldpath,0);
1423 target = yaffsfs_FindObject(NULL,newpath,0);
1427 yaffsfs_SetError(-ENOENT);
1432 yaffsfs_SetError(-EEXIST);
1437 yaffs_Object *newdir = NULL;
1438 yaffs_Object *link = NULL;
1442 newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0);
1446 yaffsfs_SetError(-ENOTDIR);
1449 else if(newdir->myDev != obj->myDev)
1451 yaffsfs_SetError(-EXDEV);
1454 if(newdir && strlen(newname) > 0)
1456 link = yaffs_Link(newdir,newname,obj);
1461 yaffsfs_SetError(-ENOSPC);
1472 int yaffs_mknod(const char *pathname, mode_t mode, dev_t dev);
1474 int yaffs_DumpDevStruct(const char *path)
1478 yaffs_Object *obj = yaffsfs_FindRoot(path,&rest);
1482 yaffs_Device *dev = obj->myDev;
1485 "nPageWrites.......... %d\n"
1486 "nPageReads........... %d\n"
1487 "nBlockErasures....... %d\n"
1488 "nGCCopies............ %d\n"
1489 "garbageCollections... %d\n"
1490 "passiveGarbageColl'ns %d\n"
1494 dev->nBlockErasures,
1496 dev->garbageCollections,
1497 dev->passiveGarbageCollections