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

Changeset 368ee04 in mainline for uspace/app/bdsh/cmds/modules/cp/cp.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/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);
Note: See TracChangeset for help on using the changeset viewer.