Mercurial > yaffs-ecoscentric
annotate direct/yaffsfs.c @ 215:b08276bd7b2d
Clean up some yaffs1 mode issues.
| author | charles |
|---|---|
| date | Wed, 02 Jul 2008 21:17:41 +0100 |
| parents | fad21fd1971d |
| children | 6dbe40ae9e54 |
| rev | line source |
|---|---|
| 1 | 1 /* |
| 173 | 2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. |
| 1 | 3 * |
| 173 | 4 * Copyright (C) 2002-2007 Aleph One Ltd. |
| 5 * for Toby Churchill Ltd and Brightstar Engineering | |
| 1 | 6 * |
| 7 * Created by Charles Manning <charles@aleph1.co.uk> | |
| 8 * | |
| 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. | |
| 12 */ | |
| 215 | 13 |
| 1 | 14 #include "yaffsfs.h" |
| 15 #include "yaffs_guts.h" | |
| 16 #include "yaffscfg.h" | |
| 17 #include <string.h> // for memset | |
| 18 #include "yportenv.h" | |
| 19 | |
| 20 #define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5 | |
| 21 | |
| 22 #ifndef NULL | |
| 23 #define NULL ((void *)0) | |
| 24 #endif | |
| 25 | |
| 26 | |
| 27 const char *yaffsfs_c_version="$Id$"; | |
| 28 | |
| 29 // configurationList is the list of devices that are supported | |
| 30 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList; | |
| 31 | |
| 32 | |
| 84 | 33 /* Some forward references */ |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
34 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path, int symDepth); |
| 84 | 35 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj); |
| 1 | 36 |
| 37 | |
| 38 // Handle management. | |
| 215 | 39 // |
| 1 | 40 |
| 185 | 41 |
| 42 unsigned int yaffs_wr_attempts; | |
| 43 | |
| 1 | 44 typedef struct |
| 45 { | |
| 46 __u8 inUse:1; // this handle is in use | |
| 47 __u8 readOnly:1; // this handle is read only | |
| 48 __u8 append:1; // append only | |
| 49 __u8 exclusive:1; // exclusive | |
| 50 __u32 position; // current position in file | |
| 51 yaffs_Object *obj; // the object | |
| 52 }yaffsfs_Handle; | |
| 53 | |
| 54 | |
| 55 static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES]; | |
| 56 | |
| 57 // yaffsfs_InitHandle | |
| 58 /// Inilitalise handles on start-up. | |
| 59 // | |
| 60 static int yaffsfs_InitHandles(void) | |
| 61 { | |
| 62 int i; | |
| 63 for(i = 0; i < YAFFSFS_N_HANDLES; i++) | |
| 64 { | |
| 65 yaffsfs_handle[i].inUse = 0; | |
| 66 yaffsfs_handle[i].obj = NULL; | |
| 67 } | |
| 68 return 0; | |
| 69 } | |
| 70 | |
| 71 yaffsfs_Handle *yaffsfs_GetHandlePointer(int h) | |
| 72 { | |
| 73 if(h < 0 || h >= YAFFSFS_N_HANDLES) | |
| 74 { | |
| 75 return NULL; | |
| 76 } | |
| 215 | 77 |
| 1 | 78 return &yaffsfs_handle[h]; |
| 79 } | |
| 80 | |
| 81 yaffs_Object *yaffsfs_GetHandleObject(int handle) | |
| 82 { | |
| 83 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle); | |
| 84 | |
| 85 if(h && h->inUse) | |
| 86 { | |
| 87 return h->obj; | |
| 88 } | |
| 215 | 89 |
| 1 | 90 return NULL; |
| 91 } | |
| 92 | |
| 93 | |
| 94 //yaffsfs_GetHandle | |
| 95 // Grab a handle (when opening a file) | |
| 96 // | |
| 97 | |
| 98 static int yaffsfs_GetHandle(void) | |
| 99 { | |
| 100 int i; | |
| 101 yaffsfs_Handle *h; | |
| 215 | 102 |
| 1 | 103 for(i = 0; i < YAFFSFS_N_HANDLES; i++) |
| 104 { | |
| 105 h = yaffsfs_GetHandlePointer(i); | |
| 106 if(!h) | |
| 107 { | |
| 108 // todo bug: should never happen | |
| 109 } | |
| 110 if(!h->inUse) | |
| 111 { | |
| 112 memset(h,0,sizeof(yaffsfs_Handle)); | |
| 113 h->inUse=1; | |
| 114 return i; | |
| 115 } | |
| 116 } | |
| 117 return -1; | |
| 118 } | |
| 119 | |
| 120 // yaffs_PutHandle | |
| 121 // Let go of a handle (when closing a file) | |
| 122 // | |
| 123 static int yaffsfs_PutHandle(int handle) | |
| 124 { | |
| 125 yaffsfs_Handle *h = yaffsfs_GetHandlePointer(handle); | |
| 215 | 126 |
| 1 | 127 if(h) |
| 128 { | |
| 129 h->inUse = 0; | |
| 130 h->obj = NULL; | |
| 131 } | |
| 132 return 0; | |
| 133 } | |
| 134 | |
| 135 | |
| 136 | |
| 137 // Stuff to search for a directory from a path | |
| 138 | |
| 139 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
140 int yaffsfs_Match(YCHAR a, YCHAR b) |
| 1 | 141 { |
| 142 // case sensitive | |
| 143 return (a == b); | |
| 144 } | |
| 145 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
146 int yaffsfs_IsPathDivider(YCHAR ch) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
147 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
148 YCHAR *str = YAFFS_PATH_DIVIDERS; |
| 215 | 149 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
150 while(*str){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
151 if(*str == ch) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
152 return 1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
153 str++; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
154 } |
| 215 | 155 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
156 return 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
157 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
158 |
| 1 | 159 // yaffsfs_FindDevice |
| 160 // yaffsfs_FindRoot | |
| 161 // Scan the configuration list to find the root. | |
| 94 | 162 // Curveballs: Should match paths that end in '/' too |
| 163 // Curveball2 Might have "/x/ and "/x/y". Need to return the longest match | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
164 static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath) |
| 1 | 165 { |
| 166 yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
167 const YCHAR *leftOver; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
168 const YCHAR *p; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
169 yaffs_Device *retval = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
170 int thisMatchLength; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
171 int longestMatch = -1; |
| 215 | 172 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
173 // Check all configs, choose the one that: |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
174 // 1) Actually matches a prefix (ie /a amd /abc will not match |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
175 // 2) Matches the longest. |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
176 while(cfg && cfg->prefix && cfg->dev) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
177 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
178 leftOver = path; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
179 p = cfg->prefix; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
180 thisMatchLength = 0; |
| 215 | 181 |
| 182 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
183 // Strip off any leading /'s |
| 215 | 184 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
185 while(yaffsfs_IsPathDivider(*p)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
186 p++; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
187 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
188 while(yaffsfs_IsPathDivider(*leftOver)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
189 leftOver++; |
| 215 | 190 |
| 191 while(*p && *leftOver && | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
192 yaffsfs_Match(*p,*leftOver)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
193 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
194 p++; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
195 leftOver++; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
196 thisMatchLength++; |
| 215 | 197 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
198 // Skip over any multiple /'s to treat them as one or |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
199 // skip over a trailling / in the prefix, but not the matching string |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
200 while(yaffsfs_IsPathDivider(*p) && |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
201 (yaffsfs_IsPathDivider(*(p+1)) || !(*(p+1)))) |
| 215 | 202 p++; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
203 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
204 // Only skip over multiple /'s |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
205 while(yaffsfs_IsPathDivider(*leftOver) && |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
206 yaffsfs_IsPathDivider(*(leftOver+1))) |
| 215 | 207 leftOver++; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
208 } |
| 215 | 209 |
| 210 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
211 if((!*p ) && |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
212 (!*leftOver || yaffsfs_IsPathDivider(*leftOver)) && // no more in this path name part |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
213 (thisMatchLength > longestMatch)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
214 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
215 // Matched prefix |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
216 *restOfPath = (YCHAR *)leftOver; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
217 retval = cfg->dev; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
218 longestMatch = thisMatchLength; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
219 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
220 cfg++; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
221 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
222 return retval; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
223 } |
| 215 | 224 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
225 #if 0 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
226 static yaffs_Device *yaffsfs_FindDevice(const YCHAR *path, YCHAR **restOfPath) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
227 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
228 yaffsfs_DeviceConfiguration *cfg = yaffsfs_configurationList; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
229 const YCHAR *leftOver; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
230 const YCHAR *p; |
| 94 | 231 yaffs_Device *retval = NULL; |
| 232 int thisMatchLength; | |
| 233 int longestMatch = -1; | |
| 215 | 234 |
| 94 | 235 // Check all configs, choose the one that: |
| 236 // 1) Actually matches a prefix (ie /a amd /abc will not match | |
| 237 // 2) Matches the longest. | |
| 1 | 238 while(cfg && cfg->prefix && cfg->dev) |
| 239 { | |
| 240 leftOver = path; | |
| 241 p = cfg->prefix; | |
| 94 | 242 thisMatchLength = 0; |
| 215 | 243 |
| 244 while(*p && //unmatched part of prefix | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
245 !(yaffsfs_IsPathDivider(*p) && (p[1] == 0)) && // the rest of the prefix is not / (to catch / at end) |
| 215 | 246 *leftOver && |
| 94 | 247 yaffsfs_Match(*p,*leftOver)) |
| 1 | 248 { |
| 249 p++; | |
| 250 leftOver++; | |
| 94 | 251 thisMatchLength++; |
| 1 | 252 } |
| 215 | 253 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
254 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
255 if((!*p || (yaffsfs_IsPathDivider(*p) && (p[1] == 0))) && // end of prefix |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
256 (!*leftOver || yaffsfs_IsPathDivider(*leftOver)) && // no more in this path name part |
| 94 | 257 (thisMatchLength > longestMatch)) |
| 1 | 258 { |
| 259 // Matched prefix | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
260 *restOfPath = (YCHAR *)leftOver; |
| 94 | 261 retval = cfg->dev; |
| 262 longestMatch = thisMatchLength; | |
| 1 | 263 } |
| 264 cfg++; | |
| 265 } | |
| 94 | 266 return retval; |
| 1 | 267 } |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
268 #endif |
| 1 | 269 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
270 static yaffs_Object *yaffsfs_FindRoot(const YCHAR *path, YCHAR **restOfPath) |
| 1 | 271 { |
| 272 | |
| 273 yaffs_Device *dev; | |
| 215 | 274 |
| 1 | 275 dev= yaffsfs_FindDevice(path,restOfPath); |
| 276 if(dev && dev->isMounted) | |
| 277 { | |
| 278 return dev->rootDir; | |
| 279 } | |
| 280 return NULL; | |
| 281 } | |
| 282 | |
| 283 static yaffs_Object *yaffsfs_FollowLink(yaffs_Object *obj,int symDepth) | |
| 284 { | |
| 285 | |
| 286 while(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) | |
| 287 { | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
288 YCHAR *alias = obj->variant.symLinkVariant.alias; |
| 215 | 289 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
290 if(yaffsfs_IsPathDivider(*alias)) |
| 1 | 291 { |
| 292 // Starts with a /, need to scan from root up | |
| 293 obj = yaffsfs_FindObject(NULL,alias,symDepth++); | |
| 294 } | |
| 295 else | |
| 296 { | |
| 297 // Relative to here, so use the parent of the symlink as a start | |
| 298 obj = yaffsfs_FindObject(obj->parent,alias,symDepth++); | |
| 299 } | |
| 300 } | |
| 301 return obj; | |
| 302 } | |
| 303 | |
| 304 | |
| 305 // yaffsfs_FindDirectory | |
| 306 // Parse a path to determine the directory and the name within the directory. | |
| 307 // | |
| 308 // eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx" | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
309 static yaffs_Object *yaffsfs_DoFindDirectory(yaffs_Object *startDir,const YCHAR *path,YCHAR **name,int symDepth) |
| 1 | 310 { |
| 311 yaffs_Object *dir; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
312 YCHAR *restOfPath; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
313 YCHAR str[YAFFS_MAX_NAME_LENGTH+1]; |
| 1 | 314 int i; |
| 215 | 315 |
| 1 | 316 if(symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES) |
| 317 { | |
| 318 return NULL; | |
| 319 } | |
| 215 | 320 |
| 1 | 321 if(startDir) |
| 322 { | |
| 323 dir = startDir; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
324 restOfPath = (YCHAR *)path; |
| 1 | 325 } |
| 326 else | |
| 327 { | |
| 328 dir = yaffsfs_FindRoot(path,&restOfPath); | |
| 329 } | |
| 215 | 330 |
| 1 | 331 while(dir) |
| 215 | 332 { |
| 1 | 333 // parse off /. |
| 215 | 334 // curve ball: also throw away surplus '/' |
| 1 | 335 // eg. "/ram/x////ff" gets treated the same as "/ram/x/ff" |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
336 while(yaffsfs_IsPathDivider(*restOfPath)) |
| 1 | 337 { |
| 338 restOfPath++; // get rid of '/' | |
| 339 } | |
| 215 | 340 |
| 1 | 341 *name = restOfPath; |
| 342 i = 0; | |
| 215 | 343 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
344 while(*restOfPath && !yaffsfs_IsPathDivider(*restOfPath)) |
| 1 | 345 { |
| 346 if (i < YAFFS_MAX_NAME_LENGTH) | |
| 347 { | |
| 348 str[i] = *restOfPath; | |
| 349 str[i+1] = '\0'; | |
| 350 i++; | |
| 351 } | |
| 352 restOfPath++; | |
| 353 } | |
| 215 | 354 |
| 1 | 355 if(!*restOfPath) |
| 356 { | |
| 357 // got to the end of the string | |
| 358 return dir; | |
| 359 } | |
| 360 else | |
| 361 { | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
362 if(yaffs_strcmp(str,_Y(".")) == 0) |
| 1 | 363 { |
| 364 // Do nothing | |
| 365 } | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
366 else if(yaffs_strcmp(str,_Y("..")) == 0) |
| 1 | 367 { |
| 368 dir = dir->parent; | |
| 369 } | |
| 370 else | |
| 371 { | |
| 372 dir = yaffs_FindObjectByName(dir,str); | |
| 215 | 373 |
| 1 | 374 while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK) |
| 375 { | |
| 215 | 376 |
| 1 | 377 dir = yaffsfs_FollowLink(dir,symDepth); |
| 215 | 378 |
| 1 | 379 } |
| 215 | 380 |
| 1 | 381 if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) |
| 382 { | |
| 383 dir = NULL; | |
| 384 } | |
| 385 } | |
| 386 } | |
| 387 } | |
| 388 // directory did not exist. | |
| 389 return NULL; | |
| 390 } | |
| 391 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
392 static yaffs_Object *yaffsfs_FindDirectory(yaffs_Object *relativeDirectory,const YCHAR *path,YCHAR **name,int symDepth) |
| 1 | 393 { |
| 394 return yaffsfs_DoFindDirectory(relativeDirectory,path,name,symDepth); | |
| 395 } | |
| 396 | |
| 397 // yaffsfs_FindObject turns a path for an existing object into the object | |
| 215 | 398 // |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
399 static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path,int symDepth) |
| 1 | 400 { |
| 401 yaffs_Object *dir; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
402 YCHAR *name; |
| 215 | 403 |
| 1 | 404 dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth); |
| 215 | 405 |
| 1 | 406 if(dir && *name) |
| 407 { | |
| 408 return yaffs_FindObjectByName(dir,name); | |
| 409 } | |
| 215 | 410 |
| 1 | 411 return dir; |
| 412 } | |
| 413 | |
| 414 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
415 int yaffs_dup(int fd) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
416 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
417 int newHandle = -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
418 yaffsfs_Handle *oldPtr = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
419 yaffsfs_Handle *newPtr = NULL; |
| 215 | 420 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
421 yaffsfs_Lock(); |
| 215 | 422 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
423 oldPtr = yaffsfs_GetHandlePointer(fd); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
424 if(oldPtr && oldPtr->inUse) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
425 newHandle = yaffsfs_GetHandle(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
426 if(newHandle >= 0) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
427 newPtr = yaffsfs_GetHandlePointer(newHandle); |
| 215 | 428 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
429 if(newPtr){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
430 *newPtr = *oldPtr; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
431 return newHandle; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
432 } |
| 215 | 433 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
434 if(!oldPtr) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
435 yaffsfs_SetError(-EBADF); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
436 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
437 yaffsfs_SetError(-ENOMEM); |
| 215 | 438 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
439 return -1; |
| 215 | 440 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
441 } |
| 1 | 442 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
443 int yaffs_open(const YCHAR *path, int oflag, int mode) |
| 1 | 444 { |
| 445 yaffs_Object *obj = NULL; | |
| 446 yaffs_Object *dir = NULL; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
447 YCHAR *name; |
| 1 | 448 int handle = -1; |
| 449 yaffsfs_Handle *h = NULL; | |
| 450 int alreadyOpen = 0; | |
| 451 int alreadyExclusive = 0; | |
| 452 int openDenied = 0; | |
| 453 int symDepth = 0; | |
| 454 int errorReported = 0; | |
| 215 | 455 |
| 1 | 456 int i; |
| 215 | 457 |
| 458 | |
| 1 | 459 // todo sanity check oflag (eg. can't have O_TRUNC without WRONLY or RDWR |
| 215 | 460 |
| 461 | |
| 1 | 462 yaffsfs_Lock(); |
| 215 | 463 |
| 1 | 464 handle = yaffsfs_GetHandle(); |
| 215 | 465 |
| 1 | 466 if(handle >= 0) |
| 467 { | |
| 468 | |
| 469 h = yaffsfs_GetHandlePointer(handle); | |
| 215 | 470 |
| 471 | |
| 1 | 472 // try to find the exisiting object |
| 473 obj = yaffsfs_FindObject(NULL,path,0); | |
| 215 | 474 |
| 1 | 475 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) |
| 476 { | |
| 215 | 477 |
| 1 | 478 obj = yaffsfs_FollowLink(obj,symDepth++); |
| 479 } | |
| 480 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
481 if(obj && obj->variantType != YAFFS_OBJECT_TYPE_FILE) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
482 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
483 obj = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
484 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
485 |
| 1 | 486 if(obj) |
| 487 { | |
| 488 // Check if the object is already in use | |
| 489 alreadyOpen = alreadyExclusive = 0; | |
| 215 | 490 |
| 1 | 491 for(i = 0; i <= YAFFSFS_N_HANDLES; i++) |
| 492 { | |
| 215 | 493 |
| 1 | 494 if(i != handle && |
| 495 yaffsfs_handle[i].inUse && | |
| 496 obj == yaffsfs_handle[i].obj) | |
| 497 { | |
| 498 alreadyOpen = 1; | |
| 499 if(yaffsfs_handle[i].exclusive) | |
| 500 { | |
| 501 alreadyExclusive = 1; | |
| 502 } | |
| 503 } | |
| 504 } | |
| 505 | |
| 506 if(((oflag & O_EXCL) && alreadyOpen) || alreadyExclusive) | |
| 507 { | |
| 508 openDenied = 1; | |
| 509 } | |
| 215 | 510 |
| 1 | 511 // Open should fail if O_CREAT and O_EXCL are specified |
| 512 if((oflag & O_EXCL) && (oflag & O_CREAT)) | |
| 513 { | |
| 514 openDenied = 1; | |
| 515 yaffsfs_SetError(-EEXIST); | |
| 516 errorReported = 1; | |
| 517 } | |
| 215 | 518 |
| 1 | 519 // Check file permissions |
| 520 if( (oflag & (O_RDWR | O_WRONLY)) == 0 && // ie O_RDONLY | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
521 !(obj->yst_mode & S_IREAD)) |
| 1 | 522 { |
| 523 openDenied = 1; | |
| 524 } | |
| 525 | |
| 215 | 526 if( (oflag & O_RDWR) && |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
527 !(obj->yst_mode & S_IREAD)) |
| 1 | 528 { |
| 529 openDenied = 1; | |
| 530 } | |
| 531 | |
| 215 | 532 if( (oflag & (O_RDWR | O_WRONLY)) && |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
533 !(obj->yst_mode & S_IWRITE)) |
| 1 | 534 { |
| 535 openDenied = 1; | |
| 536 } | |
| 215 | 537 |
| 1 | 538 } |
| 215 | 539 |
| 1 | 540 else if((oflag & O_CREAT)) |
| 541 { | |
| 542 // Let's see if we can create this file | |
| 543 dir = yaffsfs_FindDirectory(NULL,path,&name,0); | |
| 544 if(dir) | |
| 545 { | |
| 215 | 546 obj = yaffs_MknodFile(dir,name,mode,0,0); |
| 1 | 547 } |
| 548 else | |
| 549 { | |
| 550 yaffsfs_SetError(-ENOTDIR); | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
551 errorReported = 1; |
| 1 | 552 } |
| 553 } | |
| 215 | 554 |
| 1 | 555 if(obj && !openDenied) |
| 556 { | |
| 557 h->obj = obj; | |
| 558 h->inUse = 1; | |
| 559 h->readOnly = (oflag & (O_WRONLY | O_RDWR)) ? 0 : 1; | |
| 560 h->append = (oflag & O_APPEND) ? 1 : 0; | |
| 561 h->exclusive = (oflag & O_EXCL) ? 1 : 0; | |
| 562 h->position = 0; | |
| 215 | 563 |
| 564 obj->inUse++; | |
| 565 if((oflag & O_TRUNC) && !h->readOnly) | |
| 566 { | |
| 567 yaffs_ResizeFile(obj,0); | |
| 568 } | |
| 569 | |
| 1 | 570 } |
| 571 else | |
| 572 { | |
| 573 yaffsfs_PutHandle(handle); | |
| 574 if(!errorReported) | |
| 575 { | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
576 yaffsfs_SetError(-EACCES); |
| 1 | 577 errorReported = 1; |
| 578 } | |
| 579 handle = -1; | |
| 580 } | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
581 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
582 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
583 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
584 yaffsfs_Unlock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
585 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
586 return handle; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
587 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
588 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
589 int yaffs_flush(int fd) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
590 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
591 yaffsfs_Handle *h = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
592 int retVal = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
593 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
594 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
595 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
596 h = yaffsfs_GetHandlePointer(fd); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
597 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
598 if(h && h->inUse) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
599 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
600 // flush the file |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
601 yaffs_FlushFile(h->obj,1); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
602 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
603 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
604 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
605 // bad handle |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
606 yaffsfs_SetError(-EBADF); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
607 retVal = -1; |
| 1 | 608 } |
| 215 | 609 |
| 1 | 610 yaffsfs_Unlock(); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
611 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
612 return retVal; |
| 1 | 613 } |
| 614 | |
| 215 | 615 |
| 1 | 616 int yaffs_close(int fd) |
| 617 { | |
| 618 yaffsfs_Handle *h = NULL; | |
| 619 int retVal = 0; | |
| 215 | 620 |
| 1 | 621 yaffsfs_Lock(); |
| 622 | |
| 623 h = yaffsfs_GetHandlePointer(fd); | |
| 215 | 624 |
| 1 | 625 if(h && h->inUse) |
| 626 { | |
| 627 // clean up | |
| 628 yaffs_FlushFile(h->obj,1); | |
| 629 h->obj->inUse--; | |
| 630 if(h->obj->inUse <= 0 && h->obj->unlinked) | |
| 631 { | |
| 632 yaffs_DeleteFile(h->obj); | |
| 633 } | |
| 634 yaffsfs_PutHandle(fd); | |
| 635 retVal = 0; | |
| 636 } | |
| 637 else | |
| 638 { | |
| 639 // bad handle | |
| 215 | 640 yaffsfs_SetError(-EBADF); |
| 1 | 641 retVal = -1; |
| 642 } | |
| 215 | 643 |
| 1 | 644 yaffsfs_Unlock(); |
| 215 | 645 |
| 1 | 646 return retVal; |
| 647 } | |
| 648 | |
| 649 int yaffs_read(int fd, void *buf, unsigned int nbyte) | |
| 650 { | |
| 651 yaffsfs_Handle *h = NULL; | |
| 652 yaffs_Object *obj = NULL; | |
| 653 int pos = 0; | |
| 654 int nRead = -1; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
655 unsigned int maxRead; |
| 215 | 656 |
| 1 | 657 yaffsfs_Lock(); |
| 658 h = yaffsfs_GetHandlePointer(fd); | |
| 659 obj = yaffsfs_GetHandleObject(fd); | |
| 215 | 660 |
| 1 | 661 if(!h || !obj) |
| 662 { | |
| 663 // bad handle | |
| 215 | 664 yaffsfs_SetError(-EBADF); |
| 1 | 665 } |
| 666 else if( h && obj) | |
| 667 { | |
| 668 pos= h->position; | |
| 669 if(yaffs_GetObjectFileLength(obj) > pos) | |
| 670 { | |
| 671 maxRead = yaffs_GetObjectFileLength(obj) - pos; | |
| 672 } | |
| 673 else | |
| 674 { | |
| 675 maxRead = 0; | |
| 676 } | |
| 677 | |
| 678 if(nbyte > maxRead) | |
| 679 { | |
| 680 nbyte = maxRead; | |
| 681 } | |
| 682 | |
| 215 | 683 |
| 1 | 684 if(nbyte > 0) |
| 685 { | |
| 686 nRead = yaffs_ReadDataFromFile(obj,buf,pos,nbyte); | |
| 687 if(nRead >= 0) | |
| 688 { | |
| 689 h->position = pos + nRead; | |
| 690 } | |
| 691 else | |
| 692 { | |
| 693 //todo error | |
| 694 } | |
| 695 } | |
| 696 else | |
| 697 { | |
| 698 nRead = 0; | |
| 699 } | |
| 215 | 700 |
| 1 | 701 } |
| 215 | 702 |
| 1 | 703 yaffsfs_Unlock(); |
| 215 | 704 |
| 705 | |
| 1 | 706 return (nRead >= 0) ? nRead : -1; |
| 215 | 707 |
| 1 | 708 } |
| 709 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
710 int yaffs_pread(int fd, void *buf, unsigned int nbyte, unsigned int offset) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
711 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
712 yaffsfs_Handle *h = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
713 yaffs_Object *obj = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
714 int pos = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
715 int nRead = -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
716 unsigned int maxRead; |
| 215 | 717 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
718 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
719 h = yaffsfs_GetHandlePointer(fd); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
720 obj = yaffsfs_GetHandleObject(fd); |
| 215 | 721 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
722 if(!h || !obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
723 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
724 // bad handle |
| 215 | 725 yaffsfs_SetError(-EBADF); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
726 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
727 else if( h && obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
728 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
729 pos= offset; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
730 if(yaffs_GetObjectFileLength(obj) > pos) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
731 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
732 maxRead = yaffs_GetObjectFileLength(obj) - pos; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
733 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
734 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
735 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
736 maxRead = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
737 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
738 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
739 if(nbyte > maxRead) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
740 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
741 nbyte = maxRead; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
742 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
743 |
| 215 | 744 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
745 if(nbyte > 0) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
746 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
747 nRead = yaffs_ReadDataFromFile(obj,buf,pos,nbyte); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
748 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
749 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
750 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
751 nRead = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
752 } |
| 215 | 753 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
754 } |
| 215 | 755 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
756 yaffsfs_Unlock(); |
| 215 | 757 |
| 758 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
759 return (nRead >= 0) ? nRead : -1; |
| 215 | 760 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
761 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
762 |
| 1 | 763 int yaffs_write(int fd, const void *buf, unsigned int nbyte) |
| 764 { | |
| 765 yaffsfs_Handle *h = NULL; | |
| 766 yaffs_Object *obj = NULL; | |
| 767 int pos = 0; | |
| 768 int nWritten = -1; | |
| 19 | 769 int writeThrough = 0; |
| 215 | 770 |
| 1 | 771 yaffsfs_Lock(); |
| 772 h = yaffsfs_GetHandlePointer(fd); | |
| 773 obj = yaffsfs_GetHandleObject(fd); | |
| 215 | 774 |
| 1 | 775 if(!h || !obj) |
| 776 { | |
| 777 // bad handle | |
| 215 | 778 yaffsfs_SetError(-EBADF); |
| 1 | 779 } |
| 780 else if( h && obj && h->readOnly) | |
| 781 { | |
| 782 // todo error | |
| 783 } | |
| 784 else if( h && obj) | |
| 785 { | |
| 786 if(h->append) | |
| 787 { | |
| 788 pos = yaffs_GetObjectFileLength(obj); | |
| 789 } | |
| 790 else | |
| 791 { | |
| 792 pos = h->position; | |
| 793 } | |
| 215 | 794 |
| 19 | 795 nWritten = yaffs_WriteDataToFile(obj,buf,pos,nbyte,writeThrough); |
| 215 | 796 |
| 1 | 797 if(nWritten >= 0) |
| 798 { | |
| 799 h->position = pos + nWritten; | |
| 800 } | |
| 801 else | |
| 802 { | |
| 803 //todo error | |
| 804 } | |
| 215 | 805 |
| 1 | 806 } |
| 215 | 807 |
| 1 | 808 yaffsfs_Unlock(); |
| 215 | 809 |
| 810 | |
| 1 | 811 return (nWritten >= 0) ? nWritten : -1; |
| 812 | |
| 813 } | |
| 814 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
815 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, unsigned int offset) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
816 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
817 yaffsfs_Handle *h = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
818 yaffs_Object *obj = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
819 int pos = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
820 int nWritten = -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
821 int writeThrough = 0; |
| 215 | 822 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
823 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
824 h = yaffsfs_GetHandlePointer(fd); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
825 obj = yaffsfs_GetHandleObject(fd); |
| 215 | 826 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
827 if(!h || !obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
828 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
829 // bad handle |
| 215 | 830 yaffsfs_SetError(-EBADF); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
831 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
832 else if( h && obj && h->readOnly) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
833 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
834 // todo error |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
835 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
836 else if( h && obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
837 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
838 pos = offset; |
| 215 | 839 |
| 840 nWritten = yaffs_WriteDataToFile(obj,buf,pos,nbyte,writeThrough); | |
| 841 | |
| 842 if(nWritten < 0 || ((unsigned int)nWritten) < nbyte) | |
| 843 yaffsfs_SetError(-ENOSPC); | |
| 844 | |
| 845 } | |
| 846 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
847 yaffsfs_Unlock(); |
| 215 | 848 |
| 849 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
850 return (nWritten >= 0) ? nWritten : -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
851 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
852 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
853 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
854 |
| 215 | 855 int yaffs_truncate(const YCHAR *path,off_t newSize) |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
856 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
857 yaffs_Object *obj = NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
858 int result = YAFFS_FAIL; |
| 215 | 859 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
860 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
861 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
862 obj = yaffsfs_FindObject(NULL,path,0); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
863 if(obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
864 obj = yaffs_GetEquivalentObject(obj); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
865 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
866 if(!obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
867 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
868 yaffsfs_SetError(-ENOENT); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
869 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
870 else if(obj->variantType != YAFFS_OBJECT_TYPE_FILE) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
871 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
872 yaffsfs_SetError(-EISDIR); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
873 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
874 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
875 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
876 result = yaffs_ResizeFile(obj,newSize); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
877 } |
| 215 | 878 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
879 yaffsfs_Unlock(); |
| 215 | 880 |
| 881 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
882 return (result) ? 0 : -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
883 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
884 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
885 int yaffs_ftruncate(int fd, off_t newSize) |
| 1 | 886 { |
| 887 yaffsfs_Handle *h = NULL; | |
| 888 yaffs_Object *obj = NULL; | |
| 889 int result = 0; | |
| 215 | 890 |
| 1 | 891 yaffsfs_Lock(); |
| 892 h = yaffsfs_GetHandlePointer(fd); | |
| 893 obj = yaffsfs_GetHandleObject(fd); | |
| 215 | 894 |
| 1 | 895 if(!h || !obj) |
| 896 { | |
| 897 // bad handle | |
| 215 | 898 yaffsfs_SetError(-EBADF); |
| 1 | 899 } |
| 900 else | |
| 901 { | |
| 902 // resize the file | |
| 903 result = yaffs_ResizeFile(obj,newSize); | |
| 215 | 904 } |
| 1 | 905 yaffsfs_Unlock(); |
| 215 | 906 |
| 907 | |
| 1 | 908 return (result) ? 0 : -1; |
| 909 | |
| 910 } | |
| 911 | |
| 215 | 912 off_t yaffs_lseek(int fd, off_t offset, int whence) |
| 1 | 913 { |
| 914 yaffsfs_Handle *h = NULL; | |
| 915 yaffs_Object *obj = NULL; | |
| 916 int pos = -1; | |
| 917 int fSize = -1; | |
| 215 | 918 |
| 1 | 919 yaffsfs_Lock(); |
| 920 h = yaffsfs_GetHandlePointer(fd); | |
| 921 obj = yaffsfs_GetHandleObject(fd); | |
| 215 | 922 |
| 1 | 923 if(!h || !obj) |
| 924 { | |
| 925 // bad handle | |
| 215 | 926 yaffsfs_SetError(-EBADF); |
| 1 | 927 } |
| 928 else if(whence == SEEK_SET) | |
| 929 { | |
| 930 if(offset >= 0) | |
| 931 { | |
| 932 pos = offset; | |
| 933 } | |
| 934 } | |
| 935 else if(whence == SEEK_CUR) | |
| 936 { | |
| 937 if( (h->position + offset) >= 0) | |
| 938 { | |
| 939 pos = (h->position + offset); | |
| 940 } | |
| 941 } | |
| 942 else if(whence == SEEK_END) | |
| 943 { | |
| 944 fSize = yaffs_GetObjectFileLength(obj); | |
| 945 if(fSize >= 0 && (fSize + offset) >= 0) | |
| 946 { | |
| 947 pos = fSize + offset; | |
| 948 } | |
| 949 } | |
| 215 | 950 |
| 1 | 951 if(pos >= 0) |
| 952 { | |
| 953 h->position = pos; | |
| 954 } | |
| 955 else | |
| 956 { | |
| 957 // todo error | |
| 958 } | |
| 959 | |
| 215 | 960 |
| 1 | 961 yaffsfs_Unlock(); |
| 215 | 962 |
| 1 | 963 return pos; |
| 964 } | |
| 965 | |
| 966 | |
| 215 | 967 int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory) |
| 1 | 968 { |
| 969 yaffs_Object *dir = NULL; | |
| 970 yaffs_Object *obj = NULL; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
971 YCHAR *name; |
| 1 | 972 int result = YAFFS_FAIL; |
| 215 | 973 |
| 1 | 974 yaffsfs_Lock(); |
| 975 | |
| 976 obj = yaffsfs_FindObject(NULL,path,0); | |
| 977 dir = yaffsfs_FindDirectory(NULL,path,&name,0); | |
| 978 if(!dir) | |
| 979 { | |
| 980 yaffsfs_SetError(-ENOTDIR); | |
| 981 } | |
| 982 else if(!obj) | |
| 983 { | |
| 984 yaffsfs_SetError(-ENOENT); | |
| 985 } | |
| 986 else if(!isDirectory && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) | |
| 987 { | |
| 988 yaffsfs_SetError(-EISDIR); | |
| 989 } | |
| 990 else if(isDirectory && obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) | |
| 991 { | |
| 992 yaffsfs_SetError(-ENOTDIR); | |
| 993 } | |
| 994 else | |
| 995 { | |
| 996 result = yaffs_Unlink(dir,name); | |
| 215 | 997 |
| 1 | 998 if(result == YAFFS_FAIL && isDirectory) |
| 999 { | |
| 1000 yaffsfs_SetError(-ENOTEMPTY); | |
| 1001 } | |
| 1002 } | |
| 215 | 1003 |
| 1 | 1004 yaffsfs_Unlock(); |
| 215 | 1005 |
| 1 | 1006 // todo error |
| 215 | 1007 |
| 1 | 1008 return (result == YAFFS_FAIL) ? -1 : 0; |
| 1009 } | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1010 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1011 |
| 215 | 1012 int yaffs_rmdir(const YCHAR *path) |
| 1 | 1013 { |
| 1014 return yaffsfs_DoUnlink(path,1); | |
| 1015 } | |
| 1016 | |
| 215 | 1017 int yaffs_unlink(const YCHAR *path) |
| 1 | 1018 { |
| 1019 return yaffsfs_DoUnlink(path,0); | |
| 1020 } | |
| 1021 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1022 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) |
| 1 | 1023 { |
| 1024 yaffs_Object *olddir = NULL; | |
| 1025 yaffs_Object *newdir = NULL; | |
| 1026 yaffs_Object *obj = NULL; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1027 YCHAR *oldname; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1028 YCHAR *newname; |
| 1 | 1029 int result= YAFFS_FAIL; |
| 1030 int renameAllowed = 1; | |
| 215 | 1031 |
| 1 | 1032 yaffsfs_Lock(); |
| 215 | 1033 |
| 1 | 1034 olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0); |
| 1035 newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0); | |
| 1036 obj = yaffsfs_FindObject(NULL,oldPath,0); | |
| 215 | 1037 |
| 1 | 1038 if(!olddir || !newdir || !obj) |
| 1039 { | |
| 1040 // bad file | |
| 215 | 1041 yaffsfs_SetError(-EBADF); |
| 1042 renameAllowed = 0; | |
| 1 | 1043 } |
| 1044 else if(olddir->myDev != newdir->myDev) | |
| 1045 { | |
| 1046 // oops must be on same device | |
| 1047 // todo error | |
| 1048 yaffsfs_SetError(-EXDEV); | |
| 215 | 1049 renameAllowed = 0; |
| 1 | 1050 } |
| 1051 else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) | |
| 1052 { | |
| 215 | 1053 // It is a directory, check that it is not being renamed to |
| 1 | 1054 // being its own decendent. |
| 1055 // Do this by tracing from the new directory back to the root, checking for obj | |
| 215 | 1056 |
| 1 | 1057 yaffs_Object *xx = newdir; |
| 215 | 1058 |
| 1 | 1059 while( renameAllowed && xx) |
| 1060 { | |
| 1061 if(xx == obj) | |
| 1062 { | |
| 1063 renameAllowed = 0; | |
| 1064 } | |
| 1065 xx = xx->parent; | |
| 1066 } | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1067 if(!renameAllowed) yaffsfs_SetError(-EACCES); |
| 1 | 1068 } |
| 215 | 1069 |
| 1 | 1070 if(renameAllowed) |
| 1071 { | |
| 1072 result = yaffs_RenameObject(olddir,oldname,newdir,newname); | |
| 1073 } | |
| 215 | 1074 |
| 1 | 1075 yaffsfs_Unlock(); |
| 215 | 1076 |
| 1077 return (result == YAFFS_FAIL) ? -1 : 0; | |
| 1 | 1078 } |
| 1079 | |
| 1080 | |
| 1081 static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf) | |
| 1082 { | |
| 1083 int retVal = -1; | |
| 1084 | |
| 1085 if(obj) | |
| 1086 { | |
| 1087 obj = yaffs_GetEquivalentObject(obj); | |
| 1088 } | |
| 1089 | |
| 1090 if(obj && buf) | |
| 1091 { | |
| 1092 buf->st_dev = (int)obj->myDev->genericDevice; | |
| 1093 buf->st_ino = obj->objectId; | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
1094 buf->st_mode = obj->yst_mode & ~S_IFMT; // clear out file type bits |
| 215 | 1095 |
| 1096 if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) | |
| 1 | 1097 { |
| 1098 buf->st_mode |= S_IFDIR; | |
| 1099 } | |
| 215 | 1100 else if(obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) |
| 1 | 1101 { |
| 1102 buf->st_mode |= S_IFLNK; | |
| 1103 } | |
| 1104 else if(obj->variantType == YAFFS_OBJECT_TYPE_FILE) | |
| 1105 { | |
| 1106 buf->st_mode |= S_IFREG; | |
| 1107 } | |
| 215 | 1108 |
| 1 | 1109 buf->st_nlink = yaffs_GetObjectLinkCount(obj); |
| 215 | 1110 buf->st_uid = 0; |
| 1111 buf->st_gid = 0;; | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
1112 buf->st_rdev = obj->yst_rdev; |
| 1 | 1113 buf->st_size = yaffs_GetObjectFileLength(obj); |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
131
diff
changeset
|
1114 buf->st_blksize = obj->myDev->nDataBytesPerChunk; |
| 1 | 1115 buf->st_blocks = (buf->st_size + buf->st_blksize -1)/buf->st_blksize; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1116 #if CONFIG_YAFFS_WINCE |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1117 buf->yst_wince_atime[0] = obj->win_atime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1118 buf->yst_wince_atime[1] = obj->win_atime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1119 buf->yst_wince_ctime[0] = obj->win_ctime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1120 buf->yst_wince_ctime[1] = obj->win_ctime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1121 buf->yst_wince_mtime[0] = obj->win_mtime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1122 buf->yst_wince_mtime[1] = obj->win_mtime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1123 #else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1124 buf->yst_atime = obj->yst_atime; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1125 buf->yst_ctime = obj->yst_ctime; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1126 buf->yst_mtime = obj->yst_mtime; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1127 #endif |
| 1 | 1128 retVal = 0; |
| 1129 } | |
| 1130 return retVal; | |
| 1131 } | |
| 1132 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1133 static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int doLStat) |
| 1 | 1134 { |
| 1135 yaffs_Object *obj; | |
| 215 | 1136 |
| 1 | 1137 int retVal = -1; |
| 215 | 1138 |
| 1 | 1139 yaffsfs_Lock(); |
| 1140 obj = yaffsfs_FindObject(NULL,path,0); | |
| 215 | 1141 |
| 1 | 1142 if(!doLStat && obj) |
| 1143 { | |
| 1144 obj = yaffsfs_FollowLink(obj,0); | |
| 1145 } | |
| 215 | 1146 |
| 1 | 1147 if(obj) |
| 1148 { | |
| 1149 retVal = yaffsfs_DoStat(obj,buf); | |
| 1150 } | |
| 1151 else | |
| 1152 { | |
| 1153 // todo error not found | |
| 1154 yaffsfs_SetError(-ENOENT); | |
| 1155 } | |
| 215 | 1156 |
| 1 | 1157 yaffsfs_Unlock(); |
| 215 | 1158 |
| 1 | 1159 return retVal; |
| 215 | 1160 |
| 1 | 1161 } |
| 1162 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1163 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) |
| 1 | 1164 { |
| 1165 return yaffsfs_DoStatOrLStat(path,buf,0); | |
| 1166 } | |
| 1167 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1168 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) |
| 1 | 1169 { |
| 1170 return yaffsfs_DoStatOrLStat(path,buf,1); | |
| 1171 } | |
| 1172 | |
| 1173 int yaffs_fstat(int fd, struct yaffs_stat *buf) | |
| 1174 { | |
| 1175 yaffs_Object *obj; | |
| 215 | 1176 |
| 1 | 1177 int retVal = -1; |
| 215 | 1178 |
| 1 | 1179 yaffsfs_Lock(); |
| 1180 obj = yaffsfs_GetHandleObject(fd); | |
| 215 | 1181 |
| 1 | 1182 if(obj) |
| 1183 { | |
| 1184 retVal = yaffsfs_DoStat(obj,buf); | |
| 1185 } | |
| 1186 else | |
| 1187 { | |
| 1188 // bad handle | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1189 yaffsfs_SetError(-EBADF); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1190 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1191 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1192 yaffsfs_Unlock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1193 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1194 return retVal; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1195 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1196 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1197 #ifdef CONFIG_YAFFS_WINCE |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1198 int yaffs_get_wince_times(int fd, unsigned *wctime, unsigned *watime, unsigned *wmtime) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1199 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1200 yaffs_Object *obj; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1201 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1202 int retVal = -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1203 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1204 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1205 obj = yaffsfs_GetHandleObject(fd); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1206 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1207 if(obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1208 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1209 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1210 if(wctime){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1211 wctime[0] = obj->win_ctime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1212 wctime[1] = obj->win_ctime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1213 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1214 if(watime){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1215 watime[0] = obj->win_atime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1216 watime[1] = obj->win_atime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1217 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1218 if(wmtime){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1219 wmtime[0] = obj->win_mtime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1220 wmtime[1] = obj->win_mtime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1221 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1222 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1223 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1224 retVal = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1225 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1226 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1227 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1228 // bad handle |
| 1 | 1229 yaffsfs_SetError(-EBADF); |
| 1230 } | |
| 1231 | |
| 1232 yaffsfs_Unlock(); | |
| 1233 | |
| 1234 return retVal; | |
| 1235 } | |
| 1236 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1237 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1238 int yaffs_set_wince_times(int fd, |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1239 const unsigned *wctime, |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1240 const unsigned *watime, |
| 215 | 1241 const unsigned *wmtime) |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1242 { |
| 215 | 1243 yaffs_Object *obj; |
| 1244 int result; | |
| 1245 int retVal = -1; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1246 |
| 215 | 1247 yaffsfs_Lock(); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1248 obj = yaffsfs_GetHandleObject(fd); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1249 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1250 if(obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1251 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1252 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1253 if(wctime){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1254 obj->win_ctime[0] = wctime[0]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1255 obj->win_ctime[1] = wctime[1]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1256 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1257 if(watime){ |
| 215 | 1258 obj->win_atime[0] = watime[0]; |
| 1259 obj->win_atime[1] = watime[1]; | |
| 1260 } | |
| 1261 if(wmtime){ | |
| 1262 obj->win_mtime[0] = wmtime[0]; | |
| 1263 obj->win_mtime[1] = wmtime[1]; | |
| 1264 } | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1265 |
| 215 | 1266 obj->dirty = 1; |
| 1267 result = yaffs_FlushFile(obj,0); | |
| 1268 retVal = 0; | |
| 1269 } | |
| 1270 else | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1271 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1272 // bad handle |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1273 yaffsfs_SetError(-EBADF); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1274 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1275 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1276 yaffsfs_Unlock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1277 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1278 return retVal; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1279 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1280 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1281 #endif |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1282 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1283 |
| 1 | 1284 static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode) |
| 1285 { | |
| 1286 int result; | |
| 1287 | |
| 1288 if(obj) | |
| 1289 { | |
| 1290 obj = yaffs_GetEquivalentObject(obj); | |
| 1291 } | |
| 215 | 1292 |
| 1 | 1293 if(obj) |
| 1294 { | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
1295 obj->yst_mode = mode; |
| 1 | 1296 obj->dirty = 1; |
| 1297 result = yaffs_FlushFile(obj,0); | |
| 1298 } | |
| 215 | 1299 |
| 1 | 1300 return result == YAFFS_OK ? 0 : -1; |
| 1301 } | |
| 1302 | |
| 1303 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1304 int yaffs_access(const YCHAR *path, int amode) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1305 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1306 yaffs_Object *obj; |
| 215 | 1307 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1308 int retval = 0; |
| 215 | 1309 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1310 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1311 obj = yaffsfs_FindObject(NULL,path,0); |
| 215 | 1312 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1313 if(obj) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1314 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1315 int access_ok = 1; |
| 215 | 1316 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1317 if((amode & R_OK) && !(obj->yst_mode & S_IREAD)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1318 access_ok = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1319 if((amode & W_OK) && !(obj->yst_mode & S_IWRITE)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1320 access_ok = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1321 if((amode & X_OK) && !(obj->yst_mode & S_IEXEC)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1322 access_ok = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1323 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1324 if(!access_ok) { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1325 yaffsfs_SetError(-EACCES); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1326 retval = -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1327 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1328 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1329 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1330 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1331 // todo error not found |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1332 yaffsfs_SetError(-ENOENT); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1333 retval = -1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1334 } |
| 215 | 1335 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1336 yaffsfs_Unlock(); |
| 215 | 1337 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1338 return retval; |
| 215 | 1339 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1340 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1341 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1342 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1343 int yaffs_chmod(const YCHAR *path, mode_t mode) |
| 1 | 1344 { |
| 1345 yaffs_Object *obj; | |
| 215 | 1346 |
| 1 | 1347 int retVal = -1; |
| 215 | 1348 |
| 1 | 1349 yaffsfs_Lock(); |
| 1350 obj = yaffsfs_FindObject(NULL,path,0); | |
| 215 | 1351 |
| 1 | 1352 if(obj) |
| 1353 { | |
| 1354 retVal = yaffsfs_DoChMod(obj,mode); | |
| 1355 } | |
| 1356 else | |
| 1357 { | |
| 1358 // todo error not found | |
| 1359 yaffsfs_SetError(-ENOENT); | |
| 1360 } | |
| 215 | 1361 |
| 1 | 1362 yaffsfs_Unlock(); |
| 215 | 1363 |
| 1 | 1364 return retVal; |
| 215 | 1365 |
| 1 | 1366 } |
| 1367 | |
| 1368 | |
| 1369 int yaffs_fchmod(int fd, mode_t mode) | |
| 1370 { | |
| 1371 yaffs_Object *obj; | |
| 215 | 1372 |
| 1 | 1373 int retVal = -1; |
| 215 | 1374 |
| 1 | 1375 yaffsfs_Lock(); |
| 1376 obj = yaffsfs_GetHandleObject(fd); | |
| 215 | 1377 |
| 1 | 1378 if(obj) |
| 1379 { | |
| 1380 retVal = yaffsfs_DoChMod(obj,mode); | |
| 1381 } | |
| 1382 else | |
| 1383 { | |
| 1384 // bad handle | |
| 215 | 1385 yaffsfs_SetError(-EBADF); |
| 1 | 1386 } |
| 215 | 1387 |
| 1 | 1388 yaffsfs_Unlock(); |
| 215 | 1389 |
| 1 | 1390 return retVal; |
| 1391 } | |
| 1392 | |
| 1393 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1394 int yaffs_mkdir(const YCHAR *path, mode_t mode) |
| 1 | 1395 { |
| 1396 yaffs_Object *parent = NULL; | |
| 126 | 1397 yaffs_Object *dir = NULL; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1398 YCHAR *name; |
| 1 | 1399 int retVal= -1; |
| 215 | 1400 |
| 1 | 1401 yaffsfs_Lock(); |
| 1402 parent = yaffsfs_FindDirectory(NULL,path,&name,0); | |
| 126 | 1403 if(parent) |
| 1404 dir = yaffs_MknodDirectory(parent,name,mode,0,0); | |
| 1 | 1405 if(dir) |
| 1406 { | |
| 1407 retVal = 0; | |
| 1408 } | |
| 1409 else | |
| 1410 { | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1411 if(!parent){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1412 yaffsfs_SetError(-ENOENT); // missing path |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1413 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1414 else if (yaffs_FindObjectByName(parent,name)){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1415 yaffsfs_SetError(-EEXIST); // the name already exists |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1416 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1417 else |
| 215 | 1418 yaffsfs_SetError(-ENOSPC); // just assume no space |
| 1 | 1419 retVal = -1; |
| 1420 } | |
| 215 | 1421 |
| 1 | 1422 yaffsfs_Unlock(); |
| 215 | 1423 |
| 1 | 1424 return retVal; |
| 1425 } | |
| 1426 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1427 int yaffs_mount(const YCHAR *path) |
| 1 | 1428 { |
| 1429 int retVal=-1; | |
| 1430 int result=YAFFS_FAIL; | |
| 1431 yaffs_Device *dev=NULL; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1432 YCHAR *dummy; |
| 215 | 1433 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1434 T(YAFFS_TRACE_ALWAYS,(TSTR("yaffs: Mounting %s" TENDSTR),path)); |
| 215 | 1435 |
| 1 | 1436 yaffsfs_Lock(); |
| 1437 dev = yaffsfs_FindDevice(path,&dummy); | |
| 1438 if(dev) | |
| 1439 { | |
| 1440 if(!dev->isMounted) | |
| 1441 { | |
| 1442 result = yaffs_GutsInitialise(dev); | |
| 1443 if(result == YAFFS_FAIL) | |
| 1444 { | |
| 1445 // todo error - mount failed | |
| 1446 yaffsfs_SetError(-ENOMEM); | |
| 1447 } | |
| 1448 retVal = result ? 0 : -1; | |
| 215 | 1449 |
| 1 | 1450 } |
| 1451 else | |
| 1452 { | |
| 1453 //todo error - already mounted. | |
| 1454 yaffsfs_SetError(-EBUSY); | |
| 1455 } | |
| 1456 } | |
| 1457 else | |
| 1458 { | |
| 1459 // todo error - no device | |
| 1460 yaffsfs_SetError(-ENODEV); | |
| 1461 } | |
| 1462 yaffsfs_Unlock(); | |
| 1463 return retVal; | |
| 215 | 1464 |
| 1 | 1465 } |
| 1466 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1467 int yaffs_sync(const YCHAR *path) |
| 1 | 1468 { |
| 215 | 1469 int retVal=-1; |
| 1470 yaffs_Device *dev=NULL; | |
| 1471 YCHAR *dummy; | |
| 1472 | |
| 1473 yaffsfs_Lock(); | |
| 1474 dev = yaffsfs_FindDevice(path,&dummy); | |
| 1475 if(dev) | |
| 1476 { | |
| 1477 if(dev->isMounted) | |
| 1478 { | |
| 1479 | |
| 1480 yaffs_FlushEntireDeviceCache(dev); | |
| 1481 yaffs_CheckpointSave(dev); | |
| 1482 | |
| 1483 | |
| 1484 } | |
| 1485 else | |
| 1486 { | |
| 1487 //todo error - not mounted. | |
| 1488 yaffsfs_SetError(-EINVAL); | |
| 1489 | |
| 1490 } | |
| 1491 } | |
| 1492 else | |
| 1493 { | |
| 1494 // todo error - no device | |
| 1495 yaffsfs_SetError(-ENODEV); | |
| 1496 } | |
| 1497 yaffsfs_Unlock(); | |
| 1498 return retVal; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1499 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1500 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1501 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1502 int yaffs_unmount(const YCHAR *path) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1503 { |
| 215 | 1504 int retVal=-1; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1505 yaffs_Device *dev=NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1506 YCHAR *dummy; |
| 215 | 1507 |
| 1 | 1508 yaffsfs_Lock(); |
| 1509 dev = yaffsfs_FindDevice(path,&dummy); | |
| 1510 if(dev) | |
| 1511 { | |
| 1512 if(dev->isMounted) | |
| 1513 { | |
| 1514 int i; | |
| 1515 int inUse; | |
| 215 | 1516 |
| 127 | 1517 yaffs_FlushEntireDeviceCache(dev); |
| 131 | 1518 yaffs_CheckpointSave(dev); |
| 215 | 1519 |
| 1 | 1520 for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++) |
| 1521 { | |
| 1522 if(yaffsfs_handle[i].inUse && yaffsfs_handle[i].obj->myDev == dev) | |
| 1523 { | |
| 1524 inUse = 1; // the device is in use, can't unmount | |
| 1525 } | |
| 1526 } | |
| 215 | 1527 |
| 1 | 1528 if(!inUse) |
| 1529 { | |
| 1530 yaffs_Deinitialise(dev); | |
| 215 | 1531 |
| 1 | 1532 retVal = 0; |
| 1533 } | |
| 1534 else | |
| 1535 { | |
| 1536 // todo error can't unmount as files are open | |
| 1537 yaffsfs_SetError(-EBUSY); | |
| 1538 } | |
| 215 | 1539 |
| 1 | 1540 } |
| 1541 else | |
| 1542 { | |
| 1543 //todo error - not mounted. | |
| 1544 yaffsfs_SetError(-EINVAL); | |
| 215 | 1545 |
| 1 | 1546 } |
| 1547 } | |
| 1548 else | |
| 1549 { | |
| 1550 // todo error - no device | |
| 1551 yaffsfs_SetError(-ENODEV); | |
| 215 | 1552 } |
| 1 | 1553 yaffsfs_Unlock(); |
| 1554 return retVal; | |
| 215 | 1555 |
| 1 | 1556 } |
| 1557 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1558 loff_t yaffs_freespace(const YCHAR *path) |
| 1 | 1559 { |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
131
diff
changeset
|
1560 loff_t retVal=-1; |
| 1 | 1561 yaffs_Device *dev=NULL; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1562 YCHAR *dummy; |
| 215 | 1563 |
| 1 | 1564 yaffsfs_Lock(); |
| 1565 dev = yaffsfs_FindDevice(path,&dummy); | |
| 12 | 1566 if(dev && dev->isMounted) |
| 1 | 1567 { |
| 1568 retVal = yaffs_GetNumberOfFreeChunks(dev); | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
131
diff
changeset
|
1569 retVal *= dev->nDataBytesPerChunk; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1570 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1571 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1572 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1573 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1574 yaffsfs_SetError(-EINVAL); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1575 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1576 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1577 yaffsfs_Unlock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1578 return retVal; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1579 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1580 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1581 loff_t yaffs_totalspace(const YCHAR *path) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1582 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1583 loff_t retVal=-1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1584 yaffs_Device *dev=NULL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1585 YCHAR *dummy; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1586 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1587 yaffsfs_Lock(); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1588 dev = yaffsfs_FindDevice(path,&dummy); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1589 if(dev && dev->isMounted) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1590 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1591 retVal = (dev->endBlock - dev->startBlock + 1) - dev->nReservedBlocks; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1592 retVal *= dev->nChunksPerBlock; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1593 retVal *= dev->nDataBytesPerChunk; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1594 |
| 1 | 1595 } |
| 1596 else | |
| 1597 { | |
| 1598 yaffsfs_SetError(-EINVAL); | |
| 1599 } | |
| 215 | 1600 |
| 1 | 1601 yaffsfs_Unlock(); |
| 215 | 1602 return retVal; |
| 1 | 1603 } |
| 1604 | |
| 84 | 1605 |
| 1606 | |
| 1 | 1607 void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList) |
| 1608 { | |
| 215 | 1609 |
| 1 | 1610 yaffsfs_DeviceConfiguration *cfg; |
| 215 | 1611 |
| 1 | 1612 yaffsfs_configurationList = cfgList; |
| 215 | 1613 |
| 1 | 1614 yaffsfs_InitHandles(); |
| 215 | 1615 |
| 1 | 1616 cfg = yaffsfs_configurationList; |
| 215 | 1617 |
| 1 | 1618 while(cfg && cfg->prefix && cfg->dev) |
| 1619 { | |
| 1620 cfg->dev->isMounted = 0; | |
| 84 | 1621 cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback; |
| 1 | 1622 cfg++; |
| 1623 } | |
| 215 | 1624 |
| 1625 | |
| 1 | 1626 } |
| 1627 | |
| 1628 | |
| 1629 // | |
| 1630 // Directory search stuff. | |
| 1631 | |
| 84 | 1632 // |
| 1633 // Directory search context | |
| 1634 // | |
| 1635 // NB this is an opaque structure. | |
| 1636 | |
| 1637 | |
| 1638 typedef struct | |
| 1639 { | |
| 1640 __u32 magic; | |
| 1641 yaffs_dirent de; /* directory entry being used by this dsc */ | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1642 YCHAR name[NAME_MAX+1]; /* name of directory being searched */ |
| 215 | 1643 yaffs_Object *dirObj; /* ptr to directory being searched */ |
| 1644 yaffs_Object *nextReturn; /* obj to be returned by next readddir */ | |
| 1645 int offset; | |
| 1646 struct ylist_head others; | |
| 84 | 1647 } yaffsfs_DirectorySearchContext; |
| 1648 | |
| 1649 | |
| 1650 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1651 static struct ylist_head search_contexts; |
| 84 | 1652 |
| 1653 | |
| 1654 static void yaffsfs_SetDirRewound(yaffsfs_DirectorySearchContext *dsc) | |
| 1655 { | |
| 1656 if(dsc && | |
| 1657 dsc->dirObj && | |
| 1658 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){ | |
| 215 | 1659 |
| 1660 dsc->offset = 0; | |
| 1661 | |
| 1662 if( ylist_empty(&dsc->dirObj->variant.directoryVariant.children)){ | |
| 1663 dsc->nextReturn = NULL; | |
| 1664 } else { | |
| 1665 dsc->nextReturn = ylist_entry(dsc->dirObj->variant.directoryVariant.children.next, | |
| 1666 yaffs_Object,siblings); | |
| 1667 } | |
| 1668 } else { | |
| 84 | 1669 /* Hey someone isn't playing nice! */ |
| 1670 } | |
| 1671 } | |
| 1672 | |
| 1673 static void yaffsfs_DirAdvance(yaffsfs_DirectorySearchContext *dsc) | |
| 1674 { | |
| 1675 if(dsc && | |
| 1676 dsc->dirObj && | |
| 215 | 1677 dsc->dirObj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){ |
| 1678 | |
| 1679 if( dsc->nextReturn == NULL || | |
| 1680 ylist_empty(&dsc->dirObj->variant.directoryVariant.children)){ | |
| 1681 dsc->nextReturn = NULL; | |
| 1682 } else { | |
| 1683 struct ylist_head *next = dsc->nextReturn->siblings.next; | |
| 1684 | |
| 1685 if( next == &dsc->dirObj->variant.directoryVariant.children) | |
| 1686 dsc->nextReturn = NULL; /* end of list */ | |
| 1687 else | |
| 1688 dsc->nextReturn = ylist_entry(next,yaffs_Object,siblings); | |
| 1689 } | |
| 1690 } else { | |
| 1691 /* Hey someone isn't playing nice! */ | |
| 84 | 1692 } |
| 1693 } | |
| 1694 | |
| 1695 static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj) | |
| 1696 { | |
| 1697 | |
| 215 | 1698 struct ylist_head *i; |
| 1699 yaffsfs_DirectorySearchContext *dsc; | |
| 1700 | |
| 1701 /* if search contexts not initilised then skip */ | |
| 1702 if(!search_contexts.next) | |
| 1703 return; | |
| 1704 | |
| 1705 /* Iterate through the directory search contexts. | |
| 1706 * If any are the one being removed, then advance the dsc to | |
| 1707 * the next one to prevent a hanging ptr. | |
| 1708 */ | |
| 1709 ylist_for_each(i, &search_contexts) { | |
| 1710 if (i) { | |
| 1711 dsc = ylist_entry(i, yaffsfs_DirectorySearchContext,others); | |
| 1712 if(dsc->nextReturn == obj) | |
| 1713 yaffsfs_DirAdvance(dsc); | |
| 1714 } | |
| 84 | 1715 } |
| 215 | 1716 |
| 84 | 1717 } |
| 1718 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1719 yaffs_DIR *yaffs_opendir(const YCHAR *dirname) |
| 1 | 1720 { |
| 1721 yaffs_DIR *dir = NULL; | |
| 1722 yaffs_Object *obj = NULL; | |
| 1723 yaffsfs_DirectorySearchContext *dsc = NULL; | |
| 215 | 1724 |
| 1 | 1725 yaffsfs_Lock(); |
| 215 | 1726 |
| 1 | 1727 obj = yaffsfs_FindObject(NULL,dirname,0); |
| 215 | 1728 |
| 1 | 1729 if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) |
| 1730 { | |
| 215 | 1731 |
| 1 | 1732 dsc = YMALLOC(sizeof(yaffsfs_DirectorySearchContext)); |
| 1733 dir = (yaffs_DIR *)dsc; | |
| 1734 if(dsc) | |
| 1735 { | |
| 94 | 1736 memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext)); |
| 215 | 1737 dsc->magic = YAFFS_MAGIC; |
| 1738 dsc->dirObj = obj; | |
| 1739 yaffs_strncpy(dsc->name,dirname,NAME_MAX); | |
| 1740 YINIT_LIST_HEAD(&dsc->others); | |
| 1741 | |
| 1742 if(!search_contexts.next) | |
| 1743 YINIT_LIST_HEAD(&search_contexts); | |
| 1744 | |
| 1745 ylist_add(&dsc->others,&search_contexts); | |
| 1746 yaffsfs_SetDirRewound(dsc); } | |
| 1747 | |
| 1748 } | |
| 1749 | |
| 1 | 1750 yaffsfs_Unlock(); |
| 215 | 1751 |
| 1 | 1752 return dir; |
| 1753 } | |
| 1754 | |
| 1755 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) | |
| 1756 { | |
| 1757 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp; | |
| 1758 struct yaffs_dirent *retVal = NULL; | |
| 215 | 1759 |
| 1 | 1760 yaffsfs_Lock(); |
| 215 | 1761 |
| 84 | 1762 if(dsc && dsc->magic == YAFFS_MAGIC){ |
| 1 | 1763 yaffsfs_SetError(0); |
| 84 | 1764 if(dsc->nextReturn){ |
| 1765 dsc->de.d_ino = yaffs_GetEquivalentObject(dsc->nextReturn)->objectId; | |
| 157 | 1766 dsc->de.d_dont_use = (unsigned)dsc->nextReturn; |
| 84 | 1767 dsc->de.d_off = dsc->offset++; |
| 157 | 1768 yaffs_GetObjectName(dsc->nextReturn,dsc->de.d_name,NAME_MAX); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1769 if(yaffs_strlen(dsc->de.d_name) == 0) |
| 157 | 1770 { |
| 1771 // this should not happen! | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1772 yaffs_strcpy(dsc->de.d_name,_Y("zz")); |
| 157 | 1773 } |
| 84 | 1774 dsc->de.d_reclen = sizeof(struct yaffs_dirent); |
| 1775 retVal = &dsc->de; | |
| 1776 yaffsfs_DirAdvance(dsc); | |
| 1777 } else | |
| 1778 retVal = NULL; | |
| 1 | 1779 } |
| 1780 else | |
| 1781 { | |
| 1782 yaffsfs_SetError(-EBADF); | |
| 1783 } | |
| 215 | 1784 |
| 1 | 1785 yaffsfs_Unlock(); |
| 215 | 1786 |
| 1 | 1787 return retVal; |
| 215 | 1788 |
| 1 | 1789 } |
| 1790 | |
| 1791 | |
| 1792 void yaffs_rewinddir(yaffs_DIR *dirp) | |
| 1793 { | |
| 1794 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp; | |
| 215 | 1795 |
| 1 | 1796 yaffsfs_Lock(); |
| 215 | 1797 |
| 84 | 1798 yaffsfs_SetDirRewound(dsc); |
| 1799 | |
| 1 | 1800 yaffsfs_Unlock(); |
| 1801 } | |
| 1802 | |
| 1803 | |
| 1804 int yaffs_closedir(yaffs_DIR *dirp) | |
| 1805 { | |
| 1806 yaffsfs_DirectorySearchContext *dsc = (yaffsfs_DirectorySearchContext *)dirp; | |
| 215 | 1807 |
| 1808 yaffsfs_Lock(); | |
| 1809 dsc->magic = 0; | |
| 1810 ylist_del(&dsc->others); /* unhook from list */ | |
| 1811 YFREE(dsc); | |
| 1812 yaffsfs_Unlock(); | |
| 1813 return 0; | |
| 1 | 1814 } |
| 1815 | |
| 84 | 1816 // end of directory stuff |
| 1 | 1817 |
| 1818 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1819 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath) |
| 1 | 1820 { |
| 1821 yaffs_Object *parent = NULL; | |
| 1822 yaffs_Object *obj; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1823 YCHAR *name; |
| 1 | 1824 int retVal= -1; |
| 1825 int mode = 0; // ignore for now | |
| 215 | 1826 |
| 1 | 1827 yaffsfs_Lock(); |
| 1828 parent = yaffsfs_FindDirectory(NULL,newpath,&name,0); | |
| 1829 obj = yaffs_MknodSymLink(parent,name,mode,0,0,oldpath); | |
| 1830 if(obj) | |
| 1831 { | |
| 1832 retVal = 0; | |
| 1833 } | |
| 1834 else | |
| 1835 { | |
| 1836 yaffsfs_SetError(-ENOSPC); // just assume no space for now | |
| 1837 retVal = -1; | |
| 1838 } | |
| 215 | 1839 |
| 1 | 1840 yaffsfs_Unlock(); |
| 215 | 1841 |
| 1 | 1842 return retVal; |
| 215 | 1843 |
| 1 | 1844 } |
| 1845 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1846 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz) |
| 1 | 1847 { |
| 1848 yaffs_Object *obj = NULL; | |
| 1849 int retVal; | |
| 1850 | |
| 215 | 1851 |
| 1 | 1852 yaffsfs_Lock(); |
| 215 | 1853 |
| 1 | 1854 obj = yaffsfs_FindObject(NULL,path,0); |
| 215 | 1855 |
| 1 | 1856 if(!obj) |
| 1857 { | |
| 1858 yaffsfs_SetError(-ENOENT); | |
| 1859 retVal = -1; | |
| 1860 } | |
| 1861 else if(obj->variantType != YAFFS_OBJECT_TYPE_SYMLINK) | |
| 1862 { | |
| 1863 yaffsfs_SetError(-EINVAL); | |
| 1864 retVal = -1; | |
| 1865 } | |
| 1866 else | |
| 1867 { | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1868 YCHAR *alias = obj->variant.symLinkVariant.alias; |
| 1 | 1869 memset(buf,0,bufsiz); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1870 yaffs_strncpy(buf,alias,bufsiz - 1); |
| 1 | 1871 retVal = 0; |
| 1872 } | |
| 1873 yaffsfs_Unlock(); | |
| 1874 return retVal; | |
| 1875 } | |
| 1876 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1877 int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath) |
| 122 | 1878 { |
| 1879 // Creates a link called newpath to existing oldpath | |
| 1880 yaffs_Object *obj = NULL; | |
| 1881 yaffs_Object *target = NULL; | |
| 129 | 1882 int retVal = 0; |
| 122 | 1883 |
| 215 | 1884 |
| 122 | 1885 yaffsfs_Lock(); |
| 215 | 1886 |
| 122 | 1887 obj = yaffsfs_FindObject(NULL,oldpath,0); |
| 1888 target = yaffsfs_FindObject(NULL,newpath,0); | |
| 215 | 1889 |
| 122 | 1890 if(!obj) |
| 1891 { | |
| 1892 yaffsfs_SetError(-ENOENT); | |
| 1893 retVal = -1; | |
| 1894 } | |
| 1895 else if(target) | |
| 1896 { | |
| 1897 yaffsfs_SetError(-EEXIST); | |
| 1898 retVal = -1; | |
| 1899 } | |
| 215 | 1900 else |
| 122 | 1901 { |
| 1902 yaffs_Object *newdir = NULL; | |
| 1903 yaffs_Object *link = NULL; | |
| 215 | 1904 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1905 YCHAR *newname; |
| 215 | 1906 |
| 122 | 1907 newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0); |
| 215 | 1908 |
| 122 | 1909 if(!newdir) |
| 1910 { | |
| 1911 yaffsfs_SetError(-ENOTDIR); | |
| 1912 retVal = -1; | |
| 1913 } | |
| 1914 else if(newdir->myDev != obj->myDev) | |
| 1915 { | |
| 1916 yaffsfs_SetError(-EXDEV); | |
| 1917 retVal = -1; | |
| 1918 } | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1919 if(newdir && yaffs_strlen(newname) > 0) |
| 122 | 1920 { |
| 1921 link = yaffs_Link(newdir,newname,obj); | |
| 1922 if(link) | |
| 1923 retVal = 0; | |
| 1924 else | |
| 1925 { | |
| 1926 yaffsfs_SetError(-ENOSPC); | |
| 1927 retVal = -1; | |
| 1928 } | |
| 1929 | |
| 1930 } | |
| 1931 } | |
| 1932 yaffsfs_Unlock(); | |
| 215 | 1933 |
| 122 | 1934 return retVal; |
| 1935 } | |
| 1936 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1937 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev); |
| 1 | 1938 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1939 int yaffs_DumpDevStruct(const YCHAR *path) |
| 1 | 1940 { |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1941 #if 0 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1942 YCHAR *rest; |
| 215 | 1943 |
| 1 | 1944 yaffs_Object *obj = yaffsfs_FindRoot(path,&rest); |
| 215 | 1945 |
| 1 | 1946 if(obj) |
| 1947 { | |
| 1948 yaffs_Device *dev = obj->myDev; | |
| 215 | 1949 |
| 1 | 1950 printf("\n" |
| 1951 "nPageWrites.......... %d\n" | |
| 1952 "nPageReads........... %d\n" | |
| 1953 "nBlockErasures....... %d\n" | |
| 1954 "nGCCopies............ %d\n" | |
| 1955 "garbageCollections... %d\n" | |
| 1956 "passiveGarbageColl'ns %d\n" | |
| 1957 "\n", | |
| 1958 dev->nPageWrites, | |
| 1959 dev->nPageReads, | |
| 1960 dev->nBlockErasures, | |
| 1961 dev->nGCCopies, | |
| 1962 dev->garbageCollections, | |
| 1963 dev->passiveGarbageCollections | |
| 1964 ); | |
| 215 | 1965 |
| 1 | 1966 } |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1967 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
1968 #endif |
| 1 | 1969 return 0; |
| 1970 } | |
| 1971 |
