Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 368ee04 in mainline for uspace/app/sysinst/futil.c


Ignore:
Timestamp:
2017-04-05T18:10:39Z (5 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.