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.17 2007-02-14 01:09:06 wookey 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);
43 __u8 inUse:1; // this handle is in use
44 __u8 readOnly:1; // this handle is read only
45 __u8 append:1; // append only
46 __u8 exclusive:1; // exclusive
47 __u32 position; // current position in file
48 yaffs_Object *obj; // the object
52 static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
55 /// Inilitalise handles on start-up.
57 static int yaffsfs_InitHandles(void)
60 for(i = 0; i < YAFFSFS_N_HANDLES; i++)
62 yaffsfs_handle[i].inUse = 0;
63 yaffsfs_handle[i].obj = NULL;
68 yaffsfs_Handle *yaffsfs_GetHandlePointer(int h)
70 if(h < 0 || h >= YAFFSFS_N_HANDLES)
75 return &yaffsfs_handle[h];
78 yaffs_Object *yaffsfs_GetHandleObject(int handle)
80 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle);
92 // Grab a handle (when opening a file)
95 static int yaffsfs_GetHandle(void)
100 for(i = 0; i < YAFFSFS_N_HANDLES; i++)
102 h = yaffsfs_GetHandlePointer(i);
105 // todo bug: should never happen
109 memset(h,0,sizeof(yaffsfs_Handle));
118 // Let go of a handle (when closing a file)
120 static int yaffsfs_PutHandle(int handle)
122 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle);
134 // Stuff to search for a directory from a path
137 int yaffsfs_Match(char a, char b)
143 // yaffsfs_FindDevice
145 // Scan the configuration list to find the root.
146 // Curveballs: Should match paths that end in '/' too
147 // Curveball2 Might have "/x/ and "/x/y". Need to return the longest match
148 static yaffs_Device *yaffsfs_FindDevice(const char *path, char **restOfPath)
150 yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList;
151 const char *leftOver;
153 yaffs_Device *retval = NULL;
155 int longestMatch = -1;
157 // Check all configs, choose the one that:
158 // 1) Actually matches a prefix (ie /a amd /abc will not match
159 // 2) Matches the longest.
160 while(cfg && cfg->prefix && cfg->dev)
166 while(*p && //unmatched part of prefix
167 strcmp(p,"/") && // the rest of the prefix is not / (to catch / at end)
169 yaffsfs_Match(*p,*leftOver))
175 if((!*p || strcmp(p,"/") == 0) && // end of prefix
176 (!*leftOver || *leftOver == '/') && // no more in this path name part
177 (thisMatchLength > longestMatch))
180 *restOfPath = (char *)leftOver;
182 longestMatch = thisMatchLength;
189 static yaffs_Object *yaffsfs_FindRoot(const char *path, char **restOfPath)
194 dev= yaffsfs_FindDevice(path,restOfPath);
195 if(dev && dev->isMounted)
202 static yaffs_Object *yaffsfs_FollowLink(yaffs_Object *obj,int symDepth)
205 while(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
207 char *alias = obj->variant.symLinkVariant.alias;
211 // Starts with a /, need to scan from root up
212 obj = yaffsfs_FindObject(NULL,alias,symDepth++);
216 // Relative to here, so use the parent of the symlink as a start
217 obj = yaffsfs_FindObject(obj->parent,alias,symDepth++);
224 // yaffsfs_FindDirectory
225 // Parse a path to determine the directory and the name within the directory.
227 // eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
228 static yaffs_Object *yaffsfs_DoFindDirectory(yaffs_Object *startDir,const char *path,char **name,int symDepth)
232 char str[YAFFS_MAX_NAME_LENGTH+1];
235 if(symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES)
243 restOfPath = (char *)path;
247 dir = yaffsfs_FindRoot(path,&restOfPath);
253 // curve ball: also throw away surplus '/'
254 // eg. "/ram/x////ff" gets treated the same as "/ram/x/ff"
255 while(*restOfPath == '/')
257 restOfPath++; // get rid of '/'
263 while(*restOfPath && *restOfPath != '/')
265 if (i < YAFFS_MAX_NAME_LENGTH)
267 str[i] = *restOfPath;
276 // got to the end of the string
281 if(strcmp(str,".") == 0)
285 else if(strcmp(str,"..") == 0)
291 dir = yaffs_FindObjectByName(dir,str);
293 while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
296 dir = yaffsfs_FollowLink(dir,symDepth);
300 if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
307 // directory did not exist.
311 static yaffs_Object *yaffsfs_FindDirectory(yaffs_Object *relativeDirectory,const char *path,char **name,int symDepth)
313 return yaffsfs_DoFindDirectory(relativeDirectory,path,name,symDepth);
316 // yaffsfs_FindObject turns a path for an existing object into the object
318 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const char *path,int symDepth)
323 dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
327 return yaffs_FindObjectByName(dir,name);
335 int yaffs_open(const char *path, int oflag, int mode)
337 yaffs_Object *obj = NULL;
338 yaffs_Object *dir = NULL;
341 yaffsfs_Handle *h = NULL;
343 int alreadyExclusive = 0;
346 int errorReported = 0;
351 // todo sanity check oflag (eg. can't have O_TRUNC without WRONLY or RDWR
356 handle = yaffsfs_GetHandle();
361 h = yaffsfs_GetHandlePointer(handle);
364 // try to find the exisiting object
365 obj = yaffsfs_FindObject(NULL,path,0);
367 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
370 obj = yaffsfs_FollowLink(obj,symDepth++);
375 // Check if the object is already in use
376 alreadyOpen = alreadyExclusive = 0;
378 for(i = 0; i <= YAFFSFS_N_HANDLES; i++)
382 yaffsfs_handle[i].inUse &&
383 obj == yaffsfs_handle[i].obj)
386 if(yaffsfs_handle[i].exclusive)
388 alreadyExclusive = 1;
393 if(((oflag & O_EXCL) && alreadyOpen) || alreadyExclusive)
398 // Open should fail if O_CREAT and O_EXCL are specified
399 if((oflag & O_EXCL) && (oflag & O_CREAT))
402 yaffsfs_SetError(-EEXIST);
406 // Check file permissions
407 if( (oflag & (O_RDWR | O_WRONLY)) == 0 && // ie O_RDONLY
408 !(obj->yst_mode & S_IREAD))
413 if( (oflag & O_RDWR) &&
414 !(obj->yst_mode & S_IREAD))
419 if( (oflag & (O_RDWR | O_WRONLY)) &&
420 !(obj->yst_mode & S_IWRITE))
427 else if((oflag & O_CREAT))
429 // Let's see if we can create this file
430 dir = yaffsfs_FindDirectory(NULL,path,&name,0);
433 obj = yaffs_MknodFile(dir,name,mode,0,0);
437 yaffsfs_SetError(-ENOTDIR);
441 if(obj && !openDenied)
445 h->readOnly = (oflag & (O_WRONLY | O_RDWR)) ? 0 : 1;
446 h->append = (oflag & O_APPEND) ? 1 : 0;
447 h->exclusive = (oflag & O_EXCL) ? 1 : 0;
451 if((oflag & O_TRUNC) && !h->readOnly)
454 yaffs_ResizeFile(obj,0);
460 yaffsfs_PutHandle(handle);
463 yaffsfs_SetError(-EACCESS);
476 int yaffs_close(int fd)
478 yaffsfs_Handle *h = NULL;
483 h = yaffsfs_GetHandlePointer(fd);
488 yaffs_FlushFile(h->obj,1);
490 if(h->obj->inUse <= 0 && h->obj->unlinked)
492 yaffs_DeleteFile(h->obj);
494 yaffsfs_PutHandle(fd);
500 yaffsfs_SetError(-EBADF);
509 int yaffs_read(int fd, void *buf, unsigned int nbyte)
511 yaffsfs_Handle *h = NULL;
512 yaffs_Object *obj = NULL;
518 h = yaffsfs_GetHandlePointer(fd);
519 obj = yaffsfs_GetHandleObject(fd);
524 yaffsfs_SetError(-EBADF);
529 if(yaffs_GetObjectFileLength(obj) > pos)
531 maxRead = yaffs_GetObjectFileLength(obj) - pos;
546 nRead = yaffs_ReadDataFromFile(obj,buf,pos,nbyte);
549 h->position = pos + nRead;
566 return (nRead >= 0) ? nRead : -1;
570 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
572 yaffsfs_Handle *h = NULL;
573 yaffs_Object *obj = NULL;
576 int writeThrough = 0;
579 h = yaffsfs_GetHandlePointer(fd);
580 obj = yaffsfs_GetHandleObject(fd);
585 yaffsfs_SetError(-EBADF);
587 else if( h && obj && h->readOnly)
595 pos = yaffs_GetObjectFileLength(obj);
602 nWritten = yaffs_WriteDataToFile(obj,buf,pos,nbyte,writeThrough);
606 h->position = pos + nWritten;
618 return (nWritten >= 0) ? nWritten : -1;
622 int yaffs_truncate(int fd, off_t newSize)
624 yaffsfs_Handle *h = NULL;
625 yaffs_Object *obj = NULL;
629 h = yaffsfs_GetHandlePointer(fd);
630 obj = yaffsfs_GetHandleObject(fd);
635 yaffsfs_SetError(-EBADF);
640 result = yaffs_ResizeFile(obj,newSize);
645 return (result) ? 0 : -1;
649 off_t yaffs_lseek(int fd, off_t offset, int whence)
651 yaffsfs_Handle *h = NULL;
652 yaffs_Object *obj = NULL;
657 h = yaffsfs_GetHandlePointer(fd);
658 obj = yaffsfs_GetHandleObject(fd);
663 yaffsfs_SetError(-EBADF);
665 else if(whence == SEEK_SET)
672 else if(whence == SEEK_CUR)
674 if( (h->position + offset) >= 0)
676 pos = (h->position + offset);
679 else if(whence == SEEK_END)
681 fSize = yaffs_GetObjectFileLength(obj);
682 if(fSize >= 0 && (fSize + offset) >= 0)
684 pos = fSize + offset;
704 int yaffsfs_DoUnlink(const char *path,int isDirectory)
706 yaffs_Object *dir = NULL;
707 yaffs_Object *obj = NULL;
709 int result = YAFFS_FAIL;
713 obj = yaffsfs_FindObject(NULL,path,0);
714 dir = yaffsfs_FindDirectory(NULL,path,&name,0);
717 yaffsfs_SetError(-ENOTDIR);
721 yaffsfs_SetError(-ENOENT);
723 else if(!isDirectory && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
725 yaffsfs_SetError(-EISDIR);
727 else if(isDirectory && obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
729 yaffsfs_SetError(-ENOTDIR);
733 result = yaffs_Unlink(dir,name);
735 if(result == YAFFS_FAIL && isDirectory)
737 yaffsfs_SetError(-ENOTEMPTY);
745 return (result == YAFFS_FAIL) ? -1 : 0;
747 int yaffs_rmdir(const char *path)
749 return yaffsfs_DoUnlink(path,1);
752 int yaffs_unlink(const char *path)
754 return yaffsfs_DoUnlink(path,0);
757 int yaffs_rename(const char *oldPath, const char *newPath)
759 yaffs_Object *olddir = NULL;
760 yaffs_Object *newdir = NULL;
761 yaffs_Object *obj = NULL;
764 int result= YAFFS_FAIL;
765 int renameAllowed = 1;
769 olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
770 newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
771 obj = yaffsfs_FindObject(NULL,oldPath,0);
773 if(!olddir || !newdir || !obj)
776 yaffsfs_SetError(-EBADF);
779 else if(olddir->myDev != newdir->myDev)
781 // oops must be on same device
783 yaffsfs_SetError(-EXDEV);
786 else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
788 // It is a directory, check that it is not being renamed to
789 // being its own decendent.
790 // Do this by tracing from the new directory back to the root, checking for obj
792 yaffs_Object *xx = newdir;
794 while( renameAllowed && xx)
802 if(!renameAllowed) yaffsfs_SetError(-EACCESS);
807 result = yaffs_RenameObject(olddir,oldname,newdir,newname);
812 return (result == YAFFS_FAIL) ? -1 : 0;
816 static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf)
822 obj = yaffs_GetEquivalentObject(obj);
827 buf->st_dev = (int)obj->myDev->genericDevice;
828 buf->st_ino = obj->objectId;
829 buf->st_mode = obj->yst_mode & ~S_IFMT; // clear out file type bits
831 if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
833 buf->st_mode |= S_IFDIR;
835 else if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
837 buf->st_mode |= S_IFLNK;
839 else if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
841 buf->st_mode |= S_IFREG;
844 buf->st_nlink = yaffs_GetObjectLinkCount(obj);
847 buf->st_rdev = obj->yst_rdev;
848 buf->st_size = yaffs_GetObjectFileLength(obj);
849 buf->st_blksize = obj->myDev->nDataBytesPerChunk;
850 buf->st_blocks = (buf->st_size + buf->st_blksize -1)/buf->st_blksize;
851 buf->yst_atime = obj->yst_atime;
852 buf->yst_ctime = obj->yst_ctime;
853 buf->yst_mtime = obj->yst_mtime;
859 static int yaffsfs_DoStatOrLStat(const char *path, struct yaffs_stat *buf,int doLStat)
866 obj = yaffsfs_FindObject(NULL,path,0);
870 obj = yaffsfs_FollowLink(obj,0);
875 retVal = yaffsfs_DoStat(obj,buf);
879 // todo error not found
880 yaffsfs_SetError(-ENOENT);
889 int yaffs_stat(const char *path, struct yaffs_stat *buf)
891 return yaffsfs_DoStatOrLStat(path,buf,0);
894 int yaffs_lstat(const char *path, struct yaffs_stat *buf)
896 return yaffsfs_DoStatOrLStat(path,buf,1);
899 int yaffs_fstat(int fd, struct yaffs_stat *buf)
906 obj = yaffsfs_GetHandleObject(fd);
910 retVal = yaffsfs_DoStat(obj,buf);
915 yaffsfs_SetError(-EBADF);
923 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
929 obj = yaffs_GetEquivalentObject(obj);
934 obj->yst_mode = mode;
936 result = yaffs_FlushFile(obj,0);
939 return result == YAFFS_OK ? 0 : -1;
943 int yaffs_chmod(const char *path, mode_t mode)
950 obj = yaffsfs_FindObject(NULL,path,0);
954 retVal = yaffsfs_DoChMod(obj,mode);
958 // todo error not found
959 yaffsfs_SetError(-ENOENT);
969 int yaffs_fchmod(int fd, mode_t mode)
976 obj = yaffsfs_GetHandleObject(fd);
980 retVal = yaffsfs_DoChMod(obj,mode);
985 yaffsfs_SetError(-EBADF);
994 int yaffs_mkdir(const char *path, mode_t mode)
996 yaffs_Object *parent = NULL;
997 yaffs_Object *dir = NULL;
1002 parent = yaffsfs_FindDirectory(NULL,path,&name,0);
1004 dir = yaffs_MknodDirectory(parent,name,mode,0,0);
1011 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1020 int yaffs_mount(const char *path)
1023 int result=YAFFS_FAIL;
1024 yaffs_Device *dev=NULL;
1027 T(YAFFS_TRACE_ALWAYS,("yaffs: Mounting %s\n",path));
1030 dev = yaffsfs_FindDevice(path,&dummy);
1035 result = yaffs_GutsInitialise(dev);
1036 if(result == YAFFS_FAIL)
1038 // todo error - mount failed
1039 yaffsfs_SetError(-ENOMEM);
1041 retVal = result ? 0 : -1;
1046 //todo error - already mounted.
1047 yaffsfs_SetError(-EBUSY);
1052 // todo error - no device
1053 yaffsfs_SetError(-ENODEV);
1060 int yaffs_unmount(const char *path)
1063 yaffs_Device *dev=NULL;
1067 dev = yaffsfs_FindDevice(path,&dummy);
1075 yaffs_FlushEntireDeviceCache(dev);
1076 yaffs_CheckpointSave(dev);
1078 for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++)
1080 if(yaffsfs_handle[i].inUse && yaffsfs_handle[i].obj->myDev == dev)
1082 inUse = 1; // the device is in use, can't unmount
1088 yaffs_Deinitialise(dev);
1094 // todo error can't unmount as files are open
1095 yaffsfs_SetError(-EBUSY);
1101 //todo error - not mounted.
1102 yaffsfs_SetError(-EINVAL);
1108 // todo error - no device
1109 yaffsfs_SetError(-ENODEV);
1116 loff_t yaffs_freespace(const char *path)
1119 yaffs_Device *dev=NULL;
1123 dev = yaffsfs_FindDevice(path,&dummy);
1124 if(dev && dev->isMounted)
1126 retVal = yaffs_GetNumberOfFreeChunks(dev);
1127 retVal *= dev->nDataBytesPerChunk;
1132 yaffsfs_SetError(-EINVAL);
1141 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList)
1144 yaffsfs_DeviceConfiguration *cfg;
1146 yaffsfs_configurationList = cfgList;
1148 yaffsfs_InitHandles();
1150 cfg = yaffsfs_configurationList;
1152 while(cfg && cfg->prefix && cfg->dev)
1154 cfg->dev->isMounted = 0;
1155 cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback;
1164 // Directory search stuff.
1167 // Directory search context
1169 // NB this is an opaque structure.
1175 yaffs_dirent de; /* directory entry being used by this dsc */
1176 char name[NAME_MAX+1]; /* name of directory being searched */
1177 yaffs_Object *dirObj; /* ptr to directory being searched */
1178 yaffs_Object *nextReturn; /* obj to be returned by next readddir */
1180 struct list_head others;
1181 } yaffsfs_DirectorySearchContext;
1185 static struct list_head search_contexts;
1188 static void yaffsfs_SetDirRewound(yaffsfs_DirectorySearchContext *dsc)
1192 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1196 if( list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1197 dsc->nextReturn = NULL;
1199 dsc->nextReturn = list_entry(dsc->dirObj->variant.directoryVariant.children.next,
1200 yaffs_Object,siblings);
1203 /* Hey someone isn't playing nice! */
1207 static void yaffsfs_DirAdvance(yaffsfs_DirectorySearchContext *dsc)
1211 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
1213 if( dsc->nextReturn == NULL ||
1214 list_empty(&dsc->dirObj->variant.directoryVariant.children)){
1215 dsc->nextReturn = NULL;
1217 struct list_head *next = dsc->nextReturn->siblings.next;
1219 if( next == &dsc->dirObj->variant.directoryVariant.children)
1220 dsc->nextReturn = NULL; /* end of list */
1222 dsc->nextReturn = list_entry(next,yaffs_Object,siblings);
1225 /* Hey someone isn't playing nice! */
1229 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj)
1232 struct list_head *i;
1233 yaffsfs_DirectorySearchContext *dsc;
1235 /* if search contexts not initilised then skip */
1236 if(!search_contexts.next)
1239 /* Iteratethrough the directory search contexts.
1240 * If any are the one being removed, then advance the dsc to
1241 * the next one to prevent a hanging ptr.
1243 list_for_each(i, &search_contexts) {
1245 dsc = list_entry(i, yaffsfs_DirectorySearchContext,others);
1246 if(dsc->nextReturn == obj)
1247 yaffsfs_DirAdvance(dsc);
1253 yaffs_DIR *yaffs_opendir(const char *dirname)
1255 yaffs_DIR *dir = NULL;
1256 yaffs_Object *obj = NULL;
1257 yaffsfs_DirectorySearchContext *dsc = NULL;
1261 obj = yaffsfs_FindObject(NULL,dirname,0);
1263 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)
1266 dsc = YMALLOC(sizeof(yaffsfs_DirectorySearchContext));
1267 dir = (yaffs_DIR *)dsc;
1270 memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
1271 dsc->magic = YAFFS_MAGIC;
1273 strncpy(dsc->name,dirname,NAME_MAX);
1274 INIT_LIST_HEAD(&dsc->others);
1276 if(!search_contexts.next)
1277 INIT_LIST_HEAD(&search_contexts);
1279 list_add(&dsc->others,&search_contexts);
1280 yaffsfs_SetDirRewound(dsc); }
1289 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp)
1291 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1292 struct yaffs_dirent *retVal = NULL;
1296 if(dsc && dsc->magic == YAFFS_MAGIC){
1297 yaffsfs_SetError(0);
1298 if(dsc->nextReturn){
1299 dsc->de.d_ino = yaffs_GetEquivalentObject(dsc->nextReturn)->objectId;
1300 dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
1301 dsc->de.d_off = dsc->offset++;
1302 yaffs_GetObjectName(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
1303 if(strlen(dsc->de.d_name) == 0)
1305 // this should not happen!
1306 strcpy(dsc->de.d_name,"zz");
1308 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
1310 yaffsfs_DirAdvance(dsc);
1316 yaffsfs_SetError(-EBADF);
1326 void yaffs_rewinddir(yaffs_DIR *dirp)
1328 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1332 yaffsfs_SetDirRewound(dsc);
1338 int yaffs_closedir(yaffs_DIR *dirp)
1340 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp;
1344 list_del(&dsc->others); /* unhook from list */
1350 // end of directory stuff
1353 int yaffs_symlink(const char *oldpath, const char *newpath)
1355 yaffs_Object *parent = NULL;
1359 int mode = 0; // ignore for now
1362 parent = yaffsfs_FindDirectory(NULL,newpath,&name,0);
1363 obj = yaffs_MknodSymLink(parent,name,mode,0,0,oldpath);
1370 yaffsfs_SetError(-ENOSPC); // just assume no space for now
1380 int yaffs_readlink(const char *path, char *buf, int bufsiz)
1382 yaffs_Object *obj = NULL;
1388 obj = yaffsfs_FindObject(NULL,path,0);
1392 yaffsfs_SetError(-ENOENT);
1395 else if(obj->variantType != YAFFS_OBJECT_TYPE_SYMLINK)
1397 yaffsfs_SetError(-EINVAL);
1402 char *alias = obj->variant.symLinkVariant.alias;
1403 memset(buf,0,bufsiz);
1404 strncpy(buf,alias,bufsiz - 1);
1411 int yaffs_link(const char *oldpath, const char *newpath)
1413 // Creates a link called newpath to existing oldpath
1414 yaffs_Object *obj = NULL;
1415 yaffs_Object *target = NULL;
1421 obj = yaffsfs_FindObject(NULL,oldpath,0);
1422 target = yaffsfs_FindObject(NULL,newpath,0);
1426 yaffsfs_SetError(-ENOENT);
1431 yaffsfs_SetError(-EEXIST);
1436 yaffs_Object *newdir = NULL;
1437 yaffs_Object *link = NULL;
1441 newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0);
1445 yaffsfs_SetError(-ENOTDIR);
1448 else if(newdir->myDev != obj->myDev)
1450 yaffsfs_SetError(-EXDEV);
1453 if(newdir && strlen(newname) > 0)
1455 link = yaffs_Link(newdir,newname,obj);
1460 yaffsfs_SetError(-ENOSPC);
1471 int yaffs_mknod(const char *pathname, mode_t mode, dev_t dev);
1473 int yaffs_DumpDevStruct(const char *path)
1477 yaffs_Object *obj = yaffsfs_FindRoot(path,&rest);
1481 yaffs_Device *dev = obj->myDev;
1484 "nPageWrites.......... %d\n"
1485 "nPageReads........... %d\n"
1486 "nBlockErasures....... %d\n"
1487 "nGCCopies............ %d\n"
1488 "garbageCollections... %d\n"
1489 "passiveGarbageColl'ns %d\n"
1493 dev->nBlockErasures,
1495 dev->garbageCollections,
1496 dev->passiveGarbageCollections