glib2.0/debian/patches/vfat-4G.patch

120 lines
3.7 KiB
Diff

From: Yue-Lan <lanyue@kylinos.cn>
Date: Thu, 23 May 2024 16:25:49 +0800
Subject: =?utf-8?b?dmZhdOaWh+S7tui2hei/hzRH56e75Yqo5oiW5aSN5Yi255u05o6l5oql?=
=?utf-8?b?6ZSZ?=
---
gio/gfile.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/gio/gfile.c b/gio/gfile.c
index d52262f..e081bca 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -55,6 +55,9 @@
#include <string.h>
#include <sys/types.h>
+#include <mntent.h>
+#include <sys/vfs.h>
+#include <syslog.h>
#include "gfile.h"
#include "glib/gstdio.h"
@@ -390,6 +393,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)
@@ -3702,10 +3728,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;
@@ -3906,10 +3954,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;