Index: emcore/trunk/file.c |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | return open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
62 | 62 | }
|
63 | 63 |
|
64 | | -static int open_internal(const char* pathname, int flags, bool use_cache)
|
| 64 | +static int open_internal(const char* pathname, int flags, bool ignoredir)
|
65 | 65 | {
|
66 | 66 | DIR* dir;
|
67 | 67 | struct dirent* entry;
|
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | DEBUGF("'%s' is not an absolute path.", pathname);
|
77 | 77 | DEBUGF("Only absolute pathnames supported at the moment");
|
78 | 78 | errno = EINVAL;
|
79 | | - return -1;
|
| 79 | + return 0;
|
80 | 80 | }
|
81 | 81 |
|
82 | 82 | file = (struct filedesc*)memalign(0x10, sizeof(struct filedesc));
|
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | if (!file)
|
84 | 84 | {
|
85 | 85 | errno = EMFILE;
|
86 | | - return -2;
|
| 86 | + return 0;
|
87 | 87 | }
|
88 | 88 | reownalloc(file, KERNEL_OWNER(KERNEL_OWNER_FILE_HANDLE));
|
89 | 89 | memset(file, 0, sizeof(struct filedesc));
|
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | DEBUGF("Failed opening dir");
|
114 | 114 | errno = EIO;
|
115 | 115 | free(file);
|
116 | | - return -4;
|
| 116 | + return 0;
|
117 | 117 | }
|
118 | 118 |
|
119 | 119 | if(name[0] == 0) {
|
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | errno = EINVAL;
|
122 | 122 | free(file);
|
123 | 123 | closedir(dir);
|
124 | | - return -5;
|
| 124 | + return 0;
|
125 | 125 | }
|
126 | 126 |
|
127 | 127 | /* scan dir for name */
|
— | — | @@ -137,34 +137,34 @@ |
138 | 138 | }
|
139 | 139 |
|
140 | 140 | if ( !entry ) {
|
141 | | - DEBUGF("Didn't find file %s",name);
|
142 | 141 | if ( file->write && (flags & O_CREAT) ) {
|
143 | 142 | rc = fat_create_file(name,
|
144 | 143 | &(file->fatfile),
|
145 | 144 | &(dir->fatdir));
|
146 | 145 | if (rc < 0) {
|
147 | | - DEBUGF("Couldn't create %s in %s",name,pathnamecopy);
|
| 146 | + DEBUGF("Couldn't create %s", pathnamecopy);
|
148 | 147 | errno = EIO;
|
149 | 148 | free(file);
|
150 | 149 | closedir(dir);
|
151 | | - return rc * 10 - 6;
|
| 150 | + return 0;
|
152 | 151 | }
|
| 152 | + DEBUGF("File %s doesn't exist, creating it", pathnamecopy);
|
153 | 153 | file->size = 0;
|
154 | 154 | file->attr = 0;
|
155 | 155 | }
|
156 | 156 | else {
|
157 | | - DEBUGF("Couldn't find %s in %s",name,pathnamecopy);
|
| 157 | + DEBUGF("Couldn't find %s", pathnamecopy);
|
158 | 158 | errno = ENOENT;
|
159 | 159 | free(file);
|
160 | 160 | closedir(dir);
|
161 | | - return -7;
|
| 161 | + return 0;
|
162 | 162 | }
|
163 | 163 | } else {
|
164 | | - if(file->attr & FAT_ATTR_DIRECTORY) {
|
| 164 | + if (file->attr & FAT_ATTR_DIRECTORY && !ignoredir) {
|
165 | 165 | errno = EISDIR;
|
166 | 166 | free(file);
|
167 | 167 | closedir(dir);
|
168 | | - return -8;
|
| 168 | + return 0;
|
169 | 169 | }
|
170 | 170 | }
|
171 | 171 | closedir(dir);
|
— | — | @@ -177,7 +177,8 @@ |
178 | 178 | if (rc < 0 )
|
179 | 179 | {
|
180 | 180 | free(file);
|
181 | | - return rc * 10 - 9;
|
| 181 | + errno = EIO;
|
| 182 | + return 0;
|
182 | 183 | }
|
183 | 184 | }
|
184 | 185 |
|
— | — | @@ -191,8 +192,7 @@ |
192 | 193 |
|
193 | 194 | int file_open(const char* pathname, int flags)
|
194 | 195 | {
|
195 | | - /* By default, use the dircache if available. */
|
196 | | - return open_internal(pathname, flags, true);
|
| 196 | + return open_internal(pathname, flags, false);
|
197 | 197 | }
|
198 | 198 |
|
199 | 199 | void reown_file(int fd, struct scheduler_thread* owner)
|
— | — | @@ -299,10 +299,8 @@ |
300 | 300 | int remove(const char* name)
|
301 | 301 | {
|
302 | 302 | int rc;
|
303 | | - /* Can't use dircache now, because we need to access the fat structures. */
|
304 | 303 | int fd = open_internal(name, O_WRONLY, false);
|
305 | | - if ( fd < 0 )
|
306 | | - return fd * 10 - 1;
|
| 304 | + if (!fd) return - 1;
|
307 | 305 |
|
308 | 306 | struct filedesc* file = (struct filedesc*)fd;
|
309 | 307 | rc = fat_remove(&(file->fatfile));
|
— | — | @@ -332,18 +330,17 @@ |
333 | 331 |
|
334 | 332 | /* verify new path does not already exist */
|
335 | 333 | /* If it is a directory, errno == EISDIR if the name exists */
|
336 | | - fd = open(newpath, O_RDONLY);
|
337 | | - if ( fd >= 0 || errno == EISDIR) {
|
| 334 | + fd = open_internal(newpath, O_RDONLY, true);
|
| 335 | + if (fd) {
|
338 | 336 | close(fd);
|
339 | 337 | errno = EBUSY;
|
340 | 338 | return -1;
|
341 | 339 | }
|
342 | | - close(fd);
|
343 | 340 |
|
344 | | - fd = open_internal(path, O_RDONLY, false);
|
345 | | - if ( fd < 0 ) {
|
| 341 | + fd = open_internal(path, O_RDONLY, true);
|
| 342 | + if (!fd) {
|
346 | 343 | errno = EIO;
|
347 | | - return fd * 10 - 2;
|
| 344 | + return -2;
|
348 | 345 | }
|
349 | 346 |
|
350 | 347 | /* extract new file name */
|