Changeset 368ee04 in mainline for uspace/app


Ignore:
Timestamp:
2017-04-05T18:10:39Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93ad8166
Parents:
39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/vfs-2.5-cherrypick

This merge cherry-picks some of the changesets from Jiri Zarevucky's:

lp:~zarevucky-jiri/helenos/vfs-2.5

and then continues independently, yet sometime in a similar vein.

Roughly speaking, Jiri's branch is merged entirely up to its revision
1926 and then cherry-picked on and off until its revision 1965. Among
these changes are:

  • relativization of the API,
  • client-side roots,
  • server-side mounts,
  • inbox for passing arbitrary files from parent to child,
  • some streamlining and cleanup.

Additional changes include:

  • addressing issues introduced by the above changes,
  • client-side I/O cursors (file positions),
  • all HelenOS file system APIs begin with the vfs_ prefix and can be used after including vfs/vfs.h,
  • removal of some POSIX-ish headers and definitions,
  • additional cleanup.
Location:
uspace/app
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    r39f892a9 r368ee04  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <unistd.h>
    3231#include <str.h>
    3332#include <errno.h>
     33#include <vfs/vfs.h>
    3434
    3535#include "util.h"
     
    5151static bool previous_directory_set = false;
    5252
    53 static int chdir_and_remember(const char *new_dir) {
     53static int chdir_and_remember(const char *new_dir)
     54{
    5455
    55         char *ok = getcwd(previous_directory_tmp, PATH_MAX);
    56         previous_directory_valid = ok != NULL;
     56        int rc = vfs_cwd_get(previous_directory_tmp, PATH_MAX);
     57        previous_directory_valid = (rc == EOK);
    5758        previous_directory_set = true;
    5859
    59         if (chdir(new_dir) != 0)
    60                 return errno;
     60        rc = vfs_cwd_set(new_dir);
     61        if (rc != EOK)
     62                return rc;
    6163
    6264        str_cpy(previous_directory, PATH_MAX, previous_directory_tmp);
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r39f892a9 r368ee04  
    3333#include <getopt.h>
    3434#include <str.h>
    35 #include <fcntl.h>
    3635#include <io/console.h>
    3736#include <io/color.h>
     
    187186        size_t offset = 0, copied_bytes = 0;
    188187        off64_t file_size = 0, length = 0;
     188        aoff64_t pos = 0;
    189189
    190190        bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0);
     
    195195                blen = STR_BOUNDS(1);
    196196        } else
    197                 fd = open(fname, O_RDONLY);
     197                fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
    198198       
    199199        if (fd < 0) {
     
    203203
    204204        if (NULL == (buff = (char *) malloc(blen + 1))) {
    205                 close(fd);
     205                vfs_put(fd);
    206206                printf("Unable to allocate enough memory to read %s\n",
    207                         fname);
     207                    fname);
    208208                return 1;
    209209        }
    210210
    211211        if (tail != CAT_FULL_FILE) {
    212                 file_size = lseek(fd, 0, SEEK_END);
     212                struct stat st;
     213
     214                if (vfs_stat(fd, &st) != EOK) {
     215                        vfs_put(fd);
     216                        free(buff);
     217                        printf("Unable to vfs_stat %d\n", fd);
     218                        return 1;
     219                }
     220                file_size = st.size;
    213221                if (head == CAT_FULL_FILE) {
    214222                        head = file_size;
     
    223231
    224232                if (tail_first) {
    225                         lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);
     233                        pos = (tail >= file_size) ? 0 : (file_size - tail);
    226234                } else {
    227                         lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);
     235                        pos = ((head - tail) >= file_size) ? 0 : (head - tail);
    228236                }
    229237        } else
     
    243251                }
    244252               
    245                 bytes = read(fd, buff + copied_bytes, bytes_to_read);
     253                bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read);
    246254                copied_bytes = 0;
    247255
     
    279287        } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));
    280288
    281         close(fd);
     289        vfs_put(fd);
    282290        if (bytes == -1) {
    283291                printf("Error reading %s\n", fname);
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    r39f892a9 r368ee04  
    2828
    2929#include <errno.h>
    30 #include <fcntl.h>
    3130#include <getopt.h>
    3231#include <mem.h>
     
    7978        char buffer[2][CMP_BUFLEN];
    8079        ssize_t offset[2];
     80        aoff64_t pos[2] = {};
    8181
    8282        for (int i = 0; i < 2; i++) {
    83                 fd[i] = open(fn[i], O_RDONLY);
     83                fd[i] = vfs_lookup_open(fn[i], WALK_REGULAR, MODE_READ);
    8484                if (fd[i] < 0) {
    85                         rc = errno;
     85                        rc = fd[i];
    8686                        printf("Unable to open %s\n", fn[i]);
    8787                        goto end;
     
    9494                        ssize_t size;
    9595                        do {
    96                                 size = read(fd[i], buffer[i] + offset[i],
     96                                size = vfs_read(fd[i], &pos[i],
     97                                    buffer[i] + offset[i],
    9798                                    CMP_BUFLEN - offset[i]);
    9899                                if (size < 0) {
    99                                         rc = errno;
     100                                        rc = size;
    100101                                        printf("Error reading from %s\n",
    101102                                            fn[i]);
     
    115116end:
    116117        if (fd[0] >= 0)
    117                 close(fd[0]);
     118                vfs_put(fd[0]);
    118119        if (fd[1] >= 0)
    119                 close(fd[1]);
     120                vfs_put(fd[1]);
    120121        return rc;
    121122}
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r39f892a9 r368ee04  
    3535#include <getopt.h>
    3636#include <str.h>
    37 #include <fcntl.h>
    38 #include <sys/stat.h>
     37#include <vfs/vfs.h>
    3938#include <dirent.h>
    4039#include "config.h"
     
    8382        struct stat s;
    8483
    85         int r = stat(path, &s);
    86 
    87         if (r != 0)
     84        int r = vfs_stat_path(path, &s);
     85
     86        if (r != EOK)
    8887                return TYPE_NONE;
    8988        else if (s.is_directory)
     
    235234                         */
    236235                        if (force && !interactive) {
    237                                 if (unlink(dest_path) != 0) {
     236                                if (vfs_unlink_path(dest_path) != EOK) {
    238237                                        printf("Unable to remove %s\n",
    239238                                            dest_path);
     
    246245                                if (overwrite) {
    247246                                        printf("Overwriting file: %s\n", dest_path);
    248                                         if (unlink(dest_path) != 0) {
     247                                        if (vfs_unlink_path(dest_path) != EOK) {
    249248                                                printf("Unable to remove %s\n", dest_path);
    250249                                                goto exit;
     
    295294                                merge_paths(dest_path, PATH_MAX, src_dirname);
    296295
    297                                 if (mkdir(dest_path, 0) != 0) {
     296                                if (vfs_link_path(dest_path, KIND_DIRECTORY,
     297                                    NULL) != EOK) {
    298298                                        printf("Unable to create "
    299299                                            "dest directory %s\n", dest_path);
     
    309309                         * e.g. cp -r /src /data/new_dir_src
    310310                         */
    311                         if (mkdir(dest_path, 0) != 0) {
     311                        if (vfs_link_path(dest_path, KIND_DIRECTORY,
     312                            NULL) != EOK) {
    312313                                printf("Unable to create "
    313314                                    "dest directory %s\n", dest_path);
     
    341342
    342343                        /* Check if we are copying a directory into itself */
    343                         stat(src_dent, &src_s);
    344                         stat(dest_path, &dest_s);
     344                        vfs_stat_path(src_dent, &src_s);
     345                        vfs_stat_path(dest_path, &dest_s);
    345346
    346347                        if (dest_s.index == src_s.index &&
     
    377378        int64_t copied = 0;
    378379        char *buff = NULL;
     380        aoff64_t posr = 0, posw = 0;
     381        struct stat st;
    379382
    380383        if (vb)
    381384                printf("Copying %s to %s\n", src, dest);
    382385
    383         if (-1 == (fd1 = open(src, O_RDONLY))) {
     386        fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ);
     387        if (fd1 < 0) {
    384388                printf("Unable to open source file %s\n", src);
    385389                return -1;
    386390        }
    387391
    388         if (-1 == (fd2 = open(dest, O_CREAT))) {
     392        fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE);
     393        if (fd2 < 0) {
    389394                printf("Unable to open destination file %s\n", dest);
    390                 close(fd1);
     395                vfs_put(fd1);
    391396                return -1;
    392397        }
    393398
    394         total = lseek(fd1, 0, SEEK_END);
    395 
     399        if (vfs_stat(fd1, &st) != EOK) {
     400                printf("Unable to fstat %d\n", fd1);
     401                vfs_put(fd1);
     402                vfs_put(fd2);
     403                return -1;     
     404        }
     405
     406        total = st.size;
    396407        if (vb)
    397408                printf("%" PRIu64 " bytes to copy\n", total);
    398 
    399         lseek(fd1, 0, SEEK_SET);
    400409
    401410        if (NULL == (buff = (char *) malloc(blen))) {
     
    406415        }
    407416
    408         while ((bytes = read(fd1, buff, blen)) > 0) {
    409                 if ((bytes = write(fd2, buff, bytes)) < 0)
     417        while ((bytes = vfs_read(fd1, &posr, buff, blen)) > 0) {
     418                if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0)
    410419                        break;
    411420                copied += bytes;
     
    413422
    414423        if (bytes < 0) {
    415                 printf("\nError copying %s, (%d)\n", src, errno);
     424                printf("\nError copying %s, (%d)\n", src, bytes);
    416425                copied = bytes;
    417426        }
    418427
    419428out:
    420         close(fd1);
    421         close(fd2);
     429        vfs_put(fd1);
     430        vfs_put(fd2);
    422431        if (buff)
    423432                free(buff);
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r39f892a9 r368ee04  
    3434#include <stdio.h>
    3535#include <stdlib.h>
    36 #include <unistd.h>
    3736#include <dirent.h>
    38 #include <fcntl.h>
    3937#include <getopt.h>
    4038#include <sys/types.h>
    41 #include <sys/stat.h>
     39#include <vfs/vfs.h>
    4240#include <str.h>
    4341#include <sort.h>
     
    185183                buff[len] = '\0';
    186184
    187                 rc = stat(buff, &tosort[nbdirs++].s);
    188                 if (rc != 0) {
     185                rc = vfs_stat_path(buff, &tosort[nbdirs++].s);
     186                if (rc != EOK) {
    189187                        printf("ls: skipping bogus node %s\n", buff);
    190                         printf("error=%d\n", errno);
     188                        printf("error=%d\n", rc);
    191189                        goto out;
    192190                }
     
    315313static unsigned int ls_scope(const char *path, struct dir_elem_t *de)
    316314{
    317         if (stat(path, &de->s) != 0) {
     315        if (vfs_stat_path(path, &de->s) != EOK) {
    318316                cli_error(CL_ENOENT, "%s", path);
    319317                return LS_BOGUS;
     
    388386
    389387        if (argc == 0) {
    390                 if (getcwd(de.name, PATH_MAX) == NULL) {
     388                if (vfs_cwd_get(de.name, PATH_MAX) != EOK) {
    391389                        cli_error(CL_EFAIL, "%s: Failed determining working "
    392390                            "directory", cmdname);
  • uspace/app/bdsh/cmds/modules/ls/ls.h

    r39f892a9 r368ee04  
    11#ifndef LS_H
    22#define LS_H
     3
     4#include <vfs/vfs.h>
    35
    46/* Various values that can be returned by ls_scope() */
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    r39f892a9 r368ee04  
    3030#include <stdlib.h>
    3131#include <dirent.h>
    32 #include <fcntl.h>
    3332#include <sys/types.h>
    34 #include <sys/stat.h>
    3533#include <getopt.h>
    3634#include <stdarg.h>
     
    9896
    9997        if (!create_parents) {
    100                 if (mkdir(path, 0) != 0) {
     98                ret = vfs_link_path(path, KIND_DIRECTORY, NULL);
     99                if (ret != EOK) {
    101100                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    102                             cmdname, path, str_error(errno));
     101                            cmdname, path, str_error(ret));
    103102                        ret = 1;
    104103                }
     
    136135                        path[prev_off] = 0;
    137136
    138                         if (mkdir(path, 0) != 0 && errno != EEXIST) {
     137                        ret = vfs_link_path(path, KIND_DIRECTORY, NULL);
     138                        if (ret != EOK && ret != EEXIST) {
    139139                                cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    140                                     cmdname, path, str_error(errno));
     140                                    cmdname, path, str_error(ret));
    141141                                ret = 1;
    142142                                goto leave;
     
    146146                }
    147147                /* Create the final directory. */
    148                 if (mkdir(path, 0) != 0) {
     148                ret = vfs_link_path(path, KIND_DIRECTORY, NULL);
     149                if (ret != EOK) {
    149150                        cli_error(CL_EFAIL, "%s: could not create %s (%s)",
    150                             cmdname, path, str_error(errno));
     151                            cmdname, path, str_error(ret));
    151152                        ret = 1;
    152153                }
     
    207208
    208209        if (follow && (argv[optind] != NULL)) {
    209                 if (chdir(argv[optind]) != 0)
     210                if (vfs_cwd_set(argv[optind]) != EOK)
    210211                        printf("%s: Error switching to directory.", cmdname);
    211212        }
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r39f892a9 r368ee04  
    3131#include <stdlib.h>
    3232#include <dirent.h>
    33 #include <fcntl.h>
    3433#include <sys/types.h>
    35 #include <sys/stat.h>
    3634#include <macros.h>
    3735#include <getopt.h>
     
    3937#include <str.h>
    4038#include <ctype.h>
     39#include <vfs/vfs.h>
    4140
    4241#include "config.h"
     
    121120        void *buffer;
    122121        bool create_sparse = false;
     122        aoff64_t pos = 0;
    123123
    124124        file_size = 0;
     
    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);
     
    164164        if (create_sparse && file_size > 0) {
    165165                const char byte = 0x00;
    166 
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) {
    168                         close(fd);
    169                         goto error;
    170                 }
    171 
    172                 rc2 = write(fd, &byte, sizeof(char));
     166               
     167                pos = file_size - 1;
     168                rc2 = vfs_write(fd, &pos, &byte, sizeof(char));
    173169                if (rc2 < 0) {
    174                         close(fd);
     170                        vfs_put(fd);
    175171                        goto error;
    176172                }
     
    187183        while (total_written < file_size) {
    188184                to_write = min(file_size - total_written, BUFFER_SIZE);
    189                 rc = write(fd, buffer, to_write);
     185                rc = vfs_write(fd, &pos, buffer, to_write);
    190186                if (rc <= 0) {
    191187                        printf("%s: Error writing file (%d).\n", cmdname, errno);
    192                         close(fd);
     188                        vfs_put(fd);
    193189                        free(buffer);
    194190                        return CMD_FAILURE;
     
    199195        free(buffer);
    200196
    201         if (close(fd) < 0)
     197        if (vfs_put(fd) < 0)
    202198                goto error;
    203199
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    r39f892a9 r368ee04  
    3232#include <str_error.h>
    3333#include <vfs/vfs.h>
     34#include <vfs/vfs_mtab.h>
    3435#include <adt/list.h>
    3536#include <errno.h>
     
    8283
    8384                printf("%s", mtab_ent->fs_name);
    84                 if (mtab_ent->instance)
    85                         printf("/%d", mtab_ent->instance);
    8685
    8786                printf(" %s", mtab_ent->mp);
     
    9493                        printf(" (%" PRIun ")", mtab_ent->service_id);
    9594                }
    96 
    97                 if (str_size(mtab_ent->opts) > 0)
    98                         printf(" (%s)", mtab_ent->opts);
    9995
    10096                putchar('\n');
     
    151147                mopts = t_argv[4];
    152148
    153         rc = vfs_mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
     149        rc = vfs_mount_path(t_argv[2], t_argv[1], dev, mopts, 0, instance);
    154150        if (rc != EOK) {
    155151                printf("Unable to mount %s filesystem to %s on %s (rc=%s)\n",
    156                     t_argv[1], t_argv[2], t_argv[3], str_error(rc));
     152                    t_argv[2], t_argv[1], t_argv[3], str_error(rc));
    157153                return CMD_FAILURE;
    158154        }
  • uspace/app/bdsh/cmds/modules/mv/mv.c

    r39f892a9 r368ee04  
    3030#include <stdlib.h>
    3131#include <errno.h>
     32#include <vfs/vfs.h>
    3233#include "config.h"
    3334#include "util.h"
     
    5960        }
    6061
    61         rc = rename(argv[1], argv[2]);
    62         if (rc != 0) {
     62        rc = vfs_rename_path(argv[1], argv[2]);
     63        if (rc != EOK) {
    6364                printf("Unable to rename %s to %s (error=%d)\n",
    64                     argv[1], argv[2], errno);
     65                    argv[1], argv[2], rc);
    6566                return CMD_FAILURE;
    6667        }
  • uspace/app/bdsh/cmds/modules/pwd/pwd.c

    r39f892a9 r368ee04  
    3030#include <stdlib.h>
    3131#include <mem.h>
     32#include <vfs/vfs.h>
     33#include <abi/errno.h>
    3234
    3335#include "config.h"
     
    5759        memset(buff, 0, PATH_MAX);
    5860
    59         if (getcwd(buff, PATH_MAX) == NULL) {
     61        if (vfs_cwd_get(buff, PATH_MAX) != EOK) {
    6062                cli_error(CL_EFAIL,
    6163                        "Unable to determine the current working directory");
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r39f892a9 r368ee04  
    3030#include <stdio.h>
    3131#include <stdlib.h>
    32 #include <unistd.h>
    33 #include <fcntl.h>
    3432#include <dirent.h>
    3533#include <getopt.h>
    3634#include <mem.h>
    3735#include <str.h>
     36#include <vfs/vfs.h>
    3837
    3938#include "config.h"
     
    110109        memset(rm->cwd, 0, PATH_MAX);
    111110
    112         chdir(".");
    113 
    114         if (NULL == (getcwd(rm->owd, PATH_MAX)))
     111        vfs_cwd_set(".");
     112
     113        if (EOK != vfs_cwd_get(rm->owd, PATH_MAX))
    115114                return 0;
    116115
     
    132131static unsigned int rm_single(const char *path)
    133132{
    134         if (unlink(path) != 0) {
     133        if (vfs_unlink_path(path) != EOK) {
    135134                cli_error(CL_EFAIL, "rm: could not remove file %s", path);
    136135                return 1;
     
    150149        }
    151150
    152         fd = open(path, O_RDONLY);
     151        fd = vfs_lookup(path, WALK_REGULAR);
    153152        if (fd >= 0) {
    154                 close(fd);
     153                vfs_put(fd);
    155154                return RM_FILE;
    156155        }
     
    201200
    202201        /* First see if it will just go away */
    203         rc = rmdir(path);
    204         if (rc == 0)
     202        rc = vfs_unlink_path(path);
     203        if (rc == EOK)
    205204                return 0;
    206205
     
    209208
    210209        /* Delete directory */
    211         rc = rmdir(path);
    212         if (rc == 0)
    213                 return errno;
     210        rc = vfs_unlink_path(path);
     211        if (rc == EOK)
     212                return EOK;
    214213
    215214        cli_error(CL_ENOTSUP, "Can not remove %s", path);
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    r39f892a9 r368ee04  
    3535#include <stdlib.h>
    3636#include <unistd.h>
    37 #include <fcntl.h>
    3837#include <dirent.h>
    3938#include <sys/types.h>
    4039#include <str.h>
    4140#include <getopt.h>
    42 #include <sys/stat.h>
    4341#include <errno.h>
     42#include <vfs/vfs.h>
    4443
    4544#include "config.h"
     
    123122               
    124123                /* Check whether file exists if -c (--no-create) option is given */
    125                 if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == 0)))
    126                         fd = open(buff, O_RDWR | O_CREAT);
     124                if ((!no_create) ||
     125                    ((no_create) && (vfs_stat_path(buff, &file_stat) == EOK))) {
     126                        fd = vfs_lookup(buff, WALK_REGULAR | WALK_MAY_CREATE);
     127                }
    127128               
    128129                if (fd < 0) {
     
    132133                        continue;
    133134                } else {
    134                         close(fd);
     135                        vfs_put(fd);
    135136                        fd = -1;
    136137                }
  • uspace/app/bdsh/cmds/modules/unmount/unmount.c

    r39f892a9 r368ee04  
    6666        }
    6767
    68         rc = vfs_unmount(argv[1]);
     68        rc = vfs_unmount_path(argv[1]);
    6969        if (rc != EOK) {
    7070                printf("Unable to unmount %s (rc=%d)\n", argv[1], rc);
  • uspace/app/bdsh/compl.c

    r39f892a9 r368ee04  
    3333#include <macros.h>
    3434#include <stdlib.h>
    35 #include <sys/stat.h>
     35#include <vfs/vfs.h>
    3636
    3737#include "cmds/cmds.h"
     
    360360                                asprintf(&ent_path, "%s/%s", *cs->path, dent->d_name);
    361361                                struct stat ent_stat;
    362                                 if (stat(ent_path, &ent_stat) != 0) {
     362                                if (vfs_stat_path(ent_path, &ent_stat) != EOK) {
    363363                                        /* Error */
    364364                                        free(ent_path);
  • uspace/app/bdsh/exec.c

    r39f892a9 r368ee04  
    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) {
    64                 close(fd);
     63                vfs_put(fd);
    6564                return 0;
    6665        } else
     
    101100        char *tmp;
    102101        int rc, retval, i;
    103         int file_handles[3];
    104         int *file_handles_p[4];
     102        int file_handles[3] = { -1, -1, -1 };
    105103        FILE *files[3];
    106104
     
    113111       
    114112        for (i = 0; i < 3 && files[i] != NULL; i++) {
    115                 if (vfs_fhandle(files[i], &file_handles[i]) == EOK) {
    116                         file_handles_p[i] = &file_handles[i];
    117                 }
    118                 else {
    119                         file_handles_p[i] = NULL;
    120                 }
     113                vfs_fhandle(files[i], &file_handles[i]);
    121114        }
    122         file_handles_p[i] = NULL;
    123115
    124         rc = task_spawnvf(&tid, &twait, tmp, (const char **) argv, file_handles_p);
     116        rc = task_spawnvf(&tid, &twait, tmp, (const char **) argv,
     117            file_handles[0], file_handles[1], file_handles[2]);
    125118        free(tmp);
    126119
  • uspace/app/bdsh/util.c

    r39f892a9 r368ee04  
    3131#include <stdarg.h>
    3232#include <stdlib.h>
     33#include <vfs/vfs.h>
     34#include <abi/errno.h>
    3335
    3436#include "config.h"
     
    5860                return 1;
    5961        }
    60         if (!getcwd(usr->cwd, PATH_MAX))
     62        if (vfs_cwd_get(usr->cwd, PATH_MAX) != EOK)
    6163                snprintf(usr->cwd, PATH_MAX, "(unknown)");
    6264
  • uspace/app/df/df.c

    r39f892a9 r368ee04  
    4040#include <stdint.h>
    4141#include <getopt.h>
    42 #include <sys/statfs.h>
    4342#include <errno.h>
    4443#include <adt/list.h>
    4544#include <vfs/vfs.h>
     45#include <vfs/vfs_mtab.h>
    4646
    4747#define NAME  "df"
     
    123123        print_header();
    124124        list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
    125                 if (statfs(mtab_ent->mp, &st) == 0) {
     125                if (vfs_statfs_path(mtab_ent->mp, &st) == 0) {
    126126                        print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp);
    127127                } else {
  • uspace/app/fontviewer/fontviewer.c

    r39f892a9 r368ee04  
    3434
    3535#include <stdio.h>
    36 #include <unistd.h>
    37 #include <fcntl.h>
    38 #include <sys/stat.h>
     36#include <stdlib.h>
    3937#include <errno.h>
    4038#include <malloc.h>
  • uspace/app/getterm/getterm.c

    r39f892a9 r368ee04  
    3636
    3737#include <sys/types.h>
    38 #include <fcntl.h>
    3938#include <unistd.h>
    4039#include <stdio.h>
     
    4342#include <errno.h>
    4443#include <loc.h>
     44#include <vfs/vfs.h>
    4545#include "version.h"
    4646#include "welcome.h"
     
    5858}
    5959
    60 static void reopen(FILE **stream, int fd, const char *path, int flags,
    61     const char *mode)
     60static void reopen(FILE **stream, int fd, const char *path, int mode,
     61    const char *fmode)
    6262{
    6363        if (fclose(*stream))
     
    6666        *stream = NULL;
    6767       
    68         int oldfd = open(path, flags);
     68        int oldfd = vfs_lookup_open(path, WALK_REGULAR, mode);
    6969        if (oldfd < 0)
    7070                return;
    7171       
    7272        if (oldfd != fd) {
    73                 if (dup2(oldfd, fd) != fd)
     73                if (vfs_clone(oldfd, fd, false) != fd)
    7474                        return;
    7575               
    76                 if (close(oldfd))
     76                if (vfs_put(oldfd))
    7777                        return;
    7878        }
    7979       
    80         *stream = fdopen(fd, mode);
     80        *stream = fdopen(fd, fmode);
    8181}
    8282
     
    141141        snprintf(term_node, LOC_NAME_MAXLEN, "%s/%s", locfs, term);
    142142       
    143         reopen(&stdin, 0, term_node, O_RDONLY, "r");
    144         reopen(&stdout, 1, term_node, O_WRONLY, "w");
    145         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");
    146146       
    147147        if (stdin == NULL)
  • uspace/app/init/init.c

    r39f892a9 r368ee04  
    4141#include <stdbool.h>
    4242#include <errno.h>
    43 #include <fcntl.h>
    44 #include <sys/stat.h>
    4543#include <task.h>
    4644#include <malloc.h>
     
    5048#include <str_error.h>
    5149#include <config.h>
     50#include <io/logctl.h>
    5251#include "init.h"
    5352
     
    127126                opts = "restore";
    128127       
    129         int rc = vfs_mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
     128        int rc = vfs_mount_path(ROOT_MOUNT_POINT, fstype, ROOT_DEVICE, opts,
    130129            IPC_FLAG_BLOCKING, 0);
     130        if (rc == EOK)
     131                logctl_set_root();
    131132        return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
    132133            ROOT_DEVICE, rc);
     
    144145static bool mount_locfs(void)
    145146{
    146         int rc = vfs_mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
     147        int rc = vfs_mount_path(LOCFS_MOUNT_POINT, LOCFS_FS_TYPE, "", "",
    147148            IPC_FLAG_BLOCKING, 0);
    148149        return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
     
    153154{
    154155        struct stat s;
    155         if (stat(path, &s) != 0) {
     156        if (vfs_stat_path(path, &s) != EOK) {
    156157                printf("%s: Unable to stat %s\n", NAME, path);
    157158                return ENOENT;
     
    300301static bool mount_tmpfs(void)
    301302{
    302         int rc = vfs_mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
     303        int rc = vfs_mount_path(TMPFS_MOUNT_POINT, TMPFS_FS_TYPE, "", "", 0, 0);
    303304        return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
    304305            TMPFS_FS_TYPE, NULL, rc);
  • uspace/app/kio/kio.c

    r39f892a9 r368ee04  
    4848#include <adt/prodcons.h>
    4949#include <tinput.h>
     50#include <vfs/vfs.h>
    5051
    5152#define NAME       "kio"
     
    128129                       
    129130                        fflush(log);
    130                         fsync(fileno(log));
     131                        vfs_sync(fileno(log));
    131132                }
    132133               
  • uspace/app/redir/redir.c

    r39f892a9 r368ee04  
    3737#include <sys/types.h>
    3838#include <stdlib.h>
    39 #include <fcntl.h>
    4039#include <unistd.h>
    4140#include <str.h>
     
    4443#include <str_error.h>
    4544#include <errno.h>
     45#include <vfs/vfs.h>
    4646
    4747#define NAME  "redir"
     
    5353}
    5454
    55 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)
    5657{
    5758        if (fclose(*stream))
     
    6061        *stream = NULL;
    6162       
    62         int oldfd = open(path, flags);
     63        int oldfd = vfs_lookup_open(path, WALK_REGULAR | flags, mode);
    6364        if (oldfd < 0)
    6465                return;
    6566       
    6667        if (oldfd != fd) {
    67                 if (dup2(oldfd, fd) != fd)
     68                if (vfs_clone(oldfd, fd, false) != fd)
    6869                        return;
    6970               
    70                 if (close(oldfd))
     71                if (vfs_put(oldfd))
    7172                        return;
    7273        }
    7374       
    74         *stream = fdopen(fd, mode);
     75        *stream = fdopen(fd, fmode);
    7576}
    7677
     
    121122                                return -2;
    122123                        }
    123                         reopen(&stdin, 0, argv[i], O_RDONLY, "r");
     124                        reopen(&stdin, 0, argv[i], 0, MODE_READ, "r");
    124125                } else if (str_cmp(argv[i], "-o") == 0) {
    125126                        i++;
     
    128129                                return -3;
    129130                        }
    130                         reopen(&stdout, 1, argv[i], O_WRONLY | O_CREAT, "w");
     131                        reopen(&stdout, 1, argv[i], WALK_MAY_CREATE, MODE_WRITE,
     132                            "w");
    131133                } else if (str_cmp(argv[i], "-e") == 0) {
    132134                        i++;
     
    135137                                return -4;
    136138                        }
    137                         reopen(&stderr, 2, argv[i], O_WRONLY | O_CREAT, "w");
     139                        reopen(&stderr, 2, argv[i], WALK_MAY_CREATE, MODE_WRITE,
     140                            "w");
    138141                } else if (str_cmp(argv[i], "--") == 0) {
    139142                        i++;
  • uspace/app/sysinst/futil.c

    r39f892a9 r368ee04  
    3535#include <dirent.h>
    3636#include <errno.h>
    37 #include <fcntl.h>
    3837#include <stdbool.h>
    3938#include <stdio.h>
    4039#include <stdlib.h>
    41 #include <sys/stat.h>
     40#include <vfs/vfs.h>
    4241#include <sys/types.h>
    4342#include <dirent.h>
     
    6059        ssize_t nr, nw;
    6160        int rc;
     61        aoff64_t posr = 0, posw = 0;
    6262
    6363        printf("Copy '%s' to '%s'.\n", srcp, destp);
    6464
    65         sf = open(srcp, O_RDONLY);
     65        sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ);
    6666        if (sf < 0)
    6767                return EIO;
    6868
    69         df = open(destp, O_CREAT | O_WRONLY, 0);
     69        df = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE);
    7070        if (df < 0)
    7171                return EIO;
    7272
    7373        do {
    74                 nr = read(sf, buf, BUF_SIZE);
     74                nr = vfs_read(sf, &posr, buf, BUF_SIZE);
    7575                if (nr == 0)
    7676                        break;
     
    7878                        return EIO;
    7979
    80                 nw = write(df, buf, nr);
     80                nw = vfs_write(df, &posw, buf, nr);
    8181                if (nw <= 0)
    8282                        return EIO;
    8383        } while (true);
    8484
    85         (void) close(sf);
     85        (void) vfs_put(sf);
    8686
    87         rc = close(df);
     87        rc = vfs_put(df);
    8888        if (rc < 0)
    8989                return EIO;
     
    118118                        return ENOMEM;
    119119
    120                 rc = stat(srcp, &s);
     120                rc = vfs_stat_path(srcp, &s);
    121121                if (rc != EOK)
    122122                        return EIO;
     
    128128                } else if (s.is_directory) {
    129129                        printf("Create directory '%s'\n", destp);
    130                         rc = mkdir(destp, 0);
     130                        rc = vfs_link_path(destp, KIND_DIRECTORY, NULL);
    131131                        if (rc != EOK)
    132132                                return EIO;
     
    157157        int sf;
    158158        ssize_t nr;
    159         off64_t off;
    160159        size_t fsize;
    161160        char *data;
     161        struct stat st;
    162162
    163         sf = open(srcp, O_RDONLY);
     163        sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ);
    164164        if (sf < 0)
    165165                return ENOENT;
    166166
    167         off = lseek(sf, 0, SEEK_END);
    168         if (off == (off64_t)-1)
     167        if (vfs_stat(sf, &st) != EOK) {
     168                vfs_put(sf);
    169169                return EIO;
     170        }       
    170171
    171         fsize = (size_t)off;
    172 
    173         off = lseek(sf, 0, SEEK_SET);
    174         if (off == (off64_t)-1)
    175                 return EIO;
     172        fsize = st.size;
    176173
    177174        data = calloc(fsize, 1);
    178         if (data == NULL)
     175        if (data == NULL) {
     176                vfs_put(sf);
    179177                return ENOMEM;
     178        }
    180179
    181         nr = read(sf, data, fsize);
    182         if (nr != (ssize_t)fsize)
     180        nr = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize);
     181        if (nr != (ssize_t)fsize) {
     182                vfs_put(sf);
     183                free(data);
    183184                return EIO;
     185        }
    184186
    185         (void) close(sf);
     187        (void) vfs_put(sf);
    186188        *rdata = data;
    187189        *rsize = fsize;
  • uspace/app/sysinst/sysinst.c

    r39f892a9 r368ee04  
    4343#include <stdio.h>
    4444#include <stdlib.h>
    45 #include <sys/stat.h>
    4645#include <task.h>
    4746#include <vfs/vfs.h>
     
    175174                return EIO;
    176175
    177         rc = mkdir(MOUNT_POINT, 0);
     176        rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY, NULL);
    178177        if (rc != EOK)
    179178                return rc;
    180179
    181180        printf("sysinst_fs_mount(): mount filesystem\n");
    182         rc = vfs_mount(FS_TYPE, MOUNT_POINT, dev, "", 0, 0);
     181        rc = vfs_mount_path(MOUNT_POINT, FS_TYPE, dev, "", 0, 0);
    183182        if (rc != EOK)
    184183                return rc;
     
    214213
    215214        printf("sysinst_copy_boot_files(): create CD mount point\n");
    216         rc = mkdir(CD_MOUNT_POINT, 0);
     215        rc = vfs_link_path(CD_MOUNT_POINT, KIND_DIRECTORY, NULL);
    217216        if (rc != EOK)
    218217                return rc;
    219218
    220219        printf("sysinst_copy_boot_files(): mount CD filesystem\n");
    221         rc = vfs_mount(CD_FS_TYPE, CD_MOUNT_POINT, CD_DEV, "", 0, 0);
     220        rc = vfs_mount_path(CD_MOUNT_POINT, CD_FS_TYPE, CD_DEV, "", 0, 0);
    222221        if (rc != EOK)
    223222                return rc;
     
    229228
    230229        printf("sysinst_copy_boot_files(): unmount %s\n", MOUNT_POINT);
    231         rc = vfs_unmount(MOUNT_POINT);
     230        rc = vfs_unmount_path(MOUNT_POINT);
    232231        if (rc != EOK)
    233232                return rc;
  • uspace/app/taskdump/elf_core.c

    r39f892a9 r368ee04  
    5454#include <errno.h>
    5555#include <sys/types.h>
    56 #include <sys/stat.h>
    5756#include <unistd.h>
    58 #include <fcntl.h>
    5957#include <mem.h>
    6058#include <stdint.h>
     
    6361#include <macros.h>
    6462#include <libarch/istate.h>
     63#include <vfs/vfs.h>
    6564
    6665#include "elf_core.h"
    6766
    6867static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    69 static int align_pos(int, size_t);
    70 static int write_mem_area(int, as_area_info_t *, async_sess_t *);
     68static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *);
    7169
    7270#define BUFFER_SIZE 0x1000
     
    9795        elf_note_t note;
    9896        size_t word_size;
     97        aoff64_t pos = 0;
    9998
    10099        int fd;
     
    124123        }
    125124
    126         fd = open(file_name, O_CREAT | O_WRONLY, 0644);
     125        fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE,
     126            MODE_WRITE);
    127127        if (fd < 0) {
    128128                printf("Failed opening file.\n");
     
    207207        }
    208208
    209         rc = write(fd, &elf_hdr, sizeof(elf_hdr));
     209        rc = vfs_write(fd, &pos, &elf_hdr, sizeof(elf_hdr));
    210210        if (rc != sizeof(elf_hdr)) {
    211211                printf("Failed writing ELF header.\n");
     
    215215
    216216        for (i = 0; i < n_ph; ++i) {
    217                 rc = write(fd, &p_hdr[i], sizeof(p_hdr[i]));
     217                rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));
    218218                if (rc != sizeof(p_hdr[i])) {
    219219                        printf("Failed writing program header.\n");
     
    223223        }
    224224
    225         if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) {
    226                 printf("Failed writing memory data.\n");
    227                 free(p_hdr);
    228                 return EIO;
    229         }
     225        pos = p_hdr[0].p_offset;
    230226
    231227        /*
     
    236232        note.type = NT_PRSTATUS;
    237233
    238         rc = write(fd, &note, sizeof(elf_note_t));
     234        rc = vfs_write(fd, &pos, &note, sizeof(elf_note_t));
    239235        if (rc != sizeof(elf_note_t)) {
    240236                printf("Failed writing note header.\n");
     
    243239        }
    244240
    245         rc = write(fd, "CORE", note.namesz);
     241        rc = vfs_write(fd, &pos, "CORE", note.namesz);
    246242        if (rc != (ssize_t) note.namesz) {
    247243                printf("Failed writing note header.\n");
     
    250246        }
    251247
    252         rc = align_pos(fd, word_size);
    253         if (rc != EOK) {
    254                 printf("Failed writing note header.\n");
    255                 free(p_hdr);
    256                 return EIO;
    257         }
    258 
    259         rc = write(fd, &pr_status, sizeof(elf_prstatus_t));
     248        pos = ALIGN_UP(pos, word_size);
     249
     250        rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t));
    260251        if (rc != sizeof(elf_prstatus_t)) {
    261252                printf("Failed writing register data.\n");
     
    265256
    266257        for (i = 1; i < n_ph; ++i) {
    267                 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    268                         printf("Failed writing memory data.\n");
    269                         free(p_hdr);
    270                         return EIO;
    271                 }
    272                 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {
     258                pos = p_hdr[i].p_offset;
     259                if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) {
    273260                        printf("Failed writing memory data.\n");
    274261                        free(p_hdr);
     
    297284 *
    298285 * @param fd   File to write to.
     286 * @param pos  Pointer to the position to write to.
    299287 * @param area Memory area info structure.
    300288 * @param sess Debugging session.
     
    303291 *
    304292 */
    305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess)
     293static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area,
     294    async_sess_t *sess)
    306295{
    307296        size_t to_copy;
     
    321310                }
    322311
    323                 rc = write(fd, buffer, to_copy);
     312                rc = vfs_write(fd, pos, buffer, to_copy);
    324313                if (rc != (ssize_t) to_copy) {
    325314                        printf("Failed writing memory contents.\n");
     
    334323}
    335324
    336 static int align_pos(int fd, size_t align)
    337 {
    338         off64_t cur_pos;
    339         size_t rem, adv;
    340 
    341         cur_pos = lseek(fd, 0, SEEK_CUR);
    342         if (cur_pos < 0)
    343                 return -1;
    344 
    345         rem = cur_pos % align;
    346         adv = align - rem;
    347 
    348         cur_pos = lseek(fd, adv, SEEK_CUR);
    349         if (cur_pos < 0)
    350                 return -1;
    351 
    352         return EOK;
    353 }
    354 
    355325/** @}
    356326 */
  • uspace/app/taskdump/symtab.c

    r39f892a9 r368ee04  
    4141#include <errno.h>
    4242#include <sys/types.h>
    43 #include <sys/stat.h>
    44 #include <fcntl.h>
     43#include <vfs/vfs.h>
    4544
    4645#include "include/symtab.h"
     
    6867        char *shstrt, *sec_name;
    6968        void *data;
     69        aoff64_t pos = 0;
    7070
    7171        int fd;
     
    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");
     
    8888        }
    8989
    90         rc = read(fd, &elf_hdr, sizeof(elf_header_t));
     90        rc = vfs_read(fd, &pos, &elf_hdr, sizeof(elf_header_t));
    9191        if (rc != sizeof(elf_header_t)) {
    9292                printf("failed reading elf header\n");
     
    165165
    166166        free(shstrt);
    167         close(fd);
     167        vfs_put(fd);
    168168
    169169        if (stab->sym == NULL || stab->strtab == NULL) {
     
    304304{
    305305        int rc;
    306 
    307         rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t),
    308             SEEK_SET);
    309         if (rc == (off64_t) -1)
    310                 return EIO;
    311 
    312         rc = read(fd, sec_hdr, sizeof(elf_section_header_t));
     306        aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t);
     307
     308        rc = vfs_read(fd, &pos, sec_hdr, sizeof(elf_section_header_t));
    313309        if (rc != sizeof(elf_section_header_t))
    314310                return EIO;
     
    331327{
    332328        ssize_t rc;
    333         off64_t offs;
    334 
    335         offs = lseek(fd, start, SEEK_SET);
    336         if (offs == (off64_t) -1) {
    337                 printf("failed seeking chunk\n");
    338                 *ptr = NULL;
    339                 return EIO;
    340         }
     329        aoff64_t pos = start;
    341330
    342331        *ptr = malloc(size);
     
    346335        }
    347336
    348         rc = read(fd, *ptr, size);
     337        rc = vfs_read(fd, &pos, *ptr, size);
    349338        if (rc != (ssize_t) size) {
    350339                printf("failed reading chunk\n");
  • uspace/app/tester/hw/misc/virtchar1.c

    r39f892a9 r368ee04  
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
    47 #include <sys/stat.h>
    48 #include <fcntl.h>
    4947#include "../../tester.h"
    5048
     
    5654{
    5755        TPRINTF("Opening `%s'...\n", path);
    58         int fd = open(path, O_RDONLY);
     56        int fd = vfs_lookup(path, WALK_REGULAR);
    5957        if (fd < 0) {
    6058                TPRINTF("   ...error: %s\n", str_error(errno));
     
    7169        async_sess_t *sess = vfs_fd_session(fd, INTERFACE_DDF);
    7270        if (!sess) {
    73                 close(fd);
     71                vfs_put(fd);
    7472                TPRINTF("   ...error: %s\n", str_error(errno));
    7573                return "Failed to get session to device";
     
    9290        TPRINTF(" Closing session and file descriptor\n");
    9391        async_hangup(sess);
    94         close(fd);
     92        vfs_put(fd);
    9593       
    9694        return NULL;
  • uspace/app/tester/mm/pager1.c

    r39f892a9 r368ee04  
    2828
    2929#include <stdio.h>
    30 #include <unistd.h>
    31 #include <fcntl.h>
     30#include <vfs/vfs.h>
    3231#include <stdlib.h>
    3332#include <malloc.h>
     
    4847        TPRINTF("Creating temporary file...\n");
    4948
    50         fd = open(TEST_FILE, 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;
    53         (void) unlink(TEST_FILE);
    54         if (write(fd, text, sizeof(text)) != sizeof(text)) {
    55                 close(fd);
     53        (void) vfs_unlink_path(TEST_FILE);
     54
     55        if (vfs_write(fd, (aoff64_t []) {0}, text, sizeof(text)) < 0) {
     56                vfs_put(fd);
    5657                return NULL;
    5758        }
     
    6465
    6566        if (!vfs_pager_sess) {
    66                 close(fd);
     67                vfs_put(fd);
    6768                return NULL;
    6869        }
     
    7374            AS_AREA_READ | AS_AREA_CACHEABLE, vfs_pager_sess, fd, 0, 0);
    7475        if (result == AS_MAP_FAILED) {
    75                 close(fd);
     76                vfs_put(fd);
    7677                return NULL;
    7778        }
     
    101102
    102103        as_area_destroy(buffer);       
    103         close(fd);
     104        vfs_put(fd);
    104105       
    105106        return NULL;
  • uspace/app/tester/vfs/vfs1.c

    r39f892a9 r368ee04  
    3333#include <vfs/vfs.h>
    3434#include <unistd.h>
    35 #include <fcntl.h>
    3635#include <dirent.h>
    3736#include <loc.h>
    3837#include <sys/types.h>
    39 #include <sys/stat.h>
    4038#include "../tester.h"
    4139
     
    7068const char *test_vfs1(void)
    7169{
    72         if (mkdir(TEST_DIRECTORY, 0) != 0) {
    73                 TPRINTF("rc=%d\n", errno);
    74                 return "mkdir() failed";
     70        aoff64_t pos = 0;
     71        int rc;
     72
     73        rc = vfs_link_path(TEST_DIRECTORY, KIND_DIRECTORY, NULL);
     74        if (rc != EOK) {
     75                TPRINTF("rc=%d\n", rc);
     76                return "vfs_link_path() failed";
    7577        }
    7678        TPRINTF("Created directory %s\n", TEST_DIRECTORY);
    7779       
    78         int fd0 = open(TEST_FILE, O_CREAT);
     80        int fd0 = vfs_lookup_open(TEST_FILE, WALK_REGULAR | WALK_MAY_CREATE,
     81            MODE_READ | MODE_WRITE);
    7982        if (fd0 < 0)
    80                 return "open() failed";
     83                return "vfs_lookup_open() failed";
    8184        TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0);
    8285       
    8386        size_t size = sizeof(text);
    84         ssize_t cnt = write(fd0, text, size);
     87        ssize_t cnt = vfs_write(fd0, &pos, text, size);
    8588        if (cnt < 0)
    8689                return "write() failed";
    8790        TPRINTF("Written %zd bytes\n", cnt);
    88        
    89         if (lseek(fd0, 0, SEEK_SET) != 0)
    90                 return "lseek() failed";
    91         TPRINTF("Sought to position 0\n");
     91
     92        pos = 0;
    9293       
    9394        char buf[BUF_SIZE];
    9495        TPRINTF("read..\n");
    95         while ((cnt = read(fd0, buf, BUF_SIZE))) {
     96        while ((cnt = vfs_read(fd0, &pos, buf, BUF_SIZE))) {
    9697                TPRINTF("read returns %zd\n", cnt);
    9798                if (cnt < 0)
     
    107108        }
    108109       
    109         close(fd0);
     110        vfs_put(fd0);
    110111       
    111112        const char *rv = read_root();
     
    113114                return rv;
    114115       
    115         if (rename(TEST_FILE, TEST_FILE2) != 0)
    116                 return "rename() failed";
     116        if (vfs_rename_path(TEST_FILE, TEST_FILE2) != EOK)
     117                return "vfs_rename_path() failed";
    117118        TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2);
    118119       
    119         if (unlink(TEST_FILE2) != 0)
    120                 return "unlink() failed";
     120        if (vfs_unlink_path(TEST_FILE2) != EOK)
     121                return "vfs_unlink_path() failed";
    121122        TPRINTF("Unlinked %s\n", TEST_FILE2);
    122123       
    123         if (rmdir(TEST_DIRECTORY) != 0)
    124                 return "rmdir() failed";
     124        if (vfs_unlink_path(TEST_DIRECTORY) != EOK)
     125                return "vfs_unlink_path() failed";
    125126        TPRINTF("Removed directory %s\n", TEST_DIRECTORY);
    126127       
  • uspace/app/tetris/scores.c

    r39f892a9 r368ee04  
    6565#include <vfs/vfs.h>
    6666#include <stdlib.h>
    67 #include <fcntl.h>
    6867#include <err.h>
    6968#include <time.h>
  • uspace/app/trace/trace.c

    r39f892a9 r368ee04  
    512512                goto error;
    513513
    514         /* Send program pathname */
    515         rc = loader_set_pathname(ldr, path);
     514        /* Send program. */
     515        rc = loader_set_program_path(ldr, path);
    516516        if (rc != EOK)
    517517                goto error;
     
    523523
    524524        /* Send default files */
    525         int *files[4];
     525        int fd_root;
    526526        int fd_stdin;
    527527        int fd_stdout;
    528528        int fd_stderr;
    529529       
    530         if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK))
    531                 files[0] = &fd_stdin;
    532         else
    533                 files[0] = NULL;
    534        
    535         if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK))
    536                 files[1] = &fd_stdout;
    537         else
    538                 files[1] = NULL;
    539        
    540         if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK))
    541                 files[2] = &fd_stderr;
    542         else
    543                 files[2] = NULL;
    544        
    545         files[3] = NULL;
    546        
    547         rc = loader_set_files(ldr, files);
    548         if (rc != EOK)
    549                 goto error;
    550 
     530        fd_root = vfs_root();
     531        if (fd_root >= 0) {
     532                rc = loader_add_inbox(ldr, "root", fd_root);
     533                vfs_put(fd_root);
     534                if (rc != EOK)
     535                        goto error;
     536        }
     537       
     538        if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) {
     539                rc = loader_add_inbox(ldr, "stdin", fd_stdin);
     540                if (rc != EOK)
     541                        goto error;
     542        }
     543       
     544        if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) {
     545                rc = loader_add_inbox(ldr, "stdout", fd_stdout);
     546                if (rc != EOK)
     547                        goto error;
     548        }
     549       
     550        if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) {
     551                rc = loader_add_inbox(ldr, "stderr", fd_stderr);
     552                if (rc != EOK)
     553                        goto error;
     554        }
     555       
    551556        /* Load the program. */
    552557        rc = loader_load_program(ldr);
     
    696701
    697702        p = proto_new("vfs");
    698         o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def);
    699         proto_add_oper(p, VFS_IN_OPEN, o);
    700         o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
     703        o = oper_new("read", 3, arg_def, V_ERRNO, 1, resp_def);
    701704        proto_add_oper(p, VFS_IN_READ, o);
    702         o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
     705        o = oper_new("write", 3, arg_def, V_ERRNO, 1, resp_def);
    703706        proto_add_oper(p, VFS_IN_WRITE, o);
    704         o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);
    705         proto_add_oper(p, VFS_IN_SEEK, o);
    706         o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
    707         proto_add_oper(p, VFS_IN_TRUNCATE, o);
    708         o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def);
    709         proto_add_oper(p, VFS_IN_FSTAT, o);
    710         o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def);
    711         proto_add_oper(p, VFS_IN_CLOSE, o);
    712         o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def);
     707        o = oper_new("vfs_resize", 5, arg_def, V_ERRNO, 0, resp_def);
     708        proto_add_oper(p, VFS_IN_RESIZE, o);
     709        o = oper_new("vfs_stat", 1, arg_def, V_ERRNO, 0, resp_def);
     710        proto_add_oper(p, VFS_IN_STAT, o);
     711        o = oper_new("vfs_put", 1, arg_def, V_ERRNO, 0, resp_def);
     712        proto_add_oper(p, VFS_IN_PUT, o);
     713        o = oper_new("vfs_mount", 2, arg_def, V_ERRNO, 0, resp_def);
    713714        proto_add_oper(p, VFS_IN_MOUNT, o);
    714715/*      o = oper_new("unmount", 0, arg_def);
    715716        proto_add_oper(p, VFS_IN_UNMOUNT, o);*/
    716         o = oper_new("sync", 1, arg_def, V_ERRNO, 0, resp_def);
     717        o = oper_new("vfs_sync", 1, arg_def, V_ERRNO, 0, resp_def);
    717718        proto_add_oper(p, VFS_IN_SYNC, o);
    718         o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def);
    719         proto_add_oper(p, VFS_IN_MKDIR, o);
    720         o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def);
    721         proto_add_oper(p, VFS_IN_UNLINK, o);
    722719        o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def);
    723720        proto_add_oper(p, VFS_IN_RENAME, o);
    724         o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def);
    725         proto_add_oper(p, VFS_IN_STAT, o);
    726         o = oper_new("statfs", 0, arg_def, V_ERRNO, 0, resp_def);
     721        o = oper_new("vfs_statfs", 0, arg_def, V_ERRNO, 0, resp_def);
    727722        proto_add_oper(p, VFS_IN_STATFS, o);
     723        o = oper_new("vfs_walk", 2, arg_def, V_INT_ERRNO, 0, resp_def);
     724        proto_add_oper(p, VFS_IN_WALK, o);
     725        o = oper_new("vfs_open", 2, arg_def, V_ERRNO, 0, resp_def);
     726        proto_add_oper(p, VFS_IN_OPEN, o);
     727        o = oper_new("vfs_unlink", 3, arg_def, V_ERRNO, 0, resp_def);
     728        proto_add_oper(p, VFS_IN_UNLINK, o);
    728729
    729730        proto_register(SERVICE_VFS, p);
  • uspace/app/untar/main.c

    r39f892a9 r368ee04  
    3535#include <stdio.h>
    3636#include <stdlib.h>
    37 #include <sys/stat.h>
    3837#include <errno.h>
    3938#include <str_error.h>
     39#include <vfs/vfs.h>
    4040#include "tar.h"
    4141
     
    103103static int handle_directory(const tar_header_t *header, FILE *tarfile)
    104104{
    105         if (mkdir(header->filename, 0755) != 0) {
    106                 if (errno != EEXIST) {
     105        int rc;
     106
     107        rc = vfs_link_path(header->filename, KIND_DIRECTORY, NULL);
     108        if (rc != EOK) {
     109                if (rc != EEXIST) {
    107110                        fprintf(stderr, "Failed to create directory %s: %s.\n",
    108                             header->filename, str_error(errno));
    109                         return errno;
     111                            header->filename, str_error(rc));
     112                        return rc;
    110113                }
    111114        }
  • uspace/app/viewer/viewer.c

    r39f892a9 r368ee04  
    3434
    3535#include <stdio.h>
    36 #include <unistd.h>
    37 #include <fcntl.h>
    38 #include <sys/stat.h>
     36#include <stdlib.h>
     37#include <vfs/vfs.h>
    3938#include <errno.h>
    4039#include <malloc.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;
    115114       
    116115        struct stat stat;
    117         int rc = fstat(fd, &stat);
    118         if (rc != 0) {
    119                 close(fd);
     116        int rc = vfs_stat(fd, &stat);
     117        if (rc != EOK) {
     118                vfs_put(fd);
    120119                return false;
    121120        }
     
    123122        void *tga = malloc(stat.size);
    124123        if (tga == NULL) {
    125                 close(fd);
    126                 return false;
    127         }
    128        
    129         ssize_t rd = read(fd, tga, stat.size);
     124                vfs_put(fd);
     125                return false;
     126        }
     127
     128        ssize_t rd = vfs_read(fd, (aoff64_t []) {0}, tga, stat.size);
    130129        if ((rd < 0) || (rd != (ssize_t) stat.size)) {
    131130                free(tga);
    132                 close(fd);
    133                 return false;
    134         }
    135        
    136         close(fd);
     131                vfs_put(fd);
     132                return false;
     133        }
     134       
     135        vfs_put(fd);
    137136       
    138137        *p_local_surface = decode_tga(tga, stat.size, 0);
  • uspace/app/websrv/websrv.c

    r39f892a9 r368ee04  
    3939#include <stdio.h>
    4040#include <sys/types.h>
    41 #include <sys/stat.h>
    4241#include <stdlib.h>
    43 #include <fcntl.h>
    4442#include <task.h>
     43
     44#include <vfs/vfs.h>
    4545
    4646#include <inet/addr.h>
     
    225225                return ENOMEM;
    226226       
    227         int fd = open(fname, O_RDONLY);
     227        int fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
    228228        if (fd < 0) {
    229229                rc = send_response(conn, msg_not_found);
     
    238238                return rc;
    239239       
     240        aoff64_t pos = 0;
    240241        while (true) {
    241                 ssize_t nr = read(fd, fbuf, BUFFER_SIZE);
     242                ssize_t nr = vfs_read(fd, &pos, fbuf, BUFFER_SIZE);
    242243                if (nr == 0)
    243244                        break;
    244245               
    245246                if (nr < 0) {
    246                         close(fd);
     247                        vfs_put(fd);
    247248                        return EIO;
    248249                }
     
    251252                if (rc != EOK) {
    252253                        fprintf(stderr, "tcp_conn_send() failed\n");
    253                         close(fd);
     254                        vfs_put(fd);
    254255                        return rc;
    255256                }
    256257        }
    257258       
    258         close(fd);
     259        vfs_put(fd);
    259260       
    260261        return EOK;
Note: See TracChangeset for help on using the changeset viewer.