Ignore:
File:
1 edited

Legend:

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

    ra6fc88a r6afc9d7  
    3535#include <getopt.h>
    3636#include <str.h>
    37 #include <vfs/vfs.h>
     37#include <fcntl.h>
     38#include <sys/stat.h>
    3839#include <dirent.h>
    3940#include "config.h"
     
    8283        struct stat s;
    8384
    84         int r = vfs_stat_path(path, &s);
    85 
    86         if (r != EOK)
     85        int r = stat(path, &s);
     86
     87        if (r != 0)
    8788                return TYPE_NONE;
    8889        else if (s.is_directory)
     
    234235                         */
    235236                        if (force && !interactive) {
    236                                 if (vfs_unlink_path(dest_path) != EOK) {
     237                                if (unlink(dest_path) != 0) {
    237238                                        printf("Unable to remove %s\n",
    238239                                            dest_path);
     
    245246                                if (overwrite) {
    246247                                        printf("Overwriting file: %s\n", dest_path);
    247                                         if (vfs_unlink_path(dest_path) != EOK) {
     248                                        if (unlink(dest_path) != 0) {
    248249                                                printf("Unable to remove %s\n", dest_path);
    249250                                                goto exit;
     
    294295                                merge_paths(dest_path, PATH_MAX, src_dirname);
    295296
    296                                 if (vfs_link_path(dest_path, KIND_DIRECTORY,
    297                                     NULL) != EOK) {
     297                                if (mkdir(dest_path, 0) != 0) {
    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 (vfs_link_path(dest_path, KIND_DIRECTORY,
    312                             NULL) != EOK) {
     311                        if (mkdir(dest_path, 0) != 0) {
    313312                                printf("Unable to create "
    314313                                    "dest directory %s\n", dest_path);
     
    342341
    343342                        /* Check if we are copying a directory into itself */
    344                         vfs_stat_path(src_dent, &src_s);
    345                         vfs_stat_path(dest_path, &dest_s);
     343                        stat(src_dent, &src_s);
     344                        stat(dest_path, &dest_s);
    346345
    347346                        if (dest_s.index == src_s.index &&
     
    378377        int64_t copied = 0;
    379378        char *buff = NULL;
    380         aoff64_t posr = 0, posw = 0;
    381         struct stat st;
    382379
    383380        if (vb)
    384381                printf("Copying %s to %s\n", src, dest);
    385382
    386         fd1 = vfs_lookup_open(src, WALK_REGULAR, MODE_READ);
    387         if (fd1 < 0) {
     383        if (-1 == (fd1 = open(src, O_RDONLY))) {
    388384                printf("Unable to open source file %s\n", src);
    389385                return -1;
    390386        }
    391387
    392         fd2 = vfs_lookup_open(dest, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE);
    393         if (fd2 < 0) {
     388        if (-1 == (fd2 = open(dest, O_CREAT))) {
    394389                printf("Unable to open destination file %s\n", dest);
    395                 vfs_put(fd1);
     390                close(fd1);
    396391                return -1;
    397392        }
    398393
    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;
     394        total = lseek(fd1, 0, SEEK_END);
     395
    407396        if (vb)
    408397                printf("%" PRIu64 " bytes to copy\n", total);
     398
     399        lseek(fd1, 0, SEEK_SET);
    409400
    410401        if (NULL == (buff = (char *) malloc(blen))) {
     
    415406        }
    416407
    417         while ((bytes = vfs_read(fd1, &posr, buff, blen)) > 0) {
    418                 if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0)
     408        while ((bytes = read(fd1, buff, blen)) > 0) {
     409                if ((bytes = write(fd2, buff, bytes)) < 0)
    419410                        break;
    420411                copied += bytes;
     
    422413
    423414        if (bytes < 0) {
    424                 printf("\nError copying %s, (%d)\n", src, bytes);
     415                printf("\nError copying %s, (%d)\n", src, errno);
    425416                copied = bytes;
    426417        }
    427418
    428419out:
    429         vfs_put(fd1);
    430         vfs_put(fd2);
     420        close(fd1);
     421        close(fd2);
    431422        if (buff)
    432423                free(buff);
Note: See TracChangeset for help on using the changeset viewer.