Ticket #1983: 0001-try-FICLONE-in-copy-move.patch

File 0001-try-FICLONE-in-copy-move.patch, 2.3 KB (added by gray_-_wolf, 12 months ago)

ficlone.patch V2

  • lib/vfs/vfs.c

    diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c
    index 189ca7b..724bb72 100644
    a b  
    4545#include <errno.h> 
    4646#include <stdlib.h> 
    4747 
     48#ifdef __linux 
     49# include <linux/fs.h> 
     50# ifdef HAVE_SYS_IOCTL_H 
     51#  include <sys/ioctl.h> 
     52# endif 
     53#endif 
     54 
    4855#include "lib/global.h" 
    4956#include "lib/strutil.h" 
    5057#include "lib/util.h" 
    vfs_preallocate (int dest_vfs_fd, off_t src_fsize, off_t dest_fsize) 
    656663#endif /* HAVE_POSIX_FALLOCATE */ 
    657664} 
    658665 
     666int 
     667vfs_clone_file (int dest_vfs_fd, int src_vfs_fd) 
     668{ 
     669#ifdef FICLONE 
     670    void *dest_fd = NULL; 
     671    void *src_fd = NULL; 
     672    struct vfs_class *dest_class; 
     673    struct vfs_class *src_class; 
     674 
     675    dest_class = vfs_class_find_by_handle (dest_vfs_fd, &dest_fd); 
     676    if (dest_fd == NULL || (dest_class->flags & VFSF_LOCAL) == 0) 
     677    { 
     678        errno = EOPNOTSUPP; 
     679        return -1; 
     680    } 
     681 
     682    src_class = vfs_class_find_by_handle (src_vfs_fd, &src_fd); 
     683    if (src_fd == NULL || (src_class->flags & VFSF_LOCAL) == 0) 
     684    { 
     685        errno = EOPNOTSUPP; 
     686        return -1; 
     687    } 
     688 
     689    return ioctl (*(int *) dest_fd, FICLONE, *(int *) src_fd); 
     690#else 
     691    (void) dest_vfs_fd; 
     692    (void) src_vfs_fd; 
     693    errno = EOPNOTSUPP; 
     694    return -1; 
     695#endif 
     696} 
     697 
    659698/* --------------------------------------------------------------------------------------------- */ 
  • lib/vfs/vfs.h

    diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h
    index 2510195..58ba4b5 100644
    a b char *_vfs_get_cwd (void); 
    287287 
    288288int vfs_preallocate (int dest_desc, off_t src_fsize, off_t dest_fsize); 
    289289 
     290int vfs_clone_file (int dest_vfs_fd, int src_vfs_fd); 
     291 
    290292/** 
    291293 * Interface functions described in interface.c 
    292294 */ 
  • src/filemanager/file.c

    diff --git a/src/filemanager/file.c b/src/filemanager/file.c
    index 179d8c8..ad5a229 100644
    a b copy_file_file (file_op_total_context_t * tctx, file_op_context_t * ctx, 
    23662366    appending = ctx->do_append; 
    23672367    ctx->do_append = FALSE; 
    23682368 
     2369    /* Try clone the file first */ 
     2370    if (vfs_clone_file(dest_desc, src_desc) == 0) 
     2371    { 
     2372        dst_status = DEST_FULL; 
     2373        return_status = FILE_CONT; 
     2374        goto ret; 
     2375    } 
     2376 
    23692377    /* Find out the optimal buffer size.  */ 
    23702378    while (mc_fstat (dest_desc, &dst_stat) != 0) 
    23712379    {