From 16f956640c2a92bdf4eb7756a895eddb11fcf94214b571e4956f960544b10159 Mon Sep 17 00:00:00 2001 From: Petr Gajdos Date: Tue, 4 Jan 2011 09:37:38 +0000 Subject: [PATCH] - fixed dosfslabel crashing and improved label handling in mkdosfs and dosfslabel [bnc#657011] OBS-URL: https://build.opensuse.org/package/show/Base:System/dosfstools?expand=0&rev=17 --- dosfstools-label.patch | 189 +++++++++++++++++++++++++++++++++++++++++ dosfstools.changes | 6 ++ dosfstools.spec | 4 +- 3 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 dosfstools-label.patch diff --git a/dosfstools-label.patch b/dosfstools-label.patch new file mode 100644 index 0000000..e2fc64d --- /dev/null +++ b/dosfstools-label.patch @@ -0,0 +1,189 @@ +Index: dosfstools-3.0.10/src/dosfslabel.c +=================================================================== +--- dosfstools-3.0.10.orig/src/dosfslabel.c ++++ dosfstools-3.0.10/src/dosfslabel.c +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + + #include "common.h" + #include "dosfsck.h" +@@ -89,7 +90,14 @@ int main(int argc, char *argv[]) + rw = 0; + + char *device = NULL; +- char *label = NULL; ++ char label[11]; ++ ++ int i; ++ ++ loff_t offset; ++ DIR_ENT de; ++ ++ memset(&fs, 0, sizeof(fs)); + + check_atari(); + +@@ -105,19 +113,31 @@ int main(int argc, char *argv[]) + + device = argv[1]; + if (argc == 3) { +- label = argv[2]; +- if (strlen(label) > 11) { ++ if (strlen(argv[2]) > 11) { + fprintf(stderr, + "dosfslabel: labels can be no longer than 11 characters\n"); + exit(1); + } ++ strncpy(label, argv[2], 11); ++ for (i = 0; i < 11; i++) ++ if (islower(label[i])) ++ { ++ fprintf(stderr, ++ "dosfslabel: labels cannot contain lower case characters\n"); ++ exit(1); ++ } + rw = 1; + } + + fs_open(device, rw); + read_boot(&fs); ++ read_fat(&fs); + if (!rw) { +- fprintf(stdout, "%s\n", fs.label); ++ offset = find_volume_de(&fs, &de); ++ if (offset == 0) ++ fprintf(stdout, "%s\n", fs.label); ++ else ++ fprintf(stdout, "%.8s%.3s\n", de.name, de.ext); + exit(0); + } + +Index: dosfstools-3.0.10/src/mkdosfs.c +=================================================================== +--- dosfstools-3.0.10.orig/src/mkdosfs.c ++++ dosfstools-3.0.10/src/mkdosfs.c +@@ -105,6 +105,7 @@ + #define HARD_SECTOR_SIZE 512 + #define SECTORS_PER_BLOCK ( BLOCK_SIZE / HARD_SECTOR_SIZE ) + ++#define NO_NAME "NO NAME " + + /* Macro definitions */ + +@@ -285,7 +286,7 @@ static int verbose = 0; /* Default to v + static long volume_id; /* Volume ID number */ + static time_t create_time; /* Creation time */ + static struct timeval create_timeval; /* Creation time */ +-static char volume_name[] = " "; /* Volume name */ ++static char volume_name[] = NO_NAME; /* Volume name */ + static unsigned long long blocks; /* Number of blocks in filesystem */ + static int sector_size = 512; /* Size of a logical sector */ + static int sector_size_set = 0; /* User selected sector size */ +@@ -1248,7 +1249,7 @@ setup_tables (void) + } + printf ("Volume ID is %08lx, ", volume_id & + (atari_format ? 0x00ffffff : 0xffffffff)); +- if ( strcmp(volume_name, " ") ) ++ if ( strcmp(volume_name, NO_NAME) ) + printf("volume label %s.\n", volume_name); + else + printf("no volume label.\n"); +@@ -1287,7 +1288,7 @@ setup_tables (void) + } + + memset(root_dir, 0, size_root_dir); +- if ( memcmp(volume_name, " ", 11) ) ++ if ( memcmp(volume_name, NO_NAME, 11) ) + { + struct msdos_dir_entry *de = &root_dir[0]; + memcpy(de->name, volume_name, 8); +@@ -1630,6 +1631,8 @@ main (int argc, char **argv) + + case 'n': /* n : Volume name */ + sprintf(volume_name, "%-11.11s", optarg); ++ for (i = 0; i < 11; i++) ++ volume_name[i] = toupper(volume_name[i]); + break; + + case 'r': /* r : Root directory entries */ +Index: dosfstools-3.0.10/src/boot.c +=================================================================== +--- dosfstools-3.0.10.orig/src/boot.c ++++ dosfstools-3.0.10/src/boot.c +@@ -34,6 +34,7 @@ + #include "fat.h" + #include "io.h" + #include "boot.h" ++#include "check.h" + + + #define ROUND_TO_MULTIPLE(n,m) ((n) && (m) ? (n)+(m)-1-((n)-1)%(m) : 0) +@@ -453,7 +454,7 @@ static void write_boot_label(DOS_FS *fs, + fs_write(fs->backupboot_start, sizeof(b), &b); + } + +-static loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de) ++loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de) + { + unsigned long cluster; + loff_t offset; +@@ -492,7 +493,10 @@ static void write_volume_label(DOS_FS *f + + offset = find_volume_de(fs, &de); + if (offset == 0) +- return; ++ { ++ offset = alloc_rootdir_entry(fs, &de, label); ++ /*return 0;*/ ++ } + + memcpy(de.name, label, 11); + de.time = CT_LE_W((unsigned short)((mtime->tm_sec >> 1) + +@@ -501,7 +505,16 @@ static void write_volume_label(DOS_FS *f + de.date = CT_LE_W((unsigned short)(mtime->tm_mday + + ((mtime->tm_mon+1) << 5) + + ((mtime->tm_year-80) << 9))); +- fs_write(offset, sizeof(DIR_ENT), &de); ++ de.attr = ATTR_VOLUME; ++ de.ctime_ms = 0; ++ de.ctime = de.time; ++ de.cdate = de.date; ++ de.adate = de.date; ++ de.starthi = CT_LE_W(0); ++ de.start = CT_LE_W(0); ++ de.size = CT_LE_L(0); ++ ++ fs_write(offset, sizeof(DIR_ENT), &de); + } + + void write_label(DOS_FS *fs, char *label) +Index: dosfstools-3.0.10/src/check.c +=================================================================== +--- dosfstools-3.0.10.orig/src/check.c ++++ dosfstools-3.0.10/src/check.c +@@ -133,8 +133,8 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, D + while (1) { + char expanded[12]; + sprintf(expanded, pattern, curr_num); +- memcpy(de->name+4, expanded, 4); +- memcpy(de->ext, expanded+4, 3); ++ memcpy(de->name, expanded, 8); ++ memcpy(de->ext, expanded+8, 3); + clu_num = fs->root_cluster; + i = 0; + offset2 = cluster_start(fs,clu_num); +Index: dosfstools-3.0.10/src/boot.h +=================================================================== +--- dosfstools-3.0.10.orig/src/boot.h ++++ dosfstools-3.0.10/src/boot.h +@@ -25,6 +25,7 @@ + + void read_boot(DOS_FS *fs); + void write_label(DOS_FS *fs, char *label); ++loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de); + + /* Reads the boot sector from the currently open device and initializes *FS */ + diff --git a/dosfstools.changes b/dosfstools.changes index d79ec1c..fc4315d 100644 --- a/dosfstools.changes +++ b/dosfstools.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Dec 20 15:12:52 CET 2010 - pgajdos@suse.cz + +- fixed dosfslabel crashing and improved label handling in mkdosfs + and dosfslabel [bnc#657011] + ------------------------------------------------------------------- Mon Nov 1 12:15:33 CET 2010 - pgajdos@suse.cz diff --git a/dosfstools.spec b/dosfstools.spec index 6c58e54..93ed3cb 100644 --- a/dosfstools.spec +++ b/dosfstools.spec @@ -25,11 +25,12 @@ Group: System/Filesystems AutoReqProv: on Summary: Utilities for Making and Checking MS-DOS FAT File Systems on Linux Version: 3.0.10 -Release: 2 +Release: 1 Url: http://freshmeat.net/projects/dosfstools Source: %{name}_%{version}.orig.tar.bz2 Patch0: %{name}-suse-dirs.patch Patch1: %{name}-mdraid-partition.patch +Patch2: %{name}-label.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build Supplements: filesystem(vfat) @@ -50,6 +51,7 @@ Authors: %setup %patch0 -p1 %patch1 +%patch2 -p1 %build make OPTFLAGS="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE $RPM_OPT_FLAGS"