Changeset b19e892 in mainline for uspace/app


Ignore:
Timestamp:
2017-04-02T10:39:13Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9c4cf0d
Parents:
80743a1
Message:

Merge open() with posix_open() and provide vfs_lookup_open() instead

vfs_lookup_open() is really just a convenience wrapper around
vfs_lookup() and vfs_open().

Location:
uspace/app
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r80743a1 rb19e892  
    3333#include <getopt.h>
    3434#include <str.h>
    35 #include <fcntl.h>
    3635#include <io/console.h>
    3736#include <io/color.h>
     
    196195                blen = STR_BOUNDS(1);
    197196        } else
    198                 fd = open(fname, O_RDONLY);
     197                fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
    199198       
    200199        if (fd < 0) {
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    r80743a1 rb19e892  
    2828
    2929#include <errno.h>
    30 #include <fcntl.h>
    3130#include <getopt.h>
    3231#include <mem.h>
     
    8281
    8382        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);
    8584                if (fd[i] < 0) {
    86                         rc = errno;
     85                        rc = fd[i];
    8786                        printf("Unable to open %s\n", fn[i]);
    8887                        goto end;
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r80743a1 rb19e892  
    3535#include <getopt.h>
    3636#include <str.h>
    37 #include <fcntl.h>
    3837#include <vfs/vfs.h>
    3938#include <dirent.h>
     
    383382                printf("Copying %s to %s\n", src, dest);
    384383
    385         if (-1 == (fd1 = open(src, O_RDONLY))) {
     384        fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ);
     385        if (fd1 < 0) {
    386386                printf("Unable to open source file %s\n", src);
    387387                return -1;
    388388        }
    389389
    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) {
    391392                printf("Unable to open destination file %s\n", dest);
    392393                close(fd1);
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r80743a1 rb19e892  
    3636#include <unistd.h>
    3737#include <dirent.h>
    38 #include <fcntl.h>
    3938#include <getopt.h>
    4039#include <sys/types.h>
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    r80743a1 rb19e892  
    3030#include <stdlib.h>
    3131#include <dirent.h>
    32 #include <fcntl.h>
    3332#include <sys/types.h>
    3433#include <getopt.h>
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r80743a1 rb19e892  
    3131#include <stdlib.h>
    3232#include <dirent.h>
    33 #include <fcntl.h>
    3433#include <sys/types.h>
    3534#include <macros.h>
     
    3837#include <str.h>
    3938#include <ctype.h>
     39#include <vfs/vfs.h>
    4040
    4141#include "config.h"
     
    156156        file_name = argv[optind];
    157157
    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);
    159159        if (fd < 0) {
    160160                printf("%s: failed to create file %s.\n", cmdname, file_name);
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r80743a1 rb19e892  
    3131#include <stdlib.h>
    3232#include <unistd.h>
    33 #include <fcntl.h>
    3433#include <dirent.h>
    3534#include <getopt.h>
     
    151150        }
    152151
    153         fd = open(path, O_RDONLY);
     152        fd = vfs_lookup(path, WALK_REGULAR);
    154153        if (fd >= 0) {
    155154                close(fd);
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    r80743a1 rb19e892  
    3535#include <stdlib.h>
    3636#include <unistd.h>
    37 #include <fcntl.h>
    3837#include <dirent.h>
    3938#include <sys/types.h>
     
    125124                if ((!no_create) ||
    126125                    ((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);
    128127                }
    129128               
  • uspace/app/bdsh/exec.c

    r80743a1 rb19e892  
    3737#include <unistd.h>
    3838#include <str.h>
    39 #include <fcntl.h>
    4039#include <str_error.h>
    4140#include <errno.h>
     
    6059        int fd;
    6160
    62         fd = open(f, O_RDONLY);
     61        fd = vfs_lookup_open(f, WALK_REGULAR, MODE_READ);
    6362        if (fd >= 0) {
    6463                close(fd);
  • uspace/app/fontviewer/fontviewer.c

    r80743a1 rb19e892  
    3535#include <stdio.h>
    3636#include <unistd.h>
    37 #include <fcntl.h>
    3837#include <errno.h>
    3938#include <malloc.h>
  • uspace/app/getterm/getterm.c

    r80743a1 rb19e892  
    3636
    3737#include <sys/types.h>
    38 #include <fcntl.h>
    3938#include <unistd.h>
    4039#include <stdio.h>
     
    5958}
    6059
    61 static void reopen(FILE **stream, int fd, const char *path, int flags,
    62     const char *mode)
     60static void reopen(FILE **stream, int fd, const char *path, int mode,
     61    const char *fmode)
    6362{
    6463        if (fclose(*stream))
     
    6766        *stream = NULL;
    6867       
    69         int oldfd = open(path, flags);
     68        int oldfd = vfs_lookup_open(path, WALK_REGULAR, mode);
    7069        if (oldfd < 0)
    7170                return;
     
    7978        }
    8079       
    81         *stream = fdopen(fd, mode);
     80        *stream = fdopen(fd, fmode);
    8281}
    8382
     
    142141        snprintf(term_node, LOC_NAME_MAXLEN, "%s/%s", locfs, term);
    143142       
    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");
    147146       
    148147        if (stdin == NULL)
  • uspace/app/init/init.c

    r80743a1 rb19e892  
    4141#include <stdbool.h>
    4242#include <errno.h>
    43 #include <fcntl.h>
    4443#include <task.h>
    4544#include <malloc.h>
  • uspace/app/redir/redir.c

    r80743a1 rb19e892  
    3737#include <sys/types.h>
    3838#include <stdlib.h>
    39 #include <fcntl.h>
    4039#include <unistd.h>
    4140#include <str.h>
     
    5453}
    5554
    56 static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode)
     55static void reopen(FILE **stream, int fd, const char *path, int flags, int mode,
     56    const char *fmode)
    5757{
    5858        if (fclose(*stream))
     
    6161        *stream = NULL;
    6262       
    63         int oldfd = open(path, flags);
     63        int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode);
    6464        if (oldfd < 0)
    6565                return;
     
    7373        }
    7474       
    75         *stream = fdopen(fd, mode);
     75        *stream = fdopen(fd, fmode);
    7676}
    7777
     
    122122                                return -2;
    123123                        }
    124                         reopen(&stdin, 0, argv[i], O_RDONLY, "r");
     124                        reopen(&stdin, 0, argv[i], 0, MODE_READ, "r");
    125125                } else if (str_cmp(argv[i], "-o") == 0) {
    126126                        i++;
     
    129129                                return -3;
    130130                        }
    131                         reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w");
     131                        reopen(&stdout, 1, argv[i], WALK_MAY_CREATE, MODE_WRITE,
     132                            "w");
    132133                } else if (str_cmp(argv[i], "-e") == 0) {
    133134                        i++;
     
    136137                                return -4;
    137138                        }
    138                         reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w");
     139                        reopen(&stderr, 2, argv[i], WALK_MAY_CREATE, MODE_WRITE,
     140                            "w");
    139141                } else if (str_cmp(argv[i], "--") == 0) {
    140142                        i++;
  • uspace/app/sysinst/futil.c

    r80743a1 rb19e892  
    3535#include <dirent.h>
    3636#include <errno.h>
    37 #include <fcntl.h>
    3837#include <stdbool.h>
    3938#include <stdio.h>
     
    6463        printf("Copy '%s' to '%s'.\n", srcp, destp);
    6564
    66         sf = open(srcp, O_RDONLY);
     65        sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ);
    6766        if (sf < 0)
    6867                return EIO;
    6968
    70         df = open(destp, O_CREAT | O_WRONLY, 0);
     69        df = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE);
    7170        if (df < 0)
    7271                return EIO;
     
    162161        struct stat st;
    163162
    164         sf = open(srcp, O_RDONLY);
     163        sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ);
    165164        if (sf < 0)
    166165                return ENOENT;
  • uspace/app/taskdump/elf_core.c

    r80743a1 rb19e892  
    5555#include <sys/types.h>
    5656#include <unistd.h>
    57 #include <fcntl.h>
    5857#include <mem.h>
    5958#include <stdint.h>
     
    6261#include <macros.h>
    6362#include <libarch/istate.h>
     63#include <vfs/vfs.h>
    6464
    6565#include "elf_core.h"
     
    123123        }
    124124
    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);
    126127        if (fd < 0) {
    127128                printf("Failed opening file.\n");
  • uspace/app/taskdump/symtab.c

    r80743a1 rb19e892  
    4141#include <errno.h>
    4242#include <sys/types.h>
    43 #include <fcntl.h>
     43#include <vfs/vfs.h>
    4444
    4545#include "include/symtab.h"
     
    8181                return ENOMEM;
    8282
    83         fd = open(file_name, O_RDONLY);
     83        fd = vfs_lookup_open(file_name, WALK_REGULAR, MODE_READ);
    8484        if (fd < 0) {
    8585                printf("failed opening file\n");
  • uspace/app/tester/hw/misc/virtchar1.c

    r80743a1 rb19e892  
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
    47 #include <fcntl.h>
    4847#include "../../tester.h"
    4948
     
    5554{
    5655        TPRINTF("Opening `%s'...\n", path);
    57         int fd = open(path, O_RDONLY);
     56        int fd = vfs_lookup(path, WALK_REGULAR);
    5857        if (fd < 0) {
    5958                TPRINTF("   ...error: %s\n", str_error(errno));
  • uspace/app/tester/mm/pager1.c

    r80743a1 rb19e892  
    2929#include <stdio.h>
    3030#include <vfs/vfs.h>
    31 #include <fcntl.h>
    3231#include <stdlib.h>
    3332#include <malloc.h>
     
    4847        TPRINTF("Creating temporary file...\n");
    4948
    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);
    5151        if (fd < 0)
    5252                return NULL;
  • uspace/app/tester/vfs/vfs1.c

    r80743a1 rb19e892  
    3333#include <vfs/vfs.h>
    3434#include <unistd.h>
    35 #include <fcntl.h>
    3635#include <dirent.h>
    3736#include <loc.h>
     
    7978        TPRINTF("Created directory %s\n", TEST_DIRECTORY);
    8079       
    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);
    8282        if (fd0 < 0)
    83                 return "open() failed";
     83                return "vfs_lookup_open() failed";
    8484        TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0);
    8585       
  • uspace/app/tetris/scores.c

    r80743a1 rb19e892  
    6565#include <vfs/vfs.h>
    6666#include <stdlib.h>
    67 #include <fcntl.h>
    6867#include <err.h>
    6968#include <time.h>
  • uspace/app/viewer/viewer.c

    r80743a1 rb19e892  
    3535#include <stdio.h>
    3636#include <unistd.h>
    37 #include <fcntl.h>
    3837#include <vfs/vfs.h>
    3938#include <errno.h>
     
    110109static bool img_load(const char *fname, surface_t **p_local_surface)
    111110{
    112         int fd = open(fname, O_RDONLY);
     111        int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
    113112        if (fd < 0)
    114113                return false;
  • uspace/app/websrv/websrv.c

    r80743a1 rb19e892  
    4040#include <sys/types.h>
    4141#include <stdlib.h>
    42 #include <fcntl.h>
    4342#include <task.h>
     43
     44#include <vfs/vfs.h>
    4445
    4546#include <inet/addr.h>
     
    224225                return ENOMEM;
    225226       
    226         int fd = open(fname, O_RDONLY);
     227        int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
    227228        if (fd < 0) {
    228229                rc = send_response(conn, msg_not_found);
Note: See TracChangeset for help on using the changeset viewer.