Changeset b19e892 in mainline


Ignore:
Timestamp:
2017-04-02T10:39:13Z (7 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
Files:
1 deleted
44 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);
  • uspace/dist/src/c/demos/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/drv/bus/isa/isa.c

    r80743a1 rb19e892  
    5151#include <malloc.h>
    5252#include <dirent.h>
    53 #include <fcntl.h>
    5453#include <ipc/irc.h>
    5554#include <ipc/services.h>
     
    256255        struct stat st;
    257256
    258         fd = open(conf_path, O_RDONLY);
     257        fd = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ);
    259258        if (fd < 0) {
    260259                ddf_msg(LVL_ERROR, "Unable to open %s", conf_path);
  • uspace/drv/char/ns8250/ns8250.c

    r80743a1 rb19e892  
    4848#include <malloc.h>
    4949#include <dirent.h>
    50 #include <fcntl.h>
    5150#include <ddi.h>
    5251
  • uspace/lib/bithenge/src/file.c

    r80743a1 rb19e892  
    3838#include <assert.h>
    3939#include <errno.h>
    40 #include <fcntl.h>
    4140#include <stdio.h>
    4241#include <stdlib.h>
     
    146145        assert(filename);
    147146
    148         int fd = open(filename, O_RDONLY);
     147        int fd = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ);
    149148        if (fd < 0)
    150149                return errno;
  • uspace/lib/c/generic/elf/elf_mod.c

    r80743a1 rb19e892  
    9797
    9898        int ofile = vfs_clone(file, -1, true);
    99         int rc = _vfs_open(ofile, MODE_READ);
     99        int rc = vfs_open(ofile, MODE_READ);
    100100        if (rc != EOK) {
    101101                return rc;
  • uspace/lib/c/generic/io/io.c

    r80743a1 rb19e892  
    3535#include <stdio.h>
    3636#include <unistd.h>
    37 #include <fcntl.h>
    3837#include <assert.h>
    3938#include <str.h>
     
    115114                int stdinfd = vfs_clone(infd, -1, false);
    116115                assert(stdinfd == 0);
    117                 _vfs_open(stdinfd, MODE_READ);
     116                vfs_open(stdinfd, MODE_READ);
    118117                stdin = fdopen(stdinfd, "r");
    119118        } else {
     
    128127                while (stdoutfd < 1)
    129128                        stdoutfd = vfs_clone(outfd, -1, false);
    130                 _vfs_open(stdoutfd, MODE_APPEND);
     129                vfs_open(stdoutfd, MODE_APPEND);
    131130                stdout = fdopen(stdoutfd, "a");
    132131        } else {
     
    141140                while (stderrfd < 2)
    142141                        stderrfd = vfs_clone(errfd, -1, false);
    143                 _vfs_open(stderrfd, MODE_APPEND);
     142                vfs_open(stderrfd, MODE_APPEND);
    144143                stderr = fdopen(stderrfd, "a");
    145144        } else {
     
    157156}
    158157
    159 static bool parse_mode(const char *mode, int *flags)
     158static bool parse_mode(const char *fmode, int *mode, bool *create, bool *truncate)
    160159{
    161160        /* Parse mode except first character. */
    162         const char *mp = mode;
     161        const char *mp = fmode;
    163162        if (*mp++ == 0) {
    164163                errno = EINVAL;
     
    180179                return false;
    181180        }
    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]) {
    185187        case 'r':
    186                 *flags = plus ? O_RDWR : O_RDONLY;
     188                *mode = plus ? MODE_READ | MODE_WRITE : MODE_READ;
    187189                break;
    188190        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;
    190195                break;
    191196        case 'a':
     
    195200                        return false;
    196201                }
    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;
    198205                break;
    199206        default:
     
    269276 *
    270277 */
    271 FILE *fopen(const char *path, const char *mode)
    272 {
    273         int flags;
    274         if (!parse_mode(mode, &flags))
     278FILE *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))
    275285                return NULL;
    276286       
     
    281291                return NULL;
    282292        }
    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;
    287300                free(stream);
    288301                return NULL;
    289302        }
    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;
    291323        stream->pos = 0;
    292324        stream->error = false;
  • uspace/lib/c/generic/rtld/module.c

    r80743a1 rb19e892  
    3838#include <elf/elf_load.h>
    3939#include <errno.h>
    40 #include <fcntl.h>
    4140#include <loader/pcb.h>
    4241#include <stdio.h>
  • uspace/lib/c/generic/vfs/vfs.c

    r80743a1 rb19e892  
    4141#include <unistd.h>
    4242#include <dirent.h>
    43 #include <fcntl.h>
    4443#include <stdio.h>
    4544#include <sys/types.h>
     
    155154}
    156155
    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;
     156int 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
     165int 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;
    164178}
    165179
     
    353367}
    354368
    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                 else
    362                         flags |= WALK_MAY_CREATE;
    363         }
    364         return flags;
    365 }
    366 
    367 /** Open file.
    368  *
    369  * @param path File path
    370  * @param oflag O_xxx flags
    371  * @param mode File mode (only with O_CREAT)
    372  *
    373  * @return Nonnegative file descriptor on success. On error -1 is returned
    374  *         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 
    415369/** Close file.
    416370 *
     
    703657        }
    704658       
    705         int rc = _vfs_open(fd, MODE_READ);
     659        int rc = vfs_open(fd, MODE_READ);
    706660        if (rc < 0) {
    707661                free(dirp);
  • uspace/lib/c/include/vfs/vfs.h

    r80743a1 rb19e892  
    8383
    8484extern int _vfs_walk(int, const char *, int);
    85 extern int _vfs_open(int, int);
    86 extern int vfs_lookup(const char *, int);
    8785
    8886extern int vfs_pass_handle(async_exch_t *, int, async_exch_t *);
     
    9290extern int vfs_link(int, const char *, vfs_file_kind_t);
    9391extern int vfs_link_path(const char *, vfs_file_kind_t);
     92extern int vfs_lookup(const char *, int);
     93extern int vfs_lookup_open(const char *, int, int);
    9494extern int vfs_mount_path(const char *, const char *, const char *,
    9595    const char *, unsigned int, unsigned int);
    9696extern int vfs_mount(int, const char *, service_id_t, const char *, unsigned,
    9797    unsigned, int *);
     98extern int vfs_open(int, int);
    9899extern int vfs_resize(int, aoff64_t);
    99100extern int vfs_root(void);
  • uspace/lib/pcut/src/os/helenos.c

    r80743a1 rb19e892  
    4141#include <stdio.h>
    4242#include <task.h>
    43 #include <fcntl.h>
    4443#include <fibril_synch.h>
    4544#include <vfs/vfs.h>
     
    162161        char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
    163162        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);
    165164        if (tempfile < 0) {
    166165                pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to create temporary file.", NULL, NULL);
  • uspace/lib/posix/include/posix/fcntl.h

    r80743a1 rb19e892  
    4141
    4242#include "sys/types.h"
    43 #include "libc/fcntl.h"
    4443#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
    4559
    4660/* Mask for file access modes. */
  • uspace/lib/posix/source/fcntl.c

    r80743a1 rb19e892  
    100100 *
    101101 * @param pathname Path to the file.
    102  * @param flags Access mode flags.
     102 * @param posix_flags Access mode flags.
    103103 */
    104 int posix_open(const char *pathname, int flags, ...)
     104int posix_open(const char *pathname, int posix_flags, ...)
    105105{
    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) {
    108109                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);
    111112                va_end(args);
     113                (void) posix_mode;
    112114        }
    113115
    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;
    115159}
    116160
    117161/** @}
    118162 */
     163
  • uspace/lib/posix/source/stdlib.c

    r80743a1 rb19e892  
    431431                }
    432432               
    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);
    434434               
    435435                if (fd == -1) {
  • uspace/lib/posix/source/unistd.c

    r80743a1 rb19e892  
    335335                 * Check file existence by attempting to open it.
    336336                 */
    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)
    340339                        return -1;
    341                 }
    342340                close(fd);
    343341                return 0;
  • uspace/srv/devman/driver.c

    r80743a1 rb19e892  
    3333#include <dirent.h>
    3434#include <errno.h>
    35 #include <fcntl.h>
    3635#include <io/log.h>
    3736#include <vfs/vfs.h>
  • uspace/srv/devman/match.c

    r80743a1 rb19e892  
    3232
    3333#include <errno.h>
    34 #include <fcntl.h>
    3534#include <io/log.h>
    3635#include <str.h>
     
    203202        struct stat st;
    204203       
    205         fd = open(conf_path, O_RDONLY);
     204        fd = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ);
    206205        if (fd < 0) {
    207206                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.",
  • uspace/srv/hid/input/ctl/kbdev.c

    r80743a1 rb19e892  
    3939#include <stdbool.h>
    4040#include <errno.h>
    41 #include <fcntl.h>
    4241#include <io/console.h>
    4342#include <io/keycode.h>
  • uspace/srv/hid/input/port/adb.c

    r80743a1 rb19e892  
    3838#include <async.h>
    3939#include <vfs/vfs.h>
    40 #include <fcntl.h>
    4140#include <errno.h>
    4241#include <loc.h>
  • uspace/srv/hid/input/proto/mousedev.c

    r80743a1 rb19e892  
    3737
    3838#include <stdio.h>
    39 #include <fcntl.h>
    4039#include <vfs/vfs_sess.h>
    4140#include <malloc.h>
  • uspace/srv/loader/main.c

    r80743a1 rb19e892  
    4848#include <unistd.h>
    4949#include <stdbool.h>
    50 #include <fcntl.h>
    5150#include <sys/types.h>
    5251#include <ipc/services.h>
  • uspace/srv/vfs/vfs_ipc.c

    r80743a1 rb19e892  
    9999{
    100100        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);
    104104        async_answer_0(rid, rc);
    105105}
  • uspace/srv/vfs/vfs_ops.c

    r80743a1 rb19e892  
    4949#include <unistd.h>
    5050#include <ctype.h>
    51 #include <fcntl.h>
    5251#include <assert.h>
    5352#include <vfs/canonify.h>
     
    274273}
    275274
    276 int vfs_op_open(int fd, int flags)
    277 {
    278         if (flags == 0)
     275int vfs_op_open(int fd, int mode)
     276{
     277        if (mode == 0)
    279278                return EINVAL;
    280279
     
    283282                return EBADF;
    284283       
    285         if ((flags & ~file->permissions) != 0) {
     284        if ((mode & ~file->permissions) != 0) {
    286285                vfs_file_put(file);
    287286                return EPERM;
     
    293292        }
    294293       
    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;
    298297       
    299298        if (!file->open_read && !file->open_write) {
Note: See TracChangeset for help on using the changeset viewer.