2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 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"
18 #include "yaffs_trace.h"
22 #define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5
25 #define NULL ((void *)0)
28 #define ROOT_DIR(dev) (((dev) && (dev)->is_mounted) ? (dev)->root_dir : NULL)
30 /* YAFFSFS_RW_SIZE must be a power of 2 */
31 #define YAFFSFS_RW_SHIFT (13)
32 #define YAFFSFS_RW_SIZE (1<<YAFFSFS_RW_SHIFT)
34 /* Some forward references */
35 static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relativeDirectory,
37 int symDepth, int getEquiv,
38 struct yaffs_obj **dirOut,
39 int *notDir, int *loop);
41 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj);
42 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(
43 struct yaffs_obj *reldir, const YCHAR *dirname);
44 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirent);
46 unsigned int yaffs_wr_attempts;
50 * There are open inodes in struct yaffsfs_Inode.
51 * There are open file descriptors in yaffsfs_FileDes.
52 * There are open handles in yaffsfs_FileDes.
54 * Things are structured this way to be like the Linux VFS model
55 * so that interactions with the yaffs guts calls are similar.
56 * That means more common code paths and less special code.
57 * That means better testing etc.
59 * We have 3 layers because:
60 * A handle is different than an fd because you can use dup()
61 * to create a new handle that accesses the *same* fd. The two
62 * handles will use the same offset (part of the fd). We only close
63 * down the fd when there are no more handles accessing it.
65 * More than one fd can currently access one file, but each fd
66 * has its own permsiions and offset.
69 struct yaffsfs_Inode {
70 int count; /* Number of handles accessing this inode */
71 struct yaffs_obj *iObj;
75 struct yaffsfs_DirSearchContext {
76 struct yaffs_dirent de; /* directory entry */
77 YCHAR name[NAME_MAX + 1]; /* name of directory being searched */
78 struct yaffs_obj *dirObj; /* ptr to directory being searched */
79 struct yaffs_obj *nextReturn; /* obj returned by next readddir */
80 struct list_head others;
85 struct yaffsfs_FileDes {
86 u8 isDir:1; /* This s a directory */
92 s32 inodeId:12; /* Index to corresponding yaffsfs_Inode */
93 s32 handleCount:10; /* Number of handles for this fd */
95 Y_LOFF_T position; /* current position in file */
100 struct yaffsfs_Handle {
106 static struct yaffsfs_DirSearchContext yaffsfs_dsc[YAFFSFS_N_DSC];
107 static struct yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES];
108 static struct yaffsfs_FileDes yaffsfs_fd[YAFFSFS_N_HANDLES];
109 static struct yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
111 static int yaffsfs_handlesInitialised;
113 unsigned yaffs_set_trace(unsigned tm)
115 yaffs_trace_mask = tm;
116 return yaffs_trace_mask;
119 unsigned yaffs_get_trace(void)
121 return yaffs_trace_mask;
126 * Inilitalise handle management on start-up.
129 static void yaffsfs_InitHandles(void)
133 if (yaffsfs_handlesInitialised)
136 yaffsfs_handlesInitialised = 1;
138 memset(yaffsfs_inode, 0, sizeof(yaffsfs_inode));
139 memset(yaffsfs_fd, 0, sizeof(yaffsfs_fd));
140 memset(yaffsfs_handle, 0, sizeof(yaffsfs_handle));
141 memset(yaffsfs_dsc, 0, sizeof(yaffsfs_dsc));
143 for (i = 0; i < YAFFSFS_N_HANDLES; i++)
144 yaffsfs_fd[i].inodeId = -1;
145 for (i = 0; i < YAFFSFS_N_HANDLES; i++)
146 yaffsfs_handle[i].fdId = -1;
149 static struct yaffsfs_Handle *yaffsfs_HandleToPointer(int h)
151 if (h >= 0 && h < YAFFSFS_N_HANDLES)
152 return &yaffsfs_handle[h];
156 static struct yaffsfs_FileDes *yaffsfs_HandleToFileDes(int handle)
158 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
160 if (h && h->useCount > 0 && h->fdId >= 0 && h->fdId < YAFFSFS_N_HANDLES)
161 return &yaffsfs_fd[h->fdId];
166 static struct yaffsfs_Inode *yaffsfs_HandleToInode(int handle)
168 struct yaffsfs_FileDes *fd = yaffsfs_HandleToFileDes(handle);
170 if (fd && fd->handleCount > 0 &&
171 fd->inodeId >= 0 && fd->inodeId < YAFFSFS_N_HANDLES)
172 return &yaffsfs_inode[fd->inodeId];
177 static struct yaffs_obj *yaffsfs_HandleToObject(int handle)
179 struct yaffsfs_Inode *in = yaffsfs_HandleToInode(handle);
188 * yaffsfs_FindInodeIdForObject
189 * Find the inode entry for an object, if it exists.
192 static int yaffsfs_FindInodeIdForObject(struct yaffs_obj *obj)
198 obj = yaffs_get_equivalent_obj(obj);
200 /* Look for it in open inode table */
201 for (i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++) {
202 if (yaffsfs_inode[i].iObj == obj)
209 * yaffsfs_GetInodeIdForObject
210 * Grab an inode entry when opening a new inode.
212 static int yaffsfs_GetInodeIdForObject(struct yaffs_obj *obj)
216 struct yaffsfs_Inode *in = NULL;
219 obj = yaffs_get_equivalent_obj(obj);
221 ret = yaffsfs_FindInodeIdForObject(obj);
223 for (i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++) {
224 if (!yaffsfs_inode[i].iObj)
229 in = &yaffsfs_inode[ret];
239 static int yaffsfs_CountHandles(struct yaffs_obj *obj)
241 int i = yaffsfs_FindInodeIdForObject(obj);
244 return yaffsfs_inode[i].count;
249 static void yaffsfs_ReleaseInode(struct yaffsfs_Inode *in)
251 struct yaffs_obj *obj;
254 obj->my_inode = NULL;
261 static void yaffsfs_PutInode(int inodeId)
263 if (inodeId >= 0 && inodeId < YAFFSFS_N_HANDLES) {
264 struct yaffsfs_Inode *in = &yaffsfs_inode[inodeId];
266 if (in->count <= 0) {
267 yaffsfs_ReleaseInode(in);
273 static int yaffsfs_NewHandle(struct yaffsfs_Handle **hptr)
276 struct yaffsfs_Handle *h;
278 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
279 h = &yaffsfs_handle[i];
280 if (h->useCount < 1) {
281 memset(h, 0, sizeof(struct yaffsfs_Handle));
292 static int yaffsfs_NewHandleAndFileDes(void)
295 struct yaffsfs_FileDes *fd;
296 struct yaffsfs_Handle *h = NULL;
297 int handle = yaffsfs_NewHandle(&h);
302 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
304 if (fd->handleCount < 1) {
305 memset(fd, 0, sizeof(struct yaffsfs_FileDes));
313 /* Dump the handle because we could not get a fd */
320 * Increase use of handle when reading/writing a file
321 * Also gets the file descriptor.
324 static int yaffsfs_GetHandle(int handle)
326 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
328 if (h && h->useCount > 0) {
337 * Let go of a handle when closing a file or aborting an open or
338 * ending a read or write.
341 static int yaffsfs_PutFileDes(int fdId)
343 struct yaffsfs_FileDes *fd;
345 if (fdId >= 0 && fdId < YAFFSFS_N_HANDLES) {
346 fd = &yaffsfs_fd[fdId];
348 if (fd->handleCount < 1) {
350 yaffsfs_closedir_no_lock(fd->v.dir);
351 if (fd->inodeId >= 0) {
352 yaffsfs_PutInode(fd->inodeId);
360 static int yaffsfs_PutHandle(int handle)
362 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
364 if (h && h->useCount > 0) {
366 if (h->useCount < 1) {
367 yaffsfs_PutFileDes(h->fdId);
375 static void yaffsfs_BreakDeviceHandles(struct yaffs_dev *dev)
377 struct yaffsfs_FileDes *fd;
378 struct yaffsfs_Handle *h;
379 struct yaffs_obj *obj;
381 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
382 h = yaffsfs_HandleToPointer(i);
383 fd = yaffsfs_HandleToFileDes(i);
384 obj = yaffsfs_HandleToObject(i);
385 if (h && h->useCount > 0) {
389 if (fd && fd->handleCount > 0 && obj && obj->my_dev == dev) {
391 yaffsfs_PutInode(fd->inodeId);
398 * Stuff to handle names.
400 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
401 #ifndef CONFIG_YAFFS_WINCE
402 static int yaffs_toupper(YCHAR a)
404 if (a >= 'a' && a <= 'z')
405 return (a - 'a') + 'A';
411 static int yaffsfs_Match(YCHAR a, YCHAR b)
413 return (yaffs_toupper(a) == yaffs_toupper(b));
416 static int yaffsfs_Match(YCHAR a, YCHAR b)
423 static int yaffsfs_IsPathDivider(YCHAR ch)
425 const YCHAR *str = YAFFS_PATH_DIVIDERS;
436 static int yaffsfs_CheckNameLength(const YCHAR *name)
440 int nameLength = yaffs_strnlen(name, YAFFS_MAX_NAME_LENGTH + 1);
442 if (nameLength == 0) {
443 yaffsfs_SetError(-ENOENT);
445 } else if (nameLength > YAFFS_MAX_NAME_LENGTH) {
446 yaffsfs_SetError(-ENAMETOOLONG);
453 static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
455 YCHAR *alt_path = NULL;
460 * We don't have a definition for max path length.
461 * We will use 3 * max name length instead.
464 path_length = yaffs_strnlen(path, (YAFFS_MAX_NAME_LENGTH + 1) * 3 + 1);
466 /* If the last character is a path divider, then we need to
467 * trim it back so that the name look-up works properly.
468 * eg. /foo/new_dir/ -> /foo/newdir
469 * Curveball: Need to handle multiple path dividers:
470 * eg. /foof/sdfse///// -> /foo/sdfse
472 if (path_length > 0 && yaffsfs_IsPathDivider(path[path_length - 1])) {
473 alt_path = kmalloc(path_length + 1, 0);
476 yaffs_strcpy(alt_path, path);
477 for (i = path_length - 1;
478 i >= 0 && yaffsfs_IsPathDivider(alt_path[i]); i--)
479 alt_path[i] = (YCHAR) 0;
481 *ret_path = alt_path;
485 LIST_HEAD(yaffsfs_deviceList);
490 * Scan the configuration list to find the device
491 * Curveballs: Should match paths that end in '/' too
492 * Curveball2 Might have "/x/ and "/x/y". Need to return the longest match
494 static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path,
497 struct list_head *cfg;
498 const YCHAR *leftOver;
500 struct yaffs_dev *retval = NULL;
501 struct yaffs_dev *dev = NULL;
503 int longestMatch = -1;
507 * Check all configs, choose the one that:
508 * 1) Actually matches a prefix (ie /a amd /abc will not match
509 * 2) Matches the longest.
511 list_for_each(cfg, &yaffsfs_deviceList) {
512 dev = list_entry(cfg, struct yaffs_dev, dev_list);
522 /* Skip over any leading /s */
523 while (yaffsfs_IsPathDivider(*p))
525 while (yaffsfs_IsPathDivider(*leftOver))
528 while (matching && *p && *leftOver) {
530 /* Now match the text part */
532 *p && !yaffsfs_IsPathDivider(*p) &&
533 *leftOver && !yaffsfs_IsPathDivider(*leftOver)) {
534 if (yaffsfs_Match(*p, *leftOver)) {
543 if ((*p && !yaffsfs_IsPathDivider(*p)) ||
544 (*leftOver && !yaffsfs_IsPathDivider(*leftOver)))
547 while (yaffsfs_IsPathDivider(*p))
549 while (yaffsfs_IsPathDivider(*leftOver))
554 /* Skip over any /s in leftOver */
555 while (yaffsfs_IsPathDivider(*leftOver))
558 /*Skip over any /s in p */
559 while (yaffsfs_IsPathDivider(*p))
562 /* p should now be at the end of the string if fully matched */
566 if (matching && (thisMatchLength > longestMatch)) {
568 *restOfPath = (YCHAR *) leftOver;
570 longestMatch = thisMatchLength;
576 static int yaffsfs_CheckPath(const YCHAR *path)
581 while (*path && n < YAFFS_MAX_NAME_LENGTH && divs < 100) {
582 if (yaffsfs_IsPathDivider(*path)) {
590 return (*path) ? -1 : 0;
593 /* FindMountPoint only returns a dev entry if the path is a mount point */
594 static struct yaffs_dev *yaffsfs_FindMountPoint(const YCHAR *path)
596 struct yaffs_dev *dev;
597 YCHAR *restOfPath = NULL;
599 dev = yaffsfs_FindDevice(path, &restOfPath);
600 if (dev && restOfPath && *restOfPath)
605 static struct yaffs_obj *yaffsfs_FindRoot(const YCHAR *path,
608 struct yaffs_dev *dev;
610 dev = yaffsfs_FindDevice(path, restOfPath);
611 if (dev && dev->is_mounted)
612 return dev->root_dir;
617 static struct yaffs_obj *yaffsfs_FollowLink(struct yaffs_obj *obj,
618 int symDepth, int *loop)
622 obj = yaffs_get_equivalent_obj(obj);
624 while (obj && obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
625 YCHAR *alias = obj->variant.symlink_variant.alias;
627 if (yaffsfs_IsPathDivider(*alias))
629 * Starts with a /, need to scan from root up */
630 /* NB Might not work if this is called with root != NULL
632 obj = yaffsfs_FindObject(NULL, alias, symDepth++,
633 1, NULL, NULL, loop);
636 * Relative to here so use the parent of the
639 obj = yaffsfs_FindObject(obj->parent, alias, symDepth++,
640 1, NULL, NULL, loop);
646 * yaffsfs_FindDirectory
647 * Parse a path to determine the directory and the name within the directory.
649 * eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
651 static struct yaffs_obj *yaffsfs_DoFindDirectory(struct yaffs_obj *startDir,
653 YCHAR **name, int symDepth,
654 int *notDir, int *loop)
656 struct yaffs_obj *dir;
658 YCHAR str[YAFFS_MAX_NAME_LENGTH + 1];
661 if (symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES) {
669 restOfPath = (YCHAR *) path;
671 dir = yaffsfs_FindRoot(path, &restOfPath);
676 * curve ball: also throw away surplus '/'
677 * eg. "/ram/x////ff" gets treated the same as "/ram/x/ff"
679 while (yaffsfs_IsPathDivider(*restOfPath))
680 restOfPath++; /* get rid of '/' */
685 while (*restOfPath && !yaffsfs_IsPathDivider(*restOfPath)) {
686 if (i < YAFFS_MAX_NAME_LENGTH) {
687 str[i] = *restOfPath;
695 /* got to the end of the string */
698 if (yaffs_strcmp(str, _Y(".")) == 0) {
700 } else if (yaffs_strcmp(str, _Y("..")) == 0) {
703 dir = yaffs_find_by_name(dir, str);
705 dir = yaffsfs_FollowLink(dir, symDepth, loop);
707 if (dir && dir->variant_type !=
708 YAFFS_OBJECT_TYPE_DIRECTORY) {
717 /* directory did not exist. */
721 static struct yaffs_obj *yaffsfs_FindDirectory(struct yaffs_obj *relDir,
725 int *notDir, int *loop)
727 return yaffsfs_DoFindDirectory(relDir, path, name, symDepth, notDir,
732 * yaffsfs_FindObject turns a path for an existing object into the object
734 static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relDir,
735 const YCHAR *path, int symDepth,
737 struct yaffs_obj **dirOut,
738 int *notDir, int *loop)
740 struct yaffs_obj *dir;
741 struct yaffs_obj *obj;
745 yaffsfs_FindDirectory(relDir, path, &name, symDepth, notDir, loop);
750 /* At this stage we have looked up directory part and have the name part
751 * in name if there is one.
753 * eg /nand/x/ will give us a name of ""
754 * /nand/x will give us a name of "x"
756 * Since the name part might be "." or ".." which need to be fixed.
758 if (dir && (yaffs_strcmp(name, _Y("..")) == 0)) {
761 } else if (dir && (yaffs_strcmp(name, _Y(".")) == 0))
763 else if (dir && *name)
764 obj = yaffs_find_by_name(dir, name);
769 obj = yaffs_get_equivalent_obj(obj);
774 /*************************************************************************
775 * Start of yaffsfs visible functions.
776 *************************************************************************/
778 int yaffs_dup(int handle)
780 int newHandleNumber = -1;
781 struct yaffsfs_FileDes *existingFD = NULL;
782 struct yaffsfs_Handle *existingHandle = NULL;
783 struct yaffsfs_Handle *newHandle = NULL;
786 existingHandle = yaffsfs_HandleToPointer(handle);
787 existingFD = yaffsfs_HandleToFileDes(handle);
789 newHandleNumber = yaffsfs_NewHandle(&newHandle);
791 newHandle->fdId = existingHandle->fdId;
792 existingFD->handleCount++;
798 yaffsfs_SetError(-EBADF);
800 yaffsfs_SetError(-ENOMEM);
802 return newHandleNumber;
806 static int yaffsfs_TooManyObjects(struct yaffs_dev *dev)
808 int current_objects = dev->n_obj - dev->n_deleted_files;
810 if (dev->param.max_objects && current_objects > dev->param.max_objects)
816 int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
817 int oflag, int mode, int sharing)
819 struct yaffs_obj *obj = NULL;
820 struct yaffs_obj *dir = NULL;
823 struct yaffsfs_FileDes *fd = NULL;
826 int errorReported = 0;
827 int rwflags = oflag & (O_RDWR | O_RDONLY | O_WRONLY);
828 u8 shareRead = (sharing & YAFFS_SHARE_READ) ? 1 : 0;
829 u8 shareWrite = (sharing & YAFFS_SHARE_WRITE) ? 1 : 0;
830 u8 sharedReadAllowed;
831 u8 sharedWriteAllowed;
841 if (yaffsfs_CheckMemRegion(path, 0, 0)< 0) {
842 yaffsfs_SetError(-EFAULT);
846 if (yaffsfs_CheckPath(path) < 0) {
847 yaffsfs_SetError(-ENAMETOOLONG);
851 /* O_EXCL only has meaning if O_CREAT is specified */
852 if (!(oflag & O_CREAT))
855 /* O_TRUNC has no meaning if (O_CREAT | O_EXCL) is specified */
856 if ((oflag & O_CREAT) && (oflag & O_EXCL))
859 /* Todo: Are there any more flag combos to sanitise ? */
861 /* Figure out if reading or writing is requested */
863 readRequested = (rwflags == O_RDWR || rwflags == O_RDONLY) ? 1 : 0;
864 writeRequested = (rwflags == O_RDWR || rwflags == O_WRONLY) ? 1 : 0;
868 handle = yaffsfs_NewHandleAndFileDes();
871 yaffsfs_SetError(-ENFILE);
875 fd = yaffsfs_HandleToFileDes(handle);
877 /* try to find the exisiting object */
878 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
880 obj = yaffsfs_FollowLink(obj, symDepth++, &loop);
883 obj->variant_type != YAFFS_OBJECT_TYPE_FILE &&
884 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
889 /* The file already exists or it might be a directory */
890 is_dir = (obj->variant_type ==
891 YAFFS_OBJECT_TYPE_DIRECTORY);
893 /* A directory can't be opened except for read */
895 (writeRequested || !readRequested ||
896 (oflag & ~O_RDONLY))) {
898 yaffsfs_SetError(-EISDIR);
903 dsc = yaffsfs_opendir_reldir_no_lock(reldir, path);
906 yaffsfs_SetError(-ENFILE);
911 /* Open should fail if O_CREAT and O_EXCL are specified
912 * for a file that exists.
914 if (!errorReported &&
915 (oflag & O_EXCL) && (oflag & O_CREAT)) {
917 yaffsfs_SetError(-EEXIST);
921 /* Check file permissions */
922 if (readRequested && !(obj->yst_mode & S_IRUSR))
925 if (writeRequested && !(obj->yst_mode & S_IWUSR))
928 if (!errorReported && writeRequested &&
929 obj->my_dev->read_only) {
931 yaffsfs_SetError(-EROFS);
935 if (openDenied && !errorReported) {
936 yaffsfs_SetError(-EACCES);
940 /* Check sharing of an existing object. */
942 struct yaffsfs_FileDes *fdx;
945 sharedReadAllowed = 1;
946 sharedWriteAllowed = 1;
949 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
950 fdx = &yaffsfs_fd[i];
951 if (fdx->handleCount > 0 &&
953 yaffsfs_inode[fdx->inodeId].iObj
956 sharedReadAllowed = 0;
957 if (!fdx->shareWrite)
958 sharedWriteAllowed = 0;
966 if ((!sharedReadAllowed && readRequested) ||
967 (!shareRead && alreadyReading) ||
968 (!sharedWriteAllowed && writeRequested) ||
969 (!shareWrite && alreadyWriting)) {
971 yaffsfs_SetError(-EBUSY);
978 /* If we could not open an existing object, then let's see if
979 * the directory exists. If not, error.
981 if (!obj && !errorReported) {
982 dir = yaffsfs_FindDirectory(reldir, path, &name, 0,
984 if (!dir && notDir) {
985 yaffsfs_SetError(-ENOTDIR);
988 yaffsfs_SetError(-ELOOP);
991 yaffsfs_SetError(-ENOENT);
996 if (!obj && dir && !errorReported && (oflag & O_CREAT)) {
997 /* Let's see if we can create this file */
998 if (dir->my_dev->read_only) {
999 yaffsfs_SetError(-EROFS);
1001 } else if (yaffsfs_TooManyObjects(dir->my_dev)) {
1002 yaffsfs_SetError(-ENFILE);
1005 obj = yaffs_create_file(dir, name, mode, 0, 0);
1007 if (!obj && !errorReported) {
1008 yaffsfs_SetError(-ENOSPC);
1013 if (!obj && dir && !errorReported && !(oflag & O_CREAT)) {
1014 yaffsfs_SetError(-ENOENT);
1018 if (obj && !openDenied) {
1019 int inodeId = yaffsfs_GetInodeIdForObject(obj);
1023 * Todo: Fix any problem if inodes run out,
1024 * That can't happen if the number of inode
1025 * items >= number of handles.
1029 fd->inodeId = inodeId;
1030 fd->reading = readRequested;
1031 fd->writing = writeRequested;
1032 fd->append = (oflag & O_APPEND) ? 1 : 0;
1033 fd->shareRead = shareRead;
1034 fd->shareWrite = shareWrite;
1042 /* Hook inode to object */
1043 obj->my_inode = (void *)&yaffsfs_inode[inodeId];
1045 if (!is_dir && (oflag & O_TRUNC) && fd->writing)
1046 yaffs_resize_file(obj, 0);
1048 yaffsfs_PutHandle(handle);
1050 yaffsfs_SetError(0); /* Problem */
1060 int yaffs_open_sharing_reldev(struct yaffs_dev *dev, const YCHAR *path, int oflag,
1061 int mode, int sharing)
1063 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path,
1064 oflag, mode, sharing);
1067 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
1069 return yaffs_open_sharing_reldir(NULL, path, oflag, mode, sharing);
1072 int yaffs_open_reldir(struct yaffs_obj *reldir,const YCHAR *path, int oflag, int mode)
1074 return yaffs_open_sharing_reldir(reldir, path, oflag, mode,
1075 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1078 int yaffs_open_reldev(struct yaffs_dev *dev,const YCHAR *path, int oflag, int mode)
1080 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path, oflag, mode,
1081 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1084 int yaffs_open(const YCHAR *path, int oflag, int mode)
1086 return yaffs_open_reldir(NULL, path, oflag, mode);
1089 static int yaffs_Dofsync(int handle, int datasync)
1092 struct yaffs_obj *obj;
1096 obj = yaffsfs_HandleToObject(handle);
1099 yaffsfs_SetError(-EBADF);
1100 else if (obj->my_dev->read_only)
1101 yaffsfs_SetError(-EROFS);
1103 yaffs_flush_file(obj, 1, datasync, 0);
1112 int yaffs_fsync(int handle)
1114 return yaffs_Dofsync(handle, 0);
1117 int yaffs_flush(int handle)
1119 return yaffs_fsync(handle);
1122 int yaffs_fdatasync(int handle)
1124 return yaffs_Dofsync(handle, 1);
1127 int yaffs_close(int handle)
1129 struct yaffsfs_Handle *h = NULL;
1130 struct yaffsfs_FileDes *f;
1131 struct yaffs_obj *obj = NULL;
1136 h = yaffsfs_HandleToPointer(handle);
1137 f = yaffsfs_HandleToFileDes(handle);
1138 obj = yaffsfs_HandleToObject(handle);
1140 if (!h || !obj || !f)
1141 yaffsfs_SetError(-EBADF);
1145 yaffs_flush_file(obj, 1, 0, 1);
1146 yaffsfs_PutHandle(handle);
1155 static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
1156 int isPread, Y_LOFF_T offset)
1158 struct yaffsfs_FileDes *fd = NULL;
1159 struct yaffs_obj *obj = NULL;
1161 Y_LOFF_T startPos = 0;
1162 Y_LOFF_T endPos = 0;
1167 u8 *buf = (u8 *) vbuf;
1169 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) {
1170 yaffsfs_SetError(-EFAULT);
1175 fd = yaffsfs_HandleToFileDes(handle);
1176 obj = yaffsfs_HandleToObject(handle);
1180 yaffsfs_SetError(-EBADF);
1182 } else if (!fd->reading) {
1183 /* Not a reading handle */
1184 yaffsfs_SetError(-EINVAL);
1186 } else if (nbyte > YAFFS_MAX_FILE_SIZE) {
1187 yaffsfs_SetError(-EINVAL);
1193 startPos = fd->v.position;
1197 if (yaffs_get_obj_length(obj) > pos)
1198 maxRead = yaffs_get_obj_length(obj) - pos;
1202 if (nbyte > maxRead)
1205 yaffsfs_GetHandle(handle);
1207 endPos = pos + nbyte;
1209 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1210 nbyte > YAFFS_MAX_FILE_SIZE ||
1211 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1217 nToRead = YAFFSFS_RW_SIZE -
1218 (pos & (YAFFSFS_RW_SIZE - 1));
1219 if (nToRead > nbyte)
1223 * Need to reverify object in case the device was
1224 * unmounted in another thread.
1226 obj = yaffsfs_HandleToObject(handle);
1230 nRead = yaffs_file_rd(obj, buf, pos, nToRead);
1238 if (nRead == nToRead)
1241 nbyte = 0; /* no more to read */
1250 yaffsfs_PutHandle(handle);
1254 fd->v.position = startPos + totalRead;
1256 yaffsfs_SetError(-EINVAL);
1263 return (totalRead >= 0) ? totalRead : -1;
1267 int yaffs_read(int handle, void *buf, unsigned int nbyte)
1269 return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
1272 int yaffs_pread(int handle, void *buf, unsigned int nbyte, Y_LOFF_T offset)
1274 return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
1277 static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
1278 int isPwrite, Y_LOFF_T offset)
1280 struct yaffsfs_FileDes *fd = NULL;
1281 struct yaffs_obj *obj = NULL;
1283 Y_LOFF_T startPos = 0;
1286 int totalWritten = 0;
1287 int write_trhrough = 0;
1289 const u8 *buf = (const u8 *)vbuf;
1291 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) {
1292 yaffsfs_SetError(-EFAULT);
1297 fd = yaffsfs_HandleToFileDes(handle);
1298 obj = yaffsfs_HandleToObject(handle);
1302 yaffsfs_SetError(-EBADF);
1304 } else if (!fd->writing) {
1305 yaffsfs_SetError(-EINVAL);
1307 } else if (obj->my_dev->read_only) {
1308 yaffsfs_SetError(-EROFS);
1312 startPos = yaffs_get_obj_length(obj);
1316 startPos = fd->v.position;
1318 yaffsfs_GetHandle(handle);
1320 endPos = pos + nbyte;
1322 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1323 nbyte > YAFFS_MAX_FILE_SIZE ||
1324 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1331 nToWrite = YAFFSFS_RW_SIZE -
1332 (pos & (YAFFSFS_RW_SIZE - 1));
1333 if (nToWrite > nbyte)
1337 * Need to reverify object in case the device was
1338 * remounted or unmounted in another thread.
1340 obj = yaffsfs_HandleToObject(handle);
1341 if (!obj || obj->my_dev->read_only)
1345 yaffs_wr_file(obj, buf, pos, nToWrite,
1348 totalWritten += nWritten;
1353 if (nWritten == nToWrite)
1358 if (nWritten < 1 && totalWritten < 1) {
1359 yaffsfs_SetError(-ENOSPC);
1369 yaffsfs_PutHandle(handle);
1372 if (totalWritten > 0)
1373 fd->v.position = startPos + totalWritten;
1375 yaffsfs_SetError(-EINVAL);
1381 return (totalWritten >= 0) ? totalWritten : -1;
1384 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
1386 return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
1389 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset)
1391 return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
1394 int yaffs_truncate_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1397 struct yaffs_obj *obj = NULL;
1398 struct yaffs_obj *dir = NULL;
1399 int result = YAFFS_FAIL;
1403 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1404 yaffsfs_SetError(-EFAULT);
1408 if (yaffsfs_CheckPath(path) < 0) {
1409 yaffsfs_SetError(-ENAMETOOLONG);
1415 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1416 obj = yaffsfs_FollowLink(obj, 0, &loop);
1419 yaffsfs_SetError(-ENOTDIR);
1421 yaffsfs_SetError(-ELOOP);
1422 else if (!dir || !obj)
1423 yaffsfs_SetError(-ENOENT);
1424 else if (obj->my_dev->read_only)
1425 yaffsfs_SetError(-EROFS);
1426 else if (obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
1427 yaffsfs_SetError(-EISDIR);
1428 else if (obj->my_dev->read_only)
1429 yaffsfs_SetError(-EROFS);
1430 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1431 yaffsfs_SetError(-EINVAL);
1433 result = yaffs_resize_file(obj, new_size);
1437 return (result) ? 0 : -1;
1440 int yaffs_truncate_reldev(struct yaffs_dev *dev, const YCHAR *path,
1443 return yaffs_truncate_reldir(ROOT_DIR(dev), path, new_size);
1446 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size)
1448 return yaffs_truncate_reldir(NULL, path, new_size);
1451 int yaffs_ftruncate(int handle, Y_LOFF_T new_size)
1453 struct yaffsfs_FileDes *fd = NULL;
1454 struct yaffs_obj *obj = NULL;
1458 fd = yaffsfs_HandleToFileDes(handle);
1459 obj = yaffsfs_HandleToObject(handle);
1463 yaffsfs_SetError(-EBADF);
1464 else if (!fd->writing)
1465 yaffsfs_SetError(-EINVAL);
1466 else if (obj->my_dev->read_only)
1467 yaffsfs_SetError(-EROFS);
1468 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1469 yaffsfs_SetError(-EINVAL);
1471 /* resize the file */
1472 result = yaffs_resize_file(obj, new_size);
1475 return (result) ? 0 : -1;
1479 Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence)
1481 struct yaffsfs_FileDes *fd = NULL;
1482 struct yaffs_obj *obj = NULL;
1484 Y_LOFF_T fSize = -1;
1487 fd = yaffsfs_HandleToFileDes(handle);
1488 obj = yaffsfs_HandleToObject(handle);
1491 yaffsfs_SetError(-EBADF);
1492 else if (offset > YAFFS_MAX_FILE_SIZE)
1493 yaffsfs_SetError(-EINVAL);
1495 if (whence == SEEK_SET) {
1498 } else if (whence == SEEK_CUR) {
1499 if ((fd->v.position + offset) >= 0)
1500 pos = (fd->v.position + offset);
1501 } else if (whence == SEEK_END) {
1502 fSize = yaffs_get_obj_length(obj);
1503 if (fSize >= 0 && (fSize + offset) >= 0)
1504 pos = fSize + offset;
1507 if (pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE)
1508 fd->v.position = pos;
1510 yaffsfs_SetError(-EINVAL);
1520 static int yaffsfs_DoUnlink_reldir(struct yaffs_obj *reldir,
1521 const YCHAR *path, int isDirectory)
1523 struct yaffs_obj *dir = NULL;
1524 struct yaffs_obj *obj = NULL;
1526 int result = YAFFS_FAIL;
1530 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1531 yaffsfs_SetError(-EFAULT);
1535 if (yaffsfs_CheckPath(path) < 0) {
1536 yaffsfs_SetError(-ENAMETOOLONG);
1542 obj = yaffsfs_FindObject(reldir, path, 0, 0, NULL, NULL, NULL);
1543 dir = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
1546 yaffsfs_SetError(-ENOTDIR);
1548 yaffsfs_SetError(-ELOOP);
1550 yaffsfs_SetError(-ENOENT);
1551 else if (yaffs_strncmp(name, _Y("."), 2) == 0)
1552 yaffsfs_SetError(-EINVAL);
1554 yaffsfs_SetError(-ENOENT);
1555 else if (obj->my_dev->read_only)
1556 yaffsfs_SetError(-EROFS);
1557 else if (!isDirectory &&
1558 obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1559 yaffsfs_SetError(-EISDIR);
1560 else if (isDirectory &&
1561 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1562 yaffsfs_SetError(-ENOTDIR);
1563 else if (isDirectory && obj == obj->my_dev->root_dir)
1564 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1566 result = yaffs_unlinker(dir, name);
1568 if (result == YAFFS_FAIL && isDirectory)
1569 yaffsfs_SetError(-ENOTEMPTY);
1574 return (result == YAFFS_FAIL) ? -1 : 0;
1577 int yaffs_unlink_reldir(struct yaffs_obj *reldir, const YCHAR *path)
1579 return yaffsfs_DoUnlink_reldir(reldir, path, 0);
1582 int yaffs_unlink_reldev(struct yaffs_dev *dev, const YCHAR *path)
1584 return yaffsfs_DoUnlink_reldir(ROOT_DIR(dev), path, 0);
1587 int yaffs_unlink(const YCHAR *path)
1589 return yaffs_unlink_reldir(NULL, path);
1592 int yaffs_funlink(int fd)
1594 struct yaffs_obj *obj;
1598 obj = yaffsfs_HandleToObject(fd);
1601 yaffsfs_SetError(-EBADF);
1602 else if (obj->my_dev->read_only)
1603 yaffsfs_SetError(-EROFS);
1604 else if (!isDirectory &&
1605 obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1606 yaffsfs_SetError(-EISDIR);
1607 else if (isDirectory &&
1608 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1609 yaffsfs_SetError(-ENOTDIR);
1610 else if (isDirectory && obj == obj->my_dev->root_dir)
1611 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1612 else if (yaffs_unlink_obj(oobj) == YAFFS_OK)
1621 static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1623 if (obj && obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY &&
1624 newobj && newobj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1630 static int rename_dir_over_file(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1632 if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1633 newobj && newobj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1639 int yaffs_rename_reldir(struct yaffs_obj *reldir,
1640 const YCHAR *oldPath, const YCHAR *newPath)
1642 struct yaffs_obj *olddir = NULL;
1643 struct yaffs_obj *newdir = NULL;
1644 struct yaffs_obj *obj = NULL;
1645 struct yaffs_obj *newobj = NULL;
1648 int result = YAFFS_FAIL;
1649 int rename_allowed = 1;
1655 YCHAR *alt_newpath = NULL;
1657 if (yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 ||
1658 yaffsfs_CheckMemRegion(newPath, 0, 0) < 0) {
1659 yaffsfs_SetError(-EFAULT);
1663 if (yaffsfs_CheckPath(oldPath) < 0 || yaffsfs_CheckPath(newPath) < 0) {
1664 yaffsfs_SetError(-ENAMETOOLONG);
1668 if (yaffsfs_alt_dir_path(newPath, &alt_newpath) < 0) {
1669 yaffsfs_SetError(-ENOMEM);
1673 newPath = alt_newpath;
1677 olddir = yaffsfs_FindDirectory(reldir, oldPath, &oldname, 0,
1678 ¬OldDir, &oldLoop);
1679 newdir = yaffsfs_FindDirectory(reldir, newPath, &newname, 0,
1680 ¬NewDir, &newLoop);
1681 obj = yaffsfs_FindObject(reldir, oldPath, 0, 0, NULL, NULL, NULL);
1682 newobj = yaffsfs_FindObject(reldir, newPath, 0, 0, NULL, NULL, NULL);
1684 /* If the object being renamed is a directory and the
1685 * path ended with a "/" then the olddir == obj.
1686 * We pass through NULL for the old name to tell the lower layers
1687 * to use olddir as the object.
1693 if ((!olddir && notOldDir) || (!newdir && notNewDir)) {
1694 yaffsfs_SetError(-ENOTDIR);
1696 } else if (oldLoop || newLoop) {
1697 yaffsfs_SetError(-ELOOP);
1699 } else if (olddir && oldname &&
1700 yaffs_strncmp(oldname, _Y("."), 2) == 0) {
1701 yaffsfs_SetError(-EINVAL);
1703 } else if (!olddir || !newdir || !obj) {
1704 yaffsfs_SetError(-ENOENT);
1706 } else if (obj->my_dev->read_only) {
1707 yaffsfs_SetError(-EROFS);
1709 } else if (rename_file_over_dir(obj, newobj)) {
1710 yaffsfs_SetError(-EISDIR);
1712 } else if (rename_dir_over_file(obj, newobj)) {
1713 yaffsfs_SetError(-ENOTDIR);
1715 } else if (yaffs_is_non_empty_dir(newobj)) {
1716 yaffsfs_SetError(-ENOTEMPTY);
1718 } else if (olddir->my_dev != newdir->my_dev) {
1719 /* Rename must be on same device */
1720 yaffsfs_SetError(-EXDEV);
1722 } else if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
1724 * It is a directory, check that it is not being renamed to
1725 * being its own decendent.
1726 * Do this by tracing from the new directory back to the root,
1730 struct yaffs_obj *xx = newdir;
1732 while (rename_allowed && xx) {
1737 if (!rename_allowed)
1738 yaffsfs_SetError(-EINVAL);
1742 result = yaffs_rename_obj(olddir, oldname, newdir, newname);
1748 return (result == YAFFS_FAIL) ? -1 : 0;
1751 int yaffs_rename_reldev(struct yaffs_dev *dev, const YCHAR *oldPath,
1752 const YCHAR *newPath)
1754 return yaffs_rename_reldir(ROOT_DIR(dev), oldPath, newPath);
1756 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
1758 return yaffs_rename_reldir(NULL, oldPath, newPath);
1761 static int yaffsfs_DoStat(struct yaffs_obj *obj, struct yaffs_stat *buf)
1765 obj = yaffs_get_equivalent_obj(obj);
1768 buf->st_dev = (int)obj->my_dev->os_context;
1769 buf->st_ino = obj->obj_id;
1770 buf->st_mode = obj->yst_mode & ~S_IFMT;
1772 if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1773 buf->st_mode |= S_IFDIR;
1774 else if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
1775 buf->st_mode |= S_IFLNK;
1776 else if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE)
1777 buf->st_mode |= S_IFREG;
1779 buf->st_nlink = yaffs_get_obj_link_count(obj);
1782 buf->st_rdev = obj->yst_rdev;
1783 buf->st_size = yaffs_get_obj_length(obj);
1784 buf->st_blksize = obj->my_dev->data_bytes_per_chunk;
1785 buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
1787 #if CONFIG_YAFFS_WINCE
1788 buf->yst_wince_atime[0] = obj->win_atime[0];
1789 buf->yst_wince_atime[1] = obj->win_atime[1];
1790 buf->yst_wince_ctime[0] = obj->win_ctime[0];
1791 buf->yst_wince_ctime[1] = obj->win_ctime[1];
1792 buf->yst_wince_mtime[0] = obj->win_mtime[0];
1793 buf->yst_wince_mtime[1] = obj->win_mtime[1];
1795 buf->yst_atime = obj->yst_atime;
1796 buf->yst_ctime = obj->yst_ctime;
1797 buf->yst_mtime = obj->yst_mtime;
1804 static int yaffsfs_DoStatOrLStat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1805 struct yaffs_stat *buf, int doLStat)
1807 struct yaffs_obj *obj = NULL;
1808 struct yaffs_obj *dir = NULL;
1813 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
1814 yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1815 yaffsfs_SetError(-EFAULT);
1819 if (yaffsfs_CheckPath(path) < 0) {
1820 yaffsfs_SetError(-ENAMETOOLONG);
1826 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1828 if (!doLStat && obj)
1829 obj = yaffsfs_FollowLink(obj, 0, &loop);
1832 yaffsfs_SetError(-ENOTDIR);
1834 yaffsfs_SetError(-ELOOP);
1835 else if (!dir || !obj)
1836 yaffsfs_SetError(-ENOENT);
1838 retVal = yaffsfs_DoStat(obj, buf);
1846 int yaffs_stat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1847 struct yaffs_stat *buf)
1849 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 0);
1852 int yaffs_lstat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1853 struct yaffs_stat *buf)
1855 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 1);
1858 int yaffs_stat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1859 struct yaffs_stat *buf)
1861 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 0);
1864 int yaffs_lstat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1865 struct yaffs_stat *buf)
1867 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 1);
1870 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf)
1872 return yaffs_stat_reldir(NULL, path, buf);
1875 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf)
1877 return yaffs_lstat_reldir(NULL, path, buf);
1880 int yaffs_fstat(int fd, struct yaffs_stat *buf)
1882 struct yaffs_obj *obj;
1886 if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1887 yaffsfs_SetError(-EFAULT);
1892 obj = yaffsfs_HandleToObject(fd);
1895 retVal = yaffsfs_DoStat(obj, buf);
1898 yaffsfs_SetError(-EBADF);
1905 static int yaffsfs_DoUtime(struct yaffs_obj *obj,
1906 const struct yaffs_utimbuf *buf)
1909 struct yaffs_utimbuf local;
1911 obj = yaffs_get_equivalent_obj(obj);
1913 if (obj && obj->my_dev->read_only) {
1914 yaffsfs_SetError(-EROFS);
1918 #if !CONFIG_YAFFS_WINCE
1920 local.actime = Y_CURRENT_TIME;
1921 local.modtime = local.actime;
1928 obj->yst_atime = buf->actime;
1929 obj->yst_mtime = buf->modtime;
1931 result = yaffs_flush_file(obj, 0, 0, 0);
1932 retVal = result == YAFFS_OK ? 0 : -1;
1939 int yaffs_utime_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1940 const struct yaffs_utimbuf *buf)
1942 struct yaffs_obj *obj = NULL;
1943 struct yaffs_obj *dir = NULL;
1949 yaffsfs_SetError(-EFAULT);
1953 if (yaffsfs_CheckPath(path) < 0) {
1954 yaffsfs_SetError(-ENAMETOOLONG);
1960 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1963 yaffsfs_SetError(-ENOTDIR);
1965 yaffsfs_SetError(-ELOOP);
1966 else if (!dir || !obj)
1967 yaffsfs_SetError(-ENOENT);
1969 retVal = yaffsfs_DoUtime(obj, buf);
1977 int yaffs_utime_reldev(struct yaffs_dev *dev, const YCHAR *path,
1978 const struct yaffs_utimbuf *buf)
1980 return yaffs_utime_reldir(ROOT_DIR(dev), path, buf);
1983 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf)
1985 return yaffs_utime_reldir(NULL, path, buf);
1988 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf)
1990 struct yaffs_obj *obj;
1995 obj = yaffsfs_HandleToObject(fd);
1998 retVal = yaffsfs_DoUtime(obj, buf);
2001 yaffsfs_SetError(-EBADF);
2008 #ifndef CONFIG_YAFFS_WINCE
2009 /* xattrib functions */
2011 static int yaffs_do_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2012 const char *name, const void *data, int size,
2013 int flags, int follow)
2015 struct yaffs_obj *obj;
2016 struct yaffs_obj *dir;
2022 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2023 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2024 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2025 yaffsfs_SetError(-EFAULT);
2029 if (yaffsfs_CheckPath(path) < 0) {
2030 yaffsfs_SetError(-ENAMETOOLONG);
2036 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2039 obj = yaffsfs_FollowLink(obj, 0, &loop);
2042 yaffsfs_SetError(-ENOTDIR);
2044 yaffsfs_SetError(-ELOOP);
2045 else if (!dir || !obj)
2046 yaffsfs_SetError(-ENOENT);
2048 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2050 yaffsfs_SetError(retVal);
2061 int yaffs_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2062 const char *name, const void *data, int size, int flags)
2064 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 1);
2067 int yaffs_setxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
2068 const char *name, const void *data, int size, int flags)
2070 return yaffs_setxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2073 int yaffs_setxattr(const YCHAR *path, const char *name,
2074 const void *data, int size, int flags)
2076 return yaffs_setxattr_reldir(NULL, path, name, data, size, flags);
2079 int yaffs_lsetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path, const char *name,
2080 const void *data, int size, int flags)
2082 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 0);
2085 int yaffs_lsetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name,
2086 const void *data, int size, int flags)
2088 return yaffs_lsetxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2091 int yaffs_lsetxattr(const YCHAR *path, const char *name,
2092 const void *data, int size, int flags)
2094 return yaffs_lsetxattr_reldir(NULL, path, name, data, size, flags);
2097 int yaffs_fsetxattr(int fd, const char *name,
2098 const void *data, int size, int flags)
2100 struct yaffs_obj *obj;
2104 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2105 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2106 yaffsfs_SetError(-EFAULT);
2111 obj = yaffsfs_HandleToObject(fd);
2114 yaffsfs_SetError(-EBADF);
2116 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2118 yaffsfs_SetError(retVal);
2128 static int yaffs_do_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2129 const char *name, void *data, int size, int follow)
2131 struct yaffs_obj *obj;
2132 struct yaffs_obj *dir;
2137 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2138 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2139 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2140 yaffsfs_SetError(-EFAULT);
2144 if (yaffsfs_CheckPath(path) < 0) {
2145 yaffsfs_SetError(-ENAMETOOLONG);
2151 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2154 obj = yaffsfs_FollowLink(obj, 0, &loop);
2157 yaffsfs_SetError(-ENOTDIR);
2159 yaffsfs_SetError(-ELOOP);
2160 else if (!dir || !obj)
2161 yaffsfs_SetError(-ENOENT);
2163 retVal = yaffs_get_xattrib(obj, name, data, size);
2165 yaffsfs_SetError(retVal);
2175 int yaffs_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2176 const char *name, void *data, int size)
2178 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 1);
2181 int yaffs_getxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2183 return yaffs_getxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2186 int yaffs_getxattr(const YCHAR *path, const char *name, void *data, int size)
2188 return yaffs_getxattr_reldir(NULL, path, name, data, size);
2191 int yaffs_lgetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2192 const char *name, void *data, int size)
2194 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 0);
2197 int yaffs_lgetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2199 return yaffs_lgetxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2202 int yaffs_lgetxattr(const YCHAR *path, const char *name, void *data, int size)
2204 return yaffs_lgetxattr_reldir(NULL, path, name, data, size);
2207 int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
2209 struct yaffs_obj *obj;
2213 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2214 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2215 yaffsfs_SetError(-EFAULT);
2220 obj = yaffsfs_HandleToObject(fd);
2223 retVal = yaffs_get_xattrib(obj, name, data, size);
2225 yaffsfs_SetError(retVal);
2230 yaffsfs_SetError(-EBADF);
2237 static int yaffs_do_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2238 char *data, int size, int follow)
2240 struct yaffs_obj *obj = NULL;
2241 struct yaffs_obj *dir = NULL;
2246 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2247 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2248 yaffsfs_SetError(-EFAULT);
2252 if (yaffsfs_CheckPath(path) < 0) {
2253 yaffsfs_SetError(-ENAMETOOLONG);
2259 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2262 obj = yaffsfs_FollowLink(obj, 0, &loop);
2265 yaffsfs_SetError(-ENOTDIR);
2267 yaffsfs_SetError(-ELOOP);
2268 else if (!dir || !obj)
2269 yaffsfs_SetError(-ENOENT);
2271 retVal = yaffs_list_xattrib(obj, data, size);
2273 yaffsfs_SetError(retVal);
2284 int yaffs_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2285 char *data, int size)
2287 return yaffs_do_listxattr_reldir(reldir, path, data, size, 1);
2290 int yaffs_listxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2292 return yaffs_listxattr_reldir(ROOT_DIR(dev), path, data, size);
2295 int yaffs_listxattr(const YCHAR *path, char *data, int size)
2297 return yaffs_listxattr_reldir(NULL, path, data, size);
2300 int yaffs_llistxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2301 char *data, int size)
2303 return yaffs_do_listxattr_reldir(reldir, path, data, size, 0);
2306 int yaffs_llistxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2308 return yaffs_llistxattr_reldir(ROOT_DIR(dev), path, data, size);
2311 int yaffs_llistxattr(const YCHAR *path, char *data, int size)
2313 return yaffs_llistxattr_reldir(NULL, path, data, size);
2316 int yaffs_flistxattr(int fd, char *data, int size)
2318 struct yaffs_obj *obj;
2322 if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2323 yaffsfs_SetError(-EFAULT);
2328 obj = yaffsfs_HandleToObject(fd);
2331 retVal = yaffs_list_xattrib(obj, data, size);
2333 yaffsfs_SetError(retVal);
2338 yaffsfs_SetError(-EBADF);
2345 static int yaffs_do_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2346 const char *name, int follow)
2348 struct yaffs_obj *obj = NULL;
2349 struct yaffs_obj *dir = NULL;
2354 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2355 yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2356 yaffsfs_SetError(-EFAULT);
2360 if (yaffsfs_CheckPath(path) < 0) {
2361 yaffsfs_SetError(-ENAMETOOLONG);
2367 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2370 obj = yaffsfs_FollowLink(obj, 0, &loop);
2373 yaffsfs_SetError(-ENOTDIR);
2375 yaffsfs_SetError(-ELOOP);
2376 else if (!dir || !obj)
2377 yaffsfs_SetError(-ENOENT);
2379 retVal = yaffs_remove_xattrib(obj, name);
2381 yaffsfs_SetError(retVal);
2392 int yaffs_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2395 return yaffs_do_removexattr_reldir(reldir, path, name, 1);
2398 int yaffs_removexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2400 return yaffs_removexattr_reldir(ROOT_DIR(dev), path, name);
2403 int yaffs_removexattr(const YCHAR *path, const char *name)
2405 return yaffs_removexattr_reldir(NULL, path, name);
2408 int yaffs_lremovexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2411 return yaffs_do_removexattr_reldir(reldir, path, name, 0);
2414 int yaffs_lremovexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2416 return yaffs_lremovexattr_reldir(ROOT_DIR(dev), path, name);
2419 int yaffs_lremovexattr(const YCHAR *path, const char *name)
2421 return yaffs_lremovexattr_reldir(NULL, path, name);
2424 int yaffs_fremovexattr(int fd, const char *name)
2426 struct yaffs_obj *obj;
2430 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2431 yaffsfs_SetError(-EFAULT);
2436 obj = yaffsfs_HandleToObject(fd);
2439 retVal = yaffs_remove_xattrib(obj, name);
2441 yaffsfs_SetError(retVal);
2446 yaffsfs_SetError(-EBADF);
2454 #ifdef CONFIG_YAFFS_WINCE
2455 int yaffs_get_wince_times(int fd, unsigned *wctime,
2456 unsigned *watime, unsigned *wmtime)
2458 struct yaffs_obj *obj;
2463 obj = yaffsfs_HandleToObject(fd);
2468 wctime[0] = obj->win_ctime[0];
2469 wctime[1] = obj->win_ctime[1];
2472 watime[0] = obj->win_atime[0];
2473 watime[1] = obj->win_atime[1];
2476 wmtime[0] = obj->win_mtime[0];
2477 wmtime[1] = obj->win_mtime[1];
2483 yaffsfs_SetError(-EBADF);
2490 int yaffs_set_wince_times(int fd,
2491 const unsigned *wctime,
2492 const unsigned *watime, const unsigned *wmtime)
2494 struct yaffs_obj *obj;
2499 obj = yaffsfs_HandleToObject(fd);
2504 obj->win_ctime[0] = wctime[0];
2505 obj->win_ctime[1] = wctime[1];
2508 obj->win_atime[0] = watime[0];
2509 obj->win_atime[1] = watime[1];
2512 obj->win_mtime[0] = wmtime[0];
2513 obj->win_mtime[1] = wmtime[1];
2517 result = yaffs_flush_file(obj, 0, 0, 0);
2521 yaffsfs_SetError(-EBADF);
2530 static int yaffsfs_DoChMod(struct yaffs_obj *obj, mode_t mode)
2535 obj = yaffs_get_equivalent_obj(obj);
2538 obj->yst_mode = mode;
2540 result = yaffs_flush_file(obj, 0, 0, 0);
2543 return result == YAFFS_OK ? 0 : -1;
2546 int yaffs_access_reldir(struct yaffs_obj *reldir, const YCHAR *path, int amode)
2548 struct yaffs_obj *obj = NULL;
2549 struct yaffs_obj *dir = NULL;
2554 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2555 yaffsfs_SetError(-EFAULT);
2559 if (yaffsfs_CheckPath(path) < 0) {
2560 yaffsfs_SetError(-ENAMETOOLONG);
2564 if (amode & ~(R_OK | W_OK | X_OK)) {
2565 yaffsfs_SetError(-EINVAL);
2571 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2572 obj = yaffsfs_FollowLink(obj, 0, &loop);
2575 yaffsfs_SetError(-ENOTDIR);
2577 yaffsfs_SetError(-ELOOP);
2578 else if (!dir || !obj)
2579 yaffsfs_SetError(-ENOENT);
2580 else if ((amode & W_OK) && obj->my_dev->read_only)
2581 yaffsfs_SetError(-EROFS);
2585 if ((amode & R_OK) && !(obj->yst_mode & S_IRUSR))
2587 if ((amode & W_OK) && !(obj->yst_mode & S_IWUSR))
2589 if ((amode & X_OK) && !(obj->yst_mode & S_IXUSR))
2593 yaffsfs_SetError(-EACCES);
2604 int yaffs_access_reldev(struct yaffs_dev *dev, const YCHAR *path, int amode)
2606 return yaffs_access_reldir(ROOT_DIR(dev), path, amode);
2609 int yaffs_access(const YCHAR *path, int amode)
2611 return yaffs_access_reldir(NULL, path, amode);
2614 int yaffs_chmod_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2616 struct yaffs_obj *obj = NULL;
2617 struct yaffs_obj *dir = NULL;
2622 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2623 yaffsfs_SetError(-EFAULT);
2627 if (yaffsfs_CheckPath(path) < 0) {
2628 yaffsfs_SetError(-ENAMETOOLONG);
2632 if (mode & ~(0777)) {
2633 yaffsfs_SetError(-EINVAL);
2639 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2640 obj = yaffsfs_FollowLink(obj, 0, &loop);
2643 yaffsfs_SetError(-ENOTDIR);
2645 yaffsfs_SetError(-ELOOP);
2646 else if (!dir || !obj)
2647 yaffsfs_SetError(-ENOENT);
2648 else if (obj->my_dev->read_only)
2649 yaffsfs_SetError(-EROFS);
2651 retVal = yaffsfs_DoChMod(obj, mode);
2659 int yaffs_chmod_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2661 return yaffs_chmod_reldir(ROOT_DIR(dev), path, mode);
2664 int yaffs_chmod(const YCHAR *path, mode_t mode)
2666 return yaffs_chmod_reldir(NULL, path, mode);
2669 int yaffs_fchmod(int fd, mode_t mode)
2671 struct yaffs_obj *obj;
2674 if (mode & ~(0777)) {
2675 yaffsfs_SetError(-EINVAL);
2680 obj = yaffsfs_HandleToObject(fd);
2683 yaffsfs_SetError(-EBADF);
2684 else if (obj->my_dev->read_only)
2685 yaffsfs_SetError(-EROFS);
2687 retVal = yaffsfs_DoChMod(obj, mode);
2694 int yaffs_mkdir_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2696 struct yaffs_obj *parent = NULL;
2697 struct yaffs_obj *dir = NULL;
2699 YCHAR *alt_path = NULL;
2704 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2705 yaffsfs_SetError(-EFAULT);
2709 if (yaffsfs_CheckPath(path) < 0) {
2710 yaffsfs_SetError(-ENAMETOOLONG);
2714 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2715 yaffsfs_SetError(-ENOMEM);
2722 parent = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
2723 if (!parent && notDir)
2724 yaffsfs_SetError(-ENOTDIR);
2726 yaffsfs_SetError(-ELOOP);
2728 yaffsfs_SetError(-ENOENT);
2729 else if (yaffsfs_TooManyObjects(parent->my_dev))
2730 yaffsfs_SetError(-ENFILE);
2731 else if (yaffs_strnlen(name, 5) == 0) {
2732 /* Trying to make the root itself */
2733 yaffsfs_SetError(-EEXIST);
2734 } else if (parent->my_dev->read_only)
2735 yaffsfs_SetError(-EROFS);
2737 dir = yaffs_create_dir(parent, name, mode, 0, 0);
2740 else if (yaffs_find_by_name(parent, name))
2741 yaffsfs_SetError(-EEXIST); /* name exists */
2743 yaffsfs_SetError(-ENOSPC); /* assume no space */
2753 int yaffs_mkdir_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2755 return yaffs_mkdir_reldir(ROOT_DIR(dev), path, mode);
2758 int yaffs_mkdir(const YCHAR *path, mode_t mode)
2760 return yaffs_mkdir_reldir(NULL, path, mode);
2763 int yaffs_rmdir_reldir(struct yaffs_obj *reldir, const YCHAR *path)
2768 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2769 yaffsfs_SetError(-EFAULT);
2773 if (yaffsfs_CheckPath(path) < 0) {
2774 yaffsfs_SetError(-ENAMETOOLONG);
2778 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2779 yaffsfs_SetError(-ENOMEM);
2784 result = yaffsfs_DoUnlink_reldir(reldir, path, 1);
2791 int yaffs_rmdir_reldev(struct yaffs_dev *dev, const YCHAR *path)
2793 return yaffs_rmdir_reldir(ROOT_DIR(dev), path);
2796 int yaffs_rmdir(const YCHAR *path)
2798 return yaffs_rmdir_reldir(NULL, path);
2802 * The mount/unmount/sync functions act on devices rather than reldirs.
2804 void *yaffs_getdev(const YCHAR *path)
2806 struct yaffs_dev *dev = NULL;
2808 dev = yaffsfs_FindDevice(path, &dummy);
2812 int yaffs_mount_common(struct yaffs_dev *dev, const YCHAR *path,
2813 int read_only, int skip_checkpt)
2816 int result = YAFFS_FAIL;
2819 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2820 yaffsfs_SetError(-EFAULT);
2824 yaffs_trace(YAFFS_TRACE_MOUNT, "yaffs: Mounting %s", path);
2826 if (yaffsfs_CheckPath(path) < 0) {
2827 yaffsfs_SetError(-ENAMETOOLONG);
2834 yaffsfs_InitHandles();
2837 dev = yaffsfs_FindMountPoint(path);
2840 if (!dev->is_mounted) {
2841 dev->read_only = read_only ? 1 : 0;
2843 u8 skip = dev->param.skip_checkpt_rd;
2844 dev->param.skip_checkpt_rd = 1;
2845 result = yaffs_guts_initialise(dev);
2846 dev->param.skip_checkpt_rd = skip;
2848 result = yaffs_guts_initialise(dev);
2851 if (result == YAFFS_FAIL)
2852 yaffsfs_SetError(-ENOMEM);
2853 retVal = result ? 0 : -1;
2856 yaffsfs_SetError(-EBUSY);
2858 yaffsfs_SetError(-ENODEV);
2865 int yaffs_mount3_reldev(struct yaffs_dev *dev, int read_only, int skip_checkpt)
2867 return yaffs_mount_common(dev, NULL, read_only, skip_checkpt);
2870 int yaffs_mount3(const YCHAR *path, int read_only, int skip_checkpt)
2872 return yaffs_mount_common(NULL, path, read_only, skip_checkpt);
2875 int yaffs_mount2_reldev(struct yaffs_dev *dev, int readonly)
2877 return yaffs_mount_common(dev, NULL, readonly, 0);
2880 int yaffs_mount2(const YCHAR *path, int readonly)
2882 return yaffs_mount_common(NULL, path, readonly, 0);
2885 int yaffs_mount_reldev(struct yaffs_dev *dev)
2887 return yaffs_mount_common(dev, NULL, 0, 0);
2890 int yaffs_mount(const YCHAR *path)
2892 return yaffs_mount_common(NULL, path, 0, 0);
2895 static int yaffs_sync_common(struct yaffs_dev *dev,
2903 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2904 yaffsfs_SetError(-EFAULT);
2908 if (yaffsfs_CheckPath(path) < 0) {
2909 yaffsfs_SetError(-ENAMETOOLONG);
2916 dev = yaffsfs_FindDevice(path, &dummy);
2919 if (!dev->is_mounted)
2920 yaffsfs_SetError(-EINVAL);
2921 else if (dev->read_only)
2922 yaffsfs_SetError(-EROFS);
2925 yaffs_flush_whole_cache(dev, 0);
2927 yaffs_checkpoint_save(dev);
2932 yaffsfs_SetError(-ENODEV);
2938 int yaffs_sync_files_reldev(struct yaffs_dev *dev)
2940 return yaffs_sync_common(dev, NULL, 0);
2943 int yaffs_sync_files(const YCHAR *path)
2945 return yaffs_sync_common(NULL, path, 0);
2948 int yaffs_sync_reldev(struct yaffs_dev *dev)
2950 return yaffs_sync_common(dev, NULL, 1);
2953 int yaffs_sync(const YCHAR *path)
2955 return yaffs_sync_common(NULL, path, 1);
2959 static int yaffsfs_bg_gc_common(struct yaffs_dev *dev,
2967 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2968 yaffsfs_SetError(-EFAULT);
2972 if (yaffsfs_CheckPath(path) < 0) {
2973 yaffsfs_SetError(-ENAMETOOLONG);
2980 dev = yaffsfs_FindDevice(path, &dummy);
2983 if (!dev->is_mounted)
2984 yaffsfs_SetError(-EINVAL);
2986 retVal = yaffs_bg_gc(dev, urgency);
2988 yaffsfs_SetError(-ENODEV);
2994 /* Background gc functions.
2995 * These return 0 when bg done or greater than 0 when gc has been
2996 * done and there is still a lot of garbage to be cleaned up.
2999 int yaffs_do_background_gc(const YCHAR *path, int urgency)
3001 return yaffsfs_bg_gc_common(NULL, path, urgency);
3004 int yaffs_do_background_gc_reldev(struct yaffs_dev *dev, int urgency)
3006 return yaffsfs_bg_gc_common(dev, NULL, urgency);
3009 static int yaffsfs_IsDevBusy(struct yaffs_dev *dev)
3012 struct yaffs_obj *obj;
3014 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
3015 obj = yaffsfs_HandleToObject(i);
3016 if (obj && obj->my_dev == dev)
3022 int yaffs_remount_common(struct yaffs_dev *dev, const YCHAR *path,
3023 int force, int read_only)
3027 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3028 yaffsfs_SetError(-EFAULT);
3032 if (yaffsfs_CheckPath(path) < 0) {
3033 yaffsfs_SetError(-ENAMETOOLONG);
3039 dev = yaffsfs_FindMountPoint(path);
3042 if (dev->is_mounted) {
3043 yaffs_flush_whole_cache(dev, 0);
3045 if (force || !yaffsfs_IsDevBusy(dev)) {
3047 yaffs_checkpoint_save(dev);
3048 dev->read_only = read_only ? 1 : 0;
3051 yaffsfs_SetError(-EBUSY);
3054 yaffsfs_SetError(-EINVAL);
3057 yaffsfs_SetError(-ENODEV);
3064 int yaffs_remount_reldev(struct yaffs_dev *dev, int force, int read_only)
3066 return yaffs_remount_common(dev, NULL, force, read_only);
3068 int yaffs_remount(const YCHAR *path, int force, int read_only)
3070 return yaffs_remount_common(NULL, path, force, read_only);
3073 int yaffs_unmount2_common(struct yaffs_dev *dev, const YCHAR *path, int force)
3077 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3078 yaffsfs_SetError(-EFAULT);
3082 if (yaffsfs_CheckPath(path) < 0) {
3083 yaffsfs_SetError(-ENAMETOOLONG);
3089 dev = yaffsfs_FindMountPoint(path);
3092 if (dev->is_mounted) {
3094 yaffs_flush_whole_cache(dev, 0);
3095 yaffs_checkpoint_save(dev);
3096 inUse = yaffsfs_IsDevBusy(dev);
3097 if (!inUse || force) {
3099 yaffsfs_BreakDeviceHandles(dev);
3100 yaffs_deinitialise(dev);
3104 yaffsfs_SetError(-EBUSY);
3107 yaffsfs_SetError(-EINVAL);
3110 yaffsfs_SetError(-ENODEV);
3117 int yaffs_unmount2_reldev(struct yaffs_dev *dev, int force)
3119 return yaffs_unmount2_common(dev, NULL, force);
3122 int yaffs_unmount2(const YCHAR *path, int force)
3124 return yaffs_unmount2_common(NULL, path, force);
3127 int yaffs_unmount_reldev(struct yaffs_dev *dev)
3129 return yaffs_unmount2_reldev(dev, 0);
3132 int yaffs_unmount(const YCHAR *path)
3134 return yaffs_unmount2(path, 0);
3137 int yaffs_format_common(struct yaffs_dev *dev,
3140 int force_unmount_flag,
3148 yaffsfs_SetError(-EFAULT);
3152 if (yaffsfs_CheckPath(path) < 0) {
3153 yaffsfs_SetError(-ENAMETOOLONG);
3160 dev = yaffsfs_FindMountPoint(path);
3163 int was_mounted = dev->is_mounted;
3165 if (dev->is_mounted && unmount_flag) {
3167 yaffs_flush_whole_cache(dev, 0);
3168 yaffs_checkpoint_save(dev);
3169 inUse = yaffsfs_IsDevBusy(dev);
3170 if (!inUse || force_unmount_flag) {
3172 yaffsfs_BreakDeviceHandles(dev);
3173 yaffs_deinitialise(dev);
3177 if(dev->is_mounted) {
3178 yaffsfs_SetError(-EBUSY);
3181 yaffs_guts_format_dev(dev);
3182 if(was_mounted && remount_flag) {
3183 result = yaffs_guts_initialise(dev);
3184 if (result == YAFFS_FAIL) {
3185 yaffsfs_SetError(-ENOMEM);
3191 yaffsfs_SetError(-ENODEV);
3200 int yaffs_format_reldev(struct yaffs_dev *dev,
3202 int force_unmount_flag,
3205 return yaffs_format_common(dev, NULL, unmount_flag,
3206 force_unmount_flag, remount_flag);
3209 int yaffs_format(const YCHAR *path,
3211 int force_unmount_flag,
3214 return yaffs_format_common(NULL, path, unmount_flag,
3215 force_unmount_flag, remount_flag);
3218 Y_LOFF_T yaffs_freespace_common(struct yaffs_dev *dev, const YCHAR *path)
3220 Y_LOFF_T retVal = -1;
3224 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3225 yaffsfs_SetError(-EFAULT);
3229 if (yaffsfs_CheckPath(path) < 0) {
3230 yaffsfs_SetError(-ENAMETOOLONG);
3237 dev = yaffsfs_FindDevice(path, &dummy);
3238 if (dev && dev->is_mounted) {
3239 retVal = yaffs_get_n_free_chunks(dev);
3240 retVal *= dev->data_bytes_per_chunk;
3243 yaffsfs_SetError(-EINVAL);
3249 Y_LOFF_T yaffs_freespace_reldev(struct yaffs_dev *dev)
3251 return yaffs_freespace_common(dev, NULL);
3254 Y_LOFF_T yaffs_freespace(const YCHAR *path)
3256 return yaffs_freespace_common(NULL, path);
3259 Y_LOFF_T yaffs_totalspace_common(struct yaffs_dev *dev, const YCHAR *path)
3261 Y_LOFF_T retVal = -1;
3265 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3266 yaffsfs_SetError(-EFAULT);
3270 if (yaffsfs_CheckPath(path) < 0) {
3271 yaffsfs_SetError(-ENAMETOOLONG);
3278 dev = yaffsfs_FindDevice(path, &dummy);
3279 if (dev && dev->is_mounted) {
3280 retVal = (dev->param.end_block - dev->param.start_block + 1) -
3281 dev->param.n_reserved_blocks;
3282 retVal *= dev->param.chunks_per_block;
3283 retVal *= dev->data_bytes_per_chunk;
3286 yaffsfs_SetError(-EINVAL);
3292 Y_LOFF_T yaffs_totalspace_reldev(struct yaffs_dev *dev)
3294 return yaffs_totalspace_common(dev, NULL);
3297 Y_LOFF_T yaffs_totalspace(const YCHAR *path)
3299 return yaffs_totalspace_common(NULL, path);
3302 int yaffs_inodecount_common(struct yaffs_dev *dev, const YCHAR *path)
3304 Y_LOFF_T retVal = -1;
3308 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3309 yaffsfs_SetError(-EFAULT);
3313 if (yaffsfs_CheckPath(path) < 0) {
3314 yaffsfs_SetError(-ENAMETOOLONG);
3321 dev = yaffsfs_FindDevice(path, &dummy);
3322 if (dev && dev->is_mounted) {
3323 int n_obj = dev->n_obj;
3324 if (n_obj > dev->n_hardlinks)
3325 retVal = n_obj - dev->n_hardlinks;
3329 yaffsfs_SetError(-EINVAL);
3335 int yaffs_inodecount_reldev(struct yaffs_dev *dev)
3337 return yaffs_inodecount_common(dev, NULL);
3340 int yaffs_inodecount(const YCHAR *path)
3342 return yaffs_inodecount_common(NULL, path);
3345 void yaffs_add_device(struct yaffs_dev *dev)
3347 struct list_head *cfg;
3348 /* First check that the device is not in the list. */
3350 list_for_each(cfg, &yaffsfs_deviceList) {
3351 if (dev == list_entry(cfg, struct yaffs_dev, dev_list))
3355 dev->is_mounted = 0;
3356 dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
3358 if (!dev->dev_list.next)
3359 INIT_LIST_HEAD(&dev->dev_list);
3361 list_add(&dev->dev_list, &yaffsfs_deviceList);
3366 void yaffs_remove_device(struct yaffs_dev *dev)
3368 list_del_init(&dev->dev_list);
3371 /* Functions to iterate through devices. NB Use with extreme care! */
3373 static struct list_head *dev_iterator;
3374 void yaffs_dev_rewind(void)
3376 dev_iterator = yaffsfs_deviceList.next;
3379 struct yaffs_dev *yaffs_next_dev(void)
3381 struct yaffs_dev *retval;
3385 if (dev_iterator == &yaffsfs_deviceList)
3388 retval = list_entry(dev_iterator, struct yaffs_dev, dev_list);
3389 dev_iterator = dev_iterator->next;
3393 /* Directory search stuff. */
3395 static struct list_head search_contexts;
3397 static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContext *dsc)
3401 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3405 if (list_empty(&dsc->dirObj->variant.dir_variant.children))
3406 dsc->nextReturn = NULL;
3409 list_entry(dsc->dirObj->variant.dir_variant.
3410 children.next, struct yaffs_obj,
3413 /* Hey someone isn't playing nice! */
3417 static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContext *dsc)
3421 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3423 if (dsc->nextReturn == NULL ||
3424 list_empty(&dsc->dirObj->variant.dir_variant.children))
3425 dsc->nextReturn = NULL;
3427 struct list_head *next = dsc->nextReturn->siblings.next;
3429 if (next == &dsc->dirObj->variant.dir_variant.children)
3430 dsc->nextReturn = NULL; /* end of list */
3432 dsc->nextReturn = list_entry(next,
3437 /* Hey someone isn't playing nice! */
3441 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj)
3444 struct list_head *i;
3445 struct yaffsfs_DirSearchContext *dsc;
3447 /* if search contexts not initilised then skip */
3448 if (!search_contexts.next)
3451 /* Iterate through the directory search contexts.
3452 * If any are the one being removed, then advance the dsc to
3453 * the next one to prevent a hanging ptr.
3455 list_for_each(i, &search_contexts) {
3457 dsc = list_entry(i, struct yaffsfs_DirSearchContext,
3459 if (dsc->nextReturn == obj)
3460 yaffsfs_DirAdvance(dsc);
3466 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(struct yaffs_obj *reldir,
3467 const YCHAR *dirname)
3469 yaffs_DIR *dir = NULL;
3470 struct yaffs_obj *obj = NULL;
3471 struct yaffsfs_DirSearchContext *dsc = NULL;
3475 if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) {
3476 yaffsfs_SetError(-EFAULT);
3480 if (yaffsfs_CheckPath(dirname) < 0) {
3481 yaffsfs_SetError(-ENAMETOOLONG);
3485 obj = yaffsfs_FindObject(reldir, dirname, 0, 1, NULL, ¬Dir, &loop);
3486 obj = yaffsfs_FollowLink(obj, 0, &loop);
3489 yaffsfs_SetError(-ENOTDIR);
3491 yaffsfs_SetError(-ELOOP);
3493 yaffsfs_SetError(-ENOENT);
3494 else if (obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
3495 yaffsfs_SetError(-ENOTDIR);
3499 for (i = 0, dsc = NULL; i < YAFFSFS_N_DSC && !dsc; i++) {
3500 if (!yaffsfs_dsc[i].inUse)
3501 dsc = &yaffsfs_dsc[i];
3504 dir = (yaffs_DIR *) dsc;
3507 memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContext));
3510 yaffs_strncpy(dsc->name, dirname, NAME_MAX);
3511 INIT_LIST_HEAD(&dsc->others);
3513 if (!search_contexts.next)
3514 INIT_LIST_HEAD(&search_contexts);
3516 list_add(&dsc->others, &search_contexts);
3517 yaffsfs_SetDirRewound(dsc);
3523 yaffs_DIR *yaffs_opendir_reldir(struct yaffs_obj *reldir, const YCHAR *dirname)
3528 ret = yaffsfs_opendir_reldir_no_lock(reldir, dirname);
3533 yaffs_DIR *yaffs_opendir_reldev(struct yaffs_dev *dev, const YCHAR *dirname)
3535 return yaffs_opendir_reldir(ROOT_DIR(dev), dirname);
3538 yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
3540 return yaffs_opendir_reldir(NULL, dirname);
3543 struct yaffs_dirent *yaffsfs_readdir_no_lock(yaffs_DIR * dirp)
3545 struct yaffsfs_DirSearchContext *dsc;
3546 struct yaffs_dirent *retVal = NULL;
3548 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3551 if (dsc && dsc->inUse) {
3552 yaffsfs_SetError(0);
3553 if (dsc->nextReturn) {
3555 yaffs_get_equivalent_obj(dsc->nextReturn)->obj_id;
3556 dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
3557 dsc->de.d_off = dsc->offset++;
3558 yaffs_get_obj_name(dsc->nextReturn,
3559 dsc->de.d_name, NAME_MAX);
3560 if (yaffs_strnlen(dsc->de.d_name, NAME_MAX + 1) == 0) {
3561 /* this should not happen! */
3562 yaffs_strcpy(dsc->de.d_name, _Y("zz"));
3564 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
3566 yaffsfs_DirAdvance(dsc);
3570 yaffsfs_SetError(-EBADF);
3575 struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp)
3577 struct yaffs_dirent *ret;
3580 ret = yaffsfs_readdir_no_lock(dirp);
3585 static void yaffsfs_rewinddir_no_lock(yaffs_DIR *dirp)
3587 struct yaffsfs_DirSearchContext *dsc;
3589 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3591 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
3594 yaffsfs_SetDirRewound(dsc);
3598 void yaffs_rewinddir(yaffs_DIR *dirp)
3601 yaffsfs_rewinddir_no_lock(dirp);
3605 struct yaffs_dirent *yaffs_readdir_fd(int fd)
3607 struct yaffs_dirent *ret = NULL;
3608 struct yaffsfs_FileDes *f;
3611 f = yaffsfs_HandleToFileDes(fd);
3613 ret = yaffsfs_readdir_no_lock(f->v.dir);
3618 void yaffs_rewinddir_fd(int fd)
3620 struct yaffsfs_FileDes *f;
3623 f = yaffsfs_HandleToFileDes(fd);
3625 yaffsfs_rewinddir_no_lock(f->v.dir);
3630 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirp)
3632 struct yaffsfs_DirSearchContext *dsc;
3634 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3636 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) {
3637 yaffsfs_SetError(-EFAULT);
3642 list_del(&dsc->others); /* unhook from list */
3647 int yaffs_closedir(yaffs_DIR *dirp)
3652 ret = yaffsfs_closedir_no_lock(dirp);
3657 /* End of directory stuff */
3659 int yaffs_symlink_reldir(struct yaffs_obj *reldir,
3660 const YCHAR *oldpath, const YCHAR *newpath)
3662 struct yaffs_obj *parent = NULL;
3663 struct yaffs_obj *obj;
3666 int mode = 0; /* ignore for now */
3670 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3671 yaffsfs_CheckMemRegion(newpath, 0, 0) < 0) {
3672 yaffsfs_SetError(-EFAULT);
3676 if (yaffsfs_CheckPath(newpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3677 yaffsfs_SetError(-ENAMETOOLONG);
3682 parent = yaffsfs_FindDirectory(reldir, newpath, &name, 0, ¬Dir, &loop);
3683 if (!parent && notDir)
3684 yaffsfs_SetError(-ENOTDIR);
3686 yaffsfs_SetError(-ELOOP);
3687 else if (!parent || yaffs_strnlen(name, 5) < 1)
3688 yaffsfs_SetError(-ENOENT);
3689 else if (yaffsfs_TooManyObjects(parent->my_dev))
3690 yaffsfs_SetError(-ENFILE);
3691 else if (parent->my_dev->read_only)
3692 yaffsfs_SetError(-EROFS);
3694 obj = yaffs_create_symlink(parent, name, mode, 0, 0, oldpath);
3697 else if (yaffsfs_FindObject(reldir, newpath, 0, 0,
3699 yaffsfs_SetError(-EEXIST);
3701 yaffsfs_SetError(-ENOSPC);
3709 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
3711 return yaffs_symlink_reldir(NULL, oldpath, newpath);
3714 int yaffs_readlink_reldir(struct yaffs_obj *reldir,const YCHAR *path,
3715 YCHAR *buf, int bufsiz)
3717 struct yaffs_obj *obj = NULL;
3718 struct yaffs_obj *dir = NULL;
3723 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
3724 yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0) {
3725 yaffsfs_SetError(-EFAULT);
3731 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
3734 yaffsfs_SetError(-ENOTDIR);
3736 yaffsfs_SetError(-ELOOP);
3737 else if (!dir || !obj)
3738 yaffsfs_SetError(-ENOENT);
3739 else if (obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
3740 yaffsfs_SetError(-EINVAL);
3742 YCHAR *alias = obj->variant.symlink_variant.alias;
3743 memset(buf, 0, bufsiz);
3744 yaffs_strncpy(buf, alias, bufsiz - 1);
3750 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
3752 return yaffs_readlink_reldir(NULL, path, buf, bufsiz);
3755 int yaffs_link_reldir(struct yaffs_obj *reldir,
3756 const YCHAR *oldpath, const YCHAR *linkpath)
3758 /* Creates a link called newpath to existing oldpath */
3759 struct yaffs_obj *obj = NULL;
3760 struct yaffs_obj *lnk = NULL;
3761 struct yaffs_obj *obj_dir = NULL;
3762 struct yaffs_obj *lnk_dir = NULL;
3770 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3771 yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0) {
3772 yaffsfs_SetError(-EFAULT);
3776 if (yaffsfs_CheckPath(linkpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3777 yaffsfs_SetError(-ENAMETOOLONG);
3783 obj = yaffsfs_FindObject(reldir, oldpath, 0, 1,
3784 &obj_dir, ¬DirObj, &objLoop);
3785 lnk = yaffsfs_FindObject(reldir, linkpath, 0, 0, NULL, NULL, NULL);
3786 lnk_dir = yaffsfs_FindDirectory(reldir, linkpath, &newname,
3787 0, ¬DirLnk, &lnkLoop);
3789 if ((!obj_dir && notDirObj) || (!lnk_dir && notDirLnk))
3790 yaffsfs_SetError(-ENOTDIR);
3791 else if (objLoop || lnkLoop)
3792 yaffsfs_SetError(-ELOOP);
3793 else if (!obj_dir || !lnk_dir || !obj)
3794 yaffsfs_SetError(-ENOENT);
3795 else if (obj->my_dev->read_only)
3796 yaffsfs_SetError(-EROFS);
3797 else if (yaffsfs_TooManyObjects(obj->my_dev))
3798 yaffsfs_SetError(-ENFILE);
3800 yaffsfs_SetError(-EEXIST);
3801 else if (lnk_dir->my_dev != obj->my_dev)
3802 yaffsfs_SetError(-EXDEV);
3804 retVal = yaffsfs_CheckNameLength(newname);
3807 lnk = yaffs_link_obj(lnk_dir, newname, obj);
3811 yaffsfs_SetError(-ENOSPC);
3820 int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
3822 return yaffs_link_reldir(NULL, oldpath, linkpath);
3825 int yaffs_mknod_reldir(struct yaffs_obj *reldir, const YCHAR *pathname,
3826 mode_t mode, dev_t dev_val)
3833 yaffsfs_SetError(-EINVAL);
3837 int yaffs_mknod_reldev(struct yaffs_dev *dev, const YCHAR *pathname, mode_t mode, dev_t dev_val)
3839 return yaffs_mknod_reldir(ROOT_DIR(dev), pathname, mode, dev_val);
3842 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev_val)
3844 return yaffs_mknod_reldir(NULL, pathname, mode, dev_val);
3848 * D E B U G F U N C T I O N S
3853 * Returns number of handles attached to the object
3855 int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3857 struct yaffs_obj *obj;
3859 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3860 yaffsfs_SetError(-EFAULT);
3864 if (yaffsfs_CheckPath(path) < 0) {
3865 yaffsfs_SetError(-ENAMETOOLONG);
3869 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
3872 return yaffsfs_CountHandles(obj);
3877 int yaffs_n_handles(const YCHAR *path)
3879 return yaffs_n_handles_reldir(NULL, path);
3882 int yaffs_get_error(void)
3884 return yaffsfs_GetLastError();
3887 int yaffs_set_error(int error)
3889 yaffsfs_SetError(error);
3893 struct yaffs_obj * yaffs_get_obj_from_fd(int handle)
3895 return yaffsfs_HandleToObject(handle);
3898 int yaffs_dump_dev_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3908 reldir = yaffsfs_FindRoot(path, &rest);
3911 struct yaffs_dev *dev = reldir->my_dev;
3914 "n_page_writes.......... %d\n"
3915 "n_page_reads........... %d\n"
3916 "n_erasures....... %d\n"
3917 "n_gc_copies............ %d\n"
3918 "garbageCollections... %d\n"
3919 "passiveGarbageColl'ns %d\n"
3925 dev->garbageCollections, dev->passiveGarbageCollections);
3932 int yaffs_dump_dev(const YCHAR *path)
3934 return yaffs_dump_dev_reldir(NULL, path);