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 YAFFS_MAX_RW_SIZE 0x70000000
23 #define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5
26 #define NULL ((void *)0)
29 #define ROOT_DIR(dev) (((dev) && (dev)->is_mounted) ? (dev)->root_dir : NULL)
31 /* YAFFSFS_RW_SIZE must be a power of 2 */
32 #define YAFFSFS_RW_SHIFT (13)
33 #define YAFFSFS_RW_SIZE (1<<YAFFSFS_RW_SHIFT)
35 /* Some forward references */
36 static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relativeDirectory,
38 int symDepth, int getEquiv,
39 struct yaffs_obj **dirOut,
40 int *notDir, int *loop);
42 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj);
43 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(
44 struct yaffs_obj *reldir, const YCHAR *dirname);
45 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirent);
47 unsigned int yaffs_wr_attempts;
51 * There are open inodes in struct yaffsfs_Inode.
52 * There are open file descriptors in yaffsfs_FileDes.
53 * There are open handles in yaffsfs_FileDes.
55 * Things are structured this way to be like the Linux VFS model
56 * so that interactions with the yaffs guts calls are similar.
57 * That means more common code paths and less special code.
58 * That means better testing etc.
60 * We have 3 layers because:
61 * A handle is different than an fd because you can use dup()
62 * to create a new handle that accesses the *same* fd. The two
63 * handles will use the same offset (part of the fd). We only close
64 * down the fd when there are no more handles accessing it.
66 * More than one fd can currently access one file, but each fd
67 * has its own permsiions and offset.
70 struct yaffsfs_Inode {
71 int count; /* Number of handles accessing this inode */
72 struct yaffs_obj *iObj;
76 struct yaffsfs_DirSearchContext {
77 struct yaffs_dirent de; /* directory entry */
78 YCHAR name[NAME_MAX + 1]; /* name of directory being searched */
79 struct yaffs_obj *dirObj; /* ptr to directory being searched */
80 struct yaffs_obj *nextReturn; /* obj returned by next readddir */
81 struct list_head others;
86 struct yaffsfs_FileDes {
87 u8 isDir:1; /* This s a directory */
93 s32 inodeId:12; /* Index to corresponding yaffsfs_Inode */
94 s32 handleCount:10; /* Number of handles for this fd */
96 Y_LOFF_T position; /* current position in file */
101 struct yaffsfs_Handle {
107 static struct yaffsfs_DirSearchContext yaffsfs_dsc[YAFFSFS_N_DSC];
108 static struct yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES];
109 static struct yaffsfs_FileDes yaffsfs_fd[YAFFSFS_N_HANDLES];
110 static struct yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
112 static int yaffsfs_handlesInitialised;
114 unsigned yaffs_set_trace(unsigned tm)
116 yaffs_trace_mask = tm;
117 return yaffs_trace_mask;
120 unsigned yaffs_get_trace(void)
122 return yaffs_trace_mask;
127 * Inilitalise handle management on start-up.
130 static void yaffsfs_InitHandles(void)
134 if (yaffsfs_handlesInitialised)
137 yaffsfs_handlesInitialised = 1;
139 memset(yaffsfs_inode, 0, sizeof(yaffsfs_inode));
140 memset(yaffsfs_fd, 0, sizeof(yaffsfs_fd));
141 memset(yaffsfs_handle, 0, sizeof(yaffsfs_handle));
142 memset(yaffsfs_dsc, 0, sizeof(yaffsfs_dsc));
144 for (i = 0; i < YAFFSFS_N_HANDLES; i++)
145 yaffsfs_fd[i].inodeId = -1;
146 for (i = 0; i < YAFFSFS_N_HANDLES; i++)
147 yaffsfs_handle[i].fdId = -1;
150 static struct yaffsfs_Handle *yaffsfs_HandleToPointer(int h)
152 if (h >= 0 && h < YAFFSFS_N_HANDLES)
153 return &yaffsfs_handle[h];
157 static struct yaffsfs_FileDes *yaffsfs_HandleToFileDes(int handle)
159 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
161 if (h && h->useCount > 0 && h->fdId >= 0 && h->fdId < YAFFSFS_N_HANDLES)
162 return &yaffsfs_fd[h->fdId];
167 static struct yaffsfs_Inode *yaffsfs_HandleToInode(int handle)
169 struct yaffsfs_FileDes *fd = yaffsfs_HandleToFileDes(handle);
171 if (fd && fd->handleCount > 0 &&
172 fd->inodeId >= 0 && fd->inodeId < YAFFSFS_N_HANDLES)
173 return &yaffsfs_inode[fd->inodeId];
178 static struct yaffs_obj *yaffsfs_HandleToObject(int handle)
180 struct yaffsfs_Inode *in = yaffsfs_HandleToInode(handle);
189 * yaffsfs_FindInodeIdForObject
190 * Find the inode entry for an object, if it exists.
193 static int yaffsfs_FindInodeIdForObject(struct yaffs_obj *obj)
199 obj = yaffs_get_equivalent_obj(obj);
201 /* Look for it in open inode table */
202 for (i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++) {
203 if (yaffsfs_inode[i].iObj == obj)
210 * yaffsfs_GetInodeIdForObject
211 * Grab an inode entry when opening a new inode.
213 static int yaffsfs_GetInodeIdForObject(struct yaffs_obj *obj)
217 struct yaffsfs_Inode *in = NULL;
220 obj = yaffs_get_equivalent_obj(obj);
222 ret = yaffsfs_FindInodeIdForObject(obj);
224 for (i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++) {
225 if (!yaffsfs_inode[i].iObj)
230 in = &yaffsfs_inode[ret];
240 static int yaffsfs_CountHandles(struct yaffs_obj *obj)
242 int i = yaffsfs_FindInodeIdForObject(obj);
245 return yaffsfs_inode[i].count;
250 static void yaffsfs_ReleaseInode(struct yaffsfs_Inode *in)
252 struct yaffs_obj *obj;
255 obj->my_inode = NULL;
262 static void yaffsfs_PutInode(int inodeId)
264 if (inodeId >= 0 && inodeId < YAFFSFS_N_HANDLES) {
265 struct yaffsfs_Inode *in = &yaffsfs_inode[inodeId];
267 if (in->count <= 0) {
268 yaffsfs_ReleaseInode(in);
274 static int yaffsfs_NewHandle(struct yaffsfs_Handle **hptr)
277 struct yaffsfs_Handle *h;
279 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
280 h = &yaffsfs_handle[i];
281 if (h->useCount < 1) {
282 memset(h, 0, sizeof(struct yaffsfs_Handle));
293 static int yaffsfs_NewHandleAndFileDes(void)
296 struct yaffsfs_FileDes *fd;
297 struct yaffsfs_Handle *h = NULL;
298 int handle = yaffsfs_NewHandle(&h);
303 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
305 if (fd->handleCount < 1) {
306 memset(fd, 0, sizeof(struct yaffsfs_FileDes));
314 /* Dump the handle because we could not get a fd */
321 * Increase use of handle when reading/writing a file
322 * Also gets the file descriptor.
325 static int yaffsfs_GetHandle(int handle)
327 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
329 if (h && h->useCount > 0) {
338 * Let go of a handle when closing a file or aborting an open or
339 * ending a read or write.
342 static int yaffsfs_PutFileDes(int fdId)
344 struct yaffsfs_FileDes *fd;
346 if (fdId >= 0 && fdId < YAFFSFS_N_HANDLES) {
347 fd = &yaffsfs_fd[fdId];
349 if (fd->handleCount < 1) {
351 yaffsfs_closedir_no_lock(fd->v.dir);
354 if (fd->inodeId >= 0) {
355 yaffsfs_PutInode(fd->inodeId);
363 static int yaffsfs_PutHandle(int handle)
365 struct yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
367 if (h && h->useCount > 0) {
369 if (h->useCount < 1) {
370 yaffsfs_PutFileDes(h->fdId);
378 static void yaffsfs_BreakDeviceHandles(struct yaffs_dev *dev)
380 struct yaffsfs_FileDes *fd;
381 struct yaffsfs_Handle *h;
382 struct yaffs_obj *obj;
384 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
385 h = yaffsfs_HandleToPointer(i);
386 fd = yaffsfs_HandleToFileDes(i);
387 obj = yaffsfs_HandleToObject(i);
388 if (h && h->useCount > 0) {
392 if (fd && fd->handleCount > 0 && obj && obj->my_dev == dev) {
394 yaffsfs_PutInode(fd->inodeId);
401 * Stuff to handle names.
403 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
404 #ifndef CONFIG_YAFFS_WINCE
405 static int yaffs_toupper(YCHAR a)
407 if (a >= 'a' && a <= 'z')
408 return (a - 'a') + 'A';
414 static int yaffsfs_Match(YCHAR a, YCHAR b)
416 return (yaffs_toupper(a) == yaffs_toupper(b));
419 static int yaffsfs_Match(YCHAR a, YCHAR b)
426 static int yaffsfs_IsPathDivider(YCHAR ch)
428 const YCHAR *str = YAFFS_PATH_DIVIDERS;
439 static int yaffsfs_CheckNameLength(const YCHAR *name)
443 int nameLength = yaffs_strnlen(name, YAFFS_MAX_NAME_LENGTH + 1);
445 if (nameLength == 0) {
446 yaffsfs_SetError(-ENOENT);
448 } else if (nameLength > YAFFS_MAX_NAME_LENGTH) {
449 yaffsfs_SetError(-ENAMETOOLONG);
456 static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
458 YCHAR *alt_path = NULL;
463 * We don't have a definition for max path length.
464 * We will use 3 * max name length instead.
467 path_length = yaffs_strnlen(path, (YAFFS_MAX_NAME_LENGTH + 1) * 3 + 1);
469 /* If the last character is a path divider, then we need to
470 * trim it back so that the name look-up works properly.
471 * eg. /foo/new_dir/ -> /foo/newdir
472 * Curveball: Need to handle multiple path dividers:
473 * eg. /foof/sdfse///// -> /foo/sdfse
475 if (path_length > 0 && yaffsfs_IsPathDivider(path[path_length - 1])) {
476 alt_path = kmalloc(path_length + 1, 0);
479 yaffs_strcpy(alt_path, path);
480 for (i = path_length - 1;
481 i >= 0 && yaffsfs_IsPathDivider(alt_path[i]); i--)
482 alt_path[i] = (YCHAR) 0;
484 *ret_path = alt_path;
488 LIST_HEAD(yaffsfs_deviceList);
493 * Scan the configuration list to find the device
494 * Curveballs: Should match paths that end in '/' too
495 * Curveball2 Might have "/x/ and "/x/y". Need to return the longest match
497 static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path,
500 struct list_head *cfg;
501 const YCHAR *leftOver;
503 struct yaffs_dev *retval = NULL;
504 struct yaffs_dev *dev = NULL;
506 int longestMatch = -1;
510 * Check all configs, choose the one that:
511 * 1) Actually matches a prefix (ie /a amd /abc will not match
512 * 2) Matches the longest.
514 list_for_each(cfg, &yaffsfs_deviceList) {
515 dev = list_entry(cfg, struct yaffs_dev, dev_list);
525 /* Skip over any leading /s */
526 while (yaffsfs_IsPathDivider(*p))
528 while (yaffsfs_IsPathDivider(*leftOver))
531 while (matching && *p && *leftOver) {
533 /* Now match the text part */
535 *p && !yaffsfs_IsPathDivider(*p) &&
536 *leftOver && !yaffsfs_IsPathDivider(*leftOver)) {
537 if (yaffsfs_Match(*p, *leftOver)) {
546 if ((*p && !yaffsfs_IsPathDivider(*p)) ||
547 (*leftOver && !yaffsfs_IsPathDivider(*leftOver)))
550 while (yaffsfs_IsPathDivider(*p))
552 while (yaffsfs_IsPathDivider(*leftOver))
557 /* Skip over any /s in leftOver */
558 while (yaffsfs_IsPathDivider(*leftOver))
561 /*Skip over any /s in p */
562 while (yaffsfs_IsPathDivider(*p))
565 /* p should now be at the end of the string if fully matched */
569 if (matching && (thisMatchLength > longestMatch)) {
571 *restOfPath = (YCHAR *) leftOver;
573 longestMatch = thisMatchLength;
579 static int yaffsfs_CheckPath(const YCHAR *path)
584 while (*path && n < YAFFS_MAX_NAME_LENGTH && divs < 100) {
585 if (yaffsfs_IsPathDivider(*path)) {
593 return (*path) ? -1 : 0;
596 /* FindMountPoint only returns a dev entry if the path is a mount point */
597 static struct yaffs_dev *yaffsfs_FindMountPoint(const YCHAR *path)
599 struct yaffs_dev *dev;
600 YCHAR *restOfPath = NULL;
602 dev = yaffsfs_FindDevice(path, &restOfPath);
603 if (dev && restOfPath && *restOfPath)
608 static struct yaffs_obj *yaffsfs_FindRoot(const YCHAR *path,
611 struct yaffs_dev *dev;
613 dev = yaffsfs_FindDevice(path, restOfPath);
614 if (dev && dev->is_mounted)
615 return dev->root_dir;
620 static struct yaffs_obj *yaffsfs_FollowLink(struct yaffs_obj *obj,
621 int symDepth, int *loop)
625 obj = yaffs_get_equivalent_obj(obj);
627 while (obj && obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
628 YCHAR *alias = obj->variant.symlink_variant.alias;
630 if (yaffsfs_IsPathDivider(*alias))
632 * Starts with a /, need to scan from root up */
633 /* NB Might not work if this is called with root != NULL
635 obj = yaffsfs_FindObject(NULL, alias, symDepth++,
636 1, NULL, NULL, loop);
639 * Relative to here so use the parent of the
642 obj = yaffsfs_FindObject(obj->parent, alias, symDepth++,
643 1, NULL, NULL, loop);
649 * yaffsfs_FindDirectory
650 * Parse a path to determine the directory and the name within the directory.
652 * eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
654 static struct yaffs_obj *yaffsfs_DoFindDirectory(struct yaffs_obj *startDir,
656 YCHAR **name, int symDepth,
657 int *notDir, int *loop)
659 struct yaffs_obj *dir;
661 YCHAR str[YAFFS_MAX_NAME_LENGTH + 1];
664 if (symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES) {
672 restOfPath = (YCHAR *) path;
674 dir = yaffsfs_FindRoot(path, &restOfPath);
679 * curve ball: also throw away surplus '/'
680 * eg. "/ram/x////ff" gets treated the same as "/ram/x/ff"
682 while (yaffsfs_IsPathDivider(*restOfPath))
683 restOfPath++; /* get rid of '/' */
688 while (*restOfPath && !yaffsfs_IsPathDivider(*restOfPath)) {
689 if (i < YAFFS_MAX_NAME_LENGTH) {
690 str[i] = *restOfPath;
698 /* got to the end of the string */
701 if (yaffs_strcmp(str, _Y(".")) == 0) {
703 } else if (yaffs_strcmp(str, _Y("..")) == 0) {
706 dir = yaffs_find_by_name(dir, str);
708 dir = yaffsfs_FollowLink(dir, symDepth, loop);
710 if (dir && dir->variant_type !=
711 YAFFS_OBJECT_TYPE_DIRECTORY) {
720 /* directory did not exist. */
724 static struct yaffs_obj *yaffsfs_FindDirectory(struct yaffs_obj *relDir,
728 int *notDir, int *loop)
730 return yaffsfs_DoFindDirectory(relDir, path, name, symDepth, notDir,
735 * yaffsfs_FindObject turns a path for an existing object into the object
737 static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relDir,
738 const YCHAR *path, int symDepth,
740 struct yaffs_obj **dirOut,
741 int *notDir, int *loop)
743 struct yaffs_obj *dir;
744 struct yaffs_obj *obj;
748 yaffsfs_FindDirectory(relDir, path, &name, symDepth, notDir, loop);
753 /* At this stage we have looked up directory part and have the name part
754 * in name if there is one.
756 * eg /nand/x/ will give us a name of ""
757 * /nand/x will give us a name of "x"
759 * Since the name part might be "." or ".." which need to be fixed.
761 if (dir && (yaffs_strcmp(name, _Y("..")) == 0)) {
764 } else if (dir && (yaffs_strcmp(name, _Y(".")) == 0))
766 else if (dir && *name)
767 obj = yaffs_find_by_name(dir, name);
772 obj = yaffs_get_equivalent_obj(obj);
777 /*************************************************************************
778 * Start of yaffsfs visible functions.
779 *************************************************************************/
781 int yaffs_dup(int handle)
783 int newHandleNumber = -1;
784 struct yaffsfs_FileDes *existingFD = NULL;
785 struct yaffsfs_Handle *existingHandle = NULL;
786 struct yaffsfs_Handle *newHandle = NULL;
789 existingHandle = yaffsfs_HandleToPointer(handle);
790 existingFD = yaffsfs_HandleToFileDes(handle);
792 newHandleNumber = yaffsfs_NewHandle(&newHandle);
794 newHandle->fdId = existingHandle->fdId;
795 existingFD->handleCount++;
801 yaffsfs_SetError(-EBADF);
803 yaffsfs_SetError(-ENOMEM);
805 return newHandleNumber;
809 static int yaffsfs_TooManyObjects(struct yaffs_dev *dev)
811 int current_objects = dev->n_obj - dev->n_deleted_files;
813 if (dev->param.max_objects && current_objects > dev->param.max_objects)
819 int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
820 int oflag, int mode, int sharing)
822 struct yaffs_obj *obj = NULL;
823 struct yaffs_obj *dir = NULL;
826 struct yaffsfs_FileDes *fd = NULL;
829 int errorReported = 0;
830 int rwflags = oflag & (O_RDWR | O_RDONLY | O_WRONLY);
831 u8 shareRead = (sharing & YAFFS_SHARE_READ) ? 1 : 0;
832 u8 shareWrite = (sharing & YAFFS_SHARE_WRITE) ? 1 : 0;
833 u8 sharedReadAllowed;
834 u8 sharedWriteAllowed;
842 yaffs_DIR *dsc = NULL;
844 if (yaffsfs_CheckMemRegion(path, 0, 0)< 0) {
845 yaffsfs_SetError(-EFAULT);
849 if (yaffsfs_CheckPath(path) < 0) {
850 yaffsfs_SetError(-ENAMETOOLONG);
854 /* O_EXCL only has meaning if O_CREAT is specified */
855 if (!(oflag & O_CREAT))
858 /* O_TRUNC has no meaning if (O_CREAT | O_EXCL) is specified */
859 if ((oflag & O_CREAT) && (oflag & O_EXCL))
862 /* Todo: Are there any more flag combos to sanitise ? */
864 /* Figure out if reading or writing is requested */
866 readRequested = (rwflags == O_RDWR || rwflags == O_RDONLY) ? 1 : 0;
867 writeRequested = (rwflags == O_RDWR || rwflags == O_WRONLY) ? 1 : 0;
871 handle = yaffsfs_NewHandleAndFileDes();
874 yaffsfs_SetError(-ENFILE);
875 errorReported = __LINE__;
878 fd = yaffsfs_HandleToFileDes(handle);
880 /* try to find the exisiting object */
881 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
883 obj = yaffsfs_FollowLink(obj, symDepth++, &loop);
886 obj->variant_type != YAFFS_OBJECT_TYPE_FILE &&
887 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
892 /* The file already exists or it might be a directory */
893 is_dir = (obj->variant_type ==
894 YAFFS_OBJECT_TYPE_DIRECTORY);
897 * A directory can't be opened except for read, so we
907 dsc = yaffsfs_opendir_reldir_no_lock(reldir, path);
909 openDenied = __LINE__;
910 yaffsfs_SetError(-ENFILE);
911 errorReported = __LINE__;
915 /* Open should fail if O_CREAT and O_EXCL are specified
916 * for a file that exists.
918 if (!errorReported &&
919 (oflag & O_EXCL) && (oflag & O_CREAT)) {
920 openDenied = __LINE__;
921 yaffsfs_SetError(-EEXIST);
922 errorReported = __LINE__;
925 /* Check file permissions */
926 if (readRequested && !(obj->yst_mode & S_IRUSR))
927 openDenied = __LINE__;
929 if (writeRequested && !(obj->yst_mode & S_IWUSR))
930 openDenied = __LINE__;
932 if (!errorReported && writeRequested &&
933 obj->my_dev->read_only) {
934 openDenied = __LINE__;
935 yaffsfs_SetError(-EROFS);
936 errorReported = __LINE__;
939 if (openDenied && !errorReported) {
940 yaffsfs_SetError(-EACCES);
941 errorReported = __LINE__;
944 /* Check sharing of an existing object. */
946 struct yaffsfs_FileDes *fdx;
949 sharedReadAllowed = 1;
950 sharedWriteAllowed = 1;
953 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
954 fdx = &yaffsfs_fd[i];
955 if (fdx->handleCount > 0 &&
957 yaffsfs_inode[fdx->inodeId].iObj
960 sharedReadAllowed = 0;
961 if (!fdx->shareWrite)
962 sharedWriteAllowed = 0;
970 if ((!sharedReadAllowed && readRequested) ||
971 (!shareRead && alreadyReading) ||
972 (!sharedWriteAllowed && writeRequested) ||
973 (!shareWrite && alreadyWriting)) {
974 openDenied = __LINE__;
975 yaffsfs_SetError(-EBUSY);
976 errorReported = __LINE__;
982 /* If we could not open an existing object, then let's see if
983 * the directory exists. If not, error.
985 if (!obj && !errorReported) {
986 dir = yaffsfs_FindDirectory(reldir, path, &name, 0,
988 if (!dir && notDir) {
989 yaffsfs_SetError(-ENOTDIR);
990 errorReported = __LINE__;
992 yaffsfs_SetError(-ELOOP);
993 errorReported = __LINE__;
995 yaffsfs_SetError(-ENOENT);
996 errorReported = __LINE__;
1000 if (!obj && dir && !errorReported && (oflag & O_CREAT)) {
1001 /* Let's see if we can create this file */
1002 if (dir->my_dev->read_only) {
1003 yaffsfs_SetError(-EROFS);
1004 errorReported = __LINE__;
1005 } else if (yaffsfs_TooManyObjects(dir->my_dev)) {
1006 yaffsfs_SetError(-ENFILE);
1007 errorReported = __LINE__;
1009 obj = yaffs_create_file(dir, name, mode, 0, 0);
1011 if (!obj && !errorReported) {
1012 yaffsfs_SetError(-ENOSPC);
1013 errorReported = __LINE__;
1017 if (!obj && dir && !errorReported && !(oflag & O_CREAT)) {
1018 yaffsfs_SetError(-ENOENT);
1019 errorReported = __LINE__;
1022 if (obj && !openDenied) {
1023 int inodeId = yaffsfs_GetInodeIdForObject(obj);
1027 * Todo: Fix any problem if inodes run out,
1028 * That can't happen if the number of inode
1029 * items >= number of handles.
1033 fd->inodeId = inodeId;
1034 fd->reading = readRequested;
1035 fd->writing = writeRequested;
1036 fd->append = (oflag & O_APPEND) ? 1 : 0;
1037 fd->shareRead = shareRead;
1038 fd->shareWrite = shareWrite;
1046 /* Hook inode to object */
1047 obj->my_inode = (void *)&yaffsfs_inode[inodeId];
1049 if (!is_dir && (oflag & O_TRUNC) && fd->writing)
1050 yaffs_resize_file(obj, 0);
1053 yaffsfs_closedir_no_lock(dsc);
1055 yaffsfs_PutHandle(handle);
1057 yaffsfs_SetError(0); /* Problem */
1067 int yaffs_open_sharing_reldev(struct yaffs_dev *dev, const YCHAR *path, int oflag,
1068 int mode, int sharing)
1070 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path,
1071 oflag, mode, sharing);
1074 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
1076 return yaffs_open_sharing_reldir(NULL, path, oflag, mode, sharing);
1079 int yaffs_open_reldir(struct yaffs_obj *reldir,const YCHAR *path, int oflag, int mode)
1081 return yaffs_open_sharing_reldir(reldir, path, oflag, mode,
1082 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1085 int yaffs_open_reldev(struct yaffs_dev *dev,const YCHAR *path, int oflag, int mode)
1087 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path, oflag, mode,
1088 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1091 int yaffs_open(const YCHAR *path, int oflag, int mode)
1093 return yaffs_open_reldir(NULL, path, oflag, mode);
1096 static int yaffs_Dofsync(int handle, int datasync)
1099 struct yaffs_obj *obj;
1103 obj = yaffsfs_HandleToObject(handle);
1106 yaffsfs_SetError(-EBADF);
1107 else if (obj->my_dev->read_only)
1108 yaffsfs_SetError(-EROFS);
1110 yaffs_flush_file(obj, 1, datasync, 0);
1119 int yaffs_fsync(int handle)
1121 return yaffs_Dofsync(handle, 0);
1124 int yaffs_flush(int handle)
1126 return yaffs_fsync(handle);
1129 int yaffs_fdatasync(int handle)
1131 return yaffs_Dofsync(handle, 1);
1134 int yaffs_close(int handle)
1136 struct yaffsfs_Handle *h = NULL;
1137 struct yaffsfs_FileDes *f;
1138 struct yaffs_obj *obj = NULL;
1143 h = yaffsfs_HandleToPointer(handle);
1144 f = yaffsfs_HandleToFileDes(handle);
1145 obj = yaffsfs_HandleToObject(handle);
1147 if (!h || !obj || !f)
1148 yaffsfs_SetError(-EBADF);
1152 yaffs_flush_file(obj, 1, 0, 1);
1153 yaffsfs_PutHandle(handle);
1162 static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
1163 int isPread, Y_LOFF_T offset)
1165 struct yaffsfs_FileDes *fd = NULL;
1166 struct yaffs_obj *obj = NULL;
1168 Y_LOFF_T startPos = 0;
1169 Y_LOFF_T endPos = 0;
1174 u8 *buf = (u8 *) vbuf;
1176 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) {
1177 yaffsfs_SetError(-EFAULT);
1182 fd = yaffsfs_HandleToFileDes(handle);
1183 obj = yaffsfs_HandleToObject(handle);
1187 yaffsfs_SetError(-EBADF);
1189 } else if (!fd->reading) {
1190 /* Not a reading handle */
1191 yaffsfs_SetError(-EINVAL);
1193 } else if (nbyte > YAFFS_MAX_RW_SIZE) {
1194 yaffsfs_SetError(-EINVAL);
1200 startPos = fd->v.position;
1204 if (yaffs_get_obj_length(obj) > pos)
1205 maxRead = yaffs_get_obj_length(obj) - pos;
1209 if (nbyte > maxRead)
1212 yaffsfs_GetHandle(handle);
1214 endPos = pos + nbyte;
1216 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1217 nbyte > YAFFS_MAX_RW_SIZE ||
1218 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1224 nToRead = YAFFSFS_RW_SIZE -
1225 (pos & (YAFFSFS_RW_SIZE - 1));
1226 if (nToRead > (int)nbyte)
1230 * Need to reverify object in case the device was
1231 * unmounted in another thread.
1233 obj = yaffsfs_HandleToObject(handle);
1237 nRead = yaffs_file_rd(obj, buf, pos, nToRead);
1245 if (nRead == nToRead)
1248 nbyte = 0; /* no more to read */
1257 yaffsfs_PutHandle(handle);
1261 fd->v.position = startPos + totalRead;
1263 yaffsfs_SetError(-EINVAL);
1270 return (totalRead >= 0) ? totalRead : -1;
1274 int yaffs_read(int handle, void *buf, unsigned int nbyte)
1276 return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
1279 int yaffs_pread(int handle, void *buf, unsigned int nbyte, Y_LOFF_T offset)
1281 return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
1284 static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
1285 int isPwrite, Y_LOFF_T offset)
1287 struct yaffsfs_FileDes *fd = NULL;
1288 struct yaffs_obj *obj = NULL;
1290 Y_LOFF_T startPos = 0;
1293 int totalWritten = 0;
1294 int write_trhrough = 0;
1296 const u8 *buf = (const u8 *)vbuf;
1298 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) {
1299 yaffsfs_SetError(-EFAULT);
1304 fd = yaffsfs_HandleToFileDes(handle);
1305 obj = yaffsfs_HandleToObject(handle);
1309 yaffsfs_SetError(-EBADF);
1311 } else if (!fd->writing) {
1312 yaffsfs_SetError(-EINVAL);
1314 } else if (obj->my_dev->read_only) {
1315 yaffsfs_SetError(-EROFS);
1319 startPos = yaffs_get_obj_length(obj);
1323 startPos = fd->v.position;
1325 yaffsfs_GetHandle(handle);
1327 endPos = pos + nbyte;
1329 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1330 nbyte > YAFFS_MAX_RW_SIZE ||
1331 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1338 nToWrite = YAFFSFS_RW_SIZE -
1339 (pos & (YAFFSFS_RW_SIZE - 1));
1340 if (nToWrite > (int)nbyte)
1344 * Need to reverify object in case the device was
1345 * remounted or unmounted in another thread.
1347 obj = yaffsfs_HandleToObject(handle);
1348 if (!obj || obj->my_dev->read_only)
1352 yaffs_wr_file(obj, buf, pos, nToWrite,
1355 totalWritten += nWritten;
1360 if (nWritten == nToWrite)
1365 if (nWritten < 1 && totalWritten < 1) {
1366 yaffsfs_SetError(-ENOSPC);
1376 yaffsfs_PutHandle(handle);
1379 if (totalWritten > 0)
1380 fd->v.position = startPos + totalWritten;
1382 yaffsfs_SetError(-EINVAL);
1388 return (totalWritten >= 0) ? totalWritten : -1;
1391 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
1393 return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
1396 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset)
1398 return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
1401 int yaffs_truncate_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1404 struct yaffs_obj *obj = NULL;
1405 struct yaffs_obj *dir = NULL;
1406 int result = YAFFS_FAIL;
1410 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1411 yaffsfs_SetError(-EFAULT);
1415 if (yaffsfs_CheckPath(path) < 0) {
1416 yaffsfs_SetError(-ENAMETOOLONG);
1422 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1423 obj = yaffsfs_FollowLink(obj, 0, &loop);
1426 yaffsfs_SetError(-ENOTDIR);
1428 yaffsfs_SetError(-ELOOP);
1429 else if (!dir || !obj)
1430 yaffsfs_SetError(-ENOENT);
1431 else if (obj->my_dev->read_only)
1432 yaffsfs_SetError(-EROFS);
1433 else if (obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
1434 yaffsfs_SetError(-EISDIR);
1435 else if (obj->my_dev->read_only)
1436 yaffsfs_SetError(-EROFS);
1437 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1438 yaffsfs_SetError(-EINVAL);
1440 result = yaffs_resize_file(obj, new_size);
1444 return (result) ? 0 : -1;
1447 int yaffs_truncate_reldev(struct yaffs_dev *dev, const YCHAR *path,
1450 return yaffs_truncate_reldir(ROOT_DIR(dev), path, new_size);
1453 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size)
1455 return yaffs_truncate_reldir(NULL, path, new_size);
1458 int yaffs_ftruncate(int handle, Y_LOFF_T new_size)
1460 struct yaffsfs_FileDes *fd = NULL;
1461 struct yaffs_obj *obj = NULL;
1465 fd = yaffsfs_HandleToFileDes(handle);
1466 obj = yaffsfs_HandleToObject(handle);
1470 yaffsfs_SetError(-EBADF);
1471 else if (!fd->writing)
1472 yaffsfs_SetError(-EINVAL);
1473 else if (obj->my_dev->read_only)
1474 yaffsfs_SetError(-EROFS);
1475 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1476 yaffsfs_SetError(-EINVAL);
1478 /* resize the file */
1479 result = yaffs_resize_file(obj, new_size);
1482 return (result) ? 0 : -1;
1486 Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence)
1488 struct yaffsfs_FileDes *fd = NULL;
1489 struct yaffs_obj *obj = NULL;
1491 Y_LOFF_T fSize = -1;
1494 fd = yaffsfs_HandleToFileDes(handle);
1495 obj = yaffsfs_HandleToObject(handle);
1498 yaffsfs_SetError(-EBADF);
1499 else if (offset > YAFFS_MAX_FILE_SIZE)
1500 yaffsfs_SetError(-EINVAL);
1502 if (whence == SEEK_SET) {
1505 } else if (whence == SEEK_CUR) {
1506 if ((fd->v.position + offset) >= 0)
1507 pos = (fd->v.position + offset);
1508 } else if (whence == SEEK_END) {
1509 fSize = yaffs_get_obj_length(obj);
1510 if (fSize >= 0 && (fSize + offset) >= 0)
1511 pos = fSize + offset;
1514 if (pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE)
1515 fd->v.position = pos;
1517 yaffsfs_SetError(-EINVAL);
1527 static int yaffsfs_DoUnlink_reldir(struct yaffs_obj *reldir,
1528 const YCHAR *path, int isDirectory)
1530 struct yaffs_obj *dir = NULL;
1531 struct yaffs_obj *obj = NULL;
1533 int result = YAFFS_FAIL;
1537 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1538 yaffsfs_SetError(-EFAULT);
1542 if (yaffsfs_CheckPath(path) < 0) {
1543 yaffsfs_SetError(-ENAMETOOLONG);
1549 obj = yaffsfs_FindObject(reldir, path, 0, 0, NULL, NULL, NULL);
1550 dir = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
1553 yaffsfs_SetError(-ENOTDIR);
1555 yaffsfs_SetError(-ELOOP);
1557 yaffsfs_SetError(-ENOENT);
1558 else if (yaffs_strncmp(name, _Y("."), 2) == 0)
1559 yaffsfs_SetError(-EINVAL);
1561 yaffsfs_SetError(-ENOENT);
1562 else if (obj->my_dev->read_only)
1563 yaffsfs_SetError(-EROFS);
1564 else if (!isDirectory &&
1565 obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1566 yaffsfs_SetError(-EISDIR);
1567 else if (isDirectory &&
1568 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1569 yaffsfs_SetError(-ENOTDIR);
1570 else if (isDirectory && obj == obj->my_dev->root_dir)
1571 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1573 result = yaffs_unlinker(dir, name);
1575 if (result == YAFFS_FAIL && isDirectory)
1576 yaffsfs_SetError(-ENOTEMPTY);
1581 return (result == YAFFS_FAIL) ? -1 : 0;
1584 int yaffs_unlink_reldir(struct yaffs_obj *reldir, const YCHAR *path)
1586 return yaffsfs_DoUnlink_reldir(reldir, path, 0);
1589 int yaffs_unlink_reldev(struct yaffs_dev *dev, const YCHAR *path)
1591 return yaffsfs_DoUnlink_reldir(ROOT_DIR(dev), path, 0);
1594 int yaffs_unlink(const YCHAR *path)
1596 return yaffs_unlink_reldir(NULL, path);
1599 int yaffs_funlink(int fd)
1601 struct yaffs_obj *obj;
1605 obj = yaffsfs_HandleToObject(fd);
1608 yaffsfs_SetError(-EBADF);
1609 else if (obj->my_dev->read_only)
1610 yaffsfs_SetError(-EROFS);
1611 else if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1612 !(list_empty(&obj->variant.dir_variant.children)))
1613 yaffsfs_SetError(-ENOTEMPTY);
1614 else if (obj == obj->my_dev->root_dir)
1615 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1616 else if (yaffs_unlink_obj(obj) == YAFFS_OK)
1624 int yaffs_fgetfl(int fd, int *flags)
1626 struct yaffsfs_FileDes *fdp = yaffsfs_HandleToFileDes(fd);
1631 if(!flags || !fdp) {
1632 yaffsfs_SetError(-EINVAL);
1635 if (fdp->reading && fdp->writing)
1637 else if (fdp->writing)
1649 static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1651 if (obj && obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY &&
1652 newobj && newobj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1658 static int rename_dir_over_file(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1660 if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1661 newobj && newobj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1667 int yaffs_rename_reldir(struct yaffs_obj *reldir,
1668 const YCHAR *oldPath, const YCHAR *newPath)
1670 struct yaffs_obj *olddir = NULL;
1671 struct yaffs_obj *newdir = NULL;
1672 struct yaffs_obj *obj = NULL;
1673 struct yaffs_obj *newobj = NULL;
1676 int result = YAFFS_FAIL;
1677 int rename_allowed = 1;
1683 YCHAR *alt_newpath = NULL;
1685 if (yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 ||
1686 yaffsfs_CheckMemRegion(newPath, 0, 0) < 0) {
1687 yaffsfs_SetError(-EFAULT);
1691 if (yaffsfs_CheckPath(oldPath) < 0 || yaffsfs_CheckPath(newPath) < 0) {
1692 yaffsfs_SetError(-ENAMETOOLONG);
1696 if (yaffsfs_alt_dir_path(newPath, &alt_newpath) < 0) {
1697 yaffsfs_SetError(-ENOMEM);
1701 newPath = alt_newpath;
1705 olddir = yaffsfs_FindDirectory(reldir, oldPath, &oldname, 0,
1706 ¬OldDir, &oldLoop);
1707 newdir = yaffsfs_FindDirectory(reldir, newPath, &newname, 0,
1708 ¬NewDir, &newLoop);
1709 obj = yaffsfs_FindObject(reldir, oldPath, 0, 0, NULL, NULL, NULL);
1710 newobj = yaffsfs_FindObject(reldir, newPath, 0, 0, NULL, NULL, NULL);
1712 /* If the object being renamed is a directory and the
1713 * path ended with a "/" then the olddir == obj.
1714 * We pass through NULL for the old name to tell the lower layers
1715 * to use olddir as the object.
1721 if ((!olddir && notOldDir) || (!newdir && notNewDir)) {
1722 yaffsfs_SetError(-ENOTDIR);
1724 } else if (oldLoop || newLoop) {
1725 yaffsfs_SetError(-ELOOP);
1727 } else if (olddir && oldname &&
1728 yaffs_strncmp(oldname, _Y("."), 2) == 0) {
1729 yaffsfs_SetError(-EINVAL);
1731 } else if (!olddir || !newdir || !obj) {
1732 yaffsfs_SetError(-ENOENT);
1734 } else if (obj->my_dev->read_only) {
1735 yaffsfs_SetError(-EROFS);
1737 } else if (rename_file_over_dir(obj, newobj)) {
1738 yaffsfs_SetError(-EISDIR);
1740 } else if (rename_dir_over_file(obj, newobj)) {
1741 yaffsfs_SetError(-ENOTDIR);
1743 } else if (yaffs_is_non_empty_dir(newobj)) {
1744 yaffsfs_SetError(-ENOTEMPTY);
1746 } else if (olddir->my_dev != newdir->my_dev) {
1747 /* Rename must be on same device */
1748 yaffsfs_SetError(-EXDEV);
1750 } else if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
1752 * It is a directory, check that it is not being renamed to
1753 * being its own decendent.
1754 * Do this by tracing from the new directory back to the root,
1758 struct yaffs_obj *xx = newdir;
1760 while (rename_allowed && xx) {
1765 if (!rename_allowed)
1766 yaffsfs_SetError(-EINVAL);
1770 result = yaffs_rename_obj(olddir, oldname, newdir, newname);
1776 return (result == YAFFS_FAIL) ? -1 : 0;
1779 int yaffs_rename_reldev(struct yaffs_dev *dev, const YCHAR *oldPath,
1780 const YCHAR *newPath)
1782 return yaffs_rename_reldir(ROOT_DIR(dev), oldPath, newPath);
1784 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
1786 return yaffs_rename_reldir(NULL, oldPath, newPath);
1789 static int yaffsfs_DoStat(struct yaffs_obj *obj, struct yaffs_stat *buf)
1793 obj = yaffs_get_equivalent_obj(obj);
1797 buf->st_ino = obj->obj_id;
1798 buf->st_mode = obj->yst_mode & ~S_IFMT;
1800 if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1801 buf->st_mode |= S_IFDIR;
1802 else if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
1803 buf->st_mode |= S_IFLNK;
1804 else if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE)
1805 buf->st_mode |= S_IFREG;
1807 buf->st_nlink = yaffs_get_obj_link_count(obj);
1810 buf->st_rdev = obj->yst_rdev;
1811 buf->st_size = yaffs_get_obj_length(obj);
1812 buf->st_blksize = obj->my_dev->data_bytes_per_chunk;
1813 buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
1815 #if CONFIG_YAFFS_WINCE
1816 buf->yst_wince_atime[0] = obj->win_atime[0];
1817 buf->yst_wince_atime[1] = obj->win_atime[1];
1818 buf->yst_wince_ctime[0] = obj->win_ctime[0];
1819 buf->yst_wince_ctime[1] = obj->win_ctime[1];
1820 buf->yst_wince_mtime[0] = obj->win_mtime[0];
1821 buf->yst_wince_mtime[1] = obj->win_mtime[1];
1823 buf->yst_atime = obj->yst_atime;
1824 buf->yst_ctime = obj->yst_ctime;
1825 buf->yst_mtime = obj->yst_mtime;
1832 static int yaffsfs_DoStatOrLStat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1833 struct yaffs_stat *buf, int doLStat)
1835 struct yaffs_obj *obj = NULL;
1836 struct yaffs_obj *dir = NULL;
1841 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
1842 yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1843 yaffsfs_SetError(-EFAULT);
1847 if (yaffsfs_CheckPath(path) < 0) {
1848 yaffsfs_SetError(-ENAMETOOLONG);
1854 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1856 if (!doLStat && obj)
1857 obj = yaffsfs_FollowLink(obj, 0, &loop);
1860 yaffsfs_SetError(-ENOTDIR);
1862 yaffsfs_SetError(-ELOOP);
1863 else if (!dir || !obj)
1864 yaffsfs_SetError(-ENOENT);
1866 retVal = yaffsfs_DoStat(obj, buf);
1874 int yaffs_stat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1875 struct yaffs_stat *buf)
1877 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 0);
1880 int yaffs_lstat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1881 struct yaffs_stat *buf)
1883 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 1);
1886 int yaffs_stat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1887 struct yaffs_stat *buf)
1889 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 0);
1892 int yaffs_lstat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1893 struct yaffs_stat *buf)
1895 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 1);
1898 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf)
1900 return yaffs_stat_reldir(NULL, path, buf);
1903 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf)
1905 return yaffs_lstat_reldir(NULL, path, buf);
1908 int yaffs_fstat(int fd, struct yaffs_stat *buf)
1910 struct yaffs_obj *obj;
1914 if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1915 yaffsfs_SetError(-EFAULT);
1920 obj = yaffsfs_HandleToObject(fd);
1923 retVal = yaffsfs_DoStat(obj, buf);
1926 yaffsfs_SetError(-EBADF);
1933 static int yaffsfs_DoUtime(struct yaffs_obj *obj,
1934 const struct yaffs_utimbuf *buf)
1937 struct yaffs_utimbuf local;
1939 obj = yaffs_get_equivalent_obj(obj);
1941 if (obj && obj->my_dev->read_only) {
1942 yaffsfs_SetError(-EROFS);
1946 #if !CONFIG_YAFFS_WINCE
1948 local.actime = Y_CURRENT_TIME;
1949 local.modtime = local.actime;
1956 obj->yst_atime = buf->actime;
1957 obj->yst_mtime = buf->modtime;
1959 result = yaffs_flush_file(obj, 0, 0, 0);
1960 retVal = result == YAFFS_OK ? 0 : -1;
1967 int yaffs_utime_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1968 const struct yaffs_utimbuf *buf)
1970 struct yaffs_obj *obj = NULL;
1971 struct yaffs_obj *dir = NULL;
1977 yaffsfs_SetError(-EFAULT);
1981 if (yaffsfs_CheckPath(path) < 0) {
1982 yaffsfs_SetError(-ENAMETOOLONG);
1988 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1991 yaffsfs_SetError(-ENOTDIR);
1993 yaffsfs_SetError(-ELOOP);
1994 else if (!dir || !obj)
1995 yaffsfs_SetError(-ENOENT);
1997 retVal = yaffsfs_DoUtime(obj, buf);
2005 int yaffs_utime_reldev(struct yaffs_dev *dev, const YCHAR *path,
2006 const struct yaffs_utimbuf *buf)
2008 return yaffs_utime_reldir(ROOT_DIR(dev), path, buf);
2011 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf)
2013 return yaffs_utime_reldir(NULL, path, buf);
2016 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf)
2018 struct yaffs_obj *obj;
2023 obj = yaffsfs_HandleToObject(fd);
2026 retVal = yaffsfs_DoUtime(obj, buf);
2029 yaffsfs_SetError(-EBADF);
2036 #ifndef CONFIG_YAFFS_WINCE
2037 /* xattrib functions */
2039 static int yaffs_do_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2040 const char *name, const void *data, int size,
2041 int flags, int follow)
2043 struct yaffs_obj *obj;
2044 struct yaffs_obj *dir;
2050 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2051 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2052 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2053 yaffsfs_SetError(-EFAULT);
2057 if (yaffsfs_CheckPath(path) < 0) {
2058 yaffsfs_SetError(-ENAMETOOLONG);
2064 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2067 obj = yaffsfs_FollowLink(obj, 0, &loop);
2070 yaffsfs_SetError(-ENOTDIR);
2072 yaffsfs_SetError(-ELOOP);
2073 else if (!dir || !obj)
2074 yaffsfs_SetError(-ENOENT);
2076 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2078 yaffsfs_SetError(retVal);
2089 int yaffs_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2090 const char *name, const void *data, int size, int flags)
2092 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 1);
2095 int yaffs_setxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
2096 const char *name, const void *data, int size, int flags)
2098 return yaffs_setxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2101 int yaffs_setxattr(const YCHAR *path, const char *name,
2102 const void *data, int size, int flags)
2104 return yaffs_setxattr_reldir(NULL, path, name, data, size, flags);
2107 int yaffs_lsetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path, const char *name,
2108 const void *data, int size, int flags)
2110 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 0);
2113 int yaffs_lsetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name,
2114 const void *data, int size, int flags)
2116 return yaffs_lsetxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2119 int yaffs_lsetxattr(const YCHAR *path, const char *name,
2120 const void *data, int size, int flags)
2122 return yaffs_lsetxattr_reldir(NULL, path, name, data, size, flags);
2125 int yaffs_fsetxattr(int fd, const char *name,
2126 const void *data, int size, int flags)
2128 struct yaffs_obj *obj;
2132 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2133 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2134 yaffsfs_SetError(-EFAULT);
2139 obj = yaffsfs_HandleToObject(fd);
2142 yaffsfs_SetError(-EBADF);
2144 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2146 yaffsfs_SetError(retVal);
2156 static int yaffs_do_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2157 const char *name, void *data, int size, int follow)
2159 struct yaffs_obj *obj;
2160 struct yaffs_obj *dir;
2165 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2166 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2167 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2168 yaffsfs_SetError(-EFAULT);
2172 if (yaffsfs_CheckPath(path) < 0) {
2173 yaffsfs_SetError(-ENAMETOOLONG);
2179 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2182 obj = yaffsfs_FollowLink(obj, 0, &loop);
2185 yaffsfs_SetError(-ENOTDIR);
2187 yaffsfs_SetError(-ELOOP);
2188 else if (!dir || !obj)
2189 yaffsfs_SetError(-ENOENT);
2191 retVal = yaffs_get_xattrib(obj, name, data, size);
2193 yaffsfs_SetError(retVal);
2203 int yaffs_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2204 const char *name, void *data, int size)
2206 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 1);
2209 int yaffs_getxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2211 return yaffs_getxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2214 int yaffs_getxattr(const YCHAR *path, const char *name, void *data, int size)
2216 return yaffs_getxattr_reldir(NULL, path, name, data, size);
2219 int yaffs_lgetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2220 const char *name, void *data, int size)
2222 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 0);
2225 int yaffs_lgetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2227 return yaffs_lgetxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2230 int yaffs_lgetxattr(const YCHAR *path, const char *name, void *data, int size)
2232 return yaffs_lgetxattr_reldir(NULL, path, name, data, size);
2235 int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
2237 struct yaffs_obj *obj;
2241 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2242 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2243 yaffsfs_SetError(-EFAULT);
2248 obj = yaffsfs_HandleToObject(fd);
2251 retVal = yaffs_get_xattrib(obj, name, data, size);
2253 yaffsfs_SetError(retVal);
2258 yaffsfs_SetError(-EBADF);
2265 static int yaffs_do_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2266 char *data, int size, int follow)
2268 struct yaffs_obj *obj = NULL;
2269 struct yaffs_obj *dir = NULL;
2274 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2275 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2276 yaffsfs_SetError(-EFAULT);
2280 if (yaffsfs_CheckPath(path) < 0) {
2281 yaffsfs_SetError(-ENAMETOOLONG);
2287 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2290 obj = yaffsfs_FollowLink(obj, 0, &loop);
2293 yaffsfs_SetError(-ENOTDIR);
2295 yaffsfs_SetError(-ELOOP);
2296 else if (!dir || !obj)
2297 yaffsfs_SetError(-ENOENT);
2299 retVal = yaffs_list_xattrib(obj, data, size);
2301 yaffsfs_SetError(retVal);
2312 int yaffs_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2313 char *data, int size)
2315 return yaffs_do_listxattr_reldir(reldir, path, data, size, 1);
2318 int yaffs_listxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2320 return yaffs_listxattr_reldir(ROOT_DIR(dev), path, data, size);
2323 int yaffs_listxattr(const YCHAR *path, char *data, int size)
2325 return yaffs_listxattr_reldir(NULL, path, data, size);
2328 int yaffs_llistxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2329 char *data, int size)
2331 return yaffs_do_listxattr_reldir(reldir, path, data, size, 0);
2334 int yaffs_llistxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2336 return yaffs_llistxattr_reldir(ROOT_DIR(dev), path, data, size);
2339 int yaffs_llistxattr(const YCHAR *path, char *data, int size)
2341 return yaffs_llistxattr_reldir(NULL, path, data, size);
2344 int yaffs_flistxattr(int fd, char *data, int size)
2346 struct yaffs_obj *obj;
2350 if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2351 yaffsfs_SetError(-EFAULT);
2356 obj = yaffsfs_HandleToObject(fd);
2359 retVal = yaffs_list_xattrib(obj, data, size);
2361 yaffsfs_SetError(retVal);
2366 yaffsfs_SetError(-EBADF);
2373 static int yaffs_do_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2374 const char *name, int follow)
2376 struct yaffs_obj *obj = NULL;
2377 struct yaffs_obj *dir = NULL;
2382 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2383 yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2384 yaffsfs_SetError(-EFAULT);
2388 if (yaffsfs_CheckPath(path) < 0) {
2389 yaffsfs_SetError(-ENAMETOOLONG);
2395 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2398 obj = yaffsfs_FollowLink(obj, 0, &loop);
2401 yaffsfs_SetError(-ENOTDIR);
2403 yaffsfs_SetError(-ELOOP);
2404 else if (!dir || !obj)
2405 yaffsfs_SetError(-ENOENT);
2407 retVal = yaffs_remove_xattrib(obj, name);
2409 yaffsfs_SetError(retVal);
2420 int yaffs_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2423 return yaffs_do_removexattr_reldir(reldir, path, name, 1);
2426 int yaffs_removexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2428 return yaffs_removexattr_reldir(ROOT_DIR(dev), path, name);
2431 int yaffs_removexattr(const YCHAR *path, const char *name)
2433 return yaffs_removexattr_reldir(NULL, path, name);
2436 int yaffs_lremovexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2439 return yaffs_do_removexattr_reldir(reldir, path, name, 0);
2442 int yaffs_lremovexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2444 return yaffs_lremovexattr_reldir(ROOT_DIR(dev), path, name);
2447 int yaffs_lremovexattr(const YCHAR *path, const char *name)
2449 return yaffs_lremovexattr_reldir(NULL, path, name);
2452 int yaffs_fremovexattr(int fd, const char *name)
2454 struct yaffs_obj *obj;
2458 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2459 yaffsfs_SetError(-EFAULT);
2464 obj = yaffsfs_HandleToObject(fd);
2467 retVal = yaffs_remove_xattrib(obj, name);
2469 yaffsfs_SetError(retVal);
2474 yaffsfs_SetError(-EBADF);
2482 #ifdef CONFIG_YAFFS_WINCE
2483 int yaffs_get_wince_times(int fd, unsigned *wctime,
2484 unsigned *watime, unsigned *wmtime)
2486 struct yaffs_obj *obj;
2491 obj = yaffsfs_HandleToObject(fd);
2496 wctime[0] = obj->win_ctime[0];
2497 wctime[1] = obj->win_ctime[1];
2500 watime[0] = obj->win_atime[0];
2501 watime[1] = obj->win_atime[1];
2504 wmtime[0] = obj->win_mtime[0];
2505 wmtime[1] = obj->win_mtime[1];
2511 yaffsfs_SetError(-EBADF);
2518 int yaffs_set_wince_times(int fd,
2519 const unsigned *wctime,
2520 const unsigned *watime, const unsigned *wmtime)
2522 struct yaffs_obj *obj;
2527 obj = yaffsfs_HandleToObject(fd);
2532 obj->win_ctime[0] = wctime[0];
2533 obj->win_ctime[1] = wctime[1];
2536 obj->win_atime[0] = watime[0];
2537 obj->win_atime[1] = watime[1];
2540 obj->win_mtime[0] = wmtime[0];
2541 obj->win_mtime[1] = wmtime[1];
2545 result = yaffs_flush_file(obj, 0, 0, 0);
2549 yaffsfs_SetError(-EBADF);
2558 static int yaffsfs_DoChMod(struct yaffs_obj *obj, mode_t mode)
2563 obj = yaffs_get_equivalent_obj(obj);
2566 obj->yst_mode = mode;
2568 result = yaffs_flush_file(obj, 0, 0, 0);
2571 return result == YAFFS_OK ? 0 : -1;
2574 int yaffs_access_reldir(struct yaffs_obj *reldir, const YCHAR *path, int amode)
2576 struct yaffs_obj *obj = NULL;
2577 struct yaffs_obj *dir = NULL;
2582 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2583 yaffsfs_SetError(-EFAULT);
2587 if (yaffsfs_CheckPath(path) < 0) {
2588 yaffsfs_SetError(-ENAMETOOLONG);
2592 if (amode & ~(R_OK | W_OK | X_OK)) {
2593 yaffsfs_SetError(-EINVAL);
2599 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2600 obj = yaffsfs_FollowLink(obj, 0, &loop);
2603 yaffsfs_SetError(-ENOTDIR);
2605 yaffsfs_SetError(-ELOOP);
2606 else if (!dir || !obj)
2607 yaffsfs_SetError(-ENOENT);
2608 else if ((amode & W_OK) && obj->my_dev->read_only)
2609 yaffsfs_SetError(-EROFS);
2613 if ((amode & R_OK) && !(obj->yst_mode & S_IRUSR))
2615 if ((amode & W_OK) && !(obj->yst_mode & S_IWUSR))
2617 if ((amode & X_OK) && !(obj->yst_mode & S_IXUSR))
2621 yaffsfs_SetError(-EACCES);
2632 int yaffs_access_reldev(struct yaffs_dev *dev, const YCHAR *path, int amode)
2634 return yaffs_access_reldir(ROOT_DIR(dev), path, amode);
2637 int yaffs_access(const YCHAR *path, int amode)
2639 return yaffs_access_reldir(NULL, path, amode);
2642 int yaffs_chmod_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2644 struct yaffs_obj *obj = NULL;
2645 struct yaffs_obj *dir = NULL;
2650 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2651 yaffsfs_SetError(-EFAULT);
2655 if (yaffsfs_CheckPath(path) < 0) {
2656 yaffsfs_SetError(-ENAMETOOLONG);
2660 if (mode & ~(0777)) {
2661 yaffsfs_SetError(-EINVAL);
2667 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2668 obj = yaffsfs_FollowLink(obj, 0, &loop);
2671 yaffsfs_SetError(-ENOTDIR);
2673 yaffsfs_SetError(-ELOOP);
2674 else if (!dir || !obj)
2675 yaffsfs_SetError(-ENOENT);
2676 else if (obj->my_dev->read_only)
2677 yaffsfs_SetError(-EROFS);
2679 retVal = yaffsfs_DoChMod(obj, mode);
2687 int yaffs_chmod_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2689 return yaffs_chmod_reldir(ROOT_DIR(dev), path, mode);
2692 int yaffs_chmod(const YCHAR *path, mode_t mode)
2694 return yaffs_chmod_reldir(NULL, path, mode);
2697 int yaffs_fchmod(int fd, mode_t mode)
2699 struct yaffs_obj *obj;
2702 if (mode & ~(0777)) {
2703 yaffsfs_SetError(-EINVAL);
2708 obj = yaffsfs_HandleToObject(fd);
2711 yaffsfs_SetError(-EBADF);
2712 else if (obj->my_dev->read_only)
2713 yaffsfs_SetError(-EROFS);
2715 retVal = yaffsfs_DoChMod(obj, mode);
2722 int yaffs_mkdir_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2724 struct yaffs_obj *parent = NULL;
2725 struct yaffs_obj *dir = NULL;
2727 YCHAR *alt_path = NULL;
2732 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2733 yaffsfs_SetError(-EFAULT);
2737 if (yaffsfs_CheckPath(path) < 0) {
2738 yaffsfs_SetError(-ENAMETOOLONG);
2742 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2743 yaffsfs_SetError(-ENOMEM);
2750 parent = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
2751 if (!parent && notDir)
2752 yaffsfs_SetError(-ENOTDIR);
2754 yaffsfs_SetError(-ELOOP);
2756 yaffsfs_SetError(-ENOENT);
2757 else if (yaffsfs_TooManyObjects(parent->my_dev))
2758 yaffsfs_SetError(-ENFILE);
2759 else if (yaffs_strnlen(name, 5) == 0) {
2760 /* Trying to make the root itself */
2761 yaffsfs_SetError(-EEXIST);
2762 } else if (parent->my_dev->read_only)
2763 yaffsfs_SetError(-EROFS);
2765 dir = yaffs_create_dir(parent, name, mode, 0, 0);
2768 else if (yaffs_find_by_name(parent, name))
2769 yaffsfs_SetError(-EEXIST); /* name exists */
2771 yaffsfs_SetError(-ENOSPC); /* assume no space */
2781 int yaffs_mkdir_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2783 return yaffs_mkdir_reldir(ROOT_DIR(dev), path, mode);
2786 int yaffs_mkdir(const YCHAR *path, mode_t mode)
2788 return yaffs_mkdir_reldir(NULL, path, mode);
2791 int yaffs_rmdir_reldir(struct yaffs_obj *reldir, const YCHAR *path)
2796 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2797 yaffsfs_SetError(-EFAULT);
2801 if (yaffsfs_CheckPath(path) < 0) {
2802 yaffsfs_SetError(-ENAMETOOLONG);
2806 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2807 yaffsfs_SetError(-ENOMEM);
2812 result = yaffsfs_DoUnlink_reldir(reldir, path, 1);
2819 int yaffs_rmdir_reldev(struct yaffs_dev *dev, const YCHAR *path)
2821 return yaffs_rmdir_reldir(ROOT_DIR(dev), path);
2824 int yaffs_rmdir(const YCHAR *path)
2826 return yaffs_rmdir_reldir(NULL, path);
2830 * The mount/unmount/sync functions act on devices rather than reldirs.
2832 void *yaffs_getdev(const YCHAR *path)
2834 struct yaffs_dev *dev = NULL;
2836 dev = yaffsfs_FindDevice(path, &dummy);
2840 int yaffs_mount_common(struct yaffs_dev *dev, const YCHAR *path,
2841 int read_only, int skip_checkpt)
2844 int result = YAFFS_FAIL;
2847 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2848 yaffsfs_SetError(-EFAULT);
2852 yaffs_trace(YAFFS_TRACE_MOUNT, "yaffs: Mounting %s", path);
2854 if (yaffsfs_CheckPath(path) < 0) {
2855 yaffsfs_SetError(-ENAMETOOLONG);
2862 yaffsfs_InitHandles();
2865 dev = yaffsfs_FindMountPoint(path);
2868 if (!dev->is_mounted) {
2869 dev->read_only = read_only ? 1 : 0;
2871 u8 skip = dev->param.skip_checkpt_rd;
2872 dev->param.skip_checkpt_rd = 1;
2873 result = yaffs_guts_initialise(dev);
2874 dev->param.skip_checkpt_rd = skip;
2876 result = yaffs_guts_initialise(dev);
2879 if (result == YAFFS_FAIL)
2880 yaffsfs_SetError(-ENOMEM);
2881 retVal = result ? 0 : -1;
2884 yaffsfs_SetError(-EBUSY);
2886 yaffsfs_SetError(-ENODEV);
2893 int yaffs_mount3_reldev(struct yaffs_dev *dev, int read_only, int skip_checkpt)
2895 return yaffs_mount_common(dev, NULL, read_only, skip_checkpt);
2898 int yaffs_mount3(const YCHAR *path, int read_only, int skip_checkpt)
2900 return yaffs_mount_common(NULL, path, read_only, skip_checkpt);
2903 int yaffs_mount2_reldev(struct yaffs_dev *dev, int readonly)
2905 return yaffs_mount_common(dev, NULL, readonly, 0);
2908 int yaffs_mount2(const YCHAR *path, int readonly)
2910 return yaffs_mount_common(NULL, path, readonly, 0);
2913 int yaffs_mount_reldev(struct yaffs_dev *dev)
2915 return yaffs_mount_common(dev, NULL, 0, 0);
2918 int yaffs_mount(const YCHAR *path)
2920 return yaffs_mount_common(NULL, path, 0, 0);
2923 static int yaffs_sync_common(struct yaffs_dev *dev,
2931 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2932 yaffsfs_SetError(-EFAULT);
2936 if (yaffsfs_CheckPath(path) < 0) {
2937 yaffsfs_SetError(-ENAMETOOLONG);
2944 dev = yaffsfs_FindDevice(path, &dummy);
2947 if (!dev->is_mounted)
2948 yaffsfs_SetError(-EINVAL);
2949 else if (dev->read_only)
2950 yaffsfs_SetError(-EROFS);
2953 yaffs_flush_whole_cache(dev, 0);
2955 yaffs_checkpoint_save(dev);
2960 yaffsfs_SetError(-ENODEV);
2966 int yaffs_sync_files_reldev(struct yaffs_dev *dev)
2968 return yaffs_sync_common(dev, NULL, 0);
2971 int yaffs_sync_files(const YCHAR *path)
2973 return yaffs_sync_common(NULL, path, 0);
2976 int yaffs_sync_reldev(struct yaffs_dev *dev)
2978 return yaffs_sync_common(dev, NULL, 1);
2981 int yaffs_sync(const YCHAR *path)
2983 return yaffs_sync_common(NULL, path, 1);
2987 static int yaffsfs_bg_gc_common(struct yaffs_dev *dev,
2995 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2996 yaffsfs_SetError(-EFAULT);
3000 if (yaffsfs_CheckPath(path) < 0) {
3001 yaffsfs_SetError(-ENAMETOOLONG);
3008 dev = yaffsfs_FindDevice(path, &dummy);
3011 if (!dev->is_mounted)
3012 yaffsfs_SetError(-EINVAL);
3014 retVal = yaffs_bg_gc(dev, urgency);
3016 yaffsfs_SetError(-ENODEV);
3022 /* Background gc functions.
3023 * These return 0 when bg done or greater than 0 when gc has been
3024 * done and there is still a lot of garbage to be cleaned up.
3027 int yaffs_do_background_gc(const YCHAR *path, int urgency)
3029 return yaffsfs_bg_gc_common(NULL, path, urgency);
3032 int yaffs_do_background_gc_reldev(struct yaffs_dev *dev, int urgency)
3034 return yaffsfs_bg_gc_common(dev, NULL, urgency);
3037 static int yaffsfs_IsDevBusy(struct yaffs_dev *dev)
3040 struct yaffs_obj *obj;
3042 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
3043 obj = yaffsfs_HandleToObject(i);
3044 if (obj && obj->my_dev == dev)
3050 int yaffs_remount_common(struct yaffs_dev *dev, const YCHAR *path,
3051 int force, int read_only)
3055 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3056 yaffsfs_SetError(-EFAULT);
3060 if (yaffsfs_CheckPath(path) < 0) {
3061 yaffsfs_SetError(-ENAMETOOLONG);
3067 dev = yaffsfs_FindMountPoint(path);
3070 if (dev->is_mounted) {
3071 yaffs_flush_whole_cache(dev, 0);
3073 if (force || !yaffsfs_IsDevBusy(dev)) {
3075 yaffs_checkpoint_save(dev);
3076 dev->read_only = read_only ? 1 : 0;
3079 yaffsfs_SetError(-EBUSY);
3082 yaffsfs_SetError(-EINVAL);
3085 yaffsfs_SetError(-ENODEV);
3092 int yaffs_remount_reldev(struct yaffs_dev *dev, int force, int read_only)
3094 return yaffs_remount_common(dev, NULL, force, read_only);
3096 int yaffs_remount(const YCHAR *path, int force, int read_only)
3098 return yaffs_remount_common(NULL, path, force, read_only);
3101 int yaffs_unmount2_common(struct yaffs_dev *dev, const YCHAR *path, int force)
3105 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3106 yaffsfs_SetError(-EFAULT);
3110 if (yaffsfs_CheckPath(path) < 0) {
3111 yaffsfs_SetError(-ENAMETOOLONG);
3117 dev = yaffsfs_FindMountPoint(path);
3120 if (dev->is_mounted) {
3122 yaffs_flush_whole_cache(dev, 0);
3123 yaffs_checkpoint_save(dev);
3124 inUse = yaffsfs_IsDevBusy(dev);
3125 if (!inUse || force) {
3127 yaffsfs_BreakDeviceHandles(dev);
3128 yaffs_deinitialise(dev);
3132 yaffsfs_SetError(-EBUSY);
3135 yaffsfs_SetError(-EINVAL);
3138 yaffsfs_SetError(-ENODEV);
3145 int yaffs_unmount2_reldev(struct yaffs_dev *dev, int force)
3147 return yaffs_unmount2_common(dev, NULL, force);
3150 int yaffs_unmount2(const YCHAR *path, int force)
3152 return yaffs_unmount2_common(NULL, path, force);
3155 int yaffs_unmount_reldev(struct yaffs_dev *dev)
3157 return yaffs_unmount2_reldev(dev, 0);
3160 int yaffs_unmount(const YCHAR *path)
3162 return yaffs_unmount2(path, 0);
3165 int yaffs_format_common(struct yaffs_dev *dev,
3168 int force_unmount_flag,
3176 yaffsfs_SetError(-EFAULT);
3180 if (yaffsfs_CheckPath(path) < 0) {
3181 yaffsfs_SetError(-ENAMETOOLONG);
3188 dev = yaffsfs_FindMountPoint(path);
3191 int was_mounted = dev->is_mounted;
3193 if (dev->is_mounted && unmount_flag) {
3195 yaffs_flush_whole_cache(dev, 0);
3196 yaffs_checkpoint_save(dev);
3197 inUse = yaffsfs_IsDevBusy(dev);
3198 if (!inUse || force_unmount_flag) {
3200 yaffsfs_BreakDeviceHandles(dev);
3201 yaffs_deinitialise(dev);
3205 if(dev->is_mounted) {
3206 yaffsfs_SetError(-EBUSY);
3209 yaffs_guts_format_dev(dev);
3210 if(was_mounted && remount_flag) {
3211 result = yaffs_guts_initialise(dev);
3212 if (result == YAFFS_FAIL) {
3213 yaffsfs_SetError(-ENOMEM);
3219 yaffsfs_SetError(-ENODEV);
3228 int yaffs_format_reldev(struct yaffs_dev *dev,
3230 int force_unmount_flag,
3233 return yaffs_format_common(dev, NULL, unmount_flag,
3234 force_unmount_flag, remount_flag);
3237 int yaffs_format(const YCHAR *path,
3239 int force_unmount_flag,
3242 return yaffs_format_common(NULL, path, unmount_flag,
3243 force_unmount_flag, remount_flag);
3246 Y_LOFF_T yaffs_freespace_common(struct yaffs_dev *dev, const YCHAR *path)
3248 Y_LOFF_T retVal = -1;
3252 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3253 yaffsfs_SetError(-EFAULT);
3257 if (yaffsfs_CheckPath(path) < 0) {
3258 yaffsfs_SetError(-ENAMETOOLONG);
3265 dev = yaffsfs_FindDevice(path, &dummy);
3266 if (dev && dev->is_mounted) {
3267 retVal = yaffs_get_n_free_chunks(dev);
3268 retVal *= dev->data_bytes_per_chunk;
3271 yaffsfs_SetError(-EINVAL);
3277 Y_LOFF_T yaffs_freespace_reldev(struct yaffs_dev *dev)
3279 return yaffs_freespace_common(dev, NULL);
3282 Y_LOFF_T yaffs_freespace(const YCHAR *path)
3284 return yaffs_freespace_common(NULL, path);
3287 Y_LOFF_T yaffs_totalspace_common(struct yaffs_dev *dev, const YCHAR *path)
3289 Y_LOFF_T retVal = -1;
3293 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3294 yaffsfs_SetError(-EFAULT);
3298 if (yaffsfs_CheckPath(path) < 0) {
3299 yaffsfs_SetError(-ENAMETOOLONG);
3306 dev = yaffsfs_FindDevice(path, &dummy);
3307 if (dev && dev->is_mounted) {
3308 retVal = (dev->param.end_block - dev->param.start_block + 1) -
3309 dev->param.n_reserved_blocks;
3310 retVal *= dev->param.chunks_per_block;
3311 retVal *= dev->data_bytes_per_chunk;
3314 yaffsfs_SetError(-EINVAL);
3320 Y_LOFF_T yaffs_totalspace_reldev(struct yaffs_dev *dev)
3322 return yaffs_totalspace_common(dev, NULL);
3325 Y_LOFF_T yaffs_totalspace(const YCHAR *path)
3327 return yaffs_totalspace_common(NULL, path);
3330 int yaffs_inodecount_common(struct yaffs_dev *dev, const YCHAR *path)
3332 Y_LOFF_T retVal = -1;
3336 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3337 yaffsfs_SetError(-EFAULT);
3341 if (yaffsfs_CheckPath(path) < 0) {
3342 yaffsfs_SetError(-ENAMETOOLONG);
3349 dev = yaffsfs_FindDevice(path, &dummy);
3350 if (dev && dev->is_mounted) {
3351 int n_obj = dev->n_obj;
3352 if (n_obj > dev->n_hardlinks)
3353 retVal = n_obj - dev->n_hardlinks;
3357 yaffsfs_SetError(-EINVAL);
3363 int yaffs_inodecount_reldev(struct yaffs_dev *dev)
3365 return yaffs_inodecount_common(dev, NULL);
3368 int yaffs_inodecount(const YCHAR *path)
3370 return yaffs_inodecount_common(NULL, path);
3373 void yaffs_add_device(struct yaffs_dev *dev)
3375 struct list_head *cfg;
3376 /* First check that the device is not in the list. */
3378 list_for_each(cfg, &yaffsfs_deviceList) {
3379 if (dev == list_entry(cfg, struct yaffs_dev, dev_list))
3383 dev->is_mounted = 0;
3384 dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
3386 if (!dev->dev_list.next)
3387 INIT_LIST_HEAD(&dev->dev_list);
3389 list_add(&dev->dev_list, &yaffsfs_deviceList);
3394 void yaffs_remove_device(struct yaffs_dev *dev)
3396 list_del_init(&dev->dev_list);
3399 /* Functions to iterate through devices. NB Use with extreme care! */
3401 static struct list_head *dev_iterator;
3402 void yaffs_dev_rewind(void)
3404 dev_iterator = yaffsfs_deviceList.next;
3407 struct yaffs_dev *yaffs_next_dev(void)
3409 struct yaffs_dev *retval;
3413 if (dev_iterator == &yaffsfs_deviceList)
3416 retval = list_entry(dev_iterator, struct yaffs_dev, dev_list);
3417 dev_iterator = dev_iterator->next;
3421 /* Directory search stuff. */
3423 static struct list_head search_contexts;
3425 static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContext *dsc)
3429 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3433 if (list_empty(&dsc->dirObj->variant.dir_variant.children))
3434 dsc->nextReturn = NULL;
3437 list_entry(dsc->dirObj->variant.dir_variant.
3438 children.next, struct yaffs_obj,
3441 /* Hey someone isn't playing nice! */
3445 static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContext *dsc)
3449 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3451 if (dsc->nextReturn == NULL ||
3452 list_empty(&dsc->dirObj->variant.dir_variant.children))
3453 dsc->nextReturn = NULL;
3455 struct list_head *next = dsc->nextReturn->siblings.next;
3457 if (next == &dsc->dirObj->variant.dir_variant.children)
3458 dsc->nextReturn = NULL; /* end of list */
3460 dsc->nextReturn = list_entry(next,
3465 /* Hey someone isn't playing nice! */
3469 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj)
3472 struct list_head *i;
3473 struct yaffsfs_DirSearchContext *dsc;
3475 /* if search contexts not initilised then skip */
3476 if (!search_contexts.next)
3479 /* Iterate through the directory search contexts.
3480 * If any are the one being removed, then advance the dsc to
3481 * the next one to prevent a hanging ptr.
3483 list_for_each(i, &search_contexts) {
3485 dsc = list_entry(i, struct yaffsfs_DirSearchContext,
3487 if (dsc->nextReturn == obj)
3488 yaffsfs_DirAdvance(dsc);
3494 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(struct yaffs_obj *reldir,
3495 const YCHAR *dirname)
3497 yaffs_DIR *dir = NULL;
3498 struct yaffs_obj *obj = NULL;
3499 struct yaffsfs_DirSearchContext *dsc = NULL;
3503 if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) {
3504 yaffsfs_SetError(-EFAULT);
3508 if (yaffsfs_CheckPath(dirname) < 0) {
3509 yaffsfs_SetError(-ENAMETOOLONG);
3513 obj = yaffsfs_FindObject(reldir, dirname, 0, 1, NULL, ¬Dir, &loop);
3514 obj = yaffsfs_FollowLink(obj, 0, &loop);
3517 yaffsfs_SetError(-ENOTDIR);
3519 yaffsfs_SetError(-ELOOP);
3521 yaffsfs_SetError(-ENOENT);
3522 else if (obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
3523 yaffsfs_SetError(-ENOTDIR);
3527 for (i = 0, dsc = NULL; i < YAFFSFS_N_DSC && !dsc; i++) {
3528 if (!yaffsfs_dsc[i].inUse)
3529 dsc = &yaffsfs_dsc[i];
3532 dir = (yaffs_DIR *) dsc;
3535 memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContext));
3538 yaffs_strncpy(dsc->name, dirname, NAME_MAX);
3539 INIT_LIST_HEAD(&dsc->others);
3541 if (!search_contexts.next)
3542 INIT_LIST_HEAD(&search_contexts);
3544 list_add(&dsc->others, &search_contexts);
3545 yaffsfs_SetDirRewound(dsc);
3551 yaffs_DIR *yaffs_opendir_reldir(struct yaffs_obj *reldir, const YCHAR *dirname)
3556 ret = yaffsfs_opendir_reldir_no_lock(reldir, dirname);
3561 yaffs_DIR *yaffs_opendir_reldev(struct yaffs_dev *dev, const YCHAR *dirname)
3563 return yaffs_opendir_reldir(ROOT_DIR(dev), dirname);
3566 yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
3568 return yaffs_opendir_reldir(NULL, dirname);
3571 struct yaffs_dirent *yaffsfs_readdir_no_lock(yaffs_DIR * dirp)
3573 struct yaffsfs_DirSearchContext *dsc;
3574 struct yaffs_dirent *retVal = NULL;
3576 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3579 if (dsc && dsc->inUse) {
3580 yaffsfs_SetError(0);
3581 if (dsc->nextReturn) {
3583 yaffs_get_equivalent_obj(dsc->nextReturn)->obj_id;
3584 dsc->de.d_dont_use = 0;
3585 dsc->de.d_off = dsc->offset++;
3586 yaffs_get_obj_name(dsc->nextReturn,
3587 dsc->de.d_name, NAME_MAX);
3588 if (yaffs_strnlen(dsc->de.d_name, NAME_MAX + 1) == 0) {
3589 /* this should not happen! */
3590 yaffs_strcpy(dsc->de.d_name, _Y("zz"));
3592 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
3594 yaffsfs_DirAdvance(dsc);
3598 yaffsfs_SetError(-EBADF);
3603 struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp)
3605 struct yaffs_dirent *ret;
3608 ret = yaffsfs_readdir_no_lock(dirp);
3613 static void yaffsfs_rewinddir_no_lock(yaffs_DIR *dirp)
3615 struct yaffsfs_DirSearchContext *dsc;
3617 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3619 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
3622 yaffsfs_SetDirRewound(dsc);
3626 void yaffs_rewinddir(yaffs_DIR *dirp)
3629 yaffsfs_rewinddir_no_lock(dirp);
3633 struct yaffs_dirent *yaffs_readdir_fd(int fd)
3635 struct yaffs_dirent *ret = NULL;
3636 struct yaffsfs_FileDes *f;
3639 f = yaffsfs_HandleToFileDes(fd);
3640 if(f && f->isDir && f->v.dir)
3641 ret = yaffsfs_readdir_no_lock(f->v.dir);
3646 void yaffs_rewinddir_fd(int fd)
3648 struct yaffsfs_FileDes *f;
3651 f = yaffsfs_HandleToFileDes(fd);
3653 yaffsfs_rewinddir_no_lock(f->v.dir);
3658 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirp)
3660 struct yaffsfs_DirSearchContext *dsc;
3662 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3664 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) {
3665 yaffsfs_SetError(-EFAULT);
3670 list_del(&dsc->others); /* unhook from list */
3675 int yaffs_closedir(yaffs_DIR *dirp)
3680 ret = yaffsfs_closedir_no_lock(dirp);
3685 /* End of directory stuff */
3687 int yaffs_symlink_reldir(struct yaffs_obj *reldir,
3688 const YCHAR *oldpath, const YCHAR *newpath)
3690 struct yaffs_obj *parent = NULL;
3691 struct yaffs_obj *obj;
3694 int mode = 0; /* ignore for now */
3698 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3699 yaffsfs_CheckMemRegion(newpath, 0, 0) < 0) {
3700 yaffsfs_SetError(-EFAULT);
3704 if (yaffsfs_CheckPath(newpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3705 yaffsfs_SetError(-ENAMETOOLONG);
3710 parent = yaffsfs_FindDirectory(reldir, newpath, &name, 0, ¬Dir, &loop);
3711 if (!parent && notDir)
3712 yaffsfs_SetError(-ENOTDIR);
3714 yaffsfs_SetError(-ELOOP);
3715 else if (!parent || yaffs_strnlen(name, 5) < 1)
3716 yaffsfs_SetError(-ENOENT);
3717 else if (yaffsfs_TooManyObjects(parent->my_dev))
3718 yaffsfs_SetError(-ENFILE);
3719 else if (parent->my_dev->read_only)
3720 yaffsfs_SetError(-EROFS);
3722 obj = yaffs_create_symlink(parent, name, mode, 0, 0, oldpath);
3725 else if (yaffsfs_FindObject(reldir, newpath, 0, 0,
3727 yaffsfs_SetError(-EEXIST);
3729 yaffsfs_SetError(-ENOSPC);
3737 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
3739 return yaffs_symlink_reldir(NULL, oldpath, newpath);
3742 int yaffs_readlink_reldir(struct yaffs_obj *reldir,const YCHAR *path,
3743 YCHAR *buf, int bufsiz)
3745 struct yaffs_obj *obj = NULL;
3746 struct yaffs_obj *dir = NULL;
3751 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
3752 yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0) {
3753 yaffsfs_SetError(-EFAULT);
3759 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
3762 yaffsfs_SetError(-ENOTDIR);
3764 yaffsfs_SetError(-ELOOP);
3765 else if (!dir || !obj)
3766 yaffsfs_SetError(-ENOENT);
3767 else if (obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
3768 yaffsfs_SetError(-EINVAL);
3770 YCHAR *alias = obj->variant.symlink_variant.alias;
3771 memset(buf, 0, bufsiz);
3772 yaffs_strncpy(buf, alias, bufsiz - 1);
3778 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
3780 return yaffs_readlink_reldir(NULL, path, buf, bufsiz);
3783 int yaffs_link_reldir(struct yaffs_obj *reldir,
3784 const YCHAR *oldpath, const YCHAR *linkpath)
3786 /* Creates a link called newpath to existing oldpath */
3787 struct yaffs_obj *obj = NULL;
3788 struct yaffs_obj *lnk = NULL;
3789 struct yaffs_obj *obj_dir = NULL;
3790 struct yaffs_obj *lnk_dir = NULL;
3798 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3799 yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0) {
3800 yaffsfs_SetError(-EFAULT);
3804 if (yaffsfs_CheckPath(linkpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3805 yaffsfs_SetError(-ENAMETOOLONG);
3811 obj = yaffsfs_FindObject(reldir, oldpath, 0, 1,
3812 &obj_dir, ¬DirObj, &objLoop);
3813 lnk = yaffsfs_FindObject(reldir, linkpath, 0, 0, NULL, NULL, NULL);
3814 lnk_dir = yaffsfs_FindDirectory(reldir, linkpath, &newname,
3815 0, ¬DirLnk, &lnkLoop);
3817 if ((!obj_dir && notDirObj) || (!lnk_dir && notDirLnk))
3818 yaffsfs_SetError(-ENOTDIR);
3819 else if (objLoop || lnkLoop)
3820 yaffsfs_SetError(-ELOOP);
3821 else if (!obj_dir || !lnk_dir || !obj)
3822 yaffsfs_SetError(-ENOENT);
3823 else if (obj->my_dev->read_only)
3824 yaffsfs_SetError(-EROFS);
3825 else if (yaffsfs_TooManyObjects(obj->my_dev))
3826 yaffsfs_SetError(-ENFILE);
3828 yaffsfs_SetError(-EEXIST);
3829 else if (lnk_dir->my_dev != obj->my_dev)
3830 yaffsfs_SetError(-EXDEV);
3832 retVal = yaffsfs_CheckNameLength(newname);
3835 lnk = yaffs_link_obj(lnk_dir, newname, obj);
3839 yaffsfs_SetError(-ENOSPC);
3848 int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
3850 return yaffs_link_reldir(NULL, oldpath, linkpath);
3853 int yaffs_mknod_reldir(struct yaffs_obj *reldir, const YCHAR *pathname,
3854 mode_t mode, dev_t dev_val)
3861 yaffsfs_SetError(-EINVAL);
3865 int yaffs_mknod_reldev(struct yaffs_dev *dev, const YCHAR *pathname, mode_t mode, dev_t dev_val)
3867 return yaffs_mknod_reldir(ROOT_DIR(dev), pathname, mode, dev_val);
3870 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev_val)
3872 return yaffs_mknod_reldir(NULL, pathname, mode, dev_val);
3876 * D E B U G F U N C T I O N S
3881 * Returns number of handles attached to the object
3883 int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3885 struct yaffs_obj *obj;
3887 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3888 yaffsfs_SetError(-EFAULT);
3892 if (yaffsfs_CheckPath(path) < 0) {
3893 yaffsfs_SetError(-ENAMETOOLONG);
3897 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
3900 return yaffsfs_CountHandles(obj);
3905 int yaffs_n_handles(const YCHAR *path)
3907 return yaffs_n_handles_reldir(NULL, path);
3910 int yaffs_get_error(void)
3912 return yaffsfs_GetLastError();
3915 int yaffs_set_error(int error)
3917 yaffsfs_SetError(error);
3921 struct yaffs_obj * yaffs_get_obj_from_fd(int handle)
3923 return yaffsfs_HandleToObject(handle);
3926 int yaffs_dump_dev_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3936 reldir = yaffsfs_FindRoot(path, &rest);
3939 struct yaffs_dev *dev = reldir->my_dev;
3942 "n_page_writes.......... %d\n"
3943 "n_page_reads........... %d\n"
3944 "n_erasures....... %d\n"
3945 "n_gc_copies............ %d\n"
3946 "garbageCollections... %d\n"
3947 "passiveGarbageColl'ns %d\n"
3953 dev->garbageCollections, dev->passiveGarbageCollections);
3960 int yaffs_dump_dev(const YCHAR *path)
3962 return yaffs_dump_dev_reldir(NULL, path);