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);
353 if (fd->inodeId >= 0) {
354 yaffsfs_PutInode(fd->inodeId);
362 static int yaffsfs_PutHandle(int handle)
364 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
366 if (h && h->useCount > 0) {
368 if (h->useCount < 1) {
369 yaffsfs_PutFileDes(h->fdId);
377 static void yaffsfs_BreakDeviceHandles(struct yaffs_dev *dev)
379 struct yaffsfs_FileDes *fd;
380 struct yaffsfs_Handle *h;
381 struct yaffs_obj *obj;
383 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
384 h = yaffsfs_HandleToPointer(i);
385 fd = yaffsfs_HandleToFileDes(i);
386 obj = yaffsfs_HandleToObject(i);
387 if (h && h->useCount > 0) {
391 if (fd && fd->handleCount > 0 && obj && obj->my_dev == dev) {
393 yaffsfs_PutInode(fd->inodeId);
400 * Stuff to handle names.
402 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
403 #ifndef CONFIG_YAFFS_WINCE
404 static int yaffs_toupper(YCHAR a)
406 if (a >= 'a' && a <= 'z')
407 return (a - 'a') + 'A';
413 static int yaffsfs_Match(YCHAR a, YCHAR b)
415 return (yaffs_toupper(a) == yaffs_toupper(b));
418 static int yaffsfs_Match(YCHAR a, YCHAR b)
425 static int yaffsfs_IsPathDivider(YCHAR ch)
427 const YCHAR *str = YAFFS_PATH_DIVIDERS;
438 static int yaffsfs_CheckNameLength(const YCHAR *name)
442 int nameLength = yaffs_strnlen(name, YAFFS_MAX_NAME_LENGTH + 1);
444 if (nameLength == 0) {
445 yaffsfs_SetError(-ENOENT);
447 } else if (nameLength > YAFFS_MAX_NAME_LENGTH) {
448 yaffsfs_SetError(-ENAMETOOLONG);
455 static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
457 YCHAR *alt_path = NULL;
462 * We don't have a definition for max path length.
463 * We will use 3 * max name length instead.
466 path_length = yaffs_strnlen(path, (YAFFS_MAX_NAME_LENGTH + 1) * 3 + 1);
468 /* If the last character is a path divider, then we need to
469 * trim it back so that the name look-up works properly.
470 * eg. /foo/new_dir/ -> /foo/newdir
471 * Curveball: Need to handle multiple path dividers:
472 * eg. /foof/sdfse///// -> /foo/sdfse
474 if (path_length > 0 && yaffsfs_IsPathDivider(path[path_length - 1])) {
475 alt_path = kmalloc(path_length + 1, 0);
478 yaffs_strcpy(alt_path, path);
479 for (i = path_length - 1;
480 i >= 0 && yaffsfs_IsPathDivider(alt_path[i]); i--)
481 alt_path[i] = (YCHAR) 0;
483 *ret_path = alt_path;
487 LIST_HEAD(yaffsfs_deviceList);
492 * Scan the configuration list to find the device
493 * Curveballs: Should match paths that end in '/' too
494 * Curveball2 Might have "/x/ and "/x/y". Need to return the longest match
496 static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path,
499 struct list_head *cfg;
500 const YCHAR *leftOver;
502 struct yaffs_dev *retval = NULL;
503 struct yaffs_dev *dev = NULL;
505 int longestMatch = -1;
509 * Check all configs, choose the one that:
510 * 1) Actually matches a prefix (ie /a amd /abc will not match
511 * 2) Matches the longest.
513 list_for_each(cfg, &yaffsfs_deviceList) {
514 dev = list_entry(cfg, struct yaffs_dev, dev_list);
524 /* Skip over any leading /s */
525 while (yaffsfs_IsPathDivider(*p))
527 while (yaffsfs_IsPathDivider(*leftOver))
530 while (matching && *p && *leftOver) {
532 /* Now match the text part */
534 *p && !yaffsfs_IsPathDivider(*p) &&
535 *leftOver && !yaffsfs_IsPathDivider(*leftOver)) {
536 if (yaffsfs_Match(*p, *leftOver)) {
545 if ((*p && !yaffsfs_IsPathDivider(*p)) ||
546 (*leftOver && !yaffsfs_IsPathDivider(*leftOver)))
549 while (yaffsfs_IsPathDivider(*p))
551 while (yaffsfs_IsPathDivider(*leftOver))
556 /* Skip over any /s in leftOver */
557 while (yaffsfs_IsPathDivider(*leftOver))
560 /*Skip over any /s in p */
561 while (yaffsfs_IsPathDivider(*p))
564 /* p should now be at the end of the string if fully matched */
568 if (matching && (thisMatchLength > longestMatch)) {
570 *restOfPath = (YCHAR *) leftOver;
572 longestMatch = thisMatchLength;
578 static int yaffsfs_CheckPath(const YCHAR *path)
583 while (*path && n < YAFFS_MAX_NAME_LENGTH && divs < 100) {
584 if (yaffsfs_IsPathDivider(*path)) {
592 return (*path) ? -1 : 0;
595 /* FindMountPoint only returns a dev entry if the path is a mount point */
596 static struct yaffs_dev *yaffsfs_FindMountPoint(const YCHAR *path)
598 struct yaffs_dev *dev;
599 YCHAR *restOfPath = NULL;
601 dev = yaffsfs_FindDevice(path, &restOfPath);
602 if (dev && restOfPath && *restOfPath)
607 static struct yaffs_obj *yaffsfs_FindRoot(const YCHAR *path,
610 struct yaffs_dev *dev;
612 dev = yaffsfs_FindDevice(path, restOfPath);
613 if (dev && dev->is_mounted)
614 return dev->root_dir;
619 static struct yaffs_obj *yaffsfs_FollowLink(struct yaffs_obj *obj,
620 int symDepth, int *loop)
624 obj = yaffs_get_equivalent_obj(obj);
626 while (obj && obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
627 YCHAR *alias = obj->variant.symlink_variant.alias;
629 if (yaffsfs_IsPathDivider(*alias))
631 * Starts with a /, need to scan from root up */
632 /* NB Might not work if this is called with root != NULL
634 obj = yaffsfs_FindObject(NULL, alias, symDepth++,
635 1, NULL, NULL, loop);
638 * Relative to here so use the parent of the
641 obj = yaffsfs_FindObject(obj->parent, alias, symDepth++,
642 1, NULL, NULL, loop);
648 * yaffsfs_FindDirectory
649 * Parse a path to determine the directory and the name within the directory.
651 * eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
653 static struct yaffs_obj *yaffsfs_DoFindDirectory(struct yaffs_obj *startDir,
655 YCHAR **name, int symDepth,
656 int *notDir, int *loop)
658 struct yaffs_obj *dir;
660 YCHAR str[YAFFS_MAX_NAME_LENGTH + 1];
663 if (symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES) {
671 restOfPath = (YCHAR *) path;
673 dir = yaffsfs_FindRoot(path, &restOfPath);
678 * curve ball: also throw away surplus '/'
679 * eg. "/ram/x////ff" gets treated the same as "/ram/x/ff"
681 while (yaffsfs_IsPathDivider(*restOfPath))
682 restOfPath++; /* get rid of '/' */
687 while (*restOfPath && !yaffsfs_IsPathDivider(*restOfPath)) {
688 if (i < YAFFS_MAX_NAME_LENGTH) {
689 str[i] = *restOfPath;
697 /* got to the end of the string */
700 if (yaffs_strcmp(str, _Y(".")) == 0) {
702 } else if (yaffs_strcmp(str, _Y("..")) == 0) {
705 dir = yaffs_find_by_name(dir, str);
707 dir = yaffsfs_FollowLink(dir, symDepth, loop);
709 if (dir && dir->variant_type !=
710 YAFFS_OBJECT_TYPE_DIRECTORY) {
719 /* directory did not exist. */
723 static struct yaffs_obj *yaffsfs_FindDirectory(struct yaffs_obj *relDir,
727 int *notDir, int *loop)
729 return yaffsfs_DoFindDirectory(relDir, path, name, symDepth, notDir,
734 * yaffsfs_FindObject turns a path for an existing object into the object
736 static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relDir,
737 const YCHAR *path, int symDepth,
739 struct yaffs_obj **dirOut,
740 int *notDir, int *loop)
742 struct yaffs_obj *dir;
743 struct yaffs_obj *obj;
747 yaffsfs_FindDirectory(relDir, path, &name, symDepth, notDir, loop);
752 /* At this stage we have looked up directory part and have the name part
753 * in name if there is one.
755 * eg /nand/x/ will give us a name of ""
756 * /nand/x will give us a name of "x"
758 * Since the name part might be "." or ".." which need to be fixed.
760 if (dir && (yaffs_strcmp(name, _Y("..")) == 0)) {
763 } else if (dir && (yaffs_strcmp(name, _Y(".")) == 0))
765 else if (dir && *name)
766 obj = yaffs_find_by_name(dir, name);
771 obj = yaffs_get_equivalent_obj(obj);
776 /*************************************************************************
777 * Start of yaffsfs visible functions.
778 *************************************************************************/
780 int yaffs_dup(int handle)
782 int newHandleNumber = -1;
783 struct yaffsfs_FileDes *existingFD = NULL;
784 struct yaffsfs_Handle *existingHandle = NULL;
785 struct yaffsfs_Handle *newHandle = NULL;
788 existingHandle = yaffsfs_HandleToPointer(handle);
789 existingFD = yaffsfs_HandleToFileDes(handle);
791 newHandleNumber = yaffsfs_NewHandle(&newHandle);
793 newHandle->fdId = existingHandle->fdId;
794 existingFD->handleCount++;
800 yaffsfs_SetError(-EBADF);
802 yaffsfs_SetError(-ENOMEM);
804 return newHandleNumber;
808 static int yaffsfs_TooManyObjects(struct yaffs_dev *dev)
810 int current_objects = dev->n_obj - dev->n_deleted_files;
812 if (dev->param.max_objects && current_objects > dev->param.max_objects)
818 int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
819 int oflag, int mode, int sharing)
821 struct yaffs_obj *obj = NULL;
822 struct yaffs_obj *dir = NULL;
825 struct yaffsfs_FileDes *fd = NULL;
828 int errorReported = 0;
829 int rwflags = oflag & (O_RDWR | O_RDONLY | O_WRONLY);
830 u8 shareRead = (sharing & YAFFS_SHARE_READ) ? 1 : 0;
831 u8 shareWrite = (sharing & YAFFS_SHARE_WRITE) ? 1 : 0;
832 u8 sharedReadAllowed;
833 u8 sharedWriteAllowed;
841 yaffs_DIR *dsc = NULL;
843 if (yaffsfs_CheckMemRegion(path, 0, 0)< 0) {
844 yaffsfs_SetError(-EFAULT);
848 if (yaffsfs_CheckPath(path) < 0) {
849 yaffsfs_SetError(-ENAMETOOLONG);
853 /* O_EXCL only has meaning if O_CREAT is specified */
854 if (!(oflag & O_CREAT))
857 /* O_TRUNC has no meaning if (O_CREAT | O_EXCL) is specified */
858 if ((oflag & O_CREAT) && (oflag & O_EXCL))
861 /* Todo: Are there any more flag combos to sanitise ? */
863 /* Figure out if reading or writing is requested */
865 readRequested = (rwflags == O_RDWR || rwflags == O_RDONLY) ? 1 : 0;
866 writeRequested = (rwflags == O_RDWR || rwflags == O_WRONLY) ? 1 : 0;
870 handle = yaffsfs_NewHandleAndFileDes();
873 yaffsfs_SetError(-ENFILE);
874 errorReported = __LINE__;
877 fd = yaffsfs_HandleToFileDes(handle);
879 /* try to find the exisiting object */
880 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
882 obj = yaffsfs_FollowLink(obj, symDepth++, &loop);
885 obj->variant_type != YAFFS_OBJECT_TYPE_FILE &&
886 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
891 /* The file already exists or it might be a directory */
892 is_dir = (obj->variant_type ==
893 YAFFS_OBJECT_TYPE_DIRECTORY);
895 /* A directory can't be opened except for read */
897 (writeRequested || !readRequested || rwflags != O_RDONLY)) {
898 openDenied = __LINE__;
899 yaffsfs_SetError(-EISDIR);
900 errorReported = __LINE__;
904 dsc = yaffsfs_opendir_reldir_no_lock(reldir, path);
906 openDenied = __LINE__;
907 yaffsfs_SetError(-ENFILE);
908 errorReported = __LINE__;
912 /* Open should fail if O_CREAT and O_EXCL are specified
913 * for a file that exists.
915 if (!errorReported &&
916 (oflag & O_EXCL) && (oflag & O_CREAT)) {
917 openDenied = __LINE__;
918 yaffsfs_SetError(-EEXIST);
919 errorReported = __LINE__;
922 /* Check file permissions */
923 if (readRequested && !(obj->yst_mode & S_IRUSR))
924 openDenied = __LINE__;
926 if (writeRequested && !(obj->yst_mode & S_IWUSR))
927 openDenied = __LINE__;
929 if (!errorReported && writeRequested &&
930 obj->my_dev->read_only) {
931 openDenied = __LINE__;
932 yaffsfs_SetError(-EROFS);
933 errorReported = __LINE__;
936 if (openDenied && !errorReported) {
937 yaffsfs_SetError(-EACCES);
938 errorReported = __LINE__;
941 /* Check sharing of an existing object. */
943 struct yaffsfs_FileDes *fdx;
946 sharedReadAllowed = 1;
947 sharedWriteAllowed = 1;
950 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
951 fdx = &yaffsfs_fd[i];
952 if (fdx->handleCount > 0 &&
954 yaffsfs_inode[fdx->inodeId].iObj
957 sharedReadAllowed = 0;
958 if (!fdx->shareWrite)
959 sharedWriteAllowed = 0;
967 if ((!sharedReadAllowed && readRequested) ||
968 (!shareRead && alreadyReading) ||
969 (!sharedWriteAllowed && writeRequested) ||
970 (!shareWrite && alreadyWriting)) {
971 openDenied = __LINE__;
972 yaffsfs_SetError(-EBUSY);
973 errorReported = __LINE__;
979 /* If we could not open an existing object, then let's see if
980 * the directory exists. If not, error.
982 if (!obj && !errorReported) {
983 dir = yaffsfs_FindDirectory(reldir, path, &name, 0,
985 if (!dir && notDir) {
986 yaffsfs_SetError(-ENOTDIR);
987 errorReported = __LINE__;
989 yaffsfs_SetError(-ELOOP);
990 errorReported = __LINE__;
992 yaffsfs_SetError(-ENOENT);
993 errorReported = __LINE__;
997 if (!obj && dir && !errorReported && (oflag & O_CREAT)) {
998 /* Let's see if we can create this file */
999 if (dir->my_dev->read_only) {
1000 yaffsfs_SetError(-EROFS);
1001 errorReported = __LINE__;
1002 } else if (yaffsfs_TooManyObjects(dir->my_dev)) {
1003 yaffsfs_SetError(-ENFILE);
1004 errorReported = __LINE__;
1006 obj = yaffs_create_file(dir, name, mode, 0, 0);
1008 if (!obj && !errorReported) {
1009 yaffsfs_SetError(-ENOSPC);
1010 errorReported = __LINE__;
1014 if (!obj && dir && !errorReported && !(oflag & O_CREAT)) {
1015 yaffsfs_SetError(-ENOENT);
1016 errorReported = __LINE__;
1019 if (obj && !openDenied) {
1020 int inodeId = yaffsfs_GetInodeIdForObject(obj);
1024 * Todo: Fix any problem if inodes run out,
1025 * That can't happen if the number of inode
1026 * items >= number of handles.
1030 fd->inodeId = inodeId;
1031 fd->reading = readRequested;
1032 fd->writing = writeRequested;
1033 fd->append = (oflag & O_APPEND) ? 1 : 0;
1034 fd->shareRead = shareRead;
1035 fd->shareWrite = shareWrite;
1043 /* Hook inode to object */
1044 obj->my_inode = (void *)&yaffsfs_inode[inodeId];
1046 if (!is_dir && (oflag & O_TRUNC) && fd->writing)
1047 yaffs_resize_file(obj, 0);
1050 yaffsfs_closedir_no_lock(dsc);
1052 yaffsfs_PutHandle(handle);
1054 yaffsfs_SetError(0); /* Problem */
1064 int yaffs_open_sharing_reldev(struct yaffs_dev *dev, const YCHAR *path, int oflag,
1065 int mode, int sharing)
1067 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path,
1068 oflag, mode, sharing);
1071 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
1073 return yaffs_open_sharing_reldir(NULL, path, oflag, mode, sharing);
1076 int yaffs_open_reldir(struct yaffs_obj *reldir,const YCHAR *path, int oflag, int mode)
1078 return yaffs_open_sharing_reldir(reldir, path, oflag, mode,
1079 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1082 int yaffs_open_reldev(struct yaffs_dev *dev,const YCHAR *path, int oflag, int mode)
1084 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path, oflag, mode,
1085 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1088 int yaffs_open(const YCHAR *path, int oflag, int mode)
1090 return yaffs_open_reldir(NULL, path, oflag, mode);
1093 static int yaffs_Dofsync(int handle, int datasync)
1096 struct yaffs_obj *obj;
1100 obj = yaffsfs_HandleToObject(handle);
1103 yaffsfs_SetError(-EBADF);
1104 else if (obj->my_dev->read_only)
1105 yaffsfs_SetError(-EROFS);
1107 yaffs_flush_file(obj, 1, datasync, 0);
1116 int yaffs_fsync(int handle)
1118 return yaffs_Dofsync(handle, 0);
1121 int yaffs_flush(int handle)
1123 return yaffs_fsync(handle);
1126 int yaffs_fdatasync(int handle)
1128 return yaffs_Dofsync(handle, 1);
1131 int yaffs_close(int handle)
1133 struct yaffsfs_Handle *h = NULL;
1134 struct yaffsfs_FileDes *f;
1135 struct yaffs_obj *obj = NULL;
1140 h = yaffsfs_HandleToPointer(handle);
1141 f = yaffsfs_HandleToFileDes(handle);
1142 obj = yaffsfs_HandleToObject(handle);
1144 if (!h || !obj || !f)
1145 yaffsfs_SetError(-EBADF);
1149 yaffs_flush_file(obj, 1, 0, 1);
1150 yaffsfs_PutHandle(handle);
1159 static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
1160 int isPread, Y_LOFF_T offset)
1162 struct yaffsfs_FileDes *fd = NULL;
1163 struct yaffs_obj *obj = NULL;
1165 Y_LOFF_T startPos = 0;
1166 Y_LOFF_T endPos = 0;
1171 u8 *buf = (u8 *) vbuf;
1173 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) {
1174 yaffsfs_SetError(-EFAULT);
1179 fd = yaffsfs_HandleToFileDes(handle);
1180 obj = yaffsfs_HandleToObject(handle);
1184 yaffsfs_SetError(-EBADF);
1186 } else if (!fd->reading) {
1187 /* Not a reading handle */
1188 yaffsfs_SetError(-EINVAL);
1190 } else if (nbyte > YAFFS_MAX_FILE_SIZE) {
1191 yaffsfs_SetError(-EINVAL);
1197 startPos = fd->v.position;
1201 if (yaffs_get_obj_length(obj) > pos)
1202 maxRead = yaffs_get_obj_length(obj) - pos;
1206 if (nbyte > maxRead)
1209 yaffsfs_GetHandle(handle);
1211 endPos = pos + nbyte;
1213 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1214 nbyte > YAFFS_MAX_FILE_SIZE ||
1215 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1221 nToRead = YAFFSFS_RW_SIZE -
1222 (pos & (YAFFSFS_RW_SIZE - 1));
1223 if (nToRead > nbyte)
1227 * Need to reverify object in case the device was
1228 * unmounted in another thread.
1230 obj = yaffsfs_HandleToObject(handle);
1234 nRead = yaffs_file_rd(obj, buf, pos, nToRead);
1242 if (nRead == nToRead)
1245 nbyte = 0; /* no more to read */
1254 yaffsfs_PutHandle(handle);
1258 fd->v.position = startPos + totalRead;
1260 yaffsfs_SetError(-EINVAL);
1267 return (totalRead >= 0) ? totalRead : -1;
1271 int yaffs_read(int handle, void *buf, unsigned int nbyte)
1273 return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
1276 int yaffs_pread(int handle, void *buf, unsigned int nbyte, Y_LOFF_T offset)
1278 return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
1281 static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
1282 int isPwrite, Y_LOFF_T offset)
1284 struct yaffsfs_FileDes *fd = NULL;
1285 struct yaffs_obj *obj = NULL;
1287 Y_LOFF_T startPos = 0;
1290 int totalWritten = 0;
1291 int write_trhrough = 0;
1293 const u8 *buf = (const u8 *)vbuf;
1295 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) {
1296 yaffsfs_SetError(-EFAULT);
1301 fd = yaffsfs_HandleToFileDes(handle);
1302 obj = yaffsfs_HandleToObject(handle);
1306 yaffsfs_SetError(-EBADF);
1308 } else if (!fd->writing) {
1309 yaffsfs_SetError(-EINVAL);
1311 } else if (obj->my_dev->read_only) {
1312 yaffsfs_SetError(-EROFS);
1316 startPos = yaffs_get_obj_length(obj);
1320 startPos = fd->v.position;
1322 yaffsfs_GetHandle(handle);
1324 endPos = pos + nbyte;
1326 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1327 nbyte > YAFFS_MAX_FILE_SIZE ||
1328 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1335 nToWrite = YAFFSFS_RW_SIZE -
1336 (pos & (YAFFSFS_RW_SIZE - 1));
1337 if (nToWrite > nbyte)
1341 * Need to reverify object in case the device was
1342 * remounted or unmounted in another thread.
1344 obj = yaffsfs_HandleToObject(handle);
1345 if (!obj || obj->my_dev->read_only)
1349 yaffs_wr_file(obj, buf, pos, nToWrite,
1352 totalWritten += nWritten;
1357 if (nWritten == nToWrite)
1362 if (nWritten < 1 && totalWritten < 1) {
1363 yaffsfs_SetError(-ENOSPC);
1373 yaffsfs_PutHandle(handle);
1376 if (totalWritten > 0)
1377 fd->v.position = startPos + totalWritten;
1379 yaffsfs_SetError(-EINVAL);
1385 return (totalWritten >= 0) ? totalWritten : -1;
1388 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
1390 return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
1393 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset)
1395 return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
1398 int yaffs_truncate_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1401 struct yaffs_obj *obj = NULL;
1402 struct yaffs_obj *dir = NULL;
1403 int result = YAFFS_FAIL;
1407 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1408 yaffsfs_SetError(-EFAULT);
1412 if (yaffsfs_CheckPath(path) < 0) {
1413 yaffsfs_SetError(-ENAMETOOLONG);
1419 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1420 obj = yaffsfs_FollowLink(obj, 0, &loop);
1423 yaffsfs_SetError(-ENOTDIR);
1425 yaffsfs_SetError(-ELOOP);
1426 else if (!dir || !obj)
1427 yaffsfs_SetError(-ENOENT);
1428 else if (obj->my_dev->read_only)
1429 yaffsfs_SetError(-EROFS);
1430 else if (obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
1431 yaffsfs_SetError(-EISDIR);
1432 else if (obj->my_dev->read_only)
1433 yaffsfs_SetError(-EROFS);
1434 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1435 yaffsfs_SetError(-EINVAL);
1437 result = yaffs_resize_file(obj, new_size);
1441 return (result) ? 0 : -1;
1444 int yaffs_truncate_reldev(struct yaffs_dev *dev, const YCHAR *path,
1447 return yaffs_truncate_reldir(ROOT_DIR(dev), path, new_size);
1450 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size)
1452 return yaffs_truncate_reldir(NULL, path, new_size);
1455 int yaffs_ftruncate(int handle, Y_LOFF_T new_size)
1457 struct yaffsfs_FileDes *fd = NULL;
1458 struct yaffs_obj *obj = NULL;
1462 fd = yaffsfs_HandleToFileDes(handle);
1463 obj = yaffsfs_HandleToObject(handle);
1467 yaffsfs_SetError(-EBADF);
1468 else if (!fd->writing)
1469 yaffsfs_SetError(-EINVAL);
1470 else if (obj->my_dev->read_only)
1471 yaffsfs_SetError(-EROFS);
1472 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1473 yaffsfs_SetError(-EINVAL);
1475 /* resize the file */
1476 result = yaffs_resize_file(obj, new_size);
1479 return (result) ? 0 : -1;
1483 Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence)
1485 struct yaffsfs_FileDes *fd = NULL;
1486 struct yaffs_obj *obj = NULL;
1488 Y_LOFF_T fSize = -1;
1491 fd = yaffsfs_HandleToFileDes(handle);
1492 obj = yaffsfs_HandleToObject(handle);
1495 yaffsfs_SetError(-EBADF);
1496 else if (offset > YAFFS_MAX_FILE_SIZE)
1497 yaffsfs_SetError(-EINVAL);
1499 if (whence == SEEK_SET) {
1502 } else if (whence == SEEK_CUR) {
1503 if ((fd->v.position + offset) >= 0)
1504 pos = (fd->v.position + offset);
1505 } else if (whence == SEEK_END) {
1506 fSize = yaffs_get_obj_length(obj);
1507 if (fSize >= 0 && (fSize + offset) >= 0)
1508 pos = fSize + offset;
1511 if (pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE)
1512 fd->v.position = pos;
1514 yaffsfs_SetError(-EINVAL);
1524 static int yaffsfs_DoUnlink_reldir(struct yaffs_obj *reldir,
1525 const YCHAR *path, int isDirectory)
1527 struct yaffs_obj *dir = NULL;
1528 struct yaffs_obj *obj = NULL;
1530 int result = YAFFS_FAIL;
1534 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1535 yaffsfs_SetError(-EFAULT);
1539 if (yaffsfs_CheckPath(path) < 0) {
1540 yaffsfs_SetError(-ENAMETOOLONG);
1546 obj = yaffsfs_FindObject(reldir, path, 0, 0, NULL, NULL, NULL);
1547 dir = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
1550 yaffsfs_SetError(-ENOTDIR);
1552 yaffsfs_SetError(-ELOOP);
1554 yaffsfs_SetError(-ENOENT);
1555 else if (yaffs_strncmp(name, _Y("."), 2) == 0)
1556 yaffsfs_SetError(-EINVAL);
1558 yaffsfs_SetError(-ENOENT);
1559 else if (obj->my_dev->read_only)
1560 yaffsfs_SetError(-EROFS);
1561 else if (!isDirectory &&
1562 obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1563 yaffsfs_SetError(-EISDIR);
1564 else if (isDirectory &&
1565 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1566 yaffsfs_SetError(-ENOTDIR);
1567 else if (isDirectory && obj == obj->my_dev->root_dir)
1568 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1570 result = yaffs_unlinker(dir, name);
1572 if (result == YAFFS_FAIL && isDirectory)
1573 yaffsfs_SetError(-ENOTEMPTY);
1578 return (result == YAFFS_FAIL) ? -1 : 0;
1581 int yaffs_unlink_reldir(struct yaffs_obj *reldir, const YCHAR *path)
1583 return yaffsfs_DoUnlink_reldir(reldir, path, 0);
1586 int yaffs_unlink_reldev(struct yaffs_dev *dev, const YCHAR *path)
1588 return yaffsfs_DoUnlink_reldir(ROOT_DIR(dev), path, 0);
1591 int yaffs_unlink(const YCHAR *path)
1593 return yaffs_unlink_reldir(NULL, path);
1596 int yaffs_funlink(int fd)
1598 struct yaffs_obj *obj;
1602 obj = yaffsfs_HandleToObject(fd);
1605 yaffsfs_SetError(-EBADF);
1606 else if (obj->my_dev->read_only)
1607 yaffsfs_SetError(-EROFS);
1608 else if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1609 !(list_empty(&obj->variant.dir_variant.children)))
1610 yaffsfs_SetError(-ENOTEMPTY);
1611 else if (obj == obj->my_dev->root_dir)
1612 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1613 else if (yaffs_unlink_obj(obj) == YAFFS_OK)
1621 int yaffs_fgetfl(int fd, int *flags)
1623 struct yaffsfs_FileDes *fdp = yaffsfs_HandleToFileDes(fd);
1628 if(!flags || !fdp) {
1629 yaffsfs_SetError(-EINVAL);
1632 if (fdp->reading && fdp->writing)
1634 else if (fdp->writing)
1646 static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1648 if (obj && obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY &&
1649 newobj && newobj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1655 static int rename_dir_over_file(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1657 if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1658 newobj && newobj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1664 int yaffs_rename_reldir(struct yaffs_obj *reldir,
1665 const YCHAR *oldPath, const YCHAR *newPath)
1667 struct yaffs_obj *olddir = NULL;
1668 struct yaffs_obj *newdir = NULL;
1669 struct yaffs_obj *obj = NULL;
1670 struct yaffs_obj *newobj = NULL;
1673 int result = YAFFS_FAIL;
1674 int rename_allowed = 1;
1680 YCHAR *alt_newpath = NULL;
1682 if (yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 ||
1683 yaffsfs_CheckMemRegion(newPath, 0, 0) < 0) {
1684 yaffsfs_SetError(-EFAULT);
1688 if (yaffsfs_CheckPath(oldPath) < 0 || yaffsfs_CheckPath(newPath) < 0) {
1689 yaffsfs_SetError(-ENAMETOOLONG);
1693 if (yaffsfs_alt_dir_path(newPath, &alt_newpath) < 0) {
1694 yaffsfs_SetError(-ENOMEM);
1698 newPath = alt_newpath;
1702 olddir = yaffsfs_FindDirectory(reldir, oldPath, &oldname, 0,
1703 ¬OldDir, &oldLoop);
1704 newdir = yaffsfs_FindDirectory(reldir, newPath, &newname, 0,
1705 ¬NewDir, &newLoop);
1706 obj = yaffsfs_FindObject(reldir, oldPath, 0, 0, NULL, NULL, NULL);
1707 newobj = yaffsfs_FindObject(reldir, newPath, 0, 0, NULL, NULL, NULL);
1709 /* If the object being renamed is a directory and the
1710 * path ended with a "/" then the olddir == obj.
1711 * We pass through NULL for the old name to tell the lower layers
1712 * to use olddir as the object.
1718 if ((!olddir && notOldDir) || (!newdir && notNewDir)) {
1719 yaffsfs_SetError(-ENOTDIR);
1721 } else if (oldLoop || newLoop) {
1722 yaffsfs_SetError(-ELOOP);
1724 } else if (olddir && oldname &&
1725 yaffs_strncmp(oldname, _Y("."), 2) == 0) {
1726 yaffsfs_SetError(-EINVAL);
1728 } else if (!olddir || !newdir || !obj) {
1729 yaffsfs_SetError(-ENOENT);
1731 } else if (obj->my_dev->read_only) {
1732 yaffsfs_SetError(-EROFS);
1734 } else if (rename_file_over_dir(obj, newobj)) {
1735 yaffsfs_SetError(-EISDIR);
1737 } else if (rename_dir_over_file(obj, newobj)) {
1738 yaffsfs_SetError(-ENOTDIR);
1740 } else if (yaffs_is_non_empty_dir(newobj)) {
1741 yaffsfs_SetError(-ENOTEMPTY);
1743 } else if (olddir->my_dev != newdir->my_dev) {
1744 /* Rename must be on same device */
1745 yaffsfs_SetError(-EXDEV);
1747 } else if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
1749 * It is a directory, check that it is not being renamed to
1750 * being its own decendent.
1751 * Do this by tracing from the new directory back to the root,
1755 struct yaffs_obj *xx = newdir;
1757 while (rename_allowed && xx) {
1762 if (!rename_allowed)
1763 yaffsfs_SetError(-EINVAL);
1767 result = yaffs_rename_obj(olddir, oldname, newdir, newname);
1773 return (result == YAFFS_FAIL) ? -1 : 0;
1776 int yaffs_rename_reldev(struct yaffs_dev *dev, const YCHAR *oldPath,
1777 const YCHAR *newPath)
1779 return yaffs_rename_reldir(ROOT_DIR(dev), oldPath, newPath);
1781 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
1783 return yaffs_rename_reldir(NULL, oldPath, newPath);
1786 static int yaffsfs_DoStat(struct yaffs_obj *obj, struct yaffs_stat *buf)
1790 obj = yaffs_get_equivalent_obj(obj);
1793 buf->st_dev = (int)obj->my_dev->os_context;
1794 buf->st_ino = obj->obj_id;
1795 buf->st_mode = obj->yst_mode & ~S_IFMT;
1797 if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1798 buf->st_mode |= S_IFDIR;
1799 else if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
1800 buf->st_mode |= S_IFLNK;
1801 else if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE)
1802 buf->st_mode |= S_IFREG;
1804 buf->st_nlink = yaffs_get_obj_link_count(obj);
1807 buf->st_rdev = obj->yst_rdev;
1808 buf->st_size = yaffs_get_obj_length(obj);
1809 buf->st_blksize = obj->my_dev->data_bytes_per_chunk;
1810 buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
1812 #if CONFIG_YAFFS_WINCE
1813 buf->yst_wince_atime[0] = obj->win_atime[0];
1814 buf->yst_wince_atime[1] = obj->win_atime[1];
1815 buf->yst_wince_ctime[0] = obj->win_ctime[0];
1816 buf->yst_wince_ctime[1] = obj->win_ctime[1];
1817 buf->yst_wince_mtime[0] = obj->win_mtime[0];
1818 buf->yst_wince_mtime[1] = obj->win_mtime[1];
1820 buf->yst_atime = obj->yst_atime;
1821 buf->yst_ctime = obj->yst_ctime;
1822 buf->yst_mtime = obj->yst_mtime;
1829 static int yaffsfs_DoStatOrLStat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1830 struct yaffs_stat *buf, int doLStat)
1832 struct yaffs_obj *obj = NULL;
1833 struct yaffs_obj *dir = NULL;
1838 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
1839 yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1840 yaffsfs_SetError(-EFAULT);
1844 if (yaffsfs_CheckPath(path) < 0) {
1845 yaffsfs_SetError(-ENAMETOOLONG);
1851 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1853 if (!doLStat && obj)
1854 obj = yaffsfs_FollowLink(obj, 0, &loop);
1857 yaffsfs_SetError(-ENOTDIR);
1859 yaffsfs_SetError(-ELOOP);
1860 else if (!dir || !obj)
1861 yaffsfs_SetError(-ENOENT);
1863 retVal = yaffsfs_DoStat(obj, buf);
1871 int yaffs_stat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1872 struct yaffs_stat *buf)
1874 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 0);
1877 int yaffs_lstat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1878 struct yaffs_stat *buf)
1880 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 1);
1883 int yaffs_stat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1884 struct yaffs_stat *buf)
1886 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 0);
1889 int yaffs_lstat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1890 struct yaffs_stat *buf)
1892 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 1);
1895 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf)
1897 return yaffs_stat_reldir(NULL, path, buf);
1900 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf)
1902 return yaffs_lstat_reldir(NULL, path, buf);
1905 int yaffs_fstat(int fd, struct yaffs_stat *buf)
1907 struct yaffs_obj *obj;
1911 if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1912 yaffsfs_SetError(-EFAULT);
1917 obj = yaffsfs_HandleToObject(fd);
1920 retVal = yaffsfs_DoStat(obj, buf);
1923 yaffsfs_SetError(-EBADF);
1930 static int yaffsfs_DoUtime(struct yaffs_obj *obj,
1931 const struct yaffs_utimbuf *buf)
1934 struct yaffs_utimbuf local;
1936 obj = yaffs_get_equivalent_obj(obj);
1938 if (obj && obj->my_dev->read_only) {
1939 yaffsfs_SetError(-EROFS);
1943 #if !CONFIG_YAFFS_WINCE
1945 local.actime = Y_CURRENT_TIME;
1946 local.modtime = local.actime;
1953 obj->yst_atime = buf->actime;
1954 obj->yst_mtime = buf->modtime;
1956 result = yaffs_flush_file(obj, 0, 0, 0);
1957 retVal = result == YAFFS_OK ? 0 : -1;
1964 int yaffs_utime_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1965 const struct yaffs_utimbuf *buf)
1967 struct yaffs_obj *obj = NULL;
1968 struct yaffs_obj *dir = NULL;
1974 yaffsfs_SetError(-EFAULT);
1978 if (yaffsfs_CheckPath(path) < 0) {
1979 yaffsfs_SetError(-ENAMETOOLONG);
1985 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1988 yaffsfs_SetError(-ENOTDIR);
1990 yaffsfs_SetError(-ELOOP);
1991 else if (!dir || !obj)
1992 yaffsfs_SetError(-ENOENT);
1994 retVal = yaffsfs_DoUtime(obj, buf);
2002 int yaffs_utime_reldev(struct yaffs_dev *dev, const YCHAR *path,
2003 const struct yaffs_utimbuf *buf)
2005 return yaffs_utime_reldir(ROOT_DIR(dev), path, buf);
2008 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf)
2010 return yaffs_utime_reldir(NULL, path, buf);
2013 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf)
2015 struct yaffs_obj *obj;
2020 obj = yaffsfs_HandleToObject(fd);
2023 retVal = yaffsfs_DoUtime(obj, buf);
2026 yaffsfs_SetError(-EBADF);
2033 #ifndef CONFIG_YAFFS_WINCE
2034 /* xattrib functions */
2036 static int yaffs_do_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2037 const char *name, const void *data, int size,
2038 int flags, int follow)
2040 struct yaffs_obj *obj;
2041 struct yaffs_obj *dir;
2047 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2048 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2049 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2050 yaffsfs_SetError(-EFAULT);
2054 if (yaffsfs_CheckPath(path) < 0) {
2055 yaffsfs_SetError(-ENAMETOOLONG);
2061 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2064 obj = yaffsfs_FollowLink(obj, 0, &loop);
2067 yaffsfs_SetError(-ENOTDIR);
2069 yaffsfs_SetError(-ELOOP);
2070 else if (!dir || !obj)
2071 yaffsfs_SetError(-ENOENT);
2073 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2075 yaffsfs_SetError(retVal);
2086 int yaffs_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2087 const char *name, const void *data, int size, int flags)
2089 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 1);
2092 int yaffs_setxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
2093 const char *name, const void *data, int size, int flags)
2095 return yaffs_setxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2098 int yaffs_setxattr(const YCHAR *path, const char *name,
2099 const void *data, int size, int flags)
2101 return yaffs_setxattr_reldir(NULL, path, name, data, size, flags);
2104 int yaffs_lsetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path, const char *name,
2105 const void *data, int size, int flags)
2107 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 0);
2110 int yaffs_lsetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name,
2111 const void *data, int size, int flags)
2113 return yaffs_lsetxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2116 int yaffs_lsetxattr(const YCHAR *path, const char *name,
2117 const void *data, int size, int flags)
2119 return yaffs_lsetxattr_reldir(NULL, path, name, data, size, flags);
2122 int yaffs_fsetxattr(int fd, const char *name,
2123 const void *data, int size, int flags)
2125 struct yaffs_obj *obj;
2129 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2130 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2131 yaffsfs_SetError(-EFAULT);
2136 obj = yaffsfs_HandleToObject(fd);
2139 yaffsfs_SetError(-EBADF);
2141 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2143 yaffsfs_SetError(retVal);
2153 static int yaffs_do_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2154 const char *name, void *data, int size, int follow)
2156 struct yaffs_obj *obj;
2157 struct yaffs_obj *dir;
2162 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2163 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2164 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2165 yaffsfs_SetError(-EFAULT);
2169 if (yaffsfs_CheckPath(path) < 0) {
2170 yaffsfs_SetError(-ENAMETOOLONG);
2176 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2179 obj = yaffsfs_FollowLink(obj, 0, &loop);
2182 yaffsfs_SetError(-ENOTDIR);
2184 yaffsfs_SetError(-ELOOP);
2185 else if (!dir || !obj)
2186 yaffsfs_SetError(-ENOENT);
2188 retVal = yaffs_get_xattrib(obj, name, data, size);
2190 yaffsfs_SetError(retVal);
2200 int yaffs_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2201 const char *name, void *data, int size)
2203 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 1);
2206 int yaffs_getxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2208 return yaffs_getxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2211 int yaffs_getxattr(const YCHAR *path, const char *name, void *data, int size)
2213 return yaffs_getxattr_reldir(NULL, path, name, data, size);
2216 int yaffs_lgetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2217 const char *name, void *data, int size)
2219 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 0);
2222 int yaffs_lgetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2224 return yaffs_lgetxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2227 int yaffs_lgetxattr(const YCHAR *path, const char *name, void *data, int size)
2229 return yaffs_lgetxattr_reldir(NULL, path, name, data, size);
2232 int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
2234 struct yaffs_obj *obj;
2238 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2239 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2240 yaffsfs_SetError(-EFAULT);
2245 obj = yaffsfs_HandleToObject(fd);
2248 retVal = yaffs_get_xattrib(obj, name, data, size);
2250 yaffsfs_SetError(retVal);
2255 yaffsfs_SetError(-EBADF);
2262 static int yaffs_do_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2263 char *data, int size, int follow)
2265 struct yaffs_obj *obj = NULL;
2266 struct yaffs_obj *dir = NULL;
2271 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2272 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2273 yaffsfs_SetError(-EFAULT);
2277 if (yaffsfs_CheckPath(path) < 0) {
2278 yaffsfs_SetError(-ENAMETOOLONG);
2284 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2287 obj = yaffsfs_FollowLink(obj, 0, &loop);
2290 yaffsfs_SetError(-ENOTDIR);
2292 yaffsfs_SetError(-ELOOP);
2293 else if (!dir || !obj)
2294 yaffsfs_SetError(-ENOENT);
2296 retVal = yaffs_list_xattrib(obj, data, size);
2298 yaffsfs_SetError(retVal);
2309 int yaffs_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2310 char *data, int size)
2312 return yaffs_do_listxattr_reldir(reldir, path, data, size, 1);
2315 int yaffs_listxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2317 return yaffs_listxattr_reldir(ROOT_DIR(dev), path, data, size);
2320 int yaffs_listxattr(const YCHAR *path, char *data, int size)
2322 return yaffs_listxattr_reldir(NULL, path, data, size);
2325 int yaffs_llistxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2326 char *data, int size)
2328 return yaffs_do_listxattr_reldir(reldir, path, data, size, 0);
2331 int yaffs_llistxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2333 return yaffs_llistxattr_reldir(ROOT_DIR(dev), path, data, size);
2336 int yaffs_llistxattr(const YCHAR *path, char *data, int size)
2338 return yaffs_llistxattr_reldir(NULL, path, data, size);
2341 int yaffs_flistxattr(int fd, char *data, int size)
2343 struct yaffs_obj *obj;
2347 if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2348 yaffsfs_SetError(-EFAULT);
2353 obj = yaffsfs_HandleToObject(fd);
2356 retVal = yaffs_list_xattrib(obj, data, size);
2358 yaffsfs_SetError(retVal);
2363 yaffsfs_SetError(-EBADF);
2370 static int yaffs_do_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2371 const char *name, int follow)
2373 struct yaffs_obj *obj = NULL;
2374 struct yaffs_obj *dir = NULL;
2379 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2380 yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2381 yaffsfs_SetError(-EFAULT);
2385 if (yaffsfs_CheckPath(path) < 0) {
2386 yaffsfs_SetError(-ENAMETOOLONG);
2392 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2395 obj = yaffsfs_FollowLink(obj, 0, &loop);
2398 yaffsfs_SetError(-ENOTDIR);
2400 yaffsfs_SetError(-ELOOP);
2401 else if (!dir || !obj)
2402 yaffsfs_SetError(-ENOENT);
2404 retVal = yaffs_remove_xattrib(obj, name);
2406 yaffsfs_SetError(retVal);
2417 int yaffs_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2420 return yaffs_do_removexattr_reldir(reldir, path, name, 1);
2423 int yaffs_removexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2425 return yaffs_removexattr_reldir(ROOT_DIR(dev), path, name);
2428 int yaffs_removexattr(const YCHAR *path, const char *name)
2430 return yaffs_removexattr_reldir(NULL, path, name);
2433 int yaffs_lremovexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2436 return yaffs_do_removexattr_reldir(reldir, path, name, 0);
2439 int yaffs_lremovexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2441 return yaffs_lremovexattr_reldir(ROOT_DIR(dev), path, name);
2444 int yaffs_lremovexattr(const YCHAR *path, const char *name)
2446 return yaffs_lremovexattr_reldir(NULL, path, name);
2449 int yaffs_fremovexattr(int fd, const char *name)
2451 struct yaffs_obj *obj;
2455 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2456 yaffsfs_SetError(-EFAULT);
2461 obj = yaffsfs_HandleToObject(fd);
2464 retVal = yaffs_remove_xattrib(obj, name);
2466 yaffsfs_SetError(retVal);
2471 yaffsfs_SetError(-EBADF);
2479 #ifdef CONFIG_YAFFS_WINCE
2480 int yaffs_get_wince_times(int fd, unsigned *wctime,
2481 unsigned *watime, unsigned *wmtime)
2483 struct yaffs_obj *obj;
2488 obj = yaffsfs_HandleToObject(fd);
2493 wctime[0] = obj->win_ctime[0];
2494 wctime[1] = obj->win_ctime[1];
2497 watime[0] = obj->win_atime[0];
2498 watime[1] = obj->win_atime[1];
2501 wmtime[0] = obj->win_mtime[0];
2502 wmtime[1] = obj->win_mtime[1];
2508 yaffsfs_SetError(-EBADF);
2515 int yaffs_set_wince_times(int fd,
2516 const unsigned *wctime,
2517 const unsigned *watime, const unsigned *wmtime)
2519 struct yaffs_obj *obj;
2524 obj = yaffsfs_HandleToObject(fd);
2529 obj->win_ctime[0] = wctime[0];
2530 obj->win_ctime[1] = wctime[1];
2533 obj->win_atime[0] = watime[0];
2534 obj->win_atime[1] = watime[1];
2537 obj->win_mtime[0] = wmtime[0];
2538 obj->win_mtime[1] = wmtime[1];
2542 result = yaffs_flush_file(obj, 0, 0, 0);
2546 yaffsfs_SetError(-EBADF);
2555 static int yaffsfs_DoChMod(struct yaffs_obj *obj, mode_t mode)
2560 obj = yaffs_get_equivalent_obj(obj);
2563 obj->yst_mode = mode;
2565 result = yaffs_flush_file(obj, 0, 0, 0);
2568 return result == YAFFS_OK ? 0 : -1;
2571 int yaffs_access_reldir(struct yaffs_obj *reldir, const YCHAR *path, int amode)
2573 struct yaffs_obj *obj = NULL;
2574 struct yaffs_obj *dir = NULL;
2579 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2580 yaffsfs_SetError(-EFAULT);
2584 if (yaffsfs_CheckPath(path) < 0) {
2585 yaffsfs_SetError(-ENAMETOOLONG);
2589 if (amode & ~(R_OK | W_OK | X_OK)) {
2590 yaffsfs_SetError(-EINVAL);
2596 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2597 obj = yaffsfs_FollowLink(obj, 0, &loop);
2600 yaffsfs_SetError(-ENOTDIR);
2602 yaffsfs_SetError(-ELOOP);
2603 else if (!dir || !obj)
2604 yaffsfs_SetError(-ENOENT);
2605 else if ((amode & W_OK) && obj->my_dev->read_only)
2606 yaffsfs_SetError(-EROFS);
2610 if ((amode & R_OK) && !(obj->yst_mode & S_IRUSR))
2612 if ((amode & W_OK) && !(obj->yst_mode & S_IWUSR))
2614 if ((amode & X_OK) && !(obj->yst_mode & S_IXUSR))
2618 yaffsfs_SetError(-EACCES);
2629 int yaffs_access_reldev(struct yaffs_dev *dev, const YCHAR *path, int amode)
2631 return yaffs_access_reldir(ROOT_DIR(dev), path, amode);
2634 int yaffs_access(const YCHAR *path, int amode)
2636 return yaffs_access_reldir(NULL, path, amode);
2639 int yaffs_chmod_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2641 struct yaffs_obj *obj = NULL;
2642 struct yaffs_obj *dir = NULL;
2647 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2648 yaffsfs_SetError(-EFAULT);
2652 if (yaffsfs_CheckPath(path) < 0) {
2653 yaffsfs_SetError(-ENAMETOOLONG);
2657 if (mode & ~(0777)) {
2658 yaffsfs_SetError(-EINVAL);
2664 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2665 obj = yaffsfs_FollowLink(obj, 0, &loop);
2668 yaffsfs_SetError(-ENOTDIR);
2670 yaffsfs_SetError(-ELOOP);
2671 else if (!dir || !obj)
2672 yaffsfs_SetError(-ENOENT);
2673 else if (obj->my_dev->read_only)
2674 yaffsfs_SetError(-EROFS);
2676 retVal = yaffsfs_DoChMod(obj, mode);
2684 int yaffs_chmod_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2686 return yaffs_chmod_reldir(ROOT_DIR(dev), path, mode);
2689 int yaffs_chmod(const YCHAR *path, mode_t mode)
2691 return yaffs_chmod_reldir(NULL, path, mode);
2694 int yaffs_fchmod(int fd, mode_t mode)
2696 struct yaffs_obj *obj;
2699 if (mode & ~(0777)) {
2700 yaffsfs_SetError(-EINVAL);
2705 obj = yaffsfs_HandleToObject(fd);
2708 yaffsfs_SetError(-EBADF);
2709 else if (obj->my_dev->read_only)
2710 yaffsfs_SetError(-EROFS);
2712 retVal = yaffsfs_DoChMod(obj, mode);
2719 int yaffs_mkdir_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2721 struct yaffs_obj *parent = NULL;
2722 struct yaffs_obj *dir = NULL;
2724 YCHAR *alt_path = NULL;
2729 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2730 yaffsfs_SetError(-EFAULT);
2734 if (yaffsfs_CheckPath(path) < 0) {
2735 yaffsfs_SetError(-ENAMETOOLONG);
2739 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2740 yaffsfs_SetError(-ENOMEM);
2747 parent = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
2748 if (!parent && notDir)
2749 yaffsfs_SetError(-ENOTDIR);
2751 yaffsfs_SetError(-ELOOP);
2753 yaffsfs_SetError(-ENOENT);
2754 else if (yaffsfs_TooManyObjects(parent->my_dev))
2755 yaffsfs_SetError(-ENFILE);
2756 else if (yaffs_strnlen(name, 5) == 0) {
2757 /* Trying to make the root itself */
2758 yaffsfs_SetError(-EEXIST);
2759 } else if (parent->my_dev->read_only)
2760 yaffsfs_SetError(-EROFS);
2762 dir = yaffs_create_dir(parent, name, mode, 0, 0);
2765 else if (yaffs_find_by_name(parent, name))
2766 yaffsfs_SetError(-EEXIST); /* name exists */
2768 yaffsfs_SetError(-ENOSPC); /* assume no space */
2778 int yaffs_mkdir_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2780 return yaffs_mkdir_reldir(ROOT_DIR(dev), path, mode);
2783 int yaffs_mkdir(const YCHAR *path, mode_t mode)
2785 return yaffs_mkdir_reldir(NULL, path, mode);
2788 int yaffs_rmdir_reldir(struct yaffs_obj *reldir, const YCHAR *path)
2793 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2794 yaffsfs_SetError(-EFAULT);
2798 if (yaffsfs_CheckPath(path) < 0) {
2799 yaffsfs_SetError(-ENAMETOOLONG);
2803 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2804 yaffsfs_SetError(-ENOMEM);
2809 result = yaffsfs_DoUnlink_reldir(reldir, path, 1);
2816 int yaffs_rmdir_reldev(struct yaffs_dev *dev, const YCHAR *path)
2818 return yaffs_rmdir_reldir(ROOT_DIR(dev), path);
2821 int yaffs_rmdir(const YCHAR *path)
2823 return yaffs_rmdir_reldir(NULL, path);
2827 * The mount/unmount/sync functions act on devices rather than reldirs.
2829 void *yaffs_getdev(const YCHAR *path)
2831 struct yaffs_dev *dev = NULL;
2833 dev = yaffsfs_FindDevice(path, &dummy);
2837 int yaffs_mount_common(struct yaffs_dev *dev, const YCHAR *path,
2838 int read_only, int skip_checkpt)
2841 int result = YAFFS_FAIL;
2844 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2845 yaffsfs_SetError(-EFAULT);
2849 yaffs_trace(YAFFS_TRACE_MOUNT, "yaffs: Mounting %s", path);
2851 if (yaffsfs_CheckPath(path) < 0) {
2852 yaffsfs_SetError(-ENAMETOOLONG);
2859 yaffsfs_InitHandles();
2862 dev = yaffsfs_FindMountPoint(path);
2865 if (!dev->is_mounted) {
2866 dev->read_only = read_only ? 1 : 0;
2868 u8 skip = dev->param.skip_checkpt_rd;
2869 dev->param.skip_checkpt_rd = 1;
2870 result = yaffs_guts_initialise(dev);
2871 dev->param.skip_checkpt_rd = skip;
2873 result = yaffs_guts_initialise(dev);
2876 if (result == YAFFS_FAIL)
2877 yaffsfs_SetError(-ENOMEM);
2878 retVal = result ? 0 : -1;
2881 yaffsfs_SetError(-EBUSY);
2883 yaffsfs_SetError(-ENODEV);
2890 int yaffs_mount3_reldev(struct yaffs_dev *dev, int read_only, int skip_checkpt)
2892 return yaffs_mount_common(dev, NULL, read_only, skip_checkpt);
2895 int yaffs_mount3(const YCHAR *path, int read_only, int skip_checkpt)
2897 return yaffs_mount_common(NULL, path, read_only, skip_checkpt);
2900 int yaffs_mount2_reldev(struct yaffs_dev *dev, int readonly)
2902 return yaffs_mount_common(dev, NULL, readonly, 0);
2905 int yaffs_mount2(const YCHAR *path, int readonly)
2907 return yaffs_mount_common(NULL, path, readonly, 0);
2910 int yaffs_mount_reldev(struct yaffs_dev *dev)
2912 return yaffs_mount_common(dev, NULL, 0, 0);
2915 int yaffs_mount(const YCHAR *path)
2917 return yaffs_mount_common(NULL, path, 0, 0);
2920 static int yaffs_sync_common(struct yaffs_dev *dev,
2928 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2929 yaffsfs_SetError(-EFAULT);
2933 if (yaffsfs_CheckPath(path) < 0) {
2934 yaffsfs_SetError(-ENAMETOOLONG);
2941 dev = yaffsfs_FindDevice(path, &dummy);
2944 if (!dev->is_mounted)
2945 yaffsfs_SetError(-EINVAL);
2946 else if (dev->read_only)
2947 yaffsfs_SetError(-EROFS);
2950 yaffs_flush_whole_cache(dev, 0);
2952 yaffs_checkpoint_save(dev);
2957 yaffsfs_SetError(-ENODEV);
2963 int yaffs_sync_files_reldev(struct yaffs_dev *dev)
2965 return yaffs_sync_common(dev, NULL, 0);
2968 int yaffs_sync_files(const YCHAR *path)
2970 return yaffs_sync_common(NULL, path, 0);
2973 int yaffs_sync_reldev(struct yaffs_dev *dev)
2975 return yaffs_sync_common(dev, NULL, 1);
2978 int yaffs_sync(const YCHAR *path)
2980 return yaffs_sync_common(NULL, path, 1);
2984 static int yaffsfs_bg_gc_common(struct yaffs_dev *dev,
2992 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2993 yaffsfs_SetError(-EFAULT);
2997 if (yaffsfs_CheckPath(path) < 0) {
2998 yaffsfs_SetError(-ENAMETOOLONG);
3005 dev = yaffsfs_FindDevice(path, &dummy);
3008 if (!dev->is_mounted)
3009 yaffsfs_SetError(-EINVAL);
3011 retVal = yaffs_bg_gc(dev, urgency);
3013 yaffsfs_SetError(-ENODEV);
3019 /* Background gc functions.
3020 * These return 0 when bg done or greater than 0 when gc has been
3021 * done and there is still a lot of garbage to be cleaned up.
3024 int yaffs_do_background_gc(const YCHAR *path, int urgency)
3026 return yaffsfs_bg_gc_common(NULL, path, urgency);
3029 int yaffs_do_background_gc_reldev(struct yaffs_dev *dev, int urgency)
3031 return yaffsfs_bg_gc_common(dev, NULL, urgency);
3034 static int yaffsfs_IsDevBusy(struct yaffs_dev *dev)
3037 struct yaffs_obj *obj;
3039 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
3040 obj = yaffsfs_HandleToObject(i);
3041 if (obj && obj->my_dev == dev)
3047 int yaffs_remount_common(struct yaffs_dev *dev, const YCHAR *path,
3048 int force, int read_only)
3052 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3053 yaffsfs_SetError(-EFAULT);
3057 if (yaffsfs_CheckPath(path) < 0) {
3058 yaffsfs_SetError(-ENAMETOOLONG);
3064 dev = yaffsfs_FindMountPoint(path);
3067 if (dev->is_mounted) {
3068 yaffs_flush_whole_cache(dev, 0);
3070 if (force || !yaffsfs_IsDevBusy(dev)) {
3072 yaffs_checkpoint_save(dev);
3073 dev->read_only = read_only ? 1 : 0;
3076 yaffsfs_SetError(-EBUSY);
3079 yaffsfs_SetError(-EINVAL);
3082 yaffsfs_SetError(-ENODEV);
3089 int yaffs_remount_reldev(struct yaffs_dev *dev, int force, int read_only)
3091 return yaffs_remount_common(dev, NULL, force, read_only);
3093 int yaffs_remount(const YCHAR *path, int force, int read_only)
3095 return yaffs_remount_common(NULL, path, force, read_only);
3098 int yaffs_unmount2_common(struct yaffs_dev *dev, const YCHAR *path, int force)
3102 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3103 yaffsfs_SetError(-EFAULT);
3107 if (yaffsfs_CheckPath(path) < 0) {
3108 yaffsfs_SetError(-ENAMETOOLONG);
3114 dev = yaffsfs_FindMountPoint(path);
3117 if (dev->is_mounted) {
3119 yaffs_flush_whole_cache(dev, 0);
3120 yaffs_checkpoint_save(dev);
3121 inUse = yaffsfs_IsDevBusy(dev);
3122 if (!inUse || force) {
3124 yaffsfs_BreakDeviceHandles(dev);
3125 yaffs_deinitialise(dev);
3129 yaffsfs_SetError(-EBUSY);
3132 yaffsfs_SetError(-EINVAL);
3135 yaffsfs_SetError(-ENODEV);
3142 int yaffs_unmount2_reldev(struct yaffs_dev *dev, int force)
3144 return yaffs_unmount2_common(dev, NULL, force);
3147 int yaffs_unmount2(const YCHAR *path, int force)
3149 return yaffs_unmount2_common(NULL, path, force);
3152 int yaffs_unmount_reldev(struct yaffs_dev *dev)
3154 return yaffs_unmount2_reldev(dev, 0);
3157 int yaffs_unmount(const YCHAR *path)
3159 return yaffs_unmount2(path, 0);
3162 int yaffs_format_common(struct yaffs_dev *dev,
3165 int force_unmount_flag,
3173 yaffsfs_SetError(-EFAULT);
3177 if (yaffsfs_CheckPath(path) < 0) {
3178 yaffsfs_SetError(-ENAMETOOLONG);
3185 dev = yaffsfs_FindMountPoint(path);
3188 int was_mounted = dev->is_mounted;
3190 if (dev->is_mounted && unmount_flag) {
3192 yaffs_flush_whole_cache(dev, 0);
3193 yaffs_checkpoint_save(dev);
3194 inUse = yaffsfs_IsDevBusy(dev);
3195 if (!inUse || force_unmount_flag) {
3197 yaffsfs_BreakDeviceHandles(dev);
3198 yaffs_deinitialise(dev);
3202 if(dev->is_mounted) {
3203 yaffsfs_SetError(-EBUSY);
3206 yaffs_guts_format_dev(dev);
3207 if(was_mounted && remount_flag) {
3208 result = yaffs_guts_initialise(dev);
3209 if (result == YAFFS_FAIL) {
3210 yaffsfs_SetError(-ENOMEM);
3216 yaffsfs_SetError(-ENODEV);
3225 int yaffs_format_reldev(struct yaffs_dev *dev,
3227 int force_unmount_flag,
3230 return yaffs_format_common(dev, NULL, unmount_flag,
3231 force_unmount_flag, remount_flag);
3234 int yaffs_format(const YCHAR *path,
3236 int force_unmount_flag,
3239 return yaffs_format_common(NULL, path, unmount_flag,
3240 force_unmount_flag, remount_flag);
3243 Y_LOFF_T yaffs_freespace_common(struct yaffs_dev *dev, const YCHAR *path)
3245 Y_LOFF_T retVal = -1;
3249 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3250 yaffsfs_SetError(-EFAULT);
3254 if (yaffsfs_CheckPath(path) < 0) {
3255 yaffsfs_SetError(-ENAMETOOLONG);
3262 dev = yaffsfs_FindDevice(path, &dummy);
3263 if (dev && dev->is_mounted) {
3264 retVal = yaffs_get_n_free_chunks(dev);
3265 retVal *= dev->data_bytes_per_chunk;
3268 yaffsfs_SetError(-EINVAL);
3274 Y_LOFF_T yaffs_freespace_reldev(struct yaffs_dev *dev)
3276 return yaffs_freespace_common(dev, NULL);
3279 Y_LOFF_T yaffs_freespace(const YCHAR *path)
3281 return yaffs_freespace_common(NULL, path);
3284 Y_LOFF_T yaffs_totalspace_common(struct yaffs_dev *dev, const YCHAR *path)
3286 Y_LOFF_T retVal = -1;
3290 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3291 yaffsfs_SetError(-EFAULT);
3295 if (yaffsfs_CheckPath(path) < 0) {
3296 yaffsfs_SetError(-ENAMETOOLONG);
3303 dev = yaffsfs_FindDevice(path, &dummy);
3304 if (dev && dev->is_mounted) {
3305 retVal = (dev->param.end_block - dev->param.start_block + 1) -
3306 dev->param.n_reserved_blocks;
3307 retVal *= dev->param.chunks_per_block;
3308 retVal *= dev->data_bytes_per_chunk;
3311 yaffsfs_SetError(-EINVAL);
3317 Y_LOFF_T yaffs_totalspace_reldev(struct yaffs_dev *dev)
3319 return yaffs_totalspace_common(dev, NULL);
3322 Y_LOFF_T yaffs_totalspace(const YCHAR *path)
3324 return yaffs_totalspace_common(NULL, path);
3327 int yaffs_inodecount_common(struct yaffs_dev *dev, const YCHAR *path)
3329 Y_LOFF_T retVal = -1;
3333 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3334 yaffsfs_SetError(-EFAULT);
3338 if (yaffsfs_CheckPath(path) < 0) {
3339 yaffsfs_SetError(-ENAMETOOLONG);
3346 dev = yaffsfs_FindDevice(path, &dummy);
3347 if (dev && dev->is_mounted) {
3348 int n_obj = dev->n_obj;
3349 if (n_obj > dev->n_hardlinks)
3350 retVal = n_obj - dev->n_hardlinks;
3354 yaffsfs_SetError(-EINVAL);
3360 int yaffs_inodecount_reldev(struct yaffs_dev *dev)
3362 return yaffs_inodecount_common(dev, NULL);
3365 int yaffs_inodecount(const YCHAR *path)
3367 return yaffs_inodecount_common(NULL, path);
3370 void yaffs_add_device(struct yaffs_dev *dev)
3372 struct list_head *cfg;
3373 /* First check that the device is not in the list. */
3375 list_for_each(cfg, &yaffsfs_deviceList) {
3376 if (dev == list_entry(cfg, struct yaffs_dev, dev_list))
3380 dev->is_mounted = 0;
3381 dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
3383 if (!dev->dev_list.next)
3384 INIT_LIST_HEAD(&dev->dev_list);
3386 list_add(&dev->dev_list, &yaffsfs_deviceList);
3391 void yaffs_remove_device(struct yaffs_dev *dev)
3393 list_del_init(&dev->dev_list);
3396 /* Functions to iterate through devices. NB Use with extreme care! */
3398 static struct list_head *dev_iterator;
3399 void yaffs_dev_rewind(void)
3401 dev_iterator = yaffsfs_deviceList.next;
3404 struct yaffs_dev *yaffs_next_dev(void)
3406 struct yaffs_dev *retval;
3410 if (dev_iterator == &yaffsfs_deviceList)
3413 retval = list_entry(dev_iterator, struct yaffs_dev, dev_list);
3414 dev_iterator = dev_iterator->next;
3418 /* Directory search stuff. */
3420 static struct list_head search_contexts;
3422 static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContext *dsc)
3426 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3430 if (list_empty(&dsc->dirObj->variant.dir_variant.children))
3431 dsc->nextReturn = NULL;
3434 list_entry(dsc->dirObj->variant.dir_variant.
3435 children.next, struct yaffs_obj,
3438 /* Hey someone isn't playing nice! */
3442 static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContext *dsc)
3446 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3448 if (dsc->nextReturn == NULL ||
3449 list_empty(&dsc->dirObj->variant.dir_variant.children))
3450 dsc->nextReturn = NULL;
3452 struct list_head *next = dsc->nextReturn->siblings.next;
3454 if (next == &dsc->dirObj->variant.dir_variant.children)
3455 dsc->nextReturn = NULL; /* end of list */
3457 dsc->nextReturn = list_entry(next,
3462 /* Hey someone isn't playing nice! */
3466 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj)
3469 struct list_head *i;
3470 struct yaffsfs_DirSearchContext *dsc;
3472 /* if search contexts not initilised then skip */
3473 if (!search_contexts.next)
3476 /* Iterate through the directory search contexts.
3477 * If any are the one being removed, then advance the dsc to
3478 * the next one to prevent a hanging ptr.
3480 list_for_each(i, &search_contexts) {
3482 dsc = list_entry(i, struct yaffsfs_DirSearchContext,
3484 if (dsc->nextReturn == obj)
3485 yaffsfs_DirAdvance(dsc);
3491 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(struct yaffs_obj *reldir,
3492 const YCHAR *dirname)
3494 yaffs_DIR *dir = NULL;
3495 struct yaffs_obj *obj = NULL;
3496 struct yaffsfs_DirSearchContext *dsc = NULL;
3500 if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) {
3501 yaffsfs_SetError(-EFAULT);
3505 if (yaffsfs_CheckPath(dirname) < 0) {
3506 yaffsfs_SetError(-ENAMETOOLONG);
3510 obj = yaffsfs_FindObject(reldir, dirname, 0, 1, NULL, ¬Dir, &loop);
3511 obj = yaffsfs_FollowLink(obj, 0, &loop);
3514 yaffsfs_SetError(-ENOTDIR);
3516 yaffsfs_SetError(-ELOOP);
3518 yaffsfs_SetError(-ENOENT);
3519 else if (obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
3520 yaffsfs_SetError(-ENOTDIR);
3524 for (i = 0, dsc = NULL; i < YAFFSFS_N_DSC && !dsc; i++) {
3525 if (!yaffsfs_dsc[i].inUse)
3526 dsc = &yaffsfs_dsc[i];
3529 dir = (yaffs_DIR *) dsc;
3532 memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContext));
3535 yaffs_strncpy(dsc->name, dirname, NAME_MAX);
3536 INIT_LIST_HEAD(&dsc->others);
3538 if (!search_contexts.next)
3539 INIT_LIST_HEAD(&search_contexts);
3541 list_add(&dsc->others, &search_contexts);
3542 yaffsfs_SetDirRewound(dsc);
3548 yaffs_DIR *yaffs_opendir_reldir(struct yaffs_obj *reldir, const YCHAR *dirname)
3553 ret = yaffsfs_opendir_reldir_no_lock(reldir, dirname);
3558 yaffs_DIR *yaffs_opendir_reldev(struct yaffs_dev *dev, const YCHAR *dirname)
3560 return yaffs_opendir_reldir(ROOT_DIR(dev), dirname);
3563 yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
3565 return yaffs_opendir_reldir(NULL, dirname);
3568 struct yaffs_dirent *yaffsfs_readdir_no_lock(yaffs_DIR * dirp)
3570 struct yaffsfs_DirSearchContext *dsc;
3571 struct yaffs_dirent *retVal = NULL;
3573 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3576 if (dsc && dsc->inUse) {
3577 yaffsfs_SetError(0);
3578 if (dsc->nextReturn) {
3580 yaffs_get_equivalent_obj(dsc->nextReturn)->obj_id;
3581 dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
3582 dsc->de.d_off = dsc->offset++;
3583 yaffs_get_obj_name(dsc->nextReturn,
3584 dsc->de.d_name, NAME_MAX);
3585 if (yaffs_strnlen(dsc->de.d_name, NAME_MAX + 1) == 0) {
3586 /* this should not happen! */
3587 yaffs_strcpy(dsc->de.d_name, _Y("zz"));
3589 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
3591 yaffsfs_DirAdvance(dsc);
3595 yaffsfs_SetError(-EBADF);
3600 struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp)
3602 struct yaffs_dirent *ret;
3605 ret = yaffsfs_readdir_no_lock(dirp);
3610 static void yaffsfs_rewinddir_no_lock(yaffs_DIR *dirp)
3612 struct yaffsfs_DirSearchContext *dsc;
3614 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3616 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
3619 yaffsfs_SetDirRewound(dsc);
3623 void yaffs_rewinddir(yaffs_DIR *dirp)
3626 yaffsfs_rewinddir_no_lock(dirp);
3630 struct yaffs_dirent *yaffs_readdir_fd(int fd)
3632 struct yaffs_dirent *ret = NULL;
3633 struct yaffsfs_FileDes *f;
3636 f = yaffsfs_HandleToFileDes(fd);
3638 ret = yaffsfs_readdir_no_lock(f->v.dir);
3643 void yaffs_rewinddir_fd(int fd)
3645 struct yaffsfs_FileDes *f;
3648 f = yaffsfs_HandleToFileDes(fd);
3650 yaffsfs_rewinddir_no_lock(f->v.dir);
3655 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirp)
3657 struct yaffsfs_DirSearchContext *dsc;
3659 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3661 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) {
3662 yaffsfs_SetError(-EFAULT);
3667 list_del(&dsc->others); /* unhook from list */
3672 int yaffs_closedir(yaffs_DIR *dirp)
3677 ret = yaffsfs_closedir_no_lock(dirp);
3682 /* End of directory stuff */
3684 int yaffs_symlink_reldir(struct yaffs_obj *reldir,
3685 const YCHAR *oldpath, const YCHAR *newpath)
3687 struct yaffs_obj *parent = NULL;
3688 struct yaffs_obj *obj;
3691 int mode = 0; /* ignore for now */
3695 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3696 yaffsfs_CheckMemRegion(newpath, 0, 0) < 0) {
3697 yaffsfs_SetError(-EFAULT);
3701 if (yaffsfs_CheckPath(newpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3702 yaffsfs_SetError(-ENAMETOOLONG);
3707 parent = yaffsfs_FindDirectory(reldir, newpath, &name, 0, ¬Dir, &loop);
3708 if (!parent && notDir)
3709 yaffsfs_SetError(-ENOTDIR);
3711 yaffsfs_SetError(-ELOOP);
3712 else if (!parent || yaffs_strnlen(name, 5) < 1)
3713 yaffsfs_SetError(-ENOENT);
3714 else if (yaffsfs_TooManyObjects(parent->my_dev))
3715 yaffsfs_SetError(-ENFILE);
3716 else if (parent->my_dev->read_only)
3717 yaffsfs_SetError(-EROFS);
3719 obj = yaffs_create_symlink(parent, name, mode, 0, 0, oldpath);
3722 else if (yaffsfs_FindObject(reldir, newpath, 0, 0,
3724 yaffsfs_SetError(-EEXIST);
3726 yaffsfs_SetError(-ENOSPC);
3734 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
3736 return yaffs_symlink_reldir(NULL, oldpath, newpath);
3739 int yaffs_readlink_reldir(struct yaffs_obj *reldir,const YCHAR *path,
3740 YCHAR *buf, int bufsiz)
3742 struct yaffs_obj *obj = NULL;
3743 struct yaffs_obj *dir = NULL;
3748 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
3749 yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0) {
3750 yaffsfs_SetError(-EFAULT);
3756 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
3759 yaffsfs_SetError(-ENOTDIR);
3761 yaffsfs_SetError(-ELOOP);
3762 else if (!dir || !obj)
3763 yaffsfs_SetError(-ENOENT);
3764 else if (obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
3765 yaffsfs_SetError(-EINVAL);
3767 YCHAR *alias = obj->variant.symlink_variant.alias;
3768 memset(buf, 0, bufsiz);
3769 yaffs_strncpy(buf, alias, bufsiz - 1);
3775 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
3777 return yaffs_readlink_reldir(NULL, path, buf, bufsiz);
3780 int yaffs_link_reldir(struct yaffs_obj *reldir,
3781 const YCHAR *oldpath, const YCHAR *linkpath)
3783 /* Creates a link called newpath to existing oldpath */
3784 struct yaffs_obj *obj = NULL;
3785 struct yaffs_obj *lnk = NULL;
3786 struct yaffs_obj *obj_dir = NULL;
3787 struct yaffs_obj *lnk_dir = NULL;
3795 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3796 yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0) {
3797 yaffsfs_SetError(-EFAULT);
3801 if (yaffsfs_CheckPath(linkpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3802 yaffsfs_SetError(-ENAMETOOLONG);
3808 obj = yaffsfs_FindObject(reldir, oldpath, 0, 1,
3809 &obj_dir, ¬DirObj, &objLoop);
3810 lnk = yaffsfs_FindObject(reldir, linkpath, 0, 0, NULL, NULL, NULL);
3811 lnk_dir = yaffsfs_FindDirectory(reldir, linkpath, &newname,
3812 0, ¬DirLnk, &lnkLoop);
3814 if ((!obj_dir && notDirObj) || (!lnk_dir && notDirLnk))
3815 yaffsfs_SetError(-ENOTDIR);
3816 else if (objLoop || lnkLoop)
3817 yaffsfs_SetError(-ELOOP);
3818 else if (!obj_dir || !lnk_dir || !obj)
3819 yaffsfs_SetError(-ENOENT);
3820 else if (obj->my_dev->read_only)
3821 yaffsfs_SetError(-EROFS);
3822 else if (yaffsfs_TooManyObjects(obj->my_dev))
3823 yaffsfs_SetError(-ENFILE);
3825 yaffsfs_SetError(-EEXIST);
3826 else if (lnk_dir->my_dev != obj->my_dev)
3827 yaffsfs_SetError(-EXDEV);
3829 retVal = yaffsfs_CheckNameLength(newname);
3832 lnk = yaffs_link_obj(lnk_dir, newname, obj);
3836 yaffsfs_SetError(-ENOSPC);
3845 int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
3847 return yaffs_link_reldir(NULL, oldpath, linkpath);
3850 int yaffs_mknod_reldir(struct yaffs_obj *reldir, const YCHAR *pathname,
3851 mode_t mode, dev_t dev_val)
3858 yaffsfs_SetError(-EINVAL);
3862 int yaffs_mknod_reldev(struct yaffs_dev *dev, const YCHAR *pathname, mode_t mode, dev_t dev_val)
3864 return yaffs_mknod_reldir(ROOT_DIR(dev), pathname, mode, dev_val);
3867 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev_val)
3869 return yaffs_mknod_reldir(NULL, pathname, mode, dev_val);
3873 * D E B U G F U N C T I O N S
3878 * Returns number of handles attached to the object
3880 int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3882 struct yaffs_obj *obj;
3884 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3885 yaffsfs_SetError(-EFAULT);
3889 if (yaffsfs_CheckPath(path) < 0) {
3890 yaffsfs_SetError(-ENAMETOOLONG);
3894 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
3897 return yaffsfs_CountHandles(obj);
3902 int yaffs_n_handles(const YCHAR *path)
3904 return yaffs_n_handles_reldir(NULL, path);
3907 int yaffs_get_error(void)
3909 return yaffsfs_GetLastError();
3912 int yaffs_set_error(int error)
3914 yaffsfs_SetError(error);
3918 struct yaffs_obj * yaffs_get_obj_from_fd(int handle)
3920 return yaffsfs_HandleToObject(handle);
3923 int yaffs_dump_dev_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3933 reldir = yaffsfs_FindRoot(path, &rest);
3936 struct yaffs_dev *dev = reldir->my_dev;
3939 "n_page_writes.......... %d\n"
3940 "n_page_reads........... %d\n"
3941 "n_erasures....... %d\n"
3942 "n_gc_copies............ %d\n"
3943 "garbageCollections... %d\n"
3944 "passiveGarbageColl'ns %d\n"
3950 dev->garbageCollections, dev->passiveGarbageCollections);
3957 int yaffs_dump_dev(const YCHAR *path)
3959 return yaffs_dump_dev_reldir(NULL, path);