Changeset b19e892 in mainline
- 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
- Location:
- uspace
- Files:
-
- 1 deleted
- 44 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
r80743a1 rb19e892 33 33 #include <getopt.h> 34 34 #include <str.h> 35 #include <fcntl.h>36 35 #include <io/console.h> 37 36 #include <io/color.h> … … 196 195 blen = STR_BOUNDS(1); 197 196 } else 198 fd = open(fname, O_RDONLY);197 fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 199 198 200 199 if (fd < 0) { -
uspace/app/bdsh/cmds/modules/cmp/cmp.c
r80743a1 rb19e892 28 28 29 29 #include <errno.h> 30 #include <fcntl.h>31 30 #include <getopt.h> 32 31 #include <mem.h> … … 82 81 83 82 for (int i = 0; i < 2; i++) { 84 fd[i] = open(fn[i], O_RDONLY);83 fd[i] = vfs_lookup_open(fn[i], WALK_REGULAR, MODE_READ); 85 84 if (fd[i] < 0) { 86 rc = errno;85 rc = fd[i]; 87 86 printf("Unable to open %s\n", fn[i]); 88 87 goto end; -
uspace/app/bdsh/cmds/modules/cp/cp.c
r80743a1 rb19e892 35 35 #include <getopt.h> 36 36 #include <str.h> 37 #include <fcntl.h>38 37 #include <vfs/vfs.h> 39 38 #include <dirent.h> … … 383 382 printf("Copying %s to %s\n", src, dest); 384 383 385 if (-1 == (fd1 = open(src, O_RDONLY))) { 384 fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ); 385 if (fd1 < 0) { 386 386 printf("Unable to open source file %s\n", src); 387 387 return -1; 388 388 } 389 389 390 if (-1 == (fd2 = open(dest, O_WRONLY | O_CREAT))) { 390 fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 391 if (fd2 < 0) { 391 392 printf("Unable to open destination file %s\n", dest); 392 393 close(fd1); -
uspace/app/bdsh/cmds/modules/ls/ls.c
r80743a1 rb19e892 36 36 #include <unistd.h> 37 37 #include <dirent.h> 38 #include <fcntl.h>39 38 #include <getopt.h> 40 39 #include <sys/types.h> -
uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
r80743a1 rb19e892 30 30 #include <stdlib.h> 31 31 #include <dirent.h> 32 #include <fcntl.h>33 32 #include <sys/types.h> 34 33 #include <getopt.h> -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
r80743a1 rb19e892 31 31 #include <stdlib.h> 32 32 #include <dirent.h> 33 #include <fcntl.h>34 33 #include <sys/types.h> 35 34 #include <macros.h> … … 38 37 #include <str.h> 39 38 #include <ctype.h> 39 #include <vfs/vfs.h> 40 40 41 41 #include "config.h" … … 156 156 file_name = argv[optind]; 157 157 158 fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, 0666);158 fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MUST_CREATE, MODE_WRITE); 159 159 if (fd < 0) { 160 160 printf("%s: failed to create file %s.\n", cmdname, file_name); -
uspace/app/bdsh/cmds/modules/rm/rm.c
r80743a1 rb19e892 31 31 #include <stdlib.h> 32 32 #include <unistd.h> 33 #include <fcntl.h>34 33 #include <dirent.h> 35 34 #include <getopt.h> … … 151 150 } 152 151 153 fd = open(path, O_RDONLY);152 fd = vfs_lookup(path, WALK_REGULAR); 154 153 if (fd >= 0) { 155 154 close(fd); -
uspace/app/bdsh/cmds/modules/touch/touch.c
r80743a1 rb19e892 35 35 #include <stdlib.h> 36 36 #include <unistd.h> 37 #include <fcntl.h>38 37 #include <dirent.h> 39 38 #include <sys/types.h> … … 125 124 if ((!no_create) || 126 125 ((no_create) && (vfs_stat_path(buff, &file_stat) == EOK))) { 127 fd = open(buff, O_RDWR | O_CREAT);126 fd = vfs_lookup(buff, WALK_REGULAR | WALK_MAY_CREATE); 128 127 } 129 128 -
uspace/app/bdsh/exec.c
r80743a1 rb19e892 37 37 #include <unistd.h> 38 38 #include <str.h> 39 #include <fcntl.h>40 39 #include <str_error.h> 41 40 #include <errno.h> … … 60 59 int fd; 61 60 62 fd = open(f, O_RDONLY);61 fd = vfs_lookup_open(f, WALK_REGULAR, MODE_READ); 63 62 if (fd >= 0) { 64 63 close(fd); -
uspace/app/fontviewer/fontviewer.c
r80743a1 rb19e892 35 35 #include <stdio.h> 36 36 #include <unistd.h> 37 #include <fcntl.h>38 37 #include <errno.h> 39 38 #include <malloc.h> -
uspace/app/getterm/getterm.c
r80743a1 rb19e892 36 36 37 37 #include <sys/types.h> 38 #include <fcntl.h>39 38 #include <unistd.h> 40 39 #include <stdio.h> … … 59 58 } 60 59 61 static void reopen(FILE **stream, int fd, const char *path, int flags,62 const char * mode)60 static void reopen(FILE **stream, int fd, const char *path, int mode, 61 const char *fmode) 63 62 { 64 63 if (fclose(*stream)) … … 67 66 *stream = NULL; 68 67 69 int oldfd = open(path, flags);68 int oldfd = vfs_lookup_open(path, WALK_REGULAR, mode); 70 69 if (oldfd < 0) 71 70 return; … … 79 78 } 80 79 81 *stream = fdopen(fd, mode);80 *stream = fdopen(fd, fmode); 82 81 } 83 82 … … 142 141 snprintf(term_node, LOC_NAME_MAXLEN, "%s/%s", locfs, term); 143 142 144 reopen(&stdin, 0, term_node, O_RDONLY, "r");145 reopen(&stdout, 1, term_node, O_WRONLY, "w");146 reopen(&stderr, 2, term_node, O_WRONLY, "w");143 reopen(&stdin, 0, term_node, MODE_READ, "r"); 144 reopen(&stdout, 1, term_node, MODE_WRITE, "w"); 145 reopen(&stderr, 2, term_node, MODE_WRITE, "w"); 147 146 148 147 if (stdin == NULL) -
uspace/app/init/init.c
r80743a1 rb19e892 41 41 #include <stdbool.h> 42 42 #include <errno.h> 43 #include <fcntl.h>44 43 #include <task.h> 45 44 #include <malloc.h> -
uspace/app/redir/redir.c
r80743a1 rb19e892 37 37 #include <sys/types.h> 38 38 #include <stdlib.h> 39 #include <fcntl.h>40 39 #include <unistd.h> 41 40 #include <str.h> … … 54 53 } 55 54 56 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode) 55 static void reopen(FILE **stream, int fd, const char *path, int flags, int mode, 56 const char *fmode) 57 57 { 58 58 if (fclose(*stream)) … … 61 61 *stream = NULL; 62 62 63 int oldfd = open(path, flags);63 int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode); 64 64 if (oldfd < 0) 65 65 return; … … 73 73 } 74 74 75 *stream = fdopen(fd, mode);75 *stream = fdopen(fd, fmode); 76 76 } 77 77 … … 122 122 return -2; 123 123 } 124 reopen(&stdin, 0, argv[i], O_RDONLY, "r");124 reopen(&stdin, 0, argv[i], 0, MODE_READ, "r"); 125 125 } else if (str_cmp(argv[i], "-o") == 0) { 126 126 i++; … … 129 129 return -3; 130 130 } 131 reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w"); 131 reopen(&stdout, 1, argv[i], WALK_MAY_CREATE, MODE_WRITE, 132 "w"); 132 133 } else if (str_cmp(argv[i], "-e") == 0) { 133 134 i++; … … 136 137 return -4; 137 138 } 138 reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w"); 139 reopen(&stderr, 2, argv[i], WALK_MAY_CREATE, MODE_WRITE, 140 "w"); 139 141 } else if (str_cmp(argv[i], "--") == 0) { 140 142 i++; -
uspace/app/sysinst/futil.c
r80743a1 rb19e892 35 35 #include <dirent.h> 36 36 #include <errno.h> 37 #include <fcntl.h>38 37 #include <stdbool.h> 39 38 #include <stdio.h> … … 64 63 printf("Copy '%s' to '%s'.\n", srcp, destp); 65 64 66 sf = open(srcp, O_RDONLY);65 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ); 67 66 if (sf < 0) 68 67 return EIO; 69 68 70 df = open(destp, O_CREAT | O_WRONLY, 0);69 df = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 71 70 if (df < 0) 72 71 return EIO; … … 162 161 struct stat st; 163 162 164 sf = open(srcp, O_RDONLY);163 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ); 165 164 if (sf < 0) 166 165 return ENOENT; -
uspace/app/taskdump/elf_core.c
r80743a1 rb19e892 55 55 #include <sys/types.h> 56 56 #include <unistd.h> 57 #include <fcntl.h>58 57 #include <mem.h> 59 58 #include <stdint.h> … … 62 61 #include <macros.h> 63 62 #include <libarch/istate.h> 63 #include <vfs/vfs.h> 64 64 65 65 #include "elf_core.h" … … 123 123 } 124 124 125 fd = open(file_name, O_CREAT | O_WRONLY, 0644); 125 fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE, 126 MODE_WRITE); 126 127 if (fd < 0) { 127 128 printf("Failed opening file.\n"); -
uspace/app/taskdump/symtab.c
r80743a1 rb19e892 41 41 #include <errno.h> 42 42 #include <sys/types.h> 43 #include < fcntl.h>43 #include <vfs/vfs.h> 44 44 45 45 #include "include/symtab.h" … … 81 81 return ENOMEM; 82 82 83 fd = open(file_name, O_RDONLY);83 fd = vfs_lookup_open(file_name, WALK_REGULAR, MODE_READ); 84 84 if (fd < 0) { 85 85 printf("failed opening file\n"); -
uspace/app/tester/hw/misc/virtchar1.c
r80743a1 rb19e892 45 45 #include <vfs/vfs.h> 46 46 #include <vfs/vfs_sess.h> 47 #include <fcntl.h>48 47 #include "../../tester.h" 49 48 … … 55 54 { 56 55 TPRINTF("Opening `%s'...\n", path); 57 int fd = open(path, O_RDONLY);56 int fd = vfs_lookup(path, WALK_REGULAR); 58 57 if (fd < 0) { 59 58 TPRINTF(" ...error: %s\n", str_error(errno)); -
uspace/app/tester/mm/pager1.c
r80743a1 rb19e892 29 29 #include <stdio.h> 30 30 #include <vfs/vfs.h> 31 #include <fcntl.h>32 31 #include <stdlib.h> 33 32 #include <malloc.h> … … 48 47 TPRINTF("Creating temporary file...\n"); 49 48 50 fd = open(TEST_FILE, O_RDWR | O_CREAT); 49 fd = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 50 MODE_READ | MODE_WRITE); 51 51 if (fd < 0) 52 52 return NULL; -
uspace/app/tester/vfs/vfs1.c
r80743a1 rb19e892 33 33 #include <vfs/vfs.h> 34 34 #include <unistd.h> 35 #include <fcntl.h>36 35 #include <dirent.h> 37 36 #include <loc.h> … … 79 78 TPRINTF("Created directory %s\n", TEST_DIRECTORY); 80 79 81 int fd0 = open(TEST_FILE, O_RDWR | O_CREAT); 80 int fd0 = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE, 81 MODE_READ | MODE_WRITE); 82 82 if (fd0 < 0) 83 return " open() failed";83 return "vfs_lookup_open() failed"; 84 84 TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0); 85 85 -
uspace/app/tetris/scores.c
r80743a1 rb19e892 65 65 #include <vfs/vfs.h> 66 66 #include <stdlib.h> 67 #include <fcntl.h>68 67 #include <err.h> 69 68 #include <time.h> -
uspace/app/viewer/viewer.c
r80743a1 rb19e892 35 35 #include <stdio.h> 36 36 #include <unistd.h> 37 #include <fcntl.h>38 37 #include <vfs/vfs.h> 39 38 #include <errno.h> … … 110 109 static bool img_load(const char *fname, surface_t **p_local_surface) 111 110 { 112 int fd = open(fname, O_RDONLY);111 int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 113 112 if (fd < 0) 114 113 return false; -
uspace/app/websrv/websrv.c
r80743a1 rb19e892 40 40 #include <sys/types.h> 41 41 #include <stdlib.h> 42 #include <fcntl.h>43 42 #include <task.h> 43 44 #include <vfs/vfs.h> 44 45 45 46 #include <inet/addr.h> … … 224 225 return ENOMEM; 225 226 226 int fd = open(fname, O_RDONLY);227 int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ); 227 228 if (fd < 0) { 228 229 rc = send_response(conn, msg_not_found); -
uspace/dist/src/c/demos/tetris/scores.c
r80743a1 rb19e892 65 65 #include <vfs/vfs.h> 66 66 #include <stdlib.h> 67 #include <fcntl.h>68 67 #include <err.h> 69 68 #include <time.h> -
uspace/drv/bus/isa/isa.c
r80743a1 rb19e892 51 51 #include <malloc.h> 52 52 #include <dirent.h> 53 #include <fcntl.h>54 53 #include <ipc/irc.h> 55 54 #include <ipc/services.h> … … 256 255 struct stat st; 257 256 258 fd = open(conf_path, O_RDONLY);257 fd = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ); 259 258 if (fd < 0) { 260 259 ddf_msg(LVL_ERROR, "Unable to open %s", conf_path); -
uspace/drv/char/ns8250/ns8250.c
r80743a1 rb19e892 48 48 #include <malloc.h> 49 49 #include <dirent.h> 50 #include <fcntl.h>51 50 #include <ddi.h> 52 51 -
uspace/lib/bithenge/src/file.c
r80743a1 rb19e892 38 38 #include <assert.h> 39 39 #include <errno.h> 40 #include <fcntl.h>41 40 #include <stdio.h> 42 41 #include <stdlib.h> … … 146 145 assert(filename); 147 146 148 int fd = open(filename, O_RDONLY);147 int fd = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ); 149 148 if (fd < 0) 150 149 return errno; -
uspace/lib/c/generic/elf/elf_mod.c
r80743a1 rb19e892 97 97 98 98 int ofile = vfs_clone(file, -1, true); 99 int rc = _vfs_open(ofile, MODE_READ);99 int rc = vfs_open(ofile, MODE_READ); 100 100 if (rc != EOK) { 101 101 return rc; -
uspace/lib/c/generic/io/io.c
r80743a1 rb19e892 35 35 #include <stdio.h> 36 36 #include <unistd.h> 37 #include <fcntl.h>38 37 #include <assert.h> 39 38 #include <str.h> … … 115 114 int stdinfd = vfs_clone(infd, -1, false); 116 115 assert(stdinfd == 0); 117 _vfs_open(stdinfd, MODE_READ);116 vfs_open(stdinfd, MODE_READ); 118 117 stdin = fdopen(stdinfd, "r"); 119 118 } else { … … 128 127 while (stdoutfd < 1) 129 128 stdoutfd = vfs_clone(outfd, -1, false); 130 _vfs_open(stdoutfd, MODE_APPEND);129 vfs_open(stdoutfd, MODE_APPEND); 131 130 stdout = fdopen(stdoutfd, "a"); 132 131 } else { … … 141 140 while (stderrfd < 2) 142 141 stderrfd = vfs_clone(errfd, -1, false); 143 _vfs_open(stderrfd, MODE_APPEND);142 vfs_open(stderrfd, MODE_APPEND); 144 143 stderr = fdopen(stderrfd, "a"); 145 144 } else { … … 157 156 } 158 157 159 static bool parse_mode(const char * mode, int *flags)158 static bool parse_mode(const char *fmode, int *mode, bool *create, bool *truncate) 160 159 { 161 160 /* Parse mode except first character. */ 162 const char *mp = mode;161 const char *mp = fmode; 163 162 if (*mp++ == 0) { 164 163 errno = EINVAL; … … 180 179 return false; 181 180 } 182 183 /* Parse first character of mode and determine flags for open(). */ 184 switch (mode[0]) { 181 182 *create = false; 183 *truncate = false; 184 185 /* Parse first character of fmode and determine mode for vfs_open(). */ 186 switch (fmode[0]) { 185 187 case 'r': 186 * flags = plus ? O_RDWR : O_RDONLY;188 *mode = plus ? MODE_READ | MODE_WRITE : MODE_READ; 187 189 break; 188 190 case 'w': 189 *flags = (O_TRUNC | O_CREAT) | (plus ? O_RDWR : O_WRONLY); 191 *mode = plus ? MODE_READ | MODE_WRITE : MODE_WRITE; 192 *create = true; 193 if (!plus) 194 *truncate = true; 190 195 break; 191 196 case 'a': … … 195 200 return false; 196 201 } 197 *flags = (O_APPEND | O_CREAT) | (plus ? O_RDWR : O_WRONLY); 202 203 *mode = MODE_APPEND | (plus ? MODE_READ | MODE_WRITE : MODE_WRITE); 204 *create = true; 198 205 break; 199 206 default: … … 269 276 * 270 277 */ 271 FILE *fopen(const char *path, const char *mode) 272 { 273 int flags; 274 if (!parse_mode(mode, &flags)) 278 FILE *fopen(const char *path, const char *fmode) 279 { 280 int mode; 281 bool create; 282 bool truncate; 283 284 if (!parse_mode(fmode, &mode, &create, &truncate)) 275 285 return NULL; 276 286 … … 281 291 return NULL; 282 292 } 283 284 stream->fd = open(path, flags, 0666); 285 if (stream->fd < 0) { 286 /* errno was set by open() */ 293 294 int flags = WALK_REGULAR; 295 if (create) 296 flags |= WALK_MAY_CREATE; 297 int file = vfs_lookup(path, flags); 298 if (file < 0) { 299 errno = file; 287 300 free(stream); 288 301 return NULL; 289 302 } 290 303 304 int rc = vfs_open(file, mode); 305 if (rc != EOK) { 306 errno = rc; 307 close(file); 308 free(stream); 309 return NULL; 310 } 311 312 if (truncate) { 313 rc = vfs_resize(file, 0); 314 if (rc != EOK) { 315 errno = rc; 316 close(file); 317 free(stream); 318 return NULL; 319 } 320 } 321 322 stream->fd = file; 291 323 stream->pos = 0; 292 324 stream->error = false; -
uspace/lib/c/generic/rtld/module.c
r80743a1 rb19e892 38 38 #include <elf/elf_load.h> 39 39 #include <errno.h> 40 #include <fcntl.h>41 40 #include <loader/pcb.h> 42 41 #include <stdio.h> -
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); -
uspace/lib/c/include/vfs/vfs.h
r80743a1 rb19e892 83 83 84 84 extern int _vfs_walk(int, const char *, int); 85 extern int _vfs_open(int, int);86 extern int vfs_lookup(const char *, int);87 85 88 86 extern int vfs_pass_handle(async_exch_t *, int, async_exch_t *); … … 92 90 extern int vfs_link(int, const char *, vfs_file_kind_t); 93 91 extern int vfs_link_path(const char *, vfs_file_kind_t); 92 extern int vfs_lookup(const char *, int); 93 extern int vfs_lookup_open(const char *, int, int); 94 94 extern int vfs_mount_path(const char *, const char *, const char *, 95 95 const char *, unsigned int, unsigned int); 96 96 extern int vfs_mount(int, const char *, service_id_t, const char *, unsigned, 97 97 unsigned, int *); 98 extern int vfs_open(int, int); 98 99 extern int vfs_resize(int, aoff64_t); 99 100 extern int vfs_root(void); -
uspace/lib/pcut/src/os/helenos.c
r80743a1 rb19e892 41 41 #include <stdio.h> 42 42 #include <task.h> 43 #include <fcntl.h>44 43 #include <fibril_synch.h> 45 44 #include <vfs/vfs.h> … … 162 161 char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE]; 163 162 snprintf(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1, "pcut_%lld.tmp", (unsigned long long) task_get_id()); 164 int tempfile = open(tempfile_name, O_CREAT | O_RDWR);163 int tempfile = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE); 165 164 if (tempfile < 0) { 166 165 pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to create temporary file.", NULL, NULL); -
uspace/lib/posix/include/posix/fcntl.h
r80743a1 rb19e892 41 41 42 42 #include "sys/types.h" 43 #include "libc/fcntl.h"44 43 #include "errno.h" 44 45 #undef O_CREAT 46 #undef O_EXCL 47 #undef O_TRUNC 48 #undef O_APPEND 49 #undef O_RDONLY 50 #undef O_RDWR 51 #undef O_WRONLY 52 #define O_CREAT 1 53 #define O_EXCL 2 54 #define O_TRUNC 4 55 #define O_APPEND 8 56 #define O_RDONLY 16 57 #define O_RDWR 32 58 #define O_WRONLY 64 45 59 46 60 /* Mask for file access modes. */ -
uspace/lib/posix/source/fcntl.c
r80743a1 rb19e892 100 100 * 101 101 * @param pathname Path to the file. 102 * @param flags Access mode flags.102 * @param posix_flags Access mode flags. 103 103 */ 104 int posix_open(const char *pathname, int flags, ...)104 int posix_open(const char *pathname, int posix_flags, ...) 105 105 { 106 mode_t mode = 0; 107 if ((flags & O_CREAT) > 0) { 106 int rc; 107 mode_t posix_mode = 0; 108 if (posix_flags & O_CREAT) { 108 109 va_list args; 109 va_start(args, flags);110 mode = va_arg(args, mode_t);110 va_start(args, posix_flags); 111 posix_mode = va_arg(args, mode_t); 111 112 va_end(args); 113 (void) posix_mode; 112 114 } 113 115 114 return negerrno(open, pathname, flags, mode); 116 if (((posix_flags & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) || 117 ((posix_flags & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) || 118 ((posix_flags & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) || 119 ((posix_flags & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) { 120 errno = EINVAL; 121 return -1; 122 } 123 124 int flags = WALK_REGULAR; 125 if (posix_flags & O_CREAT) { 126 if (posix_flags & O_EXCL) 127 flags |= WALK_MUST_CREATE; 128 else 129 flags |= WALK_MAY_CREATE; 130 } 131 132 int mode = 133 ((posix_flags & O_RDWR) ? MODE_READ | MODE_WRITE : 0) | 134 ((posix_flags & O_RDONLY) ? MODE_READ : 0) | 135 ((posix_flags & O_WRONLY) ? MODE_WRITE : 0) | 136 ((posix_flags & O_APPEND) ? MODE_APPEND : 0); 137 138 int file = rcerrno(vfs_lookup, pathname, flags); 139 if (file < 0) 140 return -1; 141 142 rc = rcerrno(vfs_open, file, mode); 143 if (rc != EOK) { 144 close (file); 145 return -1; 146 } 147 148 if (posix_flags & O_TRUNC) { 149 if (posix_flags & (O_RDWR | O_WRONLY)) { 150 rc = rcerrno(vfs_resize, file, 0); 151 if (rc != EOK) { 152 close(file); 153 return -1; 154 } 155 } 156 } 157 158 return file; 115 159 } 116 160 117 161 /** @} 118 162 */ 163 -
uspace/lib/posix/source/stdlib.c
r80743a1 rb19e892 431 431 } 432 432 433 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);433 fd = posix_open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 434 434 435 435 if (fd == -1) { -
uspace/lib/posix/source/unistd.c
r80743a1 rb19e892 335 335 * Check file existence by attempting to open it. 336 336 */ 337 int fd = negerrno(open, path, O_RDONLY); 338 if (fd < 0) { 339 /* errno was set by open() */ 337 int fd = posix_open(path, O_RDONLY); 338 if (fd < 0) 340 339 return -1; 341 }342 340 close(fd); 343 341 return 0; -
uspace/srv/devman/driver.c
r80743a1 rb19e892 33 33 #include <dirent.h> 34 34 #include <errno.h> 35 #include <fcntl.h>36 35 #include <io/log.h> 37 36 #include <vfs/vfs.h> -
uspace/srv/devman/match.c
r80743a1 rb19e892 32 32 33 33 #include <errno.h> 34 #include <fcntl.h>35 34 #include <io/log.h> 36 35 #include <str.h> … … 203 202 struct stat st; 204 203 205 fd = open(conf_path, O_RDONLY);204 fd = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ); 206 205 if (fd < 0) { 207 206 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.", -
uspace/srv/hid/input/ctl/kbdev.c
r80743a1 rb19e892 39 39 #include <stdbool.h> 40 40 #include <errno.h> 41 #include <fcntl.h>42 41 #include <io/console.h> 43 42 #include <io/keycode.h> -
uspace/srv/hid/input/port/adb.c
r80743a1 rb19e892 38 38 #include <async.h> 39 39 #include <vfs/vfs.h> 40 #include <fcntl.h>41 40 #include <errno.h> 42 41 #include <loc.h> -
uspace/srv/hid/input/proto/mousedev.c
r80743a1 rb19e892 37 37 38 38 #include <stdio.h> 39 #include <fcntl.h>40 39 #include <vfs/vfs_sess.h> 41 40 #include <malloc.h> -
uspace/srv/loader/main.c
r80743a1 rb19e892 48 48 #include <unistd.h> 49 49 #include <stdbool.h> 50 #include <fcntl.h>51 50 #include <sys/types.h> 52 51 #include <ipc/services.h> -
uspace/srv/vfs/vfs_ipc.c
r80743a1 rb19e892 99 99 { 100 100 int fd = IPC_GET_ARG1(*request); 101 int flags= IPC_GET_ARG2(*request);102 103 int rc = vfs_op_open(fd, flags);101 int mode = IPC_GET_ARG2(*request); 102 103 int rc = vfs_op_open(fd, mode); 104 104 async_answer_0(rid, rc); 105 105 } -
uspace/srv/vfs/vfs_ops.c
r80743a1 rb19e892 49 49 #include <unistd.h> 50 50 #include <ctype.h> 51 #include <fcntl.h>52 51 #include <assert.h> 53 52 #include <vfs/canonify.h> … … 274 273 } 275 274 276 int vfs_op_open(int fd, int flags)277 { 278 if ( flags== 0)275 int vfs_op_open(int fd, int mode) 276 { 277 if (mode == 0) 279 278 return EINVAL; 280 279 … … 283 282 return EBADF; 284 283 285 if (( flags& ~file->permissions) != 0) {284 if ((mode & ~file->permissions) != 0) { 286 285 vfs_file_put(file); 287 286 return EPERM; … … 293 292 } 294 293 295 file->open_read = ( flags& MODE_READ) != 0;296 file->open_write = ( flags& (MODE_WRITE | MODE_APPEND)) != 0;297 file->append = ( flags& MODE_APPEND) != 0;294 file->open_read = (mode & MODE_READ) != 0; 295 file->open_write = (mode & (MODE_WRITE | MODE_APPEND)) != 0; 296 file->append = (mode & MODE_APPEND) != 0; 298 297 299 298 if (!file->open_read && !file->open_write) {
Note:
See TracChangeset
for help on using the changeset viewer.