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);
896 /* A directory can't be opened except for read */
898 (writeRequested || !readRequested || rwflags != O_RDONLY)) {
899 openDenied = __LINE__;
900 yaffsfs_SetError(-EISDIR);
901 errorReported = __LINE__;
905 dsc = yaffsfs_opendir_reldir_no_lock(reldir, path);
907 openDenied = __LINE__;
908 yaffsfs_SetError(-ENFILE);
909 errorReported = __LINE__;
913 /* Open should fail if O_CREAT and O_EXCL are specified
914 * for a file that exists.
916 if (!errorReported &&
917 (oflag & O_EXCL) && (oflag & O_CREAT)) {
918 openDenied = __LINE__;
919 yaffsfs_SetError(-EEXIST);
920 errorReported = __LINE__;
923 /* Check file permissions */
924 if (readRequested && !(obj->yst_mode & S_IRUSR))
925 openDenied = __LINE__;
927 if (writeRequested && !(obj->yst_mode & S_IWUSR))
928 openDenied = __LINE__;
930 if (!errorReported && writeRequested &&
931 obj->my_dev->read_only) {
932 openDenied = __LINE__;
933 yaffsfs_SetError(-EROFS);
934 errorReported = __LINE__;
937 if (openDenied && !errorReported) {
938 yaffsfs_SetError(-EACCES);
939 errorReported = __LINE__;
942 /* Check sharing of an existing object. */
944 struct yaffsfs_FileDes *fdx;
947 sharedReadAllowed = 1;
948 sharedWriteAllowed = 1;
951 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
952 fdx = &yaffsfs_fd[i];
953 if (fdx->handleCount > 0 &&
955 yaffsfs_inode[fdx->inodeId].iObj
958 sharedReadAllowed = 0;
959 if (!fdx->shareWrite)
960 sharedWriteAllowed = 0;
968 if ((!sharedReadAllowed && readRequested) ||
969 (!shareRead && alreadyReading) ||
970 (!sharedWriteAllowed && writeRequested) ||
971 (!shareWrite && alreadyWriting)) {
972 openDenied = __LINE__;
973 yaffsfs_SetError(-EBUSY);
974 errorReported = __LINE__;
980 /* If we could not open an existing object, then let's see if
981 * the directory exists. If not, error.
983 if (!obj && !errorReported) {
984 dir = yaffsfs_FindDirectory(reldir, path, &name, 0,
986 if (!dir && notDir) {
987 yaffsfs_SetError(-ENOTDIR);
988 errorReported = __LINE__;
990 yaffsfs_SetError(-ELOOP);
991 errorReported = __LINE__;
993 yaffsfs_SetError(-ENOENT);
994 errorReported = __LINE__;
998 if (!obj && dir && !errorReported && (oflag & O_CREAT)) {
999 /* Let's see if we can create this file */
1000 if (dir->my_dev->read_only) {
1001 yaffsfs_SetError(-EROFS);
1002 errorReported = __LINE__;
1003 } else if (yaffsfs_TooManyObjects(dir->my_dev)) {
1004 yaffsfs_SetError(-ENFILE);
1005 errorReported = __LINE__;
1007 obj = yaffs_create_file(dir, name, mode, 0, 0);
1009 if (!obj && !errorReported) {
1010 yaffsfs_SetError(-ENOSPC);
1011 errorReported = __LINE__;
1015 if (!obj && dir && !errorReported && !(oflag & O_CREAT)) {
1016 yaffsfs_SetError(-ENOENT);
1017 errorReported = __LINE__;
1020 if (obj && !openDenied) {
1021 int inodeId = yaffsfs_GetInodeIdForObject(obj);
1025 * Todo: Fix any problem if inodes run out,
1026 * That can't happen if the number of inode
1027 * items >= number of handles.
1031 fd->inodeId = inodeId;
1032 fd->reading = readRequested;
1033 fd->writing = writeRequested;
1034 fd->append = (oflag & O_APPEND) ? 1 : 0;
1035 fd->shareRead = shareRead;
1036 fd->shareWrite = shareWrite;
1044 /* Hook inode to object */
1045 obj->my_inode = (void *)&yaffsfs_inode[inodeId];
1047 if (!is_dir && (oflag & O_TRUNC) && fd->writing)
1048 yaffs_resize_file(obj, 0);
1051 yaffsfs_closedir_no_lock(dsc);
1053 yaffsfs_PutHandle(handle);
1055 yaffsfs_SetError(0); /* Problem */
1065 int yaffs_open_sharing_reldev(struct yaffs_dev *dev, const YCHAR *path, int oflag,
1066 int mode, int sharing)
1068 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path,
1069 oflag, mode, sharing);
1072 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
1074 return yaffs_open_sharing_reldir(NULL, path, oflag, mode, sharing);
1077 int yaffs_open_reldir(struct yaffs_obj *reldir,const YCHAR *path, int oflag, int mode)
1079 return yaffs_open_sharing_reldir(reldir, path, oflag, mode,
1080 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1083 int yaffs_open_reldev(struct yaffs_dev *dev,const YCHAR *path, int oflag, int mode)
1085 return yaffs_open_sharing_reldir(ROOT_DIR(dev), path, oflag, mode,
1086 YAFFS_SHARE_READ | YAFFS_SHARE_WRITE);
1089 int yaffs_open(const YCHAR *path, int oflag, int mode)
1091 return yaffs_open_reldir(NULL, path, oflag, mode);
1094 static int yaffs_Dofsync(int handle, int datasync)
1097 struct yaffs_obj *obj;
1101 obj = yaffsfs_HandleToObject(handle);
1104 yaffsfs_SetError(-EBADF);
1105 else if (obj->my_dev->read_only)
1106 yaffsfs_SetError(-EROFS);
1108 yaffs_flush_file(obj, 1, datasync, 0);
1117 int yaffs_fsync(int handle)
1119 return yaffs_Dofsync(handle, 0);
1122 int yaffs_flush(int handle)
1124 return yaffs_fsync(handle);
1127 int yaffs_fdatasync(int handle)
1129 return yaffs_Dofsync(handle, 1);
1132 int yaffs_close(int handle)
1134 struct yaffsfs_Handle *h = NULL;
1135 struct yaffsfs_FileDes *f;
1136 struct yaffs_obj *obj = NULL;
1141 h = yaffsfs_HandleToPointer(handle);
1142 f = yaffsfs_HandleToFileDes(handle);
1143 obj = yaffsfs_HandleToObject(handle);
1145 if (!h || !obj || !f)
1146 yaffsfs_SetError(-EBADF);
1150 yaffs_flush_file(obj, 1, 0, 1);
1151 yaffsfs_PutHandle(handle);
1160 static int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte,
1161 int isPread, Y_LOFF_T offset)
1163 struct yaffsfs_FileDes *fd = NULL;
1164 struct yaffs_obj *obj = NULL;
1166 Y_LOFF_T startPos = 0;
1167 Y_LOFF_T endPos = 0;
1172 u8 *buf = (u8 *) vbuf;
1174 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 1) < 0) {
1175 yaffsfs_SetError(-EFAULT);
1180 fd = yaffsfs_HandleToFileDes(handle);
1181 obj = yaffsfs_HandleToObject(handle);
1185 yaffsfs_SetError(-EBADF);
1187 } else if (!fd->reading) {
1188 /* Not a reading handle */
1189 yaffsfs_SetError(-EINVAL);
1191 } else if (nbyte > YAFFS_MAX_RW_SIZE) {
1192 yaffsfs_SetError(-EINVAL);
1198 startPos = fd->v.position;
1202 if (yaffs_get_obj_length(obj) > pos)
1203 maxRead = yaffs_get_obj_length(obj) - pos;
1207 if (nbyte > maxRead)
1210 yaffsfs_GetHandle(handle);
1212 endPos = pos + nbyte;
1214 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1215 nbyte > YAFFS_MAX_RW_SIZE ||
1216 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1222 nToRead = YAFFSFS_RW_SIZE -
1223 (pos & (YAFFSFS_RW_SIZE - 1));
1224 if (nToRead > (int)nbyte)
1228 * Need to reverify object in case the device was
1229 * unmounted in another thread.
1231 obj = yaffsfs_HandleToObject(handle);
1235 nRead = yaffs_file_rd(obj, buf, pos, nToRead);
1243 if (nRead == nToRead)
1246 nbyte = 0; /* no more to read */
1255 yaffsfs_PutHandle(handle);
1259 fd->v.position = startPos + totalRead;
1261 yaffsfs_SetError(-EINVAL);
1268 return (totalRead >= 0) ? totalRead : -1;
1272 int yaffs_read(int handle, void *buf, unsigned int nbyte)
1274 return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
1277 int yaffs_pread(int handle, void *buf, unsigned int nbyte, Y_LOFF_T offset)
1279 return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
1282 static int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte,
1283 int isPwrite, Y_LOFF_T offset)
1285 struct yaffsfs_FileDes *fd = NULL;
1286 struct yaffs_obj *obj = NULL;
1288 Y_LOFF_T startPos = 0;
1291 int totalWritten = 0;
1292 int write_trhrough = 0;
1294 const u8 *buf = (const u8 *)vbuf;
1296 if (yaffsfs_CheckMemRegion(vbuf, nbyte, 0) < 0) {
1297 yaffsfs_SetError(-EFAULT);
1302 fd = yaffsfs_HandleToFileDes(handle);
1303 obj = yaffsfs_HandleToObject(handle);
1307 yaffsfs_SetError(-EBADF);
1309 } else if (!fd->writing) {
1310 yaffsfs_SetError(-EINVAL);
1312 } else if (obj->my_dev->read_only) {
1313 yaffsfs_SetError(-EROFS);
1317 startPos = yaffs_get_obj_length(obj);
1321 startPos = fd->v.position;
1323 yaffsfs_GetHandle(handle);
1325 endPos = pos + nbyte;
1327 if (pos < 0 || pos > YAFFS_MAX_FILE_SIZE ||
1328 nbyte > YAFFS_MAX_RW_SIZE ||
1329 endPos < 0 || endPos > YAFFS_MAX_FILE_SIZE) {
1336 nToWrite = YAFFSFS_RW_SIZE -
1337 (pos & (YAFFSFS_RW_SIZE - 1));
1338 if (nToWrite > (int)nbyte)
1342 * Need to reverify object in case the device was
1343 * remounted or unmounted in another thread.
1345 obj = yaffsfs_HandleToObject(handle);
1346 if (!obj || obj->my_dev->read_only)
1350 yaffs_wr_file(obj, buf, pos, nToWrite,
1353 totalWritten += nWritten;
1358 if (nWritten == nToWrite)
1363 if (nWritten < 1 && totalWritten < 1) {
1364 yaffsfs_SetError(-ENOSPC);
1374 yaffsfs_PutHandle(handle);
1377 if (totalWritten > 0)
1378 fd->v.position = startPos + totalWritten;
1380 yaffsfs_SetError(-EINVAL);
1386 return (totalWritten >= 0) ? totalWritten : -1;
1389 int yaffs_write(int fd, const void *buf, unsigned int nbyte)
1391 return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
1394 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset)
1396 return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
1399 int yaffs_truncate_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1402 struct yaffs_obj *obj = NULL;
1403 struct yaffs_obj *dir = NULL;
1404 int result = YAFFS_FAIL;
1408 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1409 yaffsfs_SetError(-EFAULT);
1413 if (yaffsfs_CheckPath(path) < 0) {
1414 yaffsfs_SetError(-ENAMETOOLONG);
1420 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1421 obj = yaffsfs_FollowLink(obj, 0, &loop);
1424 yaffsfs_SetError(-ENOTDIR);
1426 yaffsfs_SetError(-ELOOP);
1427 else if (!dir || !obj)
1428 yaffsfs_SetError(-ENOENT);
1429 else if (obj->my_dev->read_only)
1430 yaffsfs_SetError(-EROFS);
1431 else if (obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
1432 yaffsfs_SetError(-EISDIR);
1433 else if (obj->my_dev->read_only)
1434 yaffsfs_SetError(-EROFS);
1435 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1436 yaffsfs_SetError(-EINVAL);
1438 result = yaffs_resize_file(obj, new_size);
1442 return (result) ? 0 : -1;
1445 int yaffs_truncate_reldev(struct yaffs_dev *dev, const YCHAR *path,
1448 return yaffs_truncate_reldir(ROOT_DIR(dev), path, new_size);
1451 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size)
1453 return yaffs_truncate_reldir(NULL, path, new_size);
1456 int yaffs_ftruncate(int handle, Y_LOFF_T new_size)
1458 struct yaffsfs_FileDes *fd = NULL;
1459 struct yaffs_obj *obj = NULL;
1463 fd = yaffsfs_HandleToFileDes(handle);
1464 obj = yaffsfs_HandleToObject(handle);
1468 yaffsfs_SetError(-EBADF);
1469 else if (!fd->writing)
1470 yaffsfs_SetError(-EINVAL);
1471 else if (obj->my_dev->read_only)
1472 yaffsfs_SetError(-EROFS);
1473 else if (new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
1474 yaffsfs_SetError(-EINVAL);
1476 /* resize the file */
1477 result = yaffs_resize_file(obj, new_size);
1480 return (result) ? 0 : -1;
1484 Y_LOFF_T yaffs_lseek(int handle, Y_LOFF_T offset, int whence)
1486 struct yaffsfs_FileDes *fd = NULL;
1487 struct yaffs_obj *obj = NULL;
1489 Y_LOFF_T fSize = -1;
1492 fd = yaffsfs_HandleToFileDes(handle);
1493 obj = yaffsfs_HandleToObject(handle);
1496 yaffsfs_SetError(-EBADF);
1497 else if (offset > YAFFS_MAX_FILE_SIZE)
1498 yaffsfs_SetError(-EINVAL);
1500 if (whence == SEEK_SET) {
1503 } else if (whence == SEEK_CUR) {
1504 if ((fd->v.position + offset) >= 0)
1505 pos = (fd->v.position + offset);
1506 } else if (whence == SEEK_END) {
1507 fSize = yaffs_get_obj_length(obj);
1508 if (fSize >= 0 && (fSize + offset) >= 0)
1509 pos = fSize + offset;
1512 if (pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE)
1513 fd->v.position = pos;
1515 yaffsfs_SetError(-EINVAL);
1525 static int yaffsfs_DoUnlink_reldir(struct yaffs_obj *reldir,
1526 const YCHAR *path, int isDirectory)
1528 struct yaffs_obj *dir = NULL;
1529 struct yaffs_obj *obj = NULL;
1531 int result = YAFFS_FAIL;
1535 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
1536 yaffsfs_SetError(-EFAULT);
1540 if (yaffsfs_CheckPath(path) < 0) {
1541 yaffsfs_SetError(-ENAMETOOLONG);
1547 obj = yaffsfs_FindObject(reldir, path, 0, 0, NULL, NULL, NULL);
1548 dir = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
1551 yaffsfs_SetError(-ENOTDIR);
1553 yaffsfs_SetError(-ELOOP);
1555 yaffsfs_SetError(-ENOENT);
1556 else if (yaffs_strncmp(name, _Y("."), 2) == 0)
1557 yaffsfs_SetError(-EINVAL);
1559 yaffsfs_SetError(-ENOENT);
1560 else if (obj->my_dev->read_only)
1561 yaffsfs_SetError(-EROFS);
1562 else if (!isDirectory &&
1563 obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1564 yaffsfs_SetError(-EISDIR);
1565 else if (isDirectory &&
1566 obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1567 yaffsfs_SetError(-ENOTDIR);
1568 else if (isDirectory && obj == obj->my_dev->root_dir)
1569 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1571 result = yaffs_unlinker(dir, name);
1573 if (result == YAFFS_FAIL && isDirectory)
1574 yaffsfs_SetError(-ENOTEMPTY);
1579 return (result == YAFFS_FAIL) ? -1 : 0;
1582 int yaffs_unlink_reldir(struct yaffs_obj *reldir, const YCHAR *path)
1584 return yaffsfs_DoUnlink_reldir(reldir, path, 0);
1587 int yaffs_unlink_reldev(struct yaffs_dev *dev, const YCHAR *path)
1589 return yaffsfs_DoUnlink_reldir(ROOT_DIR(dev), path, 0);
1592 int yaffs_unlink(const YCHAR *path)
1594 return yaffs_unlink_reldir(NULL, path);
1597 int yaffs_funlink(int fd)
1599 struct yaffs_obj *obj;
1603 obj = yaffsfs_HandleToObject(fd);
1606 yaffsfs_SetError(-EBADF);
1607 else if (obj->my_dev->read_only)
1608 yaffsfs_SetError(-EROFS);
1609 else if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1610 !(list_empty(&obj->variant.dir_variant.children)))
1611 yaffsfs_SetError(-ENOTEMPTY);
1612 else if (obj == obj->my_dev->root_dir)
1613 yaffsfs_SetError(-EBUSY); /* Can't rmdir a root */
1614 else if (yaffs_unlink_obj(obj) == YAFFS_OK)
1622 int yaffs_fgetfl(int fd, int *flags)
1624 struct yaffsfs_FileDes *fdp = yaffsfs_HandleToFileDes(fd);
1629 if(!flags || !fdp) {
1630 yaffsfs_SetError(-EINVAL);
1633 if (fdp->reading && fdp->writing)
1635 else if (fdp->writing)
1647 static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1649 if (obj && obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY &&
1650 newobj && newobj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1656 static int rename_dir_over_file(struct yaffs_obj *obj, struct yaffs_obj *newobj)
1658 if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
1659 newobj && newobj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
1665 int yaffs_rename_reldir(struct yaffs_obj *reldir,
1666 const YCHAR *oldPath, const YCHAR *newPath)
1668 struct yaffs_obj *olddir = NULL;
1669 struct yaffs_obj *newdir = NULL;
1670 struct yaffs_obj *obj = NULL;
1671 struct yaffs_obj *newobj = NULL;
1674 int result = YAFFS_FAIL;
1675 int rename_allowed = 1;
1681 YCHAR *alt_newpath = NULL;
1683 if (yaffsfs_CheckMemRegion(oldPath, 0, 0) < 0 ||
1684 yaffsfs_CheckMemRegion(newPath, 0, 0) < 0) {
1685 yaffsfs_SetError(-EFAULT);
1689 if (yaffsfs_CheckPath(oldPath) < 0 || yaffsfs_CheckPath(newPath) < 0) {
1690 yaffsfs_SetError(-ENAMETOOLONG);
1694 if (yaffsfs_alt_dir_path(newPath, &alt_newpath) < 0) {
1695 yaffsfs_SetError(-ENOMEM);
1699 newPath = alt_newpath;
1703 olddir = yaffsfs_FindDirectory(reldir, oldPath, &oldname, 0,
1704 ¬OldDir, &oldLoop);
1705 newdir = yaffsfs_FindDirectory(reldir, newPath, &newname, 0,
1706 ¬NewDir, &newLoop);
1707 obj = yaffsfs_FindObject(reldir, oldPath, 0, 0, NULL, NULL, NULL);
1708 newobj = yaffsfs_FindObject(reldir, newPath, 0, 0, NULL, NULL, NULL);
1710 /* If the object being renamed is a directory and the
1711 * path ended with a "/" then the olddir == obj.
1712 * We pass through NULL for the old name to tell the lower layers
1713 * to use olddir as the object.
1719 if ((!olddir && notOldDir) || (!newdir && notNewDir)) {
1720 yaffsfs_SetError(-ENOTDIR);
1722 } else if (oldLoop || newLoop) {
1723 yaffsfs_SetError(-ELOOP);
1725 } else if (olddir && oldname &&
1726 yaffs_strncmp(oldname, _Y("."), 2) == 0) {
1727 yaffsfs_SetError(-EINVAL);
1729 } else if (!olddir || !newdir || !obj) {
1730 yaffsfs_SetError(-ENOENT);
1732 } else if (obj->my_dev->read_only) {
1733 yaffsfs_SetError(-EROFS);
1735 } else if (rename_file_over_dir(obj, newobj)) {
1736 yaffsfs_SetError(-EISDIR);
1738 } else if (rename_dir_over_file(obj, newobj)) {
1739 yaffsfs_SetError(-ENOTDIR);
1741 } else if (yaffs_is_non_empty_dir(newobj)) {
1742 yaffsfs_SetError(-ENOTEMPTY);
1744 } else if (olddir->my_dev != newdir->my_dev) {
1745 /* Rename must be on same device */
1746 yaffsfs_SetError(-EXDEV);
1748 } else if (obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
1750 * It is a directory, check that it is not being renamed to
1751 * being its own decendent.
1752 * Do this by tracing from the new directory back to the root,
1756 struct yaffs_obj *xx = newdir;
1758 while (rename_allowed && xx) {
1763 if (!rename_allowed)
1764 yaffsfs_SetError(-EINVAL);
1768 result = yaffs_rename_obj(olddir, oldname, newdir, newname);
1774 return (result == YAFFS_FAIL) ? -1 : 0;
1777 int yaffs_rename_reldev(struct yaffs_dev *dev, const YCHAR *oldPath,
1778 const YCHAR *newPath)
1780 return yaffs_rename_reldir(ROOT_DIR(dev), oldPath, newPath);
1782 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
1784 return yaffs_rename_reldir(NULL, oldPath, newPath);
1787 static int yaffsfs_DoStat(struct yaffs_obj *obj, struct yaffs_stat *buf)
1791 obj = yaffs_get_equivalent_obj(obj);
1795 buf->st_ino = obj->obj_id;
1796 buf->st_mode = obj->yst_mode & ~S_IFMT;
1798 if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
1799 buf->st_mode |= S_IFDIR;
1800 else if (obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
1801 buf->st_mode |= S_IFLNK;
1802 else if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE)
1803 buf->st_mode |= S_IFREG;
1805 buf->st_nlink = yaffs_get_obj_link_count(obj);
1808 buf->st_rdev = obj->yst_rdev;
1809 buf->st_size = yaffs_get_obj_length(obj);
1810 buf->st_blksize = obj->my_dev->data_bytes_per_chunk;
1811 buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
1813 #if CONFIG_YAFFS_WINCE
1814 buf->yst_wince_atime[0] = obj->win_atime[0];
1815 buf->yst_wince_atime[1] = obj->win_atime[1];
1816 buf->yst_wince_ctime[0] = obj->win_ctime[0];
1817 buf->yst_wince_ctime[1] = obj->win_ctime[1];
1818 buf->yst_wince_mtime[0] = obj->win_mtime[0];
1819 buf->yst_wince_mtime[1] = obj->win_mtime[1];
1821 buf->yst_atime = obj->yst_atime;
1822 buf->yst_ctime = obj->yst_ctime;
1823 buf->yst_mtime = obj->yst_mtime;
1830 static int yaffsfs_DoStatOrLStat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1831 struct yaffs_stat *buf, int doLStat)
1833 struct yaffs_obj *obj = NULL;
1834 struct yaffs_obj *dir = NULL;
1839 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
1840 yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1841 yaffsfs_SetError(-EFAULT);
1845 if (yaffsfs_CheckPath(path) < 0) {
1846 yaffsfs_SetError(-ENAMETOOLONG);
1852 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1854 if (!doLStat && obj)
1855 obj = yaffsfs_FollowLink(obj, 0, &loop);
1858 yaffsfs_SetError(-ENOTDIR);
1860 yaffsfs_SetError(-ELOOP);
1861 else if (!dir || !obj)
1862 yaffsfs_SetError(-ENOENT);
1864 retVal = yaffsfs_DoStat(obj, buf);
1872 int yaffs_stat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1873 struct yaffs_stat *buf)
1875 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 0);
1878 int yaffs_lstat_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1879 struct yaffs_stat *buf)
1881 return yaffsfs_DoStatOrLStat_reldir(reldir, path, buf, 1);
1884 int yaffs_stat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1885 struct yaffs_stat *buf)
1887 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 0);
1890 int yaffs_lstat_reldev(struct yaffs_dev *dev, const YCHAR *path,
1891 struct yaffs_stat *buf)
1893 return yaffsfs_DoStatOrLStat_reldir(ROOT_DIR(dev), path, buf, 1);
1896 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf)
1898 return yaffs_stat_reldir(NULL, path, buf);
1901 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf)
1903 return yaffs_lstat_reldir(NULL, path, buf);
1906 int yaffs_fstat(int fd, struct yaffs_stat *buf)
1908 struct yaffs_obj *obj;
1912 if (yaffsfs_CheckMemRegion(buf, sizeof(*buf), 1) < 0) {
1913 yaffsfs_SetError(-EFAULT);
1918 obj = yaffsfs_HandleToObject(fd);
1921 retVal = yaffsfs_DoStat(obj, buf);
1924 yaffsfs_SetError(-EBADF);
1931 static int yaffsfs_DoUtime(struct yaffs_obj *obj,
1932 const struct yaffs_utimbuf *buf)
1935 struct yaffs_utimbuf local;
1937 obj = yaffs_get_equivalent_obj(obj);
1939 if (obj && obj->my_dev->read_only) {
1940 yaffsfs_SetError(-EROFS);
1944 #if !CONFIG_YAFFS_WINCE
1946 local.actime = Y_CURRENT_TIME;
1947 local.modtime = local.actime;
1954 obj->yst_atime = buf->actime;
1955 obj->yst_mtime = buf->modtime;
1957 result = yaffs_flush_file(obj, 0, 0, 0);
1958 retVal = result == YAFFS_OK ? 0 : -1;
1965 int yaffs_utime_reldir(struct yaffs_obj *reldir, const YCHAR *path,
1966 const struct yaffs_utimbuf *buf)
1968 struct yaffs_obj *obj = NULL;
1969 struct yaffs_obj *dir = NULL;
1975 yaffsfs_SetError(-EFAULT);
1979 if (yaffsfs_CheckPath(path) < 0) {
1980 yaffsfs_SetError(-ENAMETOOLONG);
1986 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
1989 yaffsfs_SetError(-ENOTDIR);
1991 yaffsfs_SetError(-ELOOP);
1992 else if (!dir || !obj)
1993 yaffsfs_SetError(-ENOENT);
1995 retVal = yaffsfs_DoUtime(obj, buf);
2003 int yaffs_utime_reldev(struct yaffs_dev *dev, const YCHAR *path,
2004 const struct yaffs_utimbuf *buf)
2006 return yaffs_utime_reldir(ROOT_DIR(dev), path, buf);
2009 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf)
2011 return yaffs_utime_reldir(NULL, path, buf);
2014 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf)
2016 struct yaffs_obj *obj;
2021 obj = yaffsfs_HandleToObject(fd);
2024 retVal = yaffsfs_DoUtime(obj, buf);
2027 yaffsfs_SetError(-EBADF);
2034 #ifndef CONFIG_YAFFS_WINCE
2035 /* xattrib functions */
2037 static int yaffs_do_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2038 const char *name, const void *data, int size,
2039 int flags, int follow)
2041 struct yaffs_obj *obj;
2042 struct yaffs_obj *dir;
2048 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2049 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2050 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2051 yaffsfs_SetError(-EFAULT);
2055 if (yaffsfs_CheckPath(path) < 0) {
2056 yaffsfs_SetError(-ENAMETOOLONG);
2062 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2065 obj = yaffsfs_FollowLink(obj, 0, &loop);
2068 yaffsfs_SetError(-ENOTDIR);
2070 yaffsfs_SetError(-ELOOP);
2071 else if (!dir || !obj)
2072 yaffsfs_SetError(-ENOENT);
2074 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2076 yaffsfs_SetError(retVal);
2087 int yaffs_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2088 const char *name, const void *data, int size, int flags)
2090 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 1);
2093 int yaffs_setxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
2094 const char *name, const void *data, int size, int flags)
2096 return yaffs_setxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2099 int yaffs_setxattr(const YCHAR *path, const char *name,
2100 const void *data, int size, int flags)
2102 return yaffs_setxattr_reldir(NULL, path, name, data, size, flags);
2105 int yaffs_lsetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path, const char *name,
2106 const void *data, int size, int flags)
2108 return yaffs_do_setxattr_reldir(reldir, path, name, data, size, flags, 0);
2111 int yaffs_lsetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name,
2112 const void *data, int size, int flags)
2114 return yaffs_lsetxattr_reldir(ROOT_DIR(dev), path, name, data, size, flags);
2117 int yaffs_lsetxattr(const YCHAR *path, const char *name,
2118 const void *data, int size, int flags)
2120 return yaffs_lsetxattr_reldir(NULL, path, name, data, size, flags);
2123 int yaffs_fsetxattr(int fd, const char *name,
2124 const void *data, int size, int flags)
2126 struct yaffs_obj *obj;
2130 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2131 yaffsfs_CheckMemRegion(data, size, 0) < 0) {
2132 yaffsfs_SetError(-EFAULT);
2137 obj = yaffsfs_HandleToObject(fd);
2140 yaffsfs_SetError(-EBADF);
2142 retVal = yaffs_set_xattrib(obj, name, data, size, flags);
2144 yaffsfs_SetError(retVal);
2154 static int yaffs_do_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2155 const char *name, void *data, int size, int follow)
2157 struct yaffs_obj *obj;
2158 struct yaffs_obj *dir;
2163 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2164 yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2165 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2166 yaffsfs_SetError(-EFAULT);
2170 if (yaffsfs_CheckPath(path) < 0) {
2171 yaffsfs_SetError(-ENAMETOOLONG);
2177 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2180 obj = yaffsfs_FollowLink(obj, 0, &loop);
2183 yaffsfs_SetError(-ENOTDIR);
2185 yaffsfs_SetError(-ELOOP);
2186 else if (!dir || !obj)
2187 yaffsfs_SetError(-ENOENT);
2189 retVal = yaffs_get_xattrib(obj, name, data, size);
2191 yaffsfs_SetError(retVal);
2201 int yaffs_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2202 const char *name, void *data, int size)
2204 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 1);
2207 int yaffs_getxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2209 return yaffs_getxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2212 int yaffs_getxattr(const YCHAR *path, const char *name, void *data, int size)
2214 return yaffs_getxattr_reldir(NULL, path, name, data, size);
2217 int yaffs_lgetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2218 const char *name, void *data, int size)
2220 return yaffs_do_getxattr_reldir(reldir, path, name, data, size, 0);
2223 int yaffs_lgetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name, void *data, int size)
2225 return yaffs_lgetxattr_reldir(ROOT_DIR(dev), path, name, data, size);
2228 int yaffs_lgetxattr(const YCHAR *path, const char *name, void *data, int size)
2230 return yaffs_lgetxattr_reldir(NULL, path, name, data, size);
2233 int yaffs_fgetxattr(int fd, const char *name, void *data, int size)
2235 struct yaffs_obj *obj;
2239 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0 ||
2240 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2241 yaffsfs_SetError(-EFAULT);
2246 obj = yaffsfs_HandleToObject(fd);
2249 retVal = yaffs_get_xattrib(obj, name, data, size);
2251 yaffsfs_SetError(retVal);
2256 yaffsfs_SetError(-EBADF);
2263 static int yaffs_do_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2264 char *data, int size, int follow)
2266 struct yaffs_obj *obj = NULL;
2267 struct yaffs_obj *dir = NULL;
2272 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2273 yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2274 yaffsfs_SetError(-EFAULT);
2278 if (yaffsfs_CheckPath(path) < 0) {
2279 yaffsfs_SetError(-ENAMETOOLONG);
2285 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2288 obj = yaffsfs_FollowLink(obj, 0, &loop);
2291 yaffsfs_SetError(-ENOTDIR);
2293 yaffsfs_SetError(-ELOOP);
2294 else if (!dir || !obj)
2295 yaffsfs_SetError(-ENOENT);
2297 retVal = yaffs_list_xattrib(obj, data, size);
2299 yaffsfs_SetError(retVal);
2310 int yaffs_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2311 char *data, int size)
2313 return yaffs_do_listxattr_reldir(reldir, path, data, size, 1);
2316 int yaffs_listxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2318 return yaffs_listxattr_reldir(ROOT_DIR(dev), path, data, size);
2321 int yaffs_listxattr(const YCHAR *path, char *data, int size)
2323 return yaffs_listxattr_reldir(NULL, path, data, size);
2326 int yaffs_llistxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2327 char *data, int size)
2329 return yaffs_do_listxattr_reldir(reldir, path, data, size, 0);
2332 int yaffs_llistxattr_reldev(struct yaffs_dev *dev, const YCHAR *path, char *data, int size)
2334 return yaffs_llistxattr_reldir(ROOT_DIR(dev), path, data, size);
2337 int yaffs_llistxattr(const YCHAR *path, char *data, int size)
2339 return yaffs_llistxattr_reldir(NULL, path, data, size);
2342 int yaffs_flistxattr(int fd, char *data, int size)
2344 struct yaffs_obj *obj;
2348 if (yaffsfs_CheckMemRegion(data, size, 1) < 0) {
2349 yaffsfs_SetError(-EFAULT);
2354 obj = yaffsfs_HandleToObject(fd);
2357 retVal = yaffs_list_xattrib(obj, data, size);
2359 yaffsfs_SetError(retVal);
2364 yaffsfs_SetError(-EBADF);
2371 static int yaffs_do_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2372 const char *name, int follow)
2374 struct yaffs_obj *obj = NULL;
2375 struct yaffs_obj *dir = NULL;
2380 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
2381 yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2382 yaffsfs_SetError(-EFAULT);
2386 if (yaffsfs_CheckPath(path) < 0) {
2387 yaffsfs_SetError(-ENAMETOOLONG);
2393 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2396 obj = yaffsfs_FollowLink(obj, 0, &loop);
2399 yaffsfs_SetError(-ENOTDIR);
2401 yaffsfs_SetError(-ELOOP);
2402 else if (!dir || !obj)
2403 yaffsfs_SetError(-ENOENT);
2405 retVal = yaffs_remove_xattrib(obj, name);
2407 yaffsfs_SetError(retVal);
2418 int yaffs_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2421 return yaffs_do_removexattr_reldir(reldir, path, name, 1);
2424 int yaffs_removexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2426 return yaffs_removexattr_reldir(ROOT_DIR(dev), path, name);
2429 int yaffs_removexattr(const YCHAR *path, const char *name)
2431 return yaffs_removexattr_reldir(NULL, path, name);
2434 int yaffs_lremovexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
2437 return yaffs_do_removexattr_reldir(reldir, path, name, 0);
2440 int yaffs_lremovexattr_reldev(struct yaffs_dev *dev, const YCHAR *path, const char *name)
2442 return yaffs_lremovexattr_reldir(ROOT_DIR(dev), path, name);
2445 int yaffs_lremovexattr(const YCHAR *path, const char *name)
2447 return yaffs_lremovexattr_reldir(NULL, path, name);
2450 int yaffs_fremovexattr(int fd, const char *name)
2452 struct yaffs_obj *obj;
2456 if (yaffsfs_CheckMemRegion(name, 0, 0) < 0) {
2457 yaffsfs_SetError(-EFAULT);
2462 obj = yaffsfs_HandleToObject(fd);
2465 retVal = yaffs_remove_xattrib(obj, name);
2467 yaffsfs_SetError(retVal);
2472 yaffsfs_SetError(-EBADF);
2480 #ifdef CONFIG_YAFFS_WINCE
2481 int yaffs_get_wince_times(int fd, unsigned *wctime,
2482 unsigned *watime, unsigned *wmtime)
2484 struct yaffs_obj *obj;
2489 obj = yaffsfs_HandleToObject(fd);
2494 wctime[0] = obj->win_ctime[0];
2495 wctime[1] = obj->win_ctime[1];
2498 watime[0] = obj->win_atime[0];
2499 watime[1] = obj->win_atime[1];
2502 wmtime[0] = obj->win_mtime[0];
2503 wmtime[1] = obj->win_mtime[1];
2509 yaffsfs_SetError(-EBADF);
2516 int yaffs_set_wince_times(int fd,
2517 const unsigned *wctime,
2518 const unsigned *watime, const unsigned *wmtime)
2520 struct yaffs_obj *obj;
2525 obj = yaffsfs_HandleToObject(fd);
2530 obj->win_ctime[0] = wctime[0];
2531 obj->win_ctime[1] = wctime[1];
2534 obj->win_atime[0] = watime[0];
2535 obj->win_atime[1] = watime[1];
2538 obj->win_mtime[0] = wmtime[0];
2539 obj->win_mtime[1] = wmtime[1];
2543 result = yaffs_flush_file(obj, 0, 0, 0);
2547 yaffsfs_SetError(-EBADF);
2556 static int yaffsfs_DoChMod(struct yaffs_obj *obj, mode_t mode)
2561 obj = yaffs_get_equivalent_obj(obj);
2564 obj->yst_mode = mode;
2566 result = yaffs_flush_file(obj, 0, 0, 0);
2569 return result == YAFFS_OK ? 0 : -1;
2572 int yaffs_access_reldir(struct yaffs_obj *reldir, const YCHAR *path, int amode)
2574 struct yaffs_obj *obj = NULL;
2575 struct yaffs_obj *dir = NULL;
2580 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2581 yaffsfs_SetError(-EFAULT);
2585 if (yaffsfs_CheckPath(path) < 0) {
2586 yaffsfs_SetError(-ENAMETOOLONG);
2590 if (amode & ~(R_OK | W_OK | X_OK)) {
2591 yaffsfs_SetError(-EINVAL);
2597 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2598 obj = yaffsfs_FollowLink(obj, 0, &loop);
2601 yaffsfs_SetError(-ENOTDIR);
2603 yaffsfs_SetError(-ELOOP);
2604 else if (!dir || !obj)
2605 yaffsfs_SetError(-ENOENT);
2606 else if ((amode & W_OK) && obj->my_dev->read_only)
2607 yaffsfs_SetError(-EROFS);
2611 if ((amode & R_OK) && !(obj->yst_mode & S_IRUSR))
2613 if ((amode & W_OK) && !(obj->yst_mode & S_IWUSR))
2615 if ((amode & X_OK) && !(obj->yst_mode & S_IXUSR))
2619 yaffsfs_SetError(-EACCES);
2630 int yaffs_access_reldev(struct yaffs_dev *dev, const YCHAR *path, int amode)
2632 return yaffs_access_reldir(ROOT_DIR(dev), path, amode);
2635 int yaffs_access(const YCHAR *path, int amode)
2637 return yaffs_access_reldir(NULL, path, amode);
2640 int yaffs_chmod_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2642 struct yaffs_obj *obj = NULL;
2643 struct yaffs_obj *dir = NULL;
2648 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2649 yaffsfs_SetError(-EFAULT);
2653 if (yaffsfs_CheckPath(path) < 0) {
2654 yaffsfs_SetError(-ENAMETOOLONG);
2658 if (mode & ~(0777)) {
2659 yaffsfs_SetError(-EINVAL);
2665 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
2666 obj = yaffsfs_FollowLink(obj, 0, &loop);
2669 yaffsfs_SetError(-ENOTDIR);
2671 yaffsfs_SetError(-ELOOP);
2672 else if (!dir || !obj)
2673 yaffsfs_SetError(-ENOENT);
2674 else if (obj->my_dev->read_only)
2675 yaffsfs_SetError(-EROFS);
2677 retVal = yaffsfs_DoChMod(obj, mode);
2685 int yaffs_chmod_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2687 return yaffs_chmod_reldir(ROOT_DIR(dev), path, mode);
2690 int yaffs_chmod(const YCHAR *path, mode_t mode)
2692 return yaffs_chmod_reldir(NULL, path, mode);
2695 int yaffs_fchmod(int fd, mode_t mode)
2697 struct yaffs_obj *obj;
2700 if (mode & ~(0777)) {
2701 yaffsfs_SetError(-EINVAL);
2706 obj = yaffsfs_HandleToObject(fd);
2709 yaffsfs_SetError(-EBADF);
2710 else if (obj->my_dev->read_only)
2711 yaffsfs_SetError(-EROFS);
2713 retVal = yaffsfs_DoChMod(obj, mode);
2720 int yaffs_mkdir_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode)
2722 struct yaffs_obj *parent = NULL;
2723 struct yaffs_obj *dir = NULL;
2725 YCHAR *alt_path = NULL;
2730 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2731 yaffsfs_SetError(-EFAULT);
2735 if (yaffsfs_CheckPath(path) < 0) {
2736 yaffsfs_SetError(-ENAMETOOLONG);
2740 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2741 yaffsfs_SetError(-ENOMEM);
2748 parent = yaffsfs_FindDirectory(reldir, path, &name, 0, ¬Dir, &loop);
2749 if (!parent && notDir)
2750 yaffsfs_SetError(-ENOTDIR);
2752 yaffsfs_SetError(-ELOOP);
2754 yaffsfs_SetError(-ENOENT);
2755 else if (yaffsfs_TooManyObjects(parent->my_dev))
2756 yaffsfs_SetError(-ENFILE);
2757 else if (yaffs_strnlen(name, 5) == 0) {
2758 /* Trying to make the root itself */
2759 yaffsfs_SetError(-EEXIST);
2760 } else if (parent->my_dev->read_only)
2761 yaffsfs_SetError(-EROFS);
2763 dir = yaffs_create_dir(parent, name, mode, 0, 0);
2766 else if (yaffs_find_by_name(parent, name))
2767 yaffsfs_SetError(-EEXIST); /* name exists */
2769 yaffsfs_SetError(-ENOSPC); /* assume no space */
2779 int yaffs_mkdir_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode)
2781 return yaffs_mkdir_reldir(ROOT_DIR(dev), path, mode);
2784 int yaffs_mkdir(const YCHAR *path, mode_t mode)
2786 return yaffs_mkdir_reldir(NULL, path, mode);
2789 int yaffs_rmdir_reldir(struct yaffs_obj *reldir, const YCHAR *path)
2794 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2795 yaffsfs_SetError(-EFAULT);
2799 if (yaffsfs_CheckPath(path) < 0) {
2800 yaffsfs_SetError(-ENAMETOOLONG);
2804 if (yaffsfs_alt_dir_path(path, &alt_path) < 0) {
2805 yaffsfs_SetError(-ENOMEM);
2810 result = yaffsfs_DoUnlink_reldir(reldir, path, 1);
2817 int yaffs_rmdir_reldev(struct yaffs_dev *dev, const YCHAR *path)
2819 return yaffs_rmdir_reldir(ROOT_DIR(dev), path);
2822 int yaffs_rmdir(const YCHAR *path)
2824 return yaffs_rmdir_reldir(NULL, path);
2828 * The mount/unmount/sync functions act on devices rather than reldirs.
2830 void *yaffs_getdev(const YCHAR *path)
2832 struct yaffs_dev *dev = NULL;
2834 dev = yaffsfs_FindDevice(path, &dummy);
2838 int yaffs_mount_common(struct yaffs_dev *dev, const YCHAR *path,
2839 int read_only, int skip_checkpt)
2842 int result = YAFFS_FAIL;
2845 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2846 yaffsfs_SetError(-EFAULT);
2850 yaffs_trace(YAFFS_TRACE_MOUNT, "yaffs: Mounting %s", path);
2852 if (yaffsfs_CheckPath(path) < 0) {
2853 yaffsfs_SetError(-ENAMETOOLONG);
2860 yaffsfs_InitHandles();
2863 dev = yaffsfs_FindMountPoint(path);
2866 if (!dev->is_mounted) {
2867 dev->read_only = read_only ? 1 : 0;
2869 u8 skip = dev->param.skip_checkpt_rd;
2870 dev->param.skip_checkpt_rd = 1;
2871 result = yaffs_guts_initialise(dev);
2872 dev->param.skip_checkpt_rd = skip;
2874 result = yaffs_guts_initialise(dev);
2877 if (result == YAFFS_FAIL)
2878 yaffsfs_SetError(-ENOMEM);
2879 retVal = result ? 0 : -1;
2882 yaffsfs_SetError(-EBUSY);
2884 yaffsfs_SetError(-ENODEV);
2891 int yaffs_mount3_reldev(struct yaffs_dev *dev, int read_only, int skip_checkpt)
2893 return yaffs_mount_common(dev, NULL, read_only, skip_checkpt);
2896 int yaffs_mount3(const YCHAR *path, int read_only, int skip_checkpt)
2898 return yaffs_mount_common(NULL, path, read_only, skip_checkpt);
2901 int yaffs_mount2_reldev(struct yaffs_dev *dev, int readonly)
2903 return yaffs_mount_common(dev, NULL, readonly, 0);
2906 int yaffs_mount2(const YCHAR *path, int readonly)
2908 return yaffs_mount_common(NULL, path, readonly, 0);
2911 int yaffs_mount_reldev(struct yaffs_dev *dev)
2913 return yaffs_mount_common(dev, NULL, 0, 0);
2916 int yaffs_mount(const YCHAR *path)
2918 return yaffs_mount_common(NULL, path, 0, 0);
2921 static int yaffs_sync_common(struct yaffs_dev *dev,
2929 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2930 yaffsfs_SetError(-EFAULT);
2934 if (yaffsfs_CheckPath(path) < 0) {
2935 yaffsfs_SetError(-ENAMETOOLONG);
2942 dev = yaffsfs_FindDevice(path, &dummy);
2945 if (!dev->is_mounted)
2946 yaffsfs_SetError(-EINVAL);
2947 else if (dev->read_only)
2948 yaffsfs_SetError(-EROFS);
2951 yaffs_flush_whole_cache(dev, 0);
2953 yaffs_checkpoint_save(dev);
2958 yaffsfs_SetError(-ENODEV);
2964 int yaffs_sync_files_reldev(struct yaffs_dev *dev)
2966 return yaffs_sync_common(dev, NULL, 0);
2969 int yaffs_sync_files(const YCHAR *path)
2971 return yaffs_sync_common(NULL, path, 0);
2974 int yaffs_sync_reldev(struct yaffs_dev *dev)
2976 return yaffs_sync_common(dev, NULL, 1);
2979 int yaffs_sync(const YCHAR *path)
2981 return yaffs_sync_common(NULL, path, 1);
2985 static int yaffsfs_bg_gc_common(struct yaffs_dev *dev,
2993 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
2994 yaffsfs_SetError(-EFAULT);
2998 if (yaffsfs_CheckPath(path) < 0) {
2999 yaffsfs_SetError(-ENAMETOOLONG);
3006 dev = yaffsfs_FindDevice(path, &dummy);
3009 if (!dev->is_mounted)
3010 yaffsfs_SetError(-EINVAL);
3012 retVal = yaffs_bg_gc(dev, urgency);
3014 yaffsfs_SetError(-ENODEV);
3020 /* Background gc functions.
3021 * These return 0 when bg done or greater than 0 when gc has been
3022 * done and there is still a lot of garbage to be cleaned up.
3025 int yaffs_do_background_gc(const YCHAR *path, int urgency)
3027 return yaffsfs_bg_gc_common(NULL, path, urgency);
3030 int yaffs_do_background_gc_reldev(struct yaffs_dev *dev, int urgency)
3032 return yaffsfs_bg_gc_common(dev, NULL, urgency);
3035 static int yaffsfs_IsDevBusy(struct yaffs_dev *dev)
3038 struct yaffs_obj *obj;
3040 for (i = 0; i < YAFFSFS_N_HANDLES; i++) {
3041 obj = yaffsfs_HandleToObject(i);
3042 if (obj && obj->my_dev == dev)
3048 int yaffs_remount_common(struct yaffs_dev *dev, const YCHAR *path,
3049 int force, int read_only)
3053 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3054 yaffsfs_SetError(-EFAULT);
3058 if (yaffsfs_CheckPath(path) < 0) {
3059 yaffsfs_SetError(-ENAMETOOLONG);
3065 dev = yaffsfs_FindMountPoint(path);
3068 if (dev->is_mounted) {
3069 yaffs_flush_whole_cache(dev, 0);
3071 if (force || !yaffsfs_IsDevBusy(dev)) {
3073 yaffs_checkpoint_save(dev);
3074 dev->read_only = read_only ? 1 : 0;
3077 yaffsfs_SetError(-EBUSY);
3080 yaffsfs_SetError(-EINVAL);
3083 yaffsfs_SetError(-ENODEV);
3090 int yaffs_remount_reldev(struct yaffs_dev *dev, int force, int read_only)
3092 return yaffs_remount_common(dev, NULL, force, read_only);
3094 int yaffs_remount(const YCHAR *path, int force, int read_only)
3096 return yaffs_remount_common(NULL, path, force, read_only);
3099 int yaffs_unmount2_common(struct yaffs_dev *dev, const YCHAR *path, int force)
3103 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3104 yaffsfs_SetError(-EFAULT);
3108 if (yaffsfs_CheckPath(path) < 0) {
3109 yaffsfs_SetError(-ENAMETOOLONG);
3115 dev = yaffsfs_FindMountPoint(path);
3118 if (dev->is_mounted) {
3120 yaffs_flush_whole_cache(dev, 0);
3121 yaffs_checkpoint_save(dev);
3122 inUse = yaffsfs_IsDevBusy(dev);
3123 if (!inUse || force) {
3125 yaffsfs_BreakDeviceHandles(dev);
3126 yaffs_deinitialise(dev);
3130 yaffsfs_SetError(-EBUSY);
3133 yaffsfs_SetError(-EINVAL);
3136 yaffsfs_SetError(-ENODEV);
3143 int yaffs_unmount2_reldev(struct yaffs_dev *dev, int force)
3145 return yaffs_unmount2_common(dev, NULL, force);
3148 int yaffs_unmount2(const YCHAR *path, int force)
3150 return yaffs_unmount2_common(NULL, path, force);
3153 int yaffs_unmount_reldev(struct yaffs_dev *dev)
3155 return yaffs_unmount2_reldev(dev, 0);
3158 int yaffs_unmount(const YCHAR *path)
3160 return yaffs_unmount2(path, 0);
3163 int yaffs_format_common(struct yaffs_dev *dev,
3166 int force_unmount_flag,
3174 yaffsfs_SetError(-EFAULT);
3178 if (yaffsfs_CheckPath(path) < 0) {
3179 yaffsfs_SetError(-ENAMETOOLONG);
3186 dev = yaffsfs_FindMountPoint(path);
3189 int was_mounted = dev->is_mounted;
3191 if (dev->is_mounted && unmount_flag) {
3193 yaffs_flush_whole_cache(dev, 0);
3194 yaffs_checkpoint_save(dev);
3195 inUse = yaffsfs_IsDevBusy(dev);
3196 if (!inUse || force_unmount_flag) {
3198 yaffsfs_BreakDeviceHandles(dev);
3199 yaffs_deinitialise(dev);
3203 if(dev->is_mounted) {
3204 yaffsfs_SetError(-EBUSY);
3207 yaffs_guts_format_dev(dev);
3208 if(was_mounted && remount_flag) {
3209 result = yaffs_guts_initialise(dev);
3210 if (result == YAFFS_FAIL) {
3211 yaffsfs_SetError(-ENOMEM);
3217 yaffsfs_SetError(-ENODEV);
3226 int yaffs_format_reldev(struct yaffs_dev *dev,
3228 int force_unmount_flag,
3231 return yaffs_format_common(dev, NULL, unmount_flag,
3232 force_unmount_flag, remount_flag);
3235 int yaffs_format(const YCHAR *path,
3237 int force_unmount_flag,
3240 return yaffs_format_common(NULL, path, unmount_flag,
3241 force_unmount_flag, remount_flag);
3244 Y_LOFF_T yaffs_freespace_common(struct yaffs_dev *dev, const YCHAR *path)
3246 Y_LOFF_T retVal = -1;
3250 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3251 yaffsfs_SetError(-EFAULT);
3255 if (yaffsfs_CheckPath(path) < 0) {
3256 yaffsfs_SetError(-ENAMETOOLONG);
3263 dev = yaffsfs_FindDevice(path, &dummy);
3264 if (dev && dev->is_mounted) {
3265 retVal = yaffs_get_n_free_chunks(dev);
3266 retVal *= dev->data_bytes_per_chunk;
3269 yaffsfs_SetError(-EINVAL);
3275 Y_LOFF_T yaffs_freespace_reldev(struct yaffs_dev *dev)
3277 return yaffs_freespace_common(dev, NULL);
3280 Y_LOFF_T yaffs_freespace(const YCHAR *path)
3282 return yaffs_freespace_common(NULL, path);
3285 Y_LOFF_T yaffs_totalspace_common(struct yaffs_dev *dev, const YCHAR *path)
3287 Y_LOFF_T retVal = -1;
3291 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3292 yaffsfs_SetError(-EFAULT);
3296 if (yaffsfs_CheckPath(path) < 0) {
3297 yaffsfs_SetError(-ENAMETOOLONG);
3304 dev = yaffsfs_FindDevice(path, &dummy);
3305 if (dev && dev->is_mounted) {
3306 retVal = (dev->param.end_block - dev->param.start_block + 1) -
3307 dev->param.n_reserved_blocks;
3308 retVal *= dev->param.chunks_per_block;
3309 retVal *= dev->data_bytes_per_chunk;
3312 yaffsfs_SetError(-EINVAL);
3318 Y_LOFF_T yaffs_totalspace_reldev(struct yaffs_dev *dev)
3320 return yaffs_totalspace_common(dev, NULL);
3323 Y_LOFF_T yaffs_totalspace(const YCHAR *path)
3325 return yaffs_totalspace_common(NULL, path);
3328 int yaffs_inodecount_common(struct yaffs_dev *dev, const YCHAR *path)
3330 Y_LOFF_T retVal = -1;
3334 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3335 yaffsfs_SetError(-EFAULT);
3339 if (yaffsfs_CheckPath(path) < 0) {
3340 yaffsfs_SetError(-ENAMETOOLONG);
3347 dev = yaffsfs_FindDevice(path, &dummy);
3348 if (dev && dev->is_mounted) {
3349 int n_obj = dev->n_obj;
3350 if (n_obj > dev->n_hardlinks)
3351 retVal = n_obj - dev->n_hardlinks;
3355 yaffsfs_SetError(-EINVAL);
3361 int yaffs_inodecount_reldev(struct yaffs_dev *dev)
3363 return yaffs_inodecount_common(dev, NULL);
3366 int yaffs_inodecount(const YCHAR *path)
3368 return yaffs_inodecount_common(NULL, path);
3371 void yaffs_add_device(struct yaffs_dev *dev)
3373 struct list_head *cfg;
3374 /* First check that the device is not in the list. */
3376 list_for_each(cfg, &yaffsfs_deviceList) {
3377 if (dev == list_entry(cfg, struct yaffs_dev, dev_list))
3381 dev->is_mounted = 0;
3382 dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
3384 if (!dev->dev_list.next)
3385 INIT_LIST_HEAD(&dev->dev_list);
3387 list_add(&dev->dev_list, &yaffsfs_deviceList);
3392 void yaffs_remove_device(struct yaffs_dev *dev)
3394 list_del_init(&dev->dev_list);
3397 /* Functions to iterate through devices. NB Use with extreme care! */
3399 static struct list_head *dev_iterator;
3400 void yaffs_dev_rewind(void)
3402 dev_iterator = yaffsfs_deviceList.next;
3405 struct yaffs_dev *yaffs_next_dev(void)
3407 struct yaffs_dev *retval;
3411 if (dev_iterator == &yaffsfs_deviceList)
3414 retval = list_entry(dev_iterator, struct yaffs_dev, dev_list);
3415 dev_iterator = dev_iterator->next;
3419 /* Directory search stuff. */
3421 static struct list_head search_contexts;
3423 static void yaffsfs_SetDirRewound(struct yaffsfs_DirSearchContext *dsc)
3427 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3431 if (list_empty(&dsc->dirObj->variant.dir_variant.children))
3432 dsc->nextReturn = NULL;
3435 list_entry(dsc->dirObj->variant.dir_variant.
3436 children.next, struct yaffs_obj,
3439 /* Hey someone isn't playing nice! */
3443 static void yaffsfs_DirAdvance(struct yaffsfs_DirSearchContext *dsc)
3447 dsc->dirObj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
3449 if (dsc->nextReturn == NULL ||
3450 list_empty(&dsc->dirObj->variant.dir_variant.children))
3451 dsc->nextReturn = NULL;
3453 struct list_head *next = dsc->nextReturn->siblings.next;
3455 if (next == &dsc->dirObj->variant.dir_variant.children)
3456 dsc->nextReturn = NULL; /* end of list */
3458 dsc->nextReturn = list_entry(next,
3463 /* Hey someone isn't playing nice! */
3467 static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj)
3470 struct list_head *i;
3471 struct yaffsfs_DirSearchContext *dsc;
3473 /* if search contexts not initilised then skip */
3474 if (!search_contexts.next)
3477 /* Iterate through the directory search contexts.
3478 * If any are the one being removed, then advance the dsc to
3479 * the next one to prevent a hanging ptr.
3481 list_for_each(i, &search_contexts) {
3483 dsc = list_entry(i, struct yaffsfs_DirSearchContext,
3485 if (dsc->nextReturn == obj)
3486 yaffsfs_DirAdvance(dsc);
3492 static yaffs_DIR *yaffsfs_opendir_reldir_no_lock(struct yaffs_obj *reldir,
3493 const YCHAR *dirname)
3495 yaffs_DIR *dir = NULL;
3496 struct yaffs_obj *obj = NULL;
3497 struct yaffsfs_DirSearchContext *dsc = NULL;
3501 if (yaffsfs_CheckMemRegion(dirname, 0, 0) < 0) {
3502 yaffsfs_SetError(-EFAULT);
3506 if (yaffsfs_CheckPath(dirname) < 0) {
3507 yaffsfs_SetError(-ENAMETOOLONG);
3511 obj = yaffsfs_FindObject(reldir, dirname, 0, 1, NULL, ¬Dir, &loop);
3512 obj = yaffsfs_FollowLink(obj, 0, &loop);
3515 yaffsfs_SetError(-ENOTDIR);
3517 yaffsfs_SetError(-ELOOP);
3519 yaffsfs_SetError(-ENOENT);
3520 else if (obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
3521 yaffsfs_SetError(-ENOTDIR);
3525 for (i = 0, dsc = NULL; i < YAFFSFS_N_DSC && !dsc; i++) {
3526 if (!yaffsfs_dsc[i].inUse)
3527 dsc = &yaffsfs_dsc[i];
3530 dir = (yaffs_DIR *) dsc;
3533 memset(dsc, 0, sizeof(struct yaffsfs_DirSearchContext));
3536 yaffs_strncpy(dsc->name, dirname, NAME_MAX);
3537 INIT_LIST_HEAD(&dsc->others);
3539 if (!search_contexts.next)
3540 INIT_LIST_HEAD(&search_contexts);
3542 list_add(&dsc->others, &search_contexts);
3543 yaffsfs_SetDirRewound(dsc);
3549 yaffs_DIR *yaffs_opendir_reldir(struct yaffs_obj *reldir, const YCHAR *dirname)
3554 ret = yaffsfs_opendir_reldir_no_lock(reldir, dirname);
3559 yaffs_DIR *yaffs_opendir_reldev(struct yaffs_dev *dev, const YCHAR *dirname)
3561 return yaffs_opendir_reldir(ROOT_DIR(dev), dirname);
3564 yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
3566 return yaffs_opendir_reldir(NULL, dirname);
3569 struct yaffs_dirent *yaffsfs_readdir_no_lock(yaffs_DIR * dirp)
3571 struct yaffsfs_DirSearchContext *dsc;
3572 struct yaffs_dirent *retVal = NULL;
3574 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3577 if (dsc && dsc->inUse) {
3578 yaffsfs_SetError(0);
3579 if (dsc->nextReturn) {
3581 yaffs_get_equivalent_obj(dsc->nextReturn)->obj_id;
3582 dsc->de.d_dont_use = 0;
3583 dsc->de.d_off = dsc->offset++;
3584 yaffs_get_obj_name(dsc->nextReturn,
3585 dsc->de.d_name, NAME_MAX);
3586 if (yaffs_strnlen(dsc->de.d_name, NAME_MAX + 1) == 0) {
3587 /* this should not happen! */
3588 yaffs_strcpy(dsc->de.d_name, _Y("zz"));
3590 dsc->de.d_reclen = sizeof(struct yaffs_dirent);
3592 yaffsfs_DirAdvance(dsc);
3596 yaffsfs_SetError(-EBADF);
3601 struct yaffs_dirent *yaffs_readdir(yaffs_DIR * dirp)
3603 struct yaffs_dirent *ret;
3606 ret = yaffsfs_readdir_no_lock(dirp);
3611 static void yaffsfs_rewinddir_no_lock(yaffs_DIR *dirp)
3613 struct yaffsfs_DirSearchContext *dsc;
3615 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3617 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0)
3620 yaffsfs_SetDirRewound(dsc);
3624 void yaffs_rewinddir(yaffs_DIR *dirp)
3627 yaffsfs_rewinddir_no_lock(dirp);
3631 struct yaffs_dirent *yaffs_readdir_fd(int fd)
3633 struct yaffs_dirent *ret = NULL;
3634 struct yaffsfs_FileDes *f;
3637 f = yaffsfs_HandleToFileDes(fd);
3639 ret = yaffsfs_readdir_no_lock(f->v.dir);
3644 void yaffs_rewinddir_fd(int fd)
3646 struct yaffsfs_FileDes *f;
3649 f = yaffsfs_HandleToFileDes(fd);
3651 yaffsfs_rewinddir_no_lock(f->v.dir);
3656 static int yaffsfs_closedir_no_lock(yaffs_DIR *dirp)
3658 struct yaffsfs_DirSearchContext *dsc;
3660 dsc = (struct yaffsfs_DirSearchContext *) dirp;
3662 if (yaffsfs_CheckMemRegion(dirp, sizeof(*dsc), 0) < 0) {
3663 yaffsfs_SetError(-EFAULT);
3668 list_del(&dsc->others); /* unhook from list */
3673 int yaffs_closedir(yaffs_DIR *dirp)
3678 ret = yaffsfs_closedir_no_lock(dirp);
3683 /* End of directory stuff */
3685 int yaffs_symlink_reldir(struct yaffs_obj *reldir,
3686 const YCHAR *oldpath, const YCHAR *newpath)
3688 struct yaffs_obj *parent = NULL;
3689 struct yaffs_obj *obj;
3692 int mode = 0; /* ignore for now */
3696 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3697 yaffsfs_CheckMemRegion(newpath, 0, 0) < 0) {
3698 yaffsfs_SetError(-EFAULT);
3702 if (yaffsfs_CheckPath(newpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3703 yaffsfs_SetError(-ENAMETOOLONG);
3708 parent = yaffsfs_FindDirectory(reldir, newpath, &name, 0, ¬Dir, &loop);
3709 if (!parent && notDir)
3710 yaffsfs_SetError(-ENOTDIR);
3712 yaffsfs_SetError(-ELOOP);
3713 else if (!parent || yaffs_strnlen(name, 5) < 1)
3714 yaffsfs_SetError(-ENOENT);
3715 else if (yaffsfs_TooManyObjects(parent->my_dev))
3716 yaffsfs_SetError(-ENFILE);
3717 else if (parent->my_dev->read_only)
3718 yaffsfs_SetError(-EROFS);
3720 obj = yaffs_create_symlink(parent, name, mode, 0, 0, oldpath);
3723 else if (yaffsfs_FindObject(reldir, newpath, 0, 0,
3725 yaffsfs_SetError(-EEXIST);
3727 yaffsfs_SetError(-ENOSPC);
3735 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
3737 return yaffs_symlink_reldir(NULL, oldpath, newpath);
3740 int yaffs_readlink_reldir(struct yaffs_obj *reldir,const YCHAR *path,
3741 YCHAR *buf, int bufsiz)
3743 struct yaffs_obj *obj = NULL;
3744 struct yaffs_obj *dir = NULL;
3749 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0 ||
3750 yaffsfs_CheckMemRegion(buf, bufsiz, 1) < 0) {
3751 yaffsfs_SetError(-EFAULT);
3757 obj = yaffsfs_FindObject(reldir, path, 0, 1, &dir, ¬Dir, &loop);
3760 yaffsfs_SetError(-ENOTDIR);
3762 yaffsfs_SetError(-ELOOP);
3763 else if (!dir || !obj)
3764 yaffsfs_SetError(-ENOENT);
3765 else if (obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
3766 yaffsfs_SetError(-EINVAL);
3768 YCHAR *alias = obj->variant.symlink_variant.alias;
3769 memset(buf, 0, bufsiz);
3770 yaffs_strncpy(buf, alias, bufsiz - 1);
3776 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
3778 return yaffs_readlink_reldir(NULL, path, buf, bufsiz);
3781 int yaffs_link_reldir(struct yaffs_obj *reldir,
3782 const YCHAR *oldpath, const YCHAR *linkpath)
3784 /* Creates a link called newpath to existing oldpath */
3785 struct yaffs_obj *obj = NULL;
3786 struct yaffs_obj *lnk = NULL;
3787 struct yaffs_obj *obj_dir = NULL;
3788 struct yaffs_obj *lnk_dir = NULL;
3796 if (yaffsfs_CheckMemRegion(oldpath, 0, 0) < 0 ||
3797 yaffsfs_CheckMemRegion(linkpath, 0, 0) < 0) {
3798 yaffsfs_SetError(-EFAULT);
3802 if (yaffsfs_CheckPath(linkpath) < 0 || yaffsfs_CheckPath(oldpath) < 0) {
3803 yaffsfs_SetError(-ENAMETOOLONG);
3809 obj = yaffsfs_FindObject(reldir, oldpath, 0, 1,
3810 &obj_dir, ¬DirObj, &objLoop);
3811 lnk = yaffsfs_FindObject(reldir, linkpath, 0, 0, NULL, NULL, NULL);
3812 lnk_dir = yaffsfs_FindDirectory(reldir, linkpath, &newname,
3813 0, ¬DirLnk, &lnkLoop);
3815 if ((!obj_dir && notDirObj) || (!lnk_dir && notDirLnk))
3816 yaffsfs_SetError(-ENOTDIR);
3817 else if (objLoop || lnkLoop)
3818 yaffsfs_SetError(-ELOOP);
3819 else if (!obj_dir || !lnk_dir || !obj)
3820 yaffsfs_SetError(-ENOENT);
3821 else if (obj->my_dev->read_only)
3822 yaffsfs_SetError(-EROFS);
3823 else if (yaffsfs_TooManyObjects(obj->my_dev))
3824 yaffsfs_SetError(-ENFILE);
3826 yaffsfs_SetError(-EEXIST);
3827 else if (lnk_dir->my_dev != obj->my_dev)
3828 yaffsfs_SetError(-EXDEV);
3830 retVal = yaffsfs_CheckNameLength(newname);
3833 lnk = yaffs_link_obj(lnk_dir, newname, obj);
3837 yaffsfs_SetError(-ENOSPC);
3846 int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
3848 return yaffs_link_reldir(NULL, oldpath, linkpath);
3851 int yaffs_mknod_reldir(struct yaffs_obj *reldir, const YCHAR *pathname,
3852 mode_t mode, dev_t dev_val)
3859 yaffsfs_SetError(-EINVAL);
3863 int yaffs_mknod_reldev(struct yaffs_dev *dev, const YCHAR *pathname, mode_t mode, dev_t dev_val)
3865 return yaffs_mknod_reldir(ROOT_DIR(dev), pathname, mode, dev_val);
3868 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev_val)
3870 return yaffs_mknod_reldir(NULL, pathname, mode, dev_val);
3874 * D E B U G F U N C T I O N S
3879 * Returns number of handles attached to the object
3881 int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3883 struct yaffs_obj *obj;
3885 if (yaffsfs_CheckMemRegion(path, 0, 0) < 0) {
3886 yaffsfs_SetError(-EFAULT);
3890 if (yaffsfs_CheckPath(path) < 0) {
3891 yaffsfs_SetError(-ENAMETOOLONG);
3895 obj = yaffsfs_FindObject(reldir, path, 0, 1, NULL, NULL, NULL);
3898 return yaffsfs_CountHandles(obj);
3903 int yaffs_n_handles(const YCHAR *path)
3905 return yaffs_n_handles_reldir(NULL, path);
3908 int yaffs_get_error(void)
3910 return yaffsfs_GetLastError();
3913 int yaffs_set_error(int error)
3915 yaffsfs_SetError(error);
3919 struct yaffs_obj * yaffs_get_obj_from_fd(int handle)
3921 return yaffsfs_HandleToObject(handle);
3924 int yaffs_dump_dev_reldir(struct yaffs_obj *reldir, const YCHAR *path)
3934 reldir = yaffsfs_FindRoot(path, &rest);
3937 struct yaffs_dev *dev = reldir->my_dev;
3940 "n_page_writes.......... %d\n"
3941 "n_page_reads........... %d\n"
3942 "n_erasures....... %d\n"
3943 "n_gc_copies............ %d\n"
3944 "garbageCollections... %d\n"
3945 "passiveGarbageColl'ns %d\n"
3951 dev->garbageCollections, dev->passiveGarbageCollections);
3958 int yaffs_dump_dev(const YCHAR *path)
3960 return yaffs_dump_dev_reldir(NULL, path);