From 2c21bc1043a3f808be55abd334befbdd490d0cf9 Mon Sep 17 00:00:00 2001 From: Debian GNOME Maintainers Date: Wed, 29 Jun 2022 16:00:15 +0800 Subject: [PATCH] =?UTF-8?q?vfat=E6=96=87=E4=BB=B6=E8=B6=85=E8=BF=874G?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E6=88=96=E5=A4=8D=E5=88=B6=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit =================================================================== Gbp-Pq: Name 20210325-file-type.patch --- gio/gfile.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/gio/gfile.c b/gio/gfile.c index e78b5e1..3f5ae63 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -55,6 +55,9 @@ #include #include +#include +#include +#include #include "gfile.h" #include "glib/gstdio.h" @@ -378,6 +381,29 @@ static gboolean g_file_real_measure_disk_usage_finish (GFile guint64 *num_files, GError **error); +static const char* get_fs_type (char* path) +{ + const char* fs_type = NULL; + struct mntent* m = NULL; + FILE* f = NULL; + + f = setmntent ("/etc/mtab", "r"); + if (!f) { + syslog (LOG_ERR, "error:%s", strerror(errno)); + } + + while ((m = getmntent(f))) { + if (!path) continue; + if (!m->mnt_dir) continue; + if (!strcmp (path, m->mnt_dir)) { + fs_type = g_strdup_printf("%s", m->mnt_type); + } + } + endmntent (f); + + return fs_type; +} + typedef GFileIface GFileInterface; G_DEFINE_INTERFACE (GFile, g_file, G_TYPE_OBJECT) @@ -3522,10 +3548,32 @@ g_file_copy (GFile *source, GFileIface *iface; GError *my_error; gboolean res; + const char* fs_type; + GMount* destination_mount; + GFile* root; + struct stat s; g_return_val_if_fail (G_IS_FILE (source), FALSE); g_return_val_if_fail (G_IS_FILE (destination), FALSE); + destination_mount = g_file_find_enclosing_mount(g_file_get_parent(destination), NULL, NULL); + if ( destination_mount != NULL) { + root = g_mount_get_default_location (destination_mount); + fs_type = get_fs_type (g_file_get_path(root)); + if(fs_type != NULL) { + if(!strcmp(fs_type,"vfat") || !strcmp(fs_type,"fat32")) { + if (stat(g_file_get_path(source), &s) == 0) { + if(s.st_size > 4294967296) { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("The file is too large, the fat format file system only supports files within 4G,can be imported in device after compression")); + return FALSE; + } + } + } + + g_free(fs_type); + } + } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; @@ -3724,10 +3772,32 @@ g_file_move (GFile *source, GFileIface *iface; GError *my_error; gboolean res; + const char* fs_type; + GMount* destination_mount; + GFile* root; + struct stat s; g_return_val_if_fail (G_IS_FILE (source), FALSE); g_return_val_if_fail (G_IS_FILE (destination), FALSE); + destination_mount = g_file_find_enclosing_mount(g_file_get_parent(destination), NULL, NULL); + if ( destination_mount != NULL) { + root = g_mount_get_default_location (destination_mount); + + fs_type = get_fs_type (g_file_get_path(root)); + if(fs_type != NULL) { + if(!strcmp(fs_type,"vfat") || !strcmp(fs_type,"fat32")) { + if (stat(g_file_get_path(source), &s) == 0) { + if(s.st_size > 4294967296) { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("The file is too large, the fat format file system only supports files within 4G,can be moved in device after compression")); + return FALSE; + } + } + } + g_free(fs_type); + } + } + if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE;