Changeset b19e892 in mainline for uspace/lib/c/generic/vfs/vfs.c
- Timestamp:
- 2017-04-02T10:39:13Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9c4cf0d
- Parents:
- 80743a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r80743a1 rb19e892 41 41 #include <unistd.h> 42 42 #include <dirent.h> 43 #include <fcntl.h>44 43 #include <stdio.h> 45 44 #include <sys/types.h> … … 155 154 } 156 155 157 int _vfs_open(int fildes, int mode) 158 { 159 async_exch_t *exch = vfs_exchange_begin(); 160 sysarg_t rc = async_req_2_0(exch, VFS_IN_OPEN, fildes, mode); 161 vfs_exchange_end(exch); 162 163 return (int) rc; 156 int vfs_open(int file, int mode) 157 { 158 async_exch_t *exch = vfs_exchange_begin(); 159 int rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode); 160 vfs_exchange_end(exch); 161 162 return rc; 163 } 164 165 int vfs_lookup_open(const char *path, int flags, int mode) 166 { 167 int file = vfs_lookup(path, flags); 168 if (file < 0) 169 return file; 170 171 int rc = vfs_open(file, mode); 172 if (rc != EOK) { 173 close(file); 174 return rc; 175 } 176 177 return file; 164 178 } 165 179 … … 353 367 } 354 368 355 static int walk_flags(int oflags)356 {357 int flags = 0;358 if (oflags & O_CREAT) {359 if (oflags & O_EXCL)360 flags |= WALK_MUST_CREATE;361 else362 flags |= WALK_MAY_CREATE;363 }364 return flags;365 }366 367 /** Open file.368 *369 * @param path File path370 * @param oflag O_xxx flags371 * @param mode File mode (only with O_CREAT)372 *373 * @return Nonnegative file descriptor on success. On error -1 is returned374 * and errno is set.375 */376 int open(const char *path, int oflag, ...)377 {378 if (((oflag & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) ||379 ((oflag & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) ||380 ((oflag & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) ||381 ((oflag & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) {382 errno = EINVAL;383 return -1;384 }385 386 int fd = vfs_lookup(path, walk_flags(oflag) | WALK_REGULAR);387 if (fd < 0) {388 errno = fd;389 return -1;390 }391 392 int mode =393 ((oflag & O_RDWR) ? MODE_READ | MODE_WRITE : 0) |394 ((oflag & O_RDONLY) ? MODE_READ : 0) |395 ((oflag & O_WRONLY) ? MODE_WRITE : 0) |396 ((oflag & O_APPEND) ? MODE_APPEND : 0);397 398 int rc = _vfs_open(fd, mode);399 if (rc < 0) {400 close(fd);401 errno = rc;402 return -1;403 }404 405 if (oflag & O_TRUNC) {406 assert(oflag & O_WRONLY || oflag & O_RDWR);407 assert(!(oflag & O_APPEND));408 409 (void) vfs_resize(fd, 0);410 }411 412 return fd;413 }414 415 369 /** Close file. 416 370 * … … 703 657 } 704 658 705 int rc = _vfs_open(fd, MODE_READ);659 int rc = vfs_open(fd, MODE_READ); 706 660 if (rc < 0) { 707 661 free(dirp);
Note:
See TracChangeset
for help on using the changeset viewer.