Skip to content

Commit e05e311

Browse files
committed
Guard the file cloning behind a user configuration option
Signed-off-by: Phil Krylov <phil@krylov.eu>
1 parent 5ab295c commit e05e311

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/global.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mc_global_t mc_global =
109109
{
110110
.cd_symlinks = TRUE,
111111
.preallocate_space = FALSE,
112+
.file_cloning = FALSE
112113
}
113114

114115
};

lib/global.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ typedef struct
220220
// Preallocate space before file copying
221221
gboolean preallocate_space;
222222

223+
// Use COW file cloning on supported filesystems;
224+
gboolean file_cloning;
223225
} vfs;
224226
} mc_global_t;
225227

src/filemanager/boxes.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#include <string.h>
3939
#include <sys/types.h>
4040
#include <sys/stat.h>
41+
#ifdef HAVE_SYS_IOCTL_H
42+
#include <sys/ioctl.h> // FICLONE
43+
#endif
4144

4245
#include "lib/global.h"
4346

@@ -569,6 +572,7 @@ configure_box (void)
569572
QUICK_CHECKBOX (_ ("Mkdi&r autoname"), &auto_fill_mkdir_name, NULL),
570573
QUICK_CHECKBOX (_ ("&Preallocate space"), &mc_global.vfs.preallocate_space,
571574
NULL),
575+
QUICK_CHECKBOX (_ ("Use COW file cloning"), &mc_global.vfs.file_cloning, NULL),
572576
QUICK_STOP_GROUPBOX,
573577
QUICK_START_GROUPBOX (_ ("Esc key mode")),
574578
QUICK_CHECKBOX (_ ("S&ingle press"), &old_esc_mode, &configure_old_esc_mode_id),
@@ -619,17 +623,22 @@ configure_box (void)
619623
g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
620624

621625
#ifndef USE_INTERNAL_EDIT
622-
quick_widgets[17].state = WST_DISABLED;
626+
quick_widgets[18].state = WST_DISABLED;
623627
#endif
624628

625629
if (!old_esc_mode)
626-
quick_widgets[10].state = WST_DISABLED;
630+
quick_widgets[11].state = WST_DISABLED;
627631

628632
#ifndef HAVE_POSIX_FALLOCATE
629633
mc_global.vfs.preallocate_space = FALSE;
630634
quick_widgets[6].state = WST_DISABLED;
631635
#endif
632636

637+
#if !defined(FICLONE) && !defined(HAVE_COPY_FILE_RANGE) && !defined(HAVE_SYS_CLONEFILE_H) && !defined(HAVE_REFLINK)
638+
mc_global.vfs.file_cloning = FALSE;
639+
quick_widgets[7].state = WST_DISABLED;
640+
#endif
641+
633642
if (quick_dialog (&qdlg) == B_ENTER)
634643
{
635644
if (time_out_new[0] == '\0')

src/filemanager/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,7 @@ copy_file_file (file_op_context_t *ctx, const char *src_path, const char *dst_pa
25972597
// On macOS 10.12+ and Solaris 11.4+, the syscalls for file cloning respond for creation of the
25982598
// destination file, so try them before mc_open to avoid handling various races later.
25992599
// Full file cloning is not supported in append and reget modes.
2600-
if (!(dst_exists && ctx->do_append))
2600+
if (mc_global.vfs.file_cloning && !(dst_exists && ctx->do_append))
26012601
{
26022602
// Destination file must not exist before the cloning syscall
26032603
if (dst_exists)
@@ -2652,7 +2652,7 @@ copy_file_file (file_op_context_t *ctx, const char *src_path, const char *dst_pa
26522652

26532653
#if defined(FICLONE) || defined(HAVE_COPY_FILE_RANGE)
26542654
// Try clone the file first. It's not supported in append mode
2655-
if (!appending && vfs_clone_file (dest_desc, src_desc) == 0)
2655+
if (mc_global.vfs.file_cloning && !appending && vfs_clone_file (dest_desc, src_desc) == 0)
26562656
{
26572657
dst_status = DEST_FULL;
26582658
return_status = FILE_CONT;

src/setup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ static const struct
365365
#ifdef ENABLE_EXT2FS_ATTR
366366
{ "copymove_persistent_ext2_attr", &copymove_persistent_ext2_attr },
367367
#endif
368+
{ "file_cloning", &mc_global.vfs.file_cloning },
368369
{
369370
NULL,
370371
NULL,

0 commit comments

Comments
 (0)