Compare commits

...

11 Commits

Author SHA1 Message Date
openeuler-ci-bot
63d29118c4
!26 mkfs.fat: Fix calculation of FAT32 cluster size on non 512 bytes sector disks
From: @wguanghao 
Reviewed-by: @swf504 
Signed-off-by: @swf504
2023-12-04 02:09:11 +00:00
wguanghao
3f129da5eb mkfs.fat: Fix calculation of FAT32 cluster size on non 512 bytes sector disks 2023-11-30 19:49:26 +08:00
openeuler-ci-bot
f8a3f323a3
!22 [sync] PR-21: fix execution successd when format a disk with partitions.
From: @openeuler-sync-bot 
Reviewed-by: @liuzhiqiang26 
Signed-off-by: @liuzhiqiang26
2022-07-05 12:26:00 +00:00
root
f6f0eeb85f fix execution succeed when format a disk with partitions.
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
(cherry picked from commit d95aa8f6df89d497f683a97991cd43b7e566c2b6)
2022-07-05 20:01:17 +08:00
openeuler-ci-bot
8efdf33bc7 !14 Synchronize Version
From: @hifi521
Reviewed-by: @wubo009
Signed-off-by: @wubo009
2021-09-28 09:33:05 +00:00
chenyanpanHW
184de68ad3 delete -S git from %autosetup, and delete BuildRequires git
Conflicts:
	dosfstools.spec
2021-09-28 17:15:09 +08:00
Zhiqiang Liu
a9b298ba7c dosfstools: backport patches to fix two memory leak problems
- backport patches to fix two memory leak problems.
- rename patches
- set release num to 9 for ci.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>

Conflicts:
	dosfstools.spec
2021-09-28 17:13:11 +08:00
lixiaokeng
93984aa7dc add make check
Conflicts:
	dosfstools.spec
2021-09-28 17:07:13 +08:00
Wu Bo
f63321a8e7 rebuild package
Conflicts:
	dosfstools.spec
2021-09-28 16:52:07 +08:00
openeuler-ci-bot
19006b1fd2 !6 dosfstools: backport patches to fix two memory leak problems
From: @liuzhiqiang26
Reviewed-by: @volcanodragon
Signed-off-by: @wubo009
2021-03-05 15:33:15 +08:00
Zhiqiang Liu
e4903d52b1 dosfstools: backport patches to fix two memory leak problems
- backport patches to fix two memory leak problems.
- rename patches
- set release num to 9 for ci.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
2021-03-05 15:02:04 +08:00
12 changed files with 231 additions and 12 deletions

View File

@ -0,0 +1,89 @@
From 1a1ba0053830b98e99f9b2713f64dbcb36e2a6cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
Date: Sun, 18 Nov 2018 20:47:29 +0100
Subject: [PATCH] Fix memory leaks in read_fat() function
Function read_fat() allocates memory to the user supplied buffer. Therefore
that function needs complement function for releasing allocated memory and
user needs to call if after finish its work.
This patch fixes memory leaks in fsck.fat and fatlabel tools.
Conflicts:
src/fsck.fat.c
src/fatlabel.c
[Zhiqiang Liu <liuzhiqiang26@huawei.com> modifies context]
Fixes #13
---
src/fat.c | 17 +++++++++++------
src/fat.h | 5 +++++
src/fsck.fat.c | 1 +
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/fat.c b/src/fat.c
index d994e8e..849c758 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -75,6 +75,16 @@ void get_fat(FAT_ENTRY * entry, void *fat, uint32_t cluster, DOS_FS * fs)
}
}
+void release_fat(DOS_FS * fs)
+{
+ if (fs->fat)
+ free(fs->fat);
+ if (fs->cluster_owner)
+ free(fs->cluster_owner);
+ fs->fat = NULL;
+ fs->cluster_owner = NULL;
+}
+
/**
* Build a bookkeeping structure from the partition's FAT table.
* If the partition has multiple FATs and they don't agree, try to pick a winner,
@@ -92,12 +102,7 @@ void read_fat(DOS_FS * fs)
uint32_t total_num_clusters;
/* Clean up from previous pass */
- if (fs->fat)
- free(fs->fat);
- if (fs->cluster_owner)
- free(fs->cluster_owner);
- fs->fat = NULL;
- fs->cluster_owner = NULL;
+ release_fat(fs);
total_num_clusters = fs->data_clusters + 2;
eff_size = (total_num_clusters * fs->fat_bits + 7) / 8ULL;
diff --git a/src/fat.h b/src/fat.h
index 5c77634..f9b7643 100644
--- a/src/fat.h
+++ b/src/fat.h
@@ -28,6 +28,11 @@ void read_fat(DOS_FS * fs);
/* Loads the FAT of the filesystem described by FS. Initializes the FAT,
replaces broken FATs and rejects invalid cluster entries. */
+void release_fat(DOS_FS * fs);
+
+/* Release the FAT of the filesystem described by FS and free allocated memory.
+ Call it after finish work with FAT. */
+
void get_fat(FAT_ENTRY * entry, void *fat, uint32_t cluster, DOS_FS * fs);
/* Retrieve the FAT entry (next chained cluster) for CLUSTER. */
diff --git a/src/fsck.fat.c b/src/fsck.fat.c
index c244aba..b1aafe9 100644
--- a/src/fsck.fat.c
+++ b/src/fsck.fat.c
@@ -203,6 +203,7 @@ int main(int argc, char **argv)
reclaim_free(&fs);
qfree(&mem_queue);
}
+ release_fat(&fs);
exit:
if (fs_changed()) {
--
1.8.3.1

View File

@ -0,0 +1,65 @@
From 08cf67bb19f8b9cce0c2dd03432951ade476dadd Mon Sep 17 00:00:00 2001
From: Andreas Bombe <aeb@debian.org>
Date: Thu, 26 Jan 2017 21:31:03 +0100
Subject: [PATCH] Turn label in struct DOS_FS into char array from pointer
Signed-off-by: Andreas Bombe <aeb@debian.org>
---
src/boot.c | 6 +-----
src/fatlabel.c | 2 +-
src/fsck.fat.h | 2 +-
3 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/boot.c b/src/boot.c
index 58b4286..b4a3300 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -435,18 +435,14 @@ void read_boot(DOS_FS * fs)
fs->eff_fat_bits = (fs->fat_bits == 32) ? 28 : fs->fat_bits;
fs->fat_size = fat_length * logical_sector_size;
- fs->label = calloc(12, sizeof(uint8_t));
+ fs->label[0] = 0;
if (fs->fat_bits == 12 || fs->fat_bits == 16) {
struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b;
if (b16->extended_sig == 0x29)
memmove(fs->label, b16->label, 11);
- else
- fs->label = NULL;
} else if (fs->fat_bits == 32) {
if (b.extended_sig == 0x29)
memmove(fs->label, &b.label, 11);
- else
- fs->label = NULL;
}
total_fat_entries = (uint64_t)fs->fat_size * 8 / fs->fat_bits;
diff --git a/src/fatlabel.c b/src/fatlabel.c
index 9268ddb..cd3d2ee 100644
--- a/src/fatlabel.c
+++ b/src/fatlabel.c
@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
if (!rw) {
offset = find_volume_de(&fs, &de);
if (offset == 0)
- fprintf(stdout, "%s\n", fs.label);
+ fprintf(stdout, "%11s\n", fs.label);
else
fprintf(stdout, "%.8s%.3s\n", de.name, de.name + 8);
exit(0);
diff --git a/src/fsck.fat.h b/src/fsck.fat.h
index 5e93178..e91437d 100644
--- a/src/fsck.fat.h
+++ b/src/fsck.fat.h
@@ -164,7 +164,7 @@ typedef struct {
off_t backupboot_start; /* 0 if not present */
unsigned char *fat;
DOS_FILE **cluster_owner;
- char *label;
+ char label[11];
} DOS_FS;
extern int interactive, rw, list, verbose, test, write_immed;
--
1.8.3.1

View File

@ -0,0 +1,40 @@
From b71c7c400276cc48acc257c294e01825773100dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
Date: Sat, 11 Aug 2018 20:34:08 +0200
Subject: [PATCH] mkfs.fat: Fix calculation of FAT32 cluster size on non 512
bytes sector disks
Previous FAT32 calculation worked correctly only for disks with 512 byte
sectors. New calculation formula is generalized variant of previous one,
but to be sector size independent.
---
src/mkfs.fat.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
index ff89013..f7d8607 100644
--- a/src/mkfs.fat.c
+++ b/src/mkfs.fat.c
@@ -588,13 +588,13 @@ static void establish_params(struct device_info *info)
* fs size <= 16G: 8k clusters
* fs size <= 32G: 16k clusters
* fs size > 32G: 32k clusters
- *
- * This only works correctly for 512 byte sectors!
*/
- uint32_t sz_mb = info->size / (1024 * 1024);
- cluster_size =
- sz_mb > 32 * 1024 ? 64 : sz_mb > 16 * 1024 ? 32 : sz_mb >
- 8 * 1024 ? 16 : sz_mb > 260 ? 8 : 1;
+ unsigned long long int sectors = info->size / sector_size;
+ cluster_size = sectors > 32*1024*1024*2 ? 64 :
+ sectors > 16*1024*1024*2 ? 32 :
+ sectors > 8*1024*1024*2 ? 16 :
+ sectors > 260*1024*2 ? 8 : 1;
+
}
if (info->geom_heads > 0) {
--
1.8.3.1

View File

@ -1,21 +1,24 @@
Name: dosfstools
Version: 4.1
Release: 7
Release: 13
Summary: FAT file system userspace tools
License: GPLv3+
URL: http://www.github.com/dosfstools/dosfstools
Source0: http://www.github.com/%{name}/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.xz
BuildRequires: gcc git autoconf automake
BuildRequires: gcc autoconf automake systemd-devel
Patch6000: 6000-Fix-signed-integer-overflow-in-FSTART.patch
Patch6001: 6001-Avoid-returning-deleted-directory-entries-as-labels.patch
Patch6002: 6002-src-check.c-Fix-up-mtools-created-bad-dir-entries.patch
Patch6003: 6003-Remove-long-file-name-when-changing-short-file-name.patch
Patch6004: 6004-Fix-gcc-sprintf-length-warnings.patch
Patch6005: 6005-fsck.fat-Fix-Year-2038-Bug.patch
Patch6006: 6006-mkfs.fat-Fix-parsing-of-block-number.patch
Patch6007: 6007-device_info-Fix-parsing-partition-number.patch
Patch0: 0000-Fix-signed-integer-overflow-in-FSTART.patch
Patch1: 0001-Avoid-returning-deleted-directory-entries-as-labels.patch
Patch2: 0002-src-check.c-Fix-up-mtools-created-bad-dir-entries.patch
Patch3: 0003-Remove-long-file-name-when-changing-short-file-name.patch
Patch4: 0004-Fix-gcc-sprintf-length-warnings.patch
Patch5: 0005-fsck.fat-Fix-Year-2038-Bug.patch
Patch6: 0006-mkfs.fat-Fix-parsing-of-block-number.patch
Patch7: 0007-device_info-Fix-parsing-partition-number.patch
Patch8: 0008-Fix-memory-leaks-in-read_fat-function.patch
Patch9: 0009-Turn-label-in-struct-DOS_FS-into-char-array-from-poi.patch
Patch10: 0010-mkfs.fat-Fix-calculation-of-FAT32-cluster-size-on-no.patch
%description
The dosfstools package contains programs mkfs.fat, fsck.fat and fatlabel to
@ -30,11 +33,14 @@ Requires: man
This package includes man pages for dosfstools.
%prep
%autosetup -n %{name}-%{version} -p1 -S git
%autosetup -n %{name}-%{version} -p1
%build
%configure --enable-compat-symlinks
%make_build CFLAGS="%{optflags} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing"
%make_build CFLAGS="%{optflags} -D HAVE_UDEV -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing"
%check
make check
%install
%make_install
@ -49,6 +55,25 @@ This package includes man pages for dosfstools.
%{_mandir}/man8/*
%changelog
* Thu Nov 30 2023 wuguanghao <wuguanghao3@huawei.com> - 4.1-13
- mkfs.fat: Fix calculation of FAT32 cluster size on no 512 bytes sector disks
* Tue Jul 5 2022 zhanchengbin <zhanchengbin1@huawei.com> - 4.1-12
- fix execution successd when format a disk with partitions.
* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 4.1-11
- DESC: delete -S git from %autosetup, and delete BuildRequires git
* Tue Feb 9 2021 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 4.1-10
- backport patches to fix two memory leak problems, rename patch names,
and set release num to 9 for CI.
* Wed Nov 4 2020 lixiaokeng <lixiaokeng@huawei.com> - 4.1-9
- add make check
* Wed Jul 1 2020 Wu Bo <wubo009@163.com> - 4.1-8
- rebuild package
* Tue Aug 20 2019 luoshijie <luoshijie1@huawei.com> - 4.1-7
- Type:enhancement
- ID:NA