Ticket #1983: 0001-Uglybtrfsclone.patch

File 0001-Uglybtrfsclone.patch, 2.3 KB (added by xake, 9 years ago)

A RFC for a possible implementation of this. Tested. Please review/comment.

  • lib/vfs/vfs.c

    From b3f1f71b4278f9bb96d20e3e333680ffb3d27902 Mon Sep 17 00:00:00 2001
    From: Peter Hjalmarsson <kanelxake@gmail.com>
    Date: Mon, 21 Sep 2015 17:27:20 +0200
    Subject: [PATCH] Uglybtrfsclone
    
    ---
     lib/vfs/vfs.c          | 23 +++++++++++++++++++++++
     lib/vfs/vfs.h          |  2 ++
     src/filemanager/file.c |  9 +++++++++
     3 files changed, 34 insertions(+)
    
    diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c
    index 01278e9..2df6d4a 100644
    a b  
    4545#include <errno.h> 
    4646#include <stdlib.h> 
    4747 
     48#ifdef HAVE_SYS_IOCTL_H 
     49#include <sys/ioctl.h> 
     50#endif 
     51 
    4852#include "lib/global.h" 
    4953#include "lib/strutil.h" 
    5054#include "lib/util.h" 
    vfs_preallocate (int dest_vfs_fd, off_t src_fsize, off_t dest_fsize) 
    644648#endif /* HAVE_POSIX_FALLOCATE */ 
    645649} 
    646650 
     651int 
     652vfs_clone_file (int dest_vfs_fd, int src_vfs_fd) 
     653{ 
     654        #ifdef __linux__ 
     655        # undef BTRFS_IOCTL_MAGIC 
     656        # define BTRFS_IOCTL_MAGIC 0x94 
     657        # undef BTRFS_IOC_CLONE 
     658        # define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int) 
     659          int *dest_fd = (int *) vfs_class_data_find_by_handle (dest_vfs_fd); 
     660          int *src_fd = (int *) vfs_class_data_find_by_handle (src_vfs_fd); 
     661          return ioctl (*dest_fd, BTRFS_IOC_CLONE, *src_fd); 
     662        #else 
     663          (void) dest_vfs_fd; 
     664          (void) src_vfs_fd; 
     665          errno = ENOTSUP; 
     666          return -1; 
     667        #endif 
     668} 
     669 
    647670/* --------------------------------------------------------------------------------------------- */ 
  • lib/vfs/vfs.h

    diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h
    index 037f889..a1b3335 100644
    a b char *_vfs_get_cwd (void); 
    273273 
    274274int vfs_preallocate (int dest_desc, off_t src_fsize, off_t dest_fsize); 
    275275 
     276int vfs_clone_file (int dest_vfs_fd, int src_vfs_fd); 
     277 
    276278/** 
    277279 * Interface functions described in interface.c 
    278280 */ 
  • src/filemanager/file.c

    diff --git a/src/filemanager/file.c b/src/filemanager/file.c
    index 0bacc54..e6aebd2 100644
    a b copy_file_file (file_op_total_context_t * tctx, file_op_context_t * ctx, 
    17371737        goto ret; 
    17381738    } 
    17391739 
     1740        /*here*/ 
     1741    if (vfs_clone_file(dest_desc,src_desc) == 0) 
     1742    { 
     1743        dst_status = DEST_FULL; 
     1744        goto ret; 
     1745    } 
     1746 
     1747 
     1748 
    17401749    /* try preallocate space; if fail, try copy anyway */ 
    17411750    while (vfs_preallocate (dest_desc, file_size, ctx->do_append != 0 ? sb.st_size : 0) != 0) 
    17421751    {