2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2018 Aleph One Ltd.
6 * Created by Charles Manning <charles@aleph1.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include "yaffs_guts.h"
17 #include "yaffs_trace.h"
21 #define YAFFS_MAX_RW_SIZE 0x70000000
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);
896 * A directory can't be opened except for read, so we
906 dsc = yaffsfs_opendir_reldir_no_lock(reldir, path);
908 openDenied = __LINE__;
909 yaffsfs_SetError(-ENFILE);
910 errorReported = __LINE__;
914 /* Open should fail if O_CREAT and O_EXCL are specified
915 * for a file that exists.
917 if (!errorReported &&
918 (oflag & O_EXCL) && (oflag & O_CREAT)) {
919 openDenied = __LINE__;
920 yaffsfs_SetError(-EEXIST);
921 errorReported = __LINE__;
924 /* Check file permissions */
925 if (readRequested && !(obj->yst_mode & S_IRUSR))
926 openDenied = __LINE__;
928 if (writeRequested && !(obj->yst_mode & S_IWUSR))
929 openDenied = __LINE__;
931 if (!errorReported && writeRequested &&
932 obj->my_dev->read_only) {
933 openDenied = __LINE__;
934 yaffsfs_SetError(-EROFS);
935 errorReported = __LINE__;
938 if (openDenied && !errorReported) {
939 yaffsfs_SetError(-EACCES);
940 errorReported = __LINE__;
943 /* Check sharing of an existing object. */
945 struct yaffsfs_FileDes *fdx;
948 sharedReadAllowed = 1;
949 sharedWriteAllowed = 1;
952 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
953 fdx = &yaffsfs_fd[i];
954 if (fdx->handleCount > 0 &&
956 yaffsfs_inode[fdx->inodeId].iObj
959 sharedReadAllowed = 0;
960 if (!fdx->shareWrite)
961 sharedWriteAllowed = 0;
969 if ((!sharedReadAllowed && readRequested) ||
970 (!shareRead && alreadyReading) ||
971 (!sharedWriteAllowed && writeRequested) ||
972 (!shareWrite && alreadyWriting)) {
973 openDenied = __LINE__;
974 yaffsfs_SetError(-EBUSY);
975 errorReported = __LINE__;
981 /* If we could not open an existing object, then let's see if
982 * the directory exists. If not, error.
984 if (!obj && !errorReported) {
985 dir = yaffsfs_FindDirectory(reldir, path, &name, 0,
987 if (!dir && notDir) {
988 yaffsfs_SetError(-ENOTDIR);
989 errorReported = __LINE__;
991 yaffsfs_SetError(-ELOOP);
992 errorReported = __LINE__;
994 yaffsfs_SetError(-ENOENT);
995 errorReported = __LINE__;
999 if (!obj && dir && !errorReported && (oflag & O_CREAT)) {
1000 /* Let's see if we can create this file */
1001 if (dir->my_dev->read_only) {
1002 yaffsfs_SetError(-EROFS);
1003 errorReported = __LINE__;
1004 } else if (yaffsfs_TooManyObjects(dir->my_dev)) {
1005 yaffsfs_SetError(-ENFILE);
1006 errorReported = __LINE__;
1008 obj = yaffs_create_file(dir, name, mode, 0, 0);
1010 if (!obj && !errorReported) {
1011 yaffsfs_SetError(-ENOSPC);
1012 errorReported = __LINE__;
1016 if (!obj && dir && !errorReported && !(oflag & O_CREAT)) {
1017 yaffsfs_SetError(-ENOENT);
1018 errorReported = __LINE__;
1021 if (obj && !openDenied) {
1022 int inodeId = yaffsfs_GetInodeIdForObject(obj);
1026 * Todo: Fix any problem if inodes run out,
1027 * That can't happen if the number of inode
1028 * items >= number of handles.
1032 fd->inodeId = inodeId;
1033 fd->reading = readRequested;
1034 fd->writing = writeRequested;
1035 fd->append = (oflag & O_APPEND) ? 1 : 0;
1036 fd->shareRead = shareRead;
1037 fd->shareWrite = shareWrite;
1045 /* Hook inode to object */
1046 obj->my_inode = (void *)&yaffsfs_inode[inodeId];
1048 if (!is_dir && (oflag & O_TRUNC) && fd->writing)
1049 yaffs_resize_file(obj, 0);
1052 yaffsfs_closedir_no_lock(dsc);
1054 yaffsfs_PutHandle(handle);
1056 yaffsfs_SetError(0); /* Problem */
1066 int yaffs_open_sharing_reldev(struct yaffs_dev *dev, const YCHAR *path, int oflag,
1067 int mode, int sharing)
1069 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path,
1070 oflag, mode, sharing);
1073 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
1075 return yaffs_open_sharing_reldir(NULL, path, oflag, mode, sharing);
1078 int yaffs_open_reldir(struct yaffs_obj *reldir,const YCHAR *path, int oflag, int mode)
1080 return yaffs_open_sharing_reldir(reldir, path, oflag, mode,
1081 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1084 int yaffs_open_reldev(struct yaffs_dev *dev,const YCHAR *path, int oflag, int mode)
1086 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path, oflag, mode,
1087 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1090 int yaffs_open(const YCHAR *path, int oflag, int mode)
1092 return yaffs_open_reldir(NULL, path, oflag, mode);
1095 static int yaffs_Dofsync(int handle, int datasync)
1098 struct yaffs_obj *obj;
1102 obj = yaffsfs_HandleToObject(handle);
1105 yaffsfs_SetError(-EBADF);
1106 else if (obj->my_dev->read_only)
1107 yaffsfs_SetError(-EROFS);
1109 yaffs_flush_file(obj, 1, datasync, 0);
1118 int yaffs_fsync(int handle)
1120 return yaffs_Dofsync(handle, 0);
1123 int yaffs_flush(int handle)
1125 return yaffs_fsync(handle);
1128 int yaffs_fdatasync(int handle)
1130 return yaffs_Dofsync(handle, 1);
1133 int yaffs_close(int handle)
1135 struct yaffsfs_Handle *h = NULL;
1136 struct yaffsfs_FileDes *f;
1137 struct yaffs_obj *obj = NULL;
1142 h = yaffsfs_HandleToPointer(handle);
1143 f = yaffsfs_HandleToFileDes(handle);
1144 obj = yaffsfs_HandleToObject(handle);
1146 if (!h || !obj || !f)
1147 yaffsfs_SetError(-EBADF);
1151 yaffs_flush_file(obj, 1, 0, 1);
1152 yaffsfs_PutHandle(handle);
1161 static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
1162 int isPread, Y_LOFF_T offset)
1164 struct yaffsfs_FileDes *fd = NULL;
1165 struct yaffs_obj *obj = NULL;
1167 Y_LOFF_T startPos = 0;
1168 Y_LOFF_T endPos = 0;
1173 u8 *buf = (u8 *) vbuf;
1175 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) {
1176 yaffsfs_SetError(-EFAULT);
1181 fd = yaffsfs_HandleToFileDes(handle);
1182 obj = yaffsfs_HandleToObject(handle);
1186 yaffsfs_SetError(-EBADF);
1188 } else if (!fd->reading) {
1189 /* Not a reading handle */
1190 yaffsfs_SetError(-EINVAL);
1192 } else if (nbyte > YAFFS_MAX_RW_SIZE) {
1193 yaffsfs_SetError(-EINVAL);
1199 startPos = fd->v.position;
1203 if (yaffs_get_obj_length(obj) > pos)
1204 maxRead = yaffs_get_obj_length(obj) - pos;
1208 if (nbyte > maxRead)
1211 yaffsfs_GetHandle(handle);
1213 endPos = pos + nbyte;
1215 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1216 nbyte > YAFFS_MAX_RW_SIZE ||
1217 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1223 nToRead = YAFFSFS_RW_SIZE -
1224 (pos & (YAFFSFS_RW_SIZE - 1));
1225 if (nToRead > (int)nbyte)
1229 * Need to reverify object in case the device was
1230 * unmounted in another thread.
1232 obj = yaffsfs_HandleToObject(handle);
1236 nRead = yaffs_file_rd(obj, buf, pos, nToRead);
1244 if (nRead == nToRead)
1247 nbyte = 0; /* no more to read */
1256 yaffsfs_PutHandle(handle);
1260 fd->v.position = startPos + totalRead;
1262 yaffsfs_SetError(-EINVAL);
1269 return (totalRead >= 0) ? totalRead : -1;
1273 int yaffs_read(int handle, void *buf, unsigned int nbyte)
1275 return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
1278 int yaffs_pread(int handle, void *buf, unsigned int nbyte, Y_LOFF_T offset)
1280 return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
1283 static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
1284 int isPwrite, Y_LOFF_T offset)
1286 struct yaffsfs_FileDes *fd = NULL;
1287 struct yaffs_obj *obj = NULL;
1289 Y_LOFF_T startPos = 0;
1292 int totalWritten = 0;
1293 int write_trhrough = 0;
1295 const u8 *buf = (const u8 *)vbuf;
1297 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) {
1298 yaffsfs_SetError(-EFAULT);
1303 fd = yaffsfs_HandleToFileDes(handle);
1304 obj = yaffsfs_HandleToObject(handle);
1308 yaffsfs_SetError(-EBADF);
1310 } else if (!fd->writing) {
1311 yaffsfs_SetError(-EINVAL);
1313 } else if (obj->my_dev->read_only) {
1314 yaffsfs_SetError(-EROFS);
1318 startPos = yaffs_get_obj_length(obj);
1322 startPos = fd->v.position;
1324 yaffsfs_GetHandle(handle);
1326 endPos = pos + nbyte;
1328 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1329 nbyte > YAFFS_MAX_RW_SIZE ||
1330 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1337 nToWrite = YAFFSFS_RW_SIZE -
1338 (pos & (YAFFSFS_RW_SIZE - 1));
1339 if (nToWrite > (int)nbyte)
1343 * Need to reverify object in case the device was
1344 * remounted or unmounted in another thread.
1346 obj = yaffsfs_HandleToObject(handle);
1347 if (!obj || obj->my_dev->read_only)
1351 yaffs_wr_file(obj, buf, pos, nToWrite,
1354 totalWritten += nWritten;
1359 if (nWritten == nToWrite)
1364 if (nWritten < 1 && totalWritten < 1) {
1365 yaffsfs_SetError(-ENOSPC);
1375 yaffsfs_PutHandle(handle);
1378 if (totalWritten > 0)
1379 fd->v.position = startPos + totalWritten;
1381 yaffsfs_SetError(-EINVAL);
1387 return (totalWritten >= 0) ? totalWritten : -1;
1390 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
1392 return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
1395 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset)
1397 return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
1400 int yaffs_truncate_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1403 struct yaffs_obj *obj = NULL;
1404 struct yaffs_obj *dir = NULL;
1405 int result = YAFFS_FAIL;
1409 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1410 yaffsfs_SetError(-EFAULT);
1414 if (yaffsfs_CheckPath(path) < 0) {
1415 yaffsfs_SetError(-ENAMETOOLONG);
1421 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1422 obj = yaffsfs_FollowLink(obj, 0, &loop);
1425 yaffsfs_SetError(-ENOTDIR);
1427 yaffsfs_SetError(-ELOOP);
1428 else if (!dir || !obj)
1429 yaffsfs_SetError(-ENOENT);
1430 else if (obj->my_dev->read_only)
1431 yaffsfs_SetError(-EROFS);
1432 else if (obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
1433 yaffsfs_SetError(-EISDIR);
1434 else if (obj->my_dev->read_only)
1435 yaffsfs_SetError(-EROFS);
1436 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1437 yaffsfs_SetError(-EINVAL);
1439 result = yaffs_resize_file(obj, new_size);
1443 return (result) ? 0 : -1;
1446 int yaffs_truncate_reldev(struct yaffs_dev *dev, const YCHAR *path,
1449 return yaffs_truncate_reldir(ROOT_DIR(dev), path, new_size);
1452 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size)
1454 return yaffs_truncate_reldir(NULL, path, new_size);
1457 int yaffs_ftruncate(int handle, Y_LOFF_T new_size)
1459 struct yaffsfs_FileDes *fd = NULL;
1460 struct yaffs_obj *obj = NULL;
1464 fd = yaffsfs_HandleToFileDes(handle);
1465 obj = yaffsfs_HandleToObject(handle);
1469 yaffsfs_SetError(-EBADF);
1470 else if (!fd->writing)
1471 yaffsfs_SetError(-EINVAL);
1472 else if (obj->my_dev->read_only)
1473 yaffsfs_SetError(-EROFS);
1474 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1475 yaffsfs_SetError(-EINVAL);
1477 /* resize the file */
1478 result = yaffs_resize_file(obj, new_size);
1481 return (result) ? 0 : -1;
1485 Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence)
1487 struct yaffsfs_FileDes *fd = NULL;
1488 struct yaffs_obj *obj = NULL;
1490 Y_LOFF_T fSize = -1;
1493 fd = yaffsfs_HandleToFileDes(handle);
1494 obj = yaffsfs_HandleToObject(handle);
1497 yaffsfs_SetError(-EBADF);
1498 else if (offset > YAFFS_MAX_FILE_SIZE)
1499 yaffsfs_SetError(-EINVAL);
1501 if (whence == SEEK_SET) {
1504 } else if (whence == SEEK_CUR) {
1505 if ((fd->v.position + offset) >= 0)
1506 pos = (fd->v.position + offset);
1507 } else if (whence == SEEK_END) {
1508 fSize = yaffs_get_obj_length(obj);
1509 if (fSize >= 0 && (fSize + offset) >= 0)
1510 pos = fSize + offset;
1513 if (pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE)
1514 fd->v.position = pos;
1516 yaffsfs_SetError(-EINVAL);
1526 static int yaffsfs_DoUnlink_reldir(struct yaffs_obj *reldir,
1527 const YCHAR *path, int isDirectory)
1529 struct yaffs_obj *dir = NULL;
1530 struct yaffs_obj *obj = NULL;
1532 int result = YAFFS_FAIL;
1536 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1537 yaffsfs_SetError(-EFAULT);
1541 if (yaffsfs_CheckPath(path) < 0) {
1542 yaffsfs_SetError(-ENAMETOOLONG);
1548 obj = yaffsfs_FindObject(reldir, path, 0, 0, NULL, NULL, NULL);
1549 dir = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
1552 yaffsfs_SetError(-ENOTDIR);
1554 yaffsfs_SetError(-ELOOP);
1556 yaffsfs_SetError(-ENOENT);
1557 else if (yaffs_strncmp(name, _Y("."), 2) == 0)
1558 yaffsfs_SetError(-EINVAL);
1560 yaffsfs_SetError(-ENOENT);
1561 else if (obj->my_dev->read_only)
1562 yaffsfs_SetError(-EROFS);
1563 else if (!isDirectory &&
1564 obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1565 yaffsfs_SetError(-EISDIR);
1566 else if (isDirectory &&
1567 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1568 yaffsfs_SetError(-ENOTDIR);
1569 else if (isDirectory && obj == obj->my_dev->root_dir)
1570 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1572 result = yaffs_unlinker(dir, name);
1574 if (result == YAFFS_FAIL && isDirectory)
1575 yaffsfs_SetError(-ENOTEMPTY);
1580 return (result == YAFFS_FAIL) ? -1 : 0;
1583 int yaffs_unlink_reldir(struct yaffs_obj *reldir, const YCHAR *path)
1585 return yaffsfs_DoUnlink_reldir(reldir, path, 0);
1588 int yaffs_unlink_reldev(struct yaffs_dev *dev, const YCHAR *path)
1590 return yaffsfs_DoUnlink_reldir(ROOT_DIR(dev), path, 0);
1593 int yaffs_unlink(const YCHAR *path)
1595 return yaffs_unlink_reldir(NULL, path);
1598 int yaffs_funlink(int fd)
1600 struct yaffs_obj *obj;
1604 obj = yaffsfs_HandleToObject(fd);
1607 yaffsfs_SetError(-EBADF);
1608 else if (obj->my_dev->read_only)
1609 yaffsfs_SetError(-EROFS);
1610 else if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1611 !(list_empty(&obj->variant.dir_variant.children)))
1612 yaffsfs_SetError(-ENOTEMPTY);
1613 else if (obj == obj->my_dev->root_dir)
1614 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1615 else if (yaffs_unlink_obj(obj) == YAFFS_OK)
1623 int yaffs_fgetfl(int fd, int *flags)
1625 struct yaffsfs_FileDes *fdp = yaffsfs_HandleToFileDes(fd);
1630 if(!flags || !fdp) {
1631 yaffsfs_SetError(-EINVAL);
1634 if (fdp->reading && fdp->writing)
1636 else if (fdp->writing)
1648 static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1650 if (obj && obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY &&
1651 newobj && newobj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1657 static int rename_dir_over_file(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1659 if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1660 newobj && newobj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1666 int yaffs_rename_reldir(struct yaffs_obj *reldir,
1667 const YCHAR *oldPath, const YCHAR *newPath)
1669 struct yaffs_obj *olddir = NULL;
1670 struct yaffs_obj *newdir = NULL;
1671 struct yaffs_obj *obj = NULL;
1672 struct yaffs_obj *newobj = NULL;
1675 int result = YAFFS_FAIL;
1676 int rename_allowed = 1;
1682 YCHAR *alt_newpath = NULL;
1684 if (yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 ||
1685 yaffsfs_CheckMemRegion(newPath, 0, 0) < 0) {
1686 yaffsfs_SetError(-EFAULT);
1690 if (yaffsfs_CheckPath(oldPath) < 0 || yaffsfs_CheckPath(newPath) < 0) {
1691 yaffsfs_SetError(-ENAMETOOLONG);
1695 if (yaffsfs_alt_dir_path(newPath, &alt_newpath) < 0) {
1696 yaffsfs_SetError(-ENOMEM);
1700 newPath = alt_newpath;
1704 olddir = yaffsfs_FindDirectory(reldir, oldPath, &oldname, 0,
1705 ¬OldDir, &oldLoop);
1706 newdir = yaffsfs_FindDirectory(reldir, newPath, &newname, 0,
1707 ¬NewDir, &newLoop);
1708 obj = yaffsfs_FindObject(reldir, oldPath, 0, 0, NULL, NULL, NULL);
1709 newobj = yaffsfs_FindObject(reldir, newPath, 0, 0, NULL, NULL, NULL);
1711 /* If the object being renamed is a directory and the
1712 * path ended with a "/" then the olddir == obj.
1713 * We pass through NULL for the old name to tell the lower layers
1714 * to use olddir as the object.
1720 if ((!olddir && notOldDir) || (!newdir && notNewDir)) {
1721 yaffsfs_SetError(-ENOTDIR);
1723 } else if (oldLoop || newLoop) {
1724 yaffsfs_SetError(-ELOOP);
1726 } else if (olddir && oldname &&
1727 yaffs_strncmp(oldname, _Y("."), 2) == 0) {
1728 yaffsfs_SetError(-EINVAL);
1730 } else if (!olddir || !newdir || !obj) {
1731 yaffsfs_SetError(-ENOENT);
1733 } else if (obj->my_dev->read_only) {
1734 yaffsfs_SetError(-EROFS);
1736 } else if (rename_file_over_dir(obj, newobj)) {
1737 yaffsfs_SetError(-EISDIR);
1739 } else if (rename_dir_over_file(obj, newobj)) {
1740 yaffsfs_SetError(-ENOTDIR);
1742 } else if (yaffs_is_non_empty_dir(newobj)) {
1743 yaffsfs_SetError(-ENOTEMPTY);
1745 } else if (olddir->my_dev != newdir->my_dev) {
1746 /* Rename must be on same device */
1747 yaffsfs_SetError(-EXDEV);
1749 } else if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
1751 * It is a directory, check that it is not being renamed to
1752 * being its own decendent.
1753 * Do this by tracing from the new directory back to the root,
1757 struct yaffs_obj *xx = newdir;
1759 while (rename_allowed && xx) {
1764 if (!rename_allowed)
1765 yaffsfs_SetError(-EINVAL);
1769 result = yaffs_rename_obj(olddir, oldname, newdir, newname);
1775 return (result == YAFFS_FAIL) ? -1 : 0;
1778 int yaffs_rename_reldev(struct yaffs_dev *dev, const YCHAR *oldPath,
1779 const YCHAR *newPath)
1781 return yaffs_rename_reldir(ROOT_DIR(dev), oldPath, newPath);
1783 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
1785 return yaffs_rename_reldir(NULL, oldPath, newPath);
1788 static int yaffsfs_DoStat(struct yaffs_obj *obj, struct yaffs_stat *buf)
1792 obj = yaffs_get_equivalent_obj(obj);
1796 buf->st_ino = obj->obj_id;
1797 buf->st_mode = obj->yst_mode & ~S_IFMT;
1799 if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1800 buf->st_mode |= S_IFDIR;
1801 else if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
1802 buf->st_mode |= S_IFLNK;
1803 else if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE)
1804 buf->st_mode |= S_IFREG;
1806 buf->st_nlink = yaffs_get_obj_link_count(obj);
1809 buf->st_rdev = obj->yst_rdev;
1810 buf->st_size = yaffs_get_obj_length(obj);
1811 buf->st_blksize = obj->my_dev->data_bytes_per_chunk;
1812 buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
1814 #if CONFIG_YAFFS_WINCE
1815 buf->yst_wince_atime[0] = obj->win_atime[0];
1816 buf->yst_wince_atime[1] = obj->win_atime[1];
1817 buf->yst_wince_ctime[0] = obj->win_ctime[0];
1818 buf->yst_wince_ctime[1] = obj->win_ctime[1];
1819 buf->yst_wince_mtime[0] = obj->win_mtime[0];
1820 buf->yst_wince_mtime[1] = obj->win_mtime[1];
1822 buf->yst_atime = obj->yst_atime;
1823 buf->yst_ctime = obj->yst_ctime;
1824 buf->yst_mtime = obj->yst_mtime;
1831 static int yaffsfs_DoStatOrLStat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1832 struct yaffs_stat *buf, int doLStat)
1834 struct yaffs_obj *obj = NULL;
1835 struct yaffs_obj *dir = NULL;
1840 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
1841 yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1842 yaffsfs_SetError(-EFAULT);
1846 if (yaffsfs_CheckPath(path) < 0) {
1847 yaffsfs_SetError(-ENAMETOOLONG);
1853 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1855 if (!doLStat && obj)
1856 obj = yaffsfs_FollowLink(obj, 0, &loop);
1859 yaffsfs_SetError(-ENOTDIR);
1861 yaffsfs_SetError(-ELOOP);
1862 else if (!dir || !obj)
1863 yaffsfs_SetError(-ENOENT);
1865 retVal = yaffsfs_DoStat(obj, buf);
1873 int yaffs_stat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1874 struct yaffs_stat *buf)
1876 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 0);
1879 int yaffs_lstat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1880 struct yaffs_stat *buf)
1882 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 1);
1885 int yaffs_stat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1886 struct yaffs_stat *buf)
1888 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 0);
1891 int yaffs_lstat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1892 struct yaffs_stat *buf)
1894 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 1);
1897 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf)
1899 return yaffs_stat_reldir(NULL, path, buf);
1902 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf)
1904 return yaffs_lstat_reldir(NULL, path, buf);
1907 int yaffs_fstat(int fd, struct yaffs_stat *buf)
1909 struct yaffs_obj *obj;
1913 if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1914 yaffsfs_SetError(-EFAULT);
1919 obj = yaffsfs_HandleToObject(fd);
1922 retVal = yaffsfs_DoStat(obj, buf);
1925 yaffsfs_SetError(-EBADF);
1932 static int yaffsfs_DoUtime(struct yaffs_obj *obj,
1933 const struct yaffs_utimbuf *buf)
1936 struct yaffs_utimbuf local;
1938 obj = yaffs_get_equivalent_obj(obj);
1940 if (obj && obj->my_dev->read_only) {
1941 yaffsfs_SetError(-EROFS);
1945 #if !CONFIG_YAFFS_WINCE
1947 local.actime = Y_CURRENT_TIME;
1948 local.modtime = local.actime;
1955 obj->yst_atime = buf->actime;
1956 obj->yst_mtime = buf->modtime;
1958 result = yaffs_flush_file(obj, 0, 0, 0);
1959 retVal = result == YAFFS_OK ? 0 : -1;
1966 int yaffs_utime_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1967 const struct yaffs_utimbuf *buf)
1969 struct yaffs_obj *obj = NULL;
1970 struct yaffs_obj *dir = NULL;
1976 yaffsfs_SetError(-EFAULT);
1980 if (yaffsfs_CheckPath(path) < 0) {
1981 yaffsfs_SetError(-ENAMETOOLONG);
1987 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1990 yaffsfs_SetError(-ENOTDIR);
1992 yaffsfs_SetError(-ELOOP);
1993 else if (!dir || !obj)
1994 yaffsfs_SetError(-ENOENT);
1996 retVal = yaffsfs_DoUtime(obj, buf);
2004 int yaffs_utime_reldev(struct yaffs_dev *dev, const YCHAR *path,
2005 const struct yaffs_utimbuf *buf)
2007 return yaffs_utime_reldir(ROOT_DIR(dev), path, buf);
2010 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf)
2012 return yaffs_utime_reldir(NULL, path, buf);
2015 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf)
2017 struct yaffs_obj *obj;
2022 obj = yaffsfs_HandleToObject(fd);
2025 retVal = yaffsfs_DoUtime(obj, buf);
2028 yaffsfs_SetError(-EBADF);
2035 #ifndef CONFIG_YAFFS_WINCE
2036 /* xattrib functions */
2038 static int yaffs_do_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2039 const char *name, const void *data, int size,
2040 int flags, int follow)
2042 struct yaffs_obj *obj;
2043 struct yaffs_obj *dir;
2049 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2050 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2051 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2052 yaffsfs_SetError(-EFAULT);
2056 if (yaffsfs_CheckPath(path) < 0) {
2057 yaffsfs_SetError(-ENAMETOOLONG);
2063 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2066 obj = yaffsfs_FollowLink(obj, 0, &loop);
2069 yaffsfs_SetError(-ENOTDIR);
2071 yaffsfs_SetError(-ELOOP);
2072 else if (!dir || !obj)
2073 yaffsfs_SetError(-ENOENT);
2075 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2077 yaffsfs_SetError(retVal);
2088 int yaffs_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2089 const char *name, const void *data, int size, int flags)
2091 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 1);
2094 int yaffs_setxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
2095 const char *name, const void *data, int size, int flags)
2097 return yaffs_setxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2100 int yaffs_setxattr(const YCHAR *path, const char *name,
2101 const void *data, int size, int flags)
2103 return yaffs_setxattr_reldir(NULL, path, name, data, size, flags);
2106 int yaffs_lsetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path, const char *name,
2107 const void *data, int size, int flags)
2109 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 0);
2112 int yaffs_lsetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name,
2113 const void *data, int size, int flags)
2115 return yaffs_lsetxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2118 int yaffs_lsetxattr(const YCHAR *path, const char *name,
2119 const void *data, int size, int flags)
2121 return yaffs_lsetxattr_reldir(NULL, path, name, data, size, flags);
2124 int yaffs_fsetxattr(int fd, const char *name,
2125 const void *data, int size, int flags)
2127 struct yaffs_obj *obj;
2131 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2132 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2133 yaffsfs_SetError(-EFAULT);
2138 obj = yaffsfs_HandleToObject(fd);
2141 yaffsfs_SetError(-EBADF);
2143 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2145 yaffsfs_SetError(retVal);
2155 static int yaffs_do_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2156 const char *name, void *data, int size, int follow)
2158 struct yaffs_obj *obj;
2159 struct yaffs_obj *dir;
2164 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2165 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2166 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2167 yaffsfs_SetError(-EFAULT);
2171 if (yaffsfs_CheckPath(path) < 0) {
2172 yaffsfs_SetError(-ENAMETOOLONG);
2178 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2181 obj = yaffsfs_FollowLink(obj, 0, &loop);
2184 yaffsfs_SetError(-ENOTDIR);
2186 yaffsfs_SetError(-ELOOP);
2187 else if (!dir || !obj)
2188 yaffsfs_SetError(-ENOENT);
2190 retVal = yaffs_get_xattrib(obj, name, data, size);
2192 yaffsfs_SetError(retVal);
2202 int yaffs_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2203 const char *name, void *data, int size)
2205 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 1);
2208 int yaffs_getxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2210 return yaffs_getxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2213 int yaffs_getxattr(const YCHAR *path, const char *name, void *data, int size)
2215 return yaffs_getxattr_reldir(NULL, path, name, data, size);
2218 int yaffs_lgetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2219 const char *name, void *data, int size)
2221 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 0);
2224 int yaffs_lgetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2226 return yaffs_lgetxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2229 int yaffs_lgetxattr(const YCHAR *path, const char *name, void *data, int size)
2231 return yaffs_lgetxattr_reldir(NULL, path, name, data, size);
2234 int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
2236 struct yaffs_obj *obj;
2240 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2241 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2242 yaffsfs_SetError(-EFAULT);
2247 obj = yaffsfs_HandleToObject(fd);
2250 retVal = yaffs_get_xattrib(obj, name, data, size);
2252 yaffsfs_SetError(retVal);
2257 yaffsfs_SetError(-EBADF);
2264 static int yaffs_do_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2265 char *data, int size, int follow)
2267 struct yaffs_obj *obj = NULL;
2268 struct yaffs_obj *dir = NULL;
2273 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2274 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2275 yaffsfs_SetError(-EFAULT);
2279 if (yaffsfs_CheckPath(path) < 0) {
2280 yaffsfs_SetError(-ENAMETOOLONG);
2286 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2289 obj = yaffsfs_FollowLink(obj, 0, &loop);
2292 yaffsfs_SetError(-ENOTDIR);
2294 yaffsfs_SetError(-ELOOP);
2295 else if (!dir || !obj)
2296 yaffsfs_SetError(-ENOENT);
2298 retVal = yaffs_list_xattrib(obj, data, size);
2300 yaffsfs_SetError(retVal);
2311 int yaffs_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2312 char *data, int size)
2314 return yaffs_do_listxattr_reldir(reldir, path, data, size, 1);
2317 int yaffs_listxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2319 return yaffs_listxattr_reldir(ROOT_DIR(dev), path, data, size);
2322 int yaffs_listxattr(const YCHAR *path, char *data, int size)
2324 return yaffs_listxattr_reldir(NULL, path, data, size);
2327 int yaffs_llistxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2328 char *data, int size)
2330 return yaffs_do_listxattr_reldir(reldir, path, data, size, 0);
2333 int yaffs_llistxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2335 return yaffs_llistxattr_reldir(ROOT_DIR(dev), path, data, size);
2338 int yaffs_llistxattr(const YCHAR *path, char *data, int size)
2340 return yaffs_llistxattr_reldir(NULL, path, data, size);
2343 int yaffs_flistxattr(int fd, char *data, int size)
2345 struct yaffs_obj *obj;
2349 if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2350 yaffsfs_SetError(-EFAULT);
2355 obj = yaffsfs_HandleToObject(fd);
2358 retVal = yaffs_list_xattrib(obj, data, size);
2360 yaffsfs_SetError(retVal);
2365 yaffsfs_SetError(-EBADF);
2372 static int yaffs_do_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2373 const char *name, int follow)
2375 struct yaffs_obj *obj = NULL;
2376 struct yaffs_obj *dir = NULL;
2381 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2382 yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2383 yaffsfs_SetError(-EFAULT);
2387 if (yaffsfs_CheckPath(path) < 0) {
2388 yaffsfs_SetError(-ENAMETOOLONG);
2394 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2397 obj = yaffsfs_FollowLink(obj, 0, &loop);
2400 yaffsfs_SetError(-ENOTDIR);
2402 yaffsfs_SetError(-ELOOP);
2403 else if (!dir || !obj)
2404 yaffsfs_SetError(-ENOENT);
2406 retVal = yaffs_remove_xattrib(obj, name);
2408 yaffsfs_SetError(retVal);
2419 int yaffs_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2422 return yaffs_do_removexattr_reldir(reldir, path, name, 1);
2425 int yaffs_removexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2427 return yaffs_removexattr_reldir(ROOT_DIR(dev), path, name);
2430 int yaffs_removexattr(const YCHAR *path, const char *name)
2432 return yaffs_removexattr_reldir(NULL, path, name);
2435 int yaffs_lremovexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2438 return yaffs_do_removexattr_reldir(reldir, path, name, 0);
2441 int yaffs_lremovexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2443 return yaffs_lremovexattr_reldir(ROOT_DIR(dev), path, name);
2446 int yaffs_lremovexattr(const YCHAR *path, const char *name)
2448 return yaffs_lremovexattr_reldir(NULL, path, name);
2451 int yaffs_fremovexattr(int fd, const char *name)
2453 struct yaffs_obj *obj;
2457 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2458 yaffsfs_SetError(-EFAULT);
2463 obj = yaffsfs_HandleToObject(fd);
2466 retVal = yaffs_remove_xattrib(obj, name);
2468 yaffsfs_SetError(retVal);
2473 yaffsfs_SetError(-EBADF);
2481 #ifdef CONFIG_YAFFS_WINCE
2482 int yaffs_get_wince_times(int fd, unsigned *wctime,
2483 unsigned *watime, unsigned *wmtime)
2485 struct yaffs_obj *obj;
2490 obj = yaffsfs_HandleToObject(fd);
2495 wctime[0] = obj->win_ctime[0];
2496 wctime[1] = obj->win_ctime[1];
2499 watime[0] = obj->win_atime[0];
2500 watime[1] = obj->win_atime[1];
2503 wmtime[0] = obj->win_mtime[0];
2504 wmtime[1] = obj->win_mtime[1];
2510 yaffsfs_SetError(-EBADF);
2517 int yaffs_set_wince_times(int fd,
2518 const unsigned *wctime,
2519 const unsigned *watime, const unsigned *wmtime)
2521 struct yaffs_obj *obj;
2526 obj = yaffsfs_HandleToObject(fd);
2531 obj->win_ctime[0] = wctime[0];
2532 obj->win_ctime[1] = wctime[1];
2535 obj->win_atime[0] = watime[0];
2536 obj->win_atime[1] = watime[1];
2539 obj->win_mtime[0] = wmtime[0];
2540 obj->win_mtime[1] = wmtime[1];
2544 result = yaffs_flush_file(obj, 0, 0, 0);
2548 yaffsfs_SetError(-EBADF);
2557 static int yaffsfs_DoChMod(struct yaffs_obj *obj, mode_t mode)
2562 obj = yaffs_get_equivalent_obj(obj);
2565 obj->yst_mode = mode;
2567 result = yaffs_flush_file(obj, 0, 0, 0);
2570 return result == YAFFS_OK ? 0 : -1;
2573 int yaffs_access_reldir(struct yaffs_obj *reldir, const YCHAR *path, int amode)
2575 struct yaffs_obj *obj = NULL;
2576 struct yaffs_obj *dir = NULL;
2581 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2582 yaffsfs_SetError(-EFAULT);
2586 if (yaffsfs_CheckPath(path) < 0) {
2587 yaffsfs_SetError(-ENAMETOOLONG);
2591 if (amode & ~(R_OK | W_OK | X_OK)) {
2592 yaffsfs_SetError(-EINVAL);
2598 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2599 obj = yaffsfs_FollowLink(obj, 0, &loop);
2602 yaffsfs_SetError(-ENOTDIR);
2604 yaffsfs_SetError(-ELOOP);
2605 else if (!dir || !obj)
2606 yaffsfs_SetError(-ENOENT);
2607 else if ((amode & W_OK) && obj->my_dev->read_only)
2608 yaffsfs_SetError(-EROFS);
2612 if ((amode & R_OK) && !(obj->yst_mode & S_IRUSR))
2614 if ((amode & W_OK) && !(obj->yst_mode & S_IWUSR))
2616 if ((amode & X_OK) && !(obj->yst_mode & S_IXUSR))
2620 yaffsfs_SetError(-EACCES);
2631 int yaffs_access_reldev(struct yaffs_dev *dev, const YCHAR *path, int amode)
2633 return yaffs_access_reldir(ROOT_DIR(dev), path, amode);
2636 int yaffs_access(const YCHAR *path, int amode)
2638 return yaffs_access_reldir(NULL, path, amode);
2641 int yaffs_chmod_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2643 struct yaffs_obj *obj = NULL;
2644 struct yaffs_obj *dir = NULL;
2649 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2650 yaffsfs_SetError(-EFAULT);
2654 if (yaffsfs_CheckPath(path) < 0) {
2655 yaffsfs_SetError(-ENAMETOOLONG);
2659 if (mode & ~(0777)) {
2660 yaffsfs_SetError(-EINVAL);
2666 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2667 obj = yaffsfs_FollowLink(obj, 0, &loop);
2670 yaffsfs_SetError(-ENOTDIR);
2672 yaffsfs_SetError(-ELOOP);
2673 else if (!dir || !obj)
2674 yaffsfs_SetError(-ENOENT);
2675 else if (obj->my_dev->read_only)
2676 yaffsfs_SetError(-EROFS);
2678 retVal = yaffsfs_DoChMod(obj, mode);
2686 int yaffs_chmod_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2688 return yaffs_chmod_reldir(ROOT_DIR(dev), path, mode);
2691 int yaffs_chmod(const YCHAR *path, mode_t mode)
2693 return yaffs_chmod_reldir(NULL, path, mode);
2696 int yaffs_fchmod(int fd, mode_t mode)
2698 struct yaffs_obj *obj;
2701 if (mode & ~(0777)) {
2702 yaffsfs_SetError(-EINVAL);
2707 obj = yaffsfs_HandleToObject(fd);
2710 yaffsfs_SetError(-EBADF);
2711 else if (obj->my_dev->read_only)
2712 yaffsfs_SetError(-EROFS);
2714 retVal = yaffsfs_DoChMod(obj, mode);
2721 int yaffs_mkdir_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2723 struct yaffs_obj *parent = NULL;
2724 struct yaffs_obj *dir = NULL;
2726 YCHAR *alt_path = NULL;
2731 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2732 yaffsfs_SetError(-EFAULT);
2736 if (yaffsfs_CheckPath(path) < 0) {
2737 yaffsfs_SetError(-ENAMETOOLONG);
2741 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2742 yaffsfs_SetError(-ENOMEM);
2749 parent = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
2750 if (!parent && notDir)
2751 yaffsfs_SetError(-ENOTDIR);
2753 yaffsfs_SetError(-ELOOP);
2755 yaffsfs_SetError(-ENOENT);
2756 else if (yaffsfs_TooManyObjects(parent->my_dev))
2757 yaffsfs_SetError(-ENFILE);
2758 else if (yaffs_strnlen(name, 5) == 0) {
2759 /* Trying to make the root itself */
2760 yaffsfs_SetError(-EEXIST);
2761 } else if (parent->my_dev->read_only)
2762 yaffsfs_SetError(-EROFS);
2764 dir = yaffs_create_dir(parent, name, mode, 0, 0);
2767 else if (yaffs_find_by_name(parent, name))
2768 yaffsfs_SetError(-EEXIST); /* name exists */
2770 yaffsfs_SetError(-ENOSPC); /* assume no space */
2780 int yaffs_mkdir_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2782 return yaffs_mkdir_reldir(ROOT_DIR(dev), path, mode);
2785 int yaffs_mkdir(const YCHAR *path, mode_t mode)
2787 return yaffs_mkdir_reldir(NULL, path, mode);
2790 int yaffs_rmdir_reldir(struct yaffs_obj *reldir, const YCHAR *path)
2795 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2796 yaffsfs_SetError(-EFAULT);
2800 if (yaffsfs_CheckPath(path) < 0) {
2801 yaffsfs_SetError(-ENAMETOOLONG);
2805 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2806 yaffsfs_SetError(-ENOMEM);
2811 result = yaffsfs_DoUnlink_reldir(reldir, path, 1);
2818 int yaffs_rmdir_reldev(struct yaffs_dev *dev, const YCHAR *path)
2820 return yaffs_rmdir_reldir(ROOT_DIR(dev), path);
2823 int yaffs_rmdir(const YCHAR *path)
2825 return yaffs_rmdir_reldir(NULL, path);
2829 * The mount/unmount/sync functions act on devices rather than reldirs.
2831 void *yaffs_getdev(const YCHAR *path)
2833 struct yaffs_dev *dev = NULL;
2835 dev = yaffsfs_FindDevice(path, &dummy);
2839 int yaffs_mount_common(struct yaffs_dev *dev, const YCHAR *path,
2840 int read_only, int skip_checkpt)
2843 int result = YAFFS_FAIL;
2846 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2847 yaffsfs_SetError(-EFAULT);
2851 yaffs_trace(YAFFS_TRACE_MOUNT, "yaffs: Mounting %s", path);
2853 if (yaffsfs_CheckPath(path) < 0) {
2854 yaffsfs_SetError(-ENAMETOOLONG);
2861 yaffsfs_InitHandles();
2864 dev = yaffsfs_FindMountPoint(path);
2867 if (!dev->is_mounted) {
2868 dev->read_only = read_only ? 1 : 0;
2870 u8 skip = dev->param.skip_checkpt_rd;
2871 dev->param.skip_checkpt_rd = 1;
2872 result = yaffs_guts_initialise(dev);
2873 dev->param.skip_checkpt_rd = skip;
2875 result = yaffs_guts_initialise(dev);
2878 if (result == YAFFS_FAIL)
2879 yaffsfs_SetError(-ENOMEM);
2880 retVal = result ? 0 : -1;
2883 yaffsfs_SetError(-EBUSY);
2885 yaffsfs_SetError(-ENODEV);
2892 int yaffs_mount3_reldev(struct yaffs_dev *dev, int read_only, int skip_checkpt)
2894 return yaffs_mount_common(dev, NULL, read_only, skip_checkpt);
2897 int yaffs_mount3(const YCHAR *path, int read_only, int skip_checkpt)
2899 return yaffs_mount_common(NULL, path, read_only, skip_checkpt);
2902 int yaffs_mount2_reldev(struct yaffs_dev *dev, int readonly)
2904 return yaffs_mount_common(dev, NULL, readonly, 0);
2907 int yaffs_mount2(const YCHAR *path, int readonly)
2909 return yaffs_mount_common(NULL, path, readonly, 0);
2912 int yaffs_mount_reldev(struct yaffs_dev *dev)
2914 return yaffs_mount_common(dev, NULL, 0, 0);
2917 int yaffs_mount(const YCHAR *path)
2919 return yaffs_mount_common(NULL, path, 0, 0);
2922 static int yaffs_sync_common(struct yaffs_dev *dev,
2930 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2931 yaffsfs_SetError(-EFAULT);
2935 if (yaffsfs_CheckPath(path) < 0) {
2936 yaffsfs_SetError(-ENAMETOOLONG);
2943 dev = yaffsfs_FindDevice(path, &dummy);
2946 if (!dev->is_mounted)
2947 yaffsfs_SetError(-EINVAL);
2948 else if (dev->read_only)
2949 yaffsfs_SetError(-EROFS);
2952 yaffs_flush_whole_cache(dev, 0);
2954 yaffs_checkpoint_save(dev);
2959 yaffsfs_SetError(-ENODEV);
2965 int yaffs_sync_files_reldev(struct yaffs_dev *dev)
2967 return yaffs_sync_common(dev, NULL, 0);
2970 int yaffs_sync_files(const YCHAR *path)
2972 return yaffs_sync_common(NULL, path, 0);
2975 int yaffs_sync_reldev(struct yaffs_dev *dev)
2977 return yaffs_sync_common(dev, NULL, 1);
2980 int yaffs_sync(const YCHAR *path)
2982 return yaffs_sync_common(NULL, path, 1);
2986 static int yaffsfs_bg_gc_common(struct yaffs_dev *dev,
2994 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2995 yaffsfs_SetError(-EFAULT);
2999 if (yaffsfs_CheckPath(path) < 0) {
3000 yaffsfs_SetError(-ENAMETOOLONG);
3007 dev = yaffsfs_FindDevice(path, &dummy);
3010 if (!dev->is_mounted)
3011 yaffsfs_SetError(-EINVAL);
3013 retVal = yaffs_bg_gc(dev, urgency);
3015 yaffsfs_SetError(-ENODEV);
3021 /* Background gc functions.
3022 * These return 0 when bg done or greater than 0 when gc has been
3023 * done and there is still a lot of garbage to be cleaned up.
3026 int yaffs_do_background_gc(const YCHAR *path, int urgency)
3028 return yaffsfs_bg_gc_common(NULL, path, urgency);
3031 int yaffs_do_background_gc_reldev(struct yaffs_dev *dev, int urgency)
3033 return yaffsfs_bg_gc_common(dev, NULL, urgency);
3036 static int yaffsfs_IsDevBusy(struct yaffs_dev *dev)
3039 struct yaffs_obj *obj;
3041 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
3042 obj = yaffsfs_HandleToObject(i);
3043 if (obj && obj->my_dev == dev)
3049 int yaffs_remount_common(struct yaffs_dev *dev, const YCHAR *path,
3050 int force, int read_only)
3054 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3055 yaffsfs_SetError(-EFAULT);
3059 if (yaffsfs_CheckPath(path) < 0) {
3060 yaffsfs_SetError(-ENAMETOOLONG);
3066 dev = yaffsfs_FindMountPoint(path);
3069 if (dev->is_mounted) {
3070 yaffs_flush_whole_cache(dev, 0);
3072 if (force || !yaffsfs_IsDevBusy(dev)) {
3074 yaffs_checkpoint_save(dev);
3075 dev->read_only = read_only ? 1 : 0;
3078 yaffsfs_SetError(-EBUSY);
3081 yaffsfs_SetError(-EINVAL);
3084 yaffsfs_SetError(-ENODEV);
3091 int yaffs_remount_reldev(struct yaffs_dev *dev, int force, int read_only)
3093 return yaffs_remount_common(dev, NULL, force, read_only);
3095 int yaffs_remount(const YCHAR *path, int force, int read_only)
3097 return yaffs_remount_common(NULL, path, force, read_only);
3100 int yaffs_unmount2_common(struct yaffs_dev *dev, const YCHAR *path, int force)
3104 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3105 yaffsfs_SetError(-EFAULT);
3109 if (yaffsfs_CheckPath(path) < 0) {
3110 yaffsfs_SetError(-ENAMETOOLONG);
3116 dev = yaffsfs_FindMountPoint(path);
3119 if (dev->is_mounted) {
3121 yaffs_flush_whole_cache(dev, 0);
3122 yaffs_checkpoint_save(dev);
3123 inUse = yaffsfs_IsDevBusy(dev);
3124 if (!inUse || force) {
3126 yaffsfs_BreakDeviceHandles(dev);
3127 yaffs_deinitialise(dev);
3131 yaffsfs_SetError(-EBUSY);
3134 yaffsfs_SetError(-EINVAL);
3137 yaffsfs_SetError(-ENODEV);
3144 int yaffs_unmount2_reldev(struct yaffs_dev *dev, int force)
3146 return yaffs_unmount2_common(dev, NULL, force);
3149 int yaffs_unmount2(const YCHAR *path, int force)
3151 return yaffs_unmount2_common(NULL, path, force);
3154 int yaffs_unmount_reldev(struct yaffs_dev *dev)
3156 return yaffs_unmount2_reldev(dev, 0);
3159 int yaffs_unmount(const YCHAR *path)
3161 return yaffs_unmount2(path, 0);
3164 int yaffs_format_common(struct yaffs_dev *dev,
3167 int force_unmount_flag,
3175 yaffsfs_SetError(-EFAULT);
3179 if (yaffsfs_CheckPath(path) < 0) {
3180 yaffsfs_SetError(-ENAMETOOLONG);
3187 dev = yaffsfs_FindMountPoint(path);
3190 int was_mounted = dev->is_mounted;
3192 if (dev->is_mounted && unmount_flag) {
3194 yaffs_flush_whole_cache(dev, 0);
3195 yaffs_checkpoint_save(dev);
3196 inUse = yaffsfs_IsDevBusy(dev);
3197 if (!inUse || force_unmount_flag) {
3199 yaffsfs_BreakDeviceHandles(dev);
3200 yaffs_deinitialise(dev);
3204 if(dev->is_mounted) {
3205 yaffsfs_SetError(-EBUSY);
3208 yaffs_guts_format_dev(dev);
3209 if(was_mounted && remount_flag) {
3210 result = yaffs_guts_initialise(dev);
3211 if (result == YAFFS_FAIL) {
3212 yaffsfs_SetError(-ENOMEM);
3218 yaffsfs_SetError(-ENODEV);
3227 int yaffs_format_reldev(struct yaffs_dev *dev,
3229 int force_unmount_flag,
3232 return yaffs_format_common(dev, NULL, unmount_flag,
3233 force_unmount_flag, remount_flag);
3236 int yaffs_format(const YCHAR *path,
3238 int force_unmount_flag,
3241 return yaffs_format_common(NULL, path, unmount_flag,
3242 force_unmount_flag, remount_flag);
3245 Y_LOFF_T yaffs_freespace_common(struct yaffs_dev *dev, const YCHAR *path)
3247 Y_LOFF_T retVal = -1;
3251 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3252 yaffsfs_SetError(-EFAULT);
3256 if (yaffsfs_CheckPath(path) < 0) {
3257 yaffsfs_SetError(-ENAMETOOLONG);
3264 dev = yaffsfs_FindDevice(path, &dummy);
3265 if (dev && dev->is_mounted) {
3266 retVal = yaffs_get_n_free_chunks(dev);
3267 retVal *= dev->data_bytes_per_chunk;
3270 yaffsfs_SetError(-EINVAL);
3276 Y_LOFF_T yaffs_freespace_reldev(struct yaffs_dev *dev)
3278 return yaffs_freespace_common(dev, NULL);
3281 Y_LOFF_T yaffs_freespace(const YCHAR *path)
3283 return yaffs_freespace_common(NULL, path);
3286 Y_LOFF_T yaffs_totalspace_common(struct yaffs_dev *dev, const YCHAR *path)
3288 Y_LOFF_T retVal = -1;
3292 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3293 yaffsfs_SetError(-EFAULT);
3297 if (yaffsfs_CheckPath(path) < 0) {
3298 yaffsfs_SetError(-ENAMETOOLONG);
3305 dev = yaffsfs_FindDevice(path, &dummy);
3306 if (dev && dev->is_mounted) {
3307 retVal = (dev->param.end_block - dev->param.start_block + 1) -
3308 dev->param.n_reserved_blocks;
3309 retVal *= dev->param.chunks_per_block;
3310 retVal *= dev->data_bytes_per_chunk;
3313 yaffsfs_SetError(-EINVAL);
3319 Y_LOFF_T yaffs_totalspace_reldev(struct yaffs_dev *dev)
3321 return yaffs_totalspace_common(dev, NULL);
3324 Y_LOFF_T yaffs_totalspace(const YCHAR *path)
3326 return yaffs_totalspace_common(NULL, path);
3329 int yaffs_inodecount_common(struct yaffs_dev *dev, const YCHAR *path)
3331 Y_LOFF_T retVal = -1;
3335 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3336 yaffsfs_SetError(-EFAULT);
3340 if (yaffsfs_CheckPath(path) < 0) {
3341 yaffsfs_SetError(-ENAMETOOLONG);
3348 dev = yaffsfs_FindDevice(path, &dummy);
3349 if (dev && dev->is_mounted) {
3350 int n_obj = dev->n_obj;
3351 if (n_obj > dev->n_hardlinks)
3352 retVal = n_obj - dev->n_hardlinks;
3356 yaffsfs_SetError(-EINVAL);
3362 int yaffs_inodecount_reldev(struct yaffs_dev *dev)
3364 return yaffs_inodecount_common(dev, NULL);
3367 int yaffs_inodecount(const YCHAR *path)
3369 return yaffs_inodecount_common(NULL, path);
3372 void yaffs_add_device(struct yaffs_dev *dev)
3374 struct list_head *cfg;
3375 /* First check that the device is not in the list. */
3377 list_for_each(cfg, &yaffsfs_deviceList) {
3378 if (dev == list_entry(cfg, struct yaffs_dev, dev_list))
3382 dev->is_mounted = 0;
3383 dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
3385 if (!dev->dev_list.next)
3386 INIT_LIST_HEAD(&dev->dev_list);
3388 list_add(&dev->dev_list, &yaffsfs_deviceList);
3393 void yaffs_remove_device(struct yaffs_dev *dev)
3395 list_del_init(&dev->dev_list);
3398 /* Functions to iterate through devices. NB Use with extreme care! */
3400 static struct list_head *dev_iterator;
3401 void yaffs_dev_rewind(void)
3403 dev_iterator = yaffsfs_deviceList.next;
3406 struct yaffs_dev *yaffs_next_dev(void)
3408 struct yaffs_dev *retval;
3412 if (dev_iterator == &yaffsfs_deviceList)
3415 retval = list_entry(dev_iterator, struct yaffs_dev, dev_list);
3416 dev_iterator = dev_iterator->next;
3420 /* Directory search stuff. */
3422 static struct list_head search_contexts;
3424 static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContext *dsc)
3428 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3432 if (list_empty(&dsc->dirObj->variant.dir_variant.children))
3433 dsc->nextReturn = NULL;
3436 list_entry(dsc->dirObj->variant.dir_variant.
3437 children.next, struct yaffs_obj,
3440 /* Hey someone isn't playing nice! */
3444 static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContext *dsc)
3448 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3450 if (dsc->nextReturn == NULL ||
3451 list_empty(&dsc->dirObj->variant.dir_variant.children))
3452 dsc->nextReturn = NULL;
3454 struct list_head *next = dsc->nextReturn->siblings.next;
3456 if (next == &dsc->dirObj->variant.dir_variant.children)
3457 dsc->nextReturn = NULL; /* end of list */
3459 dsc->nextReturn = list_entry(next,
3464 /* Hey someone isn't playing nice! */
3468 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj)
3471 struct list_head *i;
3472 struct yaffsfs_DirSearchContext *dsc;
3474 /* if search contexts not initilised then skip */
3475 if (!search_contexts.next)
3478 /* Iterate through the directory search contexts.
3479 * If any are the one being removed, then advance the dsc to
3480 * the next one to prevent a hanging ptr.
3482 list_for_each(i, &search_contexts) {
3484 dsc = list_entry(i, struct yaffsfs_DirSearchContext,
3486 if (dsc->nextReturn == obj)
3487 yaffsfs_DirAdvance(dsc);
3493 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(struct yaffs_obj *reldir,
3494 const YCHAR *dirname)
3496 yaffs_DIR *dir = NULL;
3497 struct yaffs_obj *obj = NULL;
3498 struct yaffsfs_DirSearchContext *dsc = NULL;
3502 if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) {
3503 yaffsfs_SetError(-EFAULT);
3507 if (yaffsfs_CheckPath(dirname) < 0) {
3508 yaffsfs_SetError(-ENAMETOOLONG);
3512 obj = yaffsfs_FindObject(reldir, dirname, 0, 1, NULL, ¬Dir, &loop);
3513 obj = yaffsfs_FollowLink(obj, 0, &loop);
3516 yaffsfs_SetError(-ENOTDIR);
3518 yaffsfs_SetError(-ELOOP);
3520 yaffsfs_SetError(-ENOENT);
3521 else if (obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
3522 yaffsfs_SetError(-ENOTDIR);
3526 for (i = 0, dsc = NULL; i < YAFFSFS_N_DSC && !dsc; i++) {
3527 if (!yaffsfs_dsc[i].inUse)
3528 dsc = &yaffsfs_dsc[i];
3531 dir = (yaffs_DIR *) dsc;
3534 memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContext));
3537 yaffs_strncpy(dsc->name, dirname, NAME_MAX);
3538 INIT_LIST_HEAD(&dsc->others);
3540 if (!search_contexts.next)
3541 INIT_LIST_HEAD(&search_contexts);
3543 list_add(&dsc->others, &search_contexts);
3544 yaffsfs_SetDirRewound(dsc);
3550 yaffs_DIR *yaffs_opendir_reldir(struct yaffs_obj *reldir, const YCHAR *dirname)
3555 ret = yaffsfs_opendir_reldir_no_lock(reldir, dirname);
3560 yaffs_DIR *yaffs_opendir_reldev(struct yaffs_dev *dev, const YCHAR *dirname)
3562 return yaffs_opendir_reldir(ROOT_DIR(dev), dirname);
3565 yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
3567 return yaffs_opendir_reldir(NULL, dirname);
3570 struct yaffs_dirent *yaffsfs_readdir_no_lock(yaffs_DIR * dirp)
3572 struct yaffsfs_DirSearchContext *dsc;
3573 struct yaffs_dirent *retVal = NULL;
3575 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3578 if (dsc && dsc->inUse) {
3579 yaffsfs_SetError(0);
3580 if (dsc->nextReturn) {
3582 yaffs_get_equivalent_obj(dsc->nextReturn)->obj_id;
3583 dsc->de.d_dont_use = 0;
3584 dsc->de.d_off = dsc->offset++;
3585 yaffs_get_obj_name(dsc->nextReturn,
3586 dsc->de.d_name, NAME_MAX);
3587 if (yaffs_strnlen(dsc->de.d_name, NAME_MAX + 1) == 0) {
3588 /* this should not happen! */
3589 yaffs_strcpy(dsc->de.d_name, _Y("zz"));
3591 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
3593 yaffsfs_DirAdvance(dsc);
3597 yaffsfs_SetError(-EBADF);
3602 struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp)
3604 struct yaffs_dirent *ret;
3607 ret = yaffsfs_readdir_no_lock(dirp);
3612 static void yaffsfs_rewinddir_no_lock(yaffs_DIR *dirp)
3614 struct yaffsfs_DirSearchContext *dsc;
3616 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3618 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
3621 yaffsfs_SetDirRewound(dsc);
3625 void yaffs_rewinddir(yaffs_DIR *dirp)
3628 yaffsfs_rewinddir_no_lock(dirp);
3632 struct yaffs_dirent *yaffs_readdir_fd(int fd)
3634 struct yaffs_dirent *ret = NULL;
3635 struct yaffsfs_FileDes *f;
3638 f = yaffsfs_HandleToFileDes(fd);
3639 if(f && f->isDir && f->v.dir)
3640 ret = yaffsfs_readdir_no_lock(f->v.dir);
3645 void yaffs_rewinddir_fd(int fd)
3647 struct yaffsfs_FileDes *f;
3650 f = yaffsfs_HandleToFileDes(fd);
3652 yaffsfs_rewinddir_no_lock(f->v.dir);
3657 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirp)
3659 struct yaffsfs_DirSearchContext *dsc;
3661 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3663 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) {
3664 yaffsfs_SetError(-EFAULT);
3669 list_del(&dsc->others); /* unhook from list */
3674 int yaffs_closedir(yaffs_DIR *dirp)
3679 ret = yaffsfs_closedir_no_lock(dirp);
3684 /* End of directory stuff */
3686 int yaffs_symlink_reldir(struct yaffs_obj *reldir,
3687 const YCHAR *oldpath, const YCHAR *newpath)
3689 struct yaffs_obj *parent = NULL;
3690 struct yaffs_obj *obj;
3693 int mode = 0; /* ignore for now */
3697 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3698 yaffsfs_CheckMemRegion(newpath, 0, 0) < 0) {
3699 yaffsfs_SetError(-EFAULT);
3703 if (yaffsfs_CheckPath(newpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3704 yaffsfs_SetError(-ENAMETOOLONG);
3709 parent = yaffsfs_FindDirectory(reldir, newpath, &name, 0, ¬Dir, &loop);
3710 if (!parent && notDir)
3711 yaffsfs_SetError(-ENOTDIR);
3713 yaffsfs_SetError(-ELOOP);
3714 else if (!parent || yaffs_strnlen(name, 5) < 1)
3715 yaffsfs_SetError(-ENOENT);
3716 else if (yaffsfs_TooManyObjects(parent->my_dev))
3717 yaffsfs_SetError(-ENFILE);
3718 else if (parent->my_dev->read_only)
3719 yaffsfs_SetError(-EROFS);
3721 obj = yaffs_create_symlink(parent, name, mode, 0, 0, oldpath);
3724 else if (yaffsfs_FindObject(reldir, newpath, 0, 0,
3726 yaffsfs_SetError(-EEXIST);
3728 yaffsfs_SetError(-ENOSPC);
3736 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
3738 return yaffs_symlink_reldir(NULL, oldpath, newpath);
3741 int yaffs_readlink_reldir(struct yaffs_obj *reldir,const YCHAR *path,
3742 YCHAR *buf, int bufsiz)
3744 struct yaffs_obj *obj = NULL;
3745 struct yaffs_obj *dir = NULL;
3750 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
3751 yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0) {
3752 yaffsfs_SetError(-EFAULT);
3758 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
3761 yaffsfs_SetError(-ENOTDIR);
3763 yaffsfs_SetError(-ELOOP);
3764 else if (!dir || !obj)
3765 yaffsfs_SetError(-ENOENT);
3766 else if (obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
3767 yaffsfs_SetError(-EINVAL);
3769 YCHAR *alias = obj->variant.symlink_variant.alias;
3770 memset(buf, 0, bufsiz);
3771 yaffs_strncpy(buf, alias, bufsiz - 1);
3777 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
3779 return yaffs_readlink_reldir(NULL, path, buf, bufsiz);
3782 int yaffs_link_reldir(struct yaffs_obj *reldir,
3783 const YCHAR *oldpath, const YCHAR *linkpath)
3785 /* Creates a link called newpath to existing oldpath */
3786 struct yaffs_obj *obj = NULL;
3787 struct yaffs_obj *lnk = NULL;
3788 struct yaffs_obj *obj_dir = NULL;
3789 struct yaffs_obj *lnk_dir = NULL;
3797 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3798 yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0) {
3799 yaffsfs_SetError(-EFAULT);
3803 if (yaffsfs_CheckPath(linkpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3804 yaffsfs_SetError(-ENAMETOOLONG);
3810 obj = yaffsfs_FindObject(reldir, oldpath, 0, 1,
3811 &obj_dir, ¬DirObj, &objLoop);
3812 lnk = yaffsfs_FindObject(reldir, linkpath, 0, 0, NULL, NULL, NULL);
3813 lnk_dir = yaffsfs_FindDirectory(reldir, linkpath, &newname,
3814 0, ¬DirLnk, &lnkLoop);
3816 if ((!obj_dir && notDirObj) || (!lnk_dir && notDirLnk))
3817 yaffsfs_SetError(-ENOTDIR);
3818 else if (objLoop || lnkLoop)
3819 yaffsfs_SetError(-ELOOP);
3820 else if (!obj_dir || !lnk_dir || !obj)
3821 yaffsfs_SetError(-ENOENT);
3822 else if (obj->my_dev->read_only)
3823 yaffsfs_SetError(-EROFS);
3824 else if (yaffsfs_TooManyObjects(obj->my_dev))
3825 yaffsfs_SetError(-ENFILE);
3827 yaffsfs_SetError(-EEXIST);
3828 else if (lnk_dir->my_dev != obj->my_dev)
3829 yaffsfs_SetError(-EXDEV);
3831 retVal = yaffsfs_CheckNameLength(newname);
3834 lnk = yaffs_link_obj(lnk_dir, newname, obj);
3838 yaffsfs_SetError(-ENOSPC);
3847 int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
3849 return yaffs_link_reldir(NULL, oldpath, linkpath);
3852 int yaffs_mknod_reldir(struct yaffs_obj *reldir, const YCHAR *pathname,
3853 mode_t mode, dev_t dev_val)
3860 yaffsfs_SetError(-EINVAL);
3864 int yaffs_mknod_reldev(struct yaffs_dev *dev, const YCHAR *pathname, mode_t mode, dev_t dev_val)
3866 return yaffs_mknod_reldir(ROOT_DIR(dev), pathname, mode, dev_val);
3869 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev_val)
3871 return yaffs_mknod_reldir(NULL, pathname, mode, dev_val);
3875 * D E B U G F U N C T I O N S
3880 * Returns number of handles attached to the object
3882 int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3884 struct yaffs_obj *obj;
3886 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3887 yaffsfs_SetError(-EFAULT);
3891 if (yaffsfs_CheckPath(path) < 0) {
3892 yaffsfs_SetError(-ENAMETOOLONG);
3896 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
3899 return yaffsfs_CountHandles(obj);
3904 int yaffs_n_handles(const YCHAR *path)
3906 return yaffs_n_handles_reldir(NULL, path);
3909 int yaffs_get_error(void)
3911 return yaffsfs_GetLastError();
3914 int yaffs_set_error(int error)
3916 yaffsfs_SetError(error);
3920 struct yaffs_obj * yaffs_get_obj_from_fd(int handle)
3922 return yaffsfs_HandleToObject(handle);
3925 int yaffs_dump_dev_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3935 reldir = yaffsfs_FindRoot(path, &rest);
3938 struct yaffs_dev *dev = reldir->my_dev;
3941 "n_page_writes.......... %d\n"
3942 "n_page_reads........... %d\n"
3943 "n_erasures....... %d\n"
3944 "n_gc_copies............ %d\n"
3945 "garbageCollections... %d\n"
3946 "passiveGarbageColl'ns %d\n"
3952 dev->garbageCollections, dev->passiveGarbageCollections);
3959 int yaffs_dump_dev(const YCHAR *path)
3961 return yaffs_dump_dev_reldir(NULL, path);