diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | ChangeLog | 161 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | man/dosfsck.8 | 2 | ||||
-rw-r--r-- | man/dosfslabel.8 | 4 | ||||
-rw-r--r-- | src/boot.c | 124 | ||||
-rw-r--r-- | src/check.c | 65 | ||||
-rw-r--r-- | src/dosfsck.c | 7 | ||||
-rw-r--r-- | src/dosfsck.h | 22 | ||||
-rw-r--r-- | src/dosfslabel.c | 6 | ||||
-rw-r--r-- | src/fat.c | 16 | ||||
-rw-r--r-- | src/lfn.c | 10 | ||||
-rw-r--r-- | src/mkdosfs.c | 137 | ||||
-rw-r--r-- | src/version.h | 4 |
14 files changed, 321 insertions, 245 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3956eda --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +/dosfsck +/dosfslabel +/mkdosfs @@ -1,4 +1,117 @@ -commit ac4d30646425e19e8682cf7c9055014cbdb54c6f +commit 3aa88ed2a22d517d4a392bef3fc3f27b878ee8a6 (HEAD, origin/master, origin/HEAD, master) +Author: Daniel Baumann <mail@daniel-baumann.ch> +Date: Wed May 29 09:48:24 2013 +0200 + + Updating maximal lenght of a label in manpage to talk about bytes instead of characters, thanks to Francois Wendling <frwendling@gmail.com> (Closes: #655953). + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 0916f8a0e0051ddfe1c4c96a399421a3832acd4f +Author: Jaroslav Skarvada <jskarvad@redhat.com> +Date: Wed May 29 09:56:08 2013 +0200 + + Fixing segfault in dosfslabel. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 4a265c67e036ee12a0393656b0167d3e7833cda8 +Author: James Byrne <jbyrne@aminocom.com> +Date: Mon Apr 22 12:29:51 2013 +0100 + + Allow operation on SH4 CPUs and remove compiler warnings. + + Simplify the GET_UNALIGNED_W macro and use it in all cases instead of making it + conditional on CPU types. This missed some CPUs that needed it (e.g. SH4), and + in any case the implementation caused "dereferencing type-punned pointer will + break strict-aliasing rules" warnings. + + Enable extra warnings, but disable signed comparison and missing field + initializer warnings as these are not helpful. + + Update write_boot_label() so that the boot_sector_16 and boot_sector cases are + handled separately instead of using an aliased pointer, as that causes + "dereferencing type-punned pointer will break strict-aliasing rules" warnings. + + Make date_dos2unix(), usage() and cdiv() static functions as they are only used + in the files in which they are declared. + + Update bad_name() and lfn_get() so that the extension is processed separately + instead of by indexing past the end of the name field as that causes "array + subscript is above array bounds" warnings. + + Update the dosfsck() main function to avoid a warning that free_clusters may + be used uninitialized. Do not print the final count of files and clusters when + dosfsck is run with the "-b" option because the used files and clusters have + not been counted in this case. + + Alter the setup_tables() function so that it does not cause an "array subscript + is below array bounds" warning. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit eb68a14005ec5230eed4615576a70406bc37f66d +Author: James Byrne <jbyrne@aminocom.com> +Date: Mon Apr 22 13:32:01 2013 +0100 + + Add a .gitignore file. + + Add a .gitignore file so that the results of compilation do not appear as + changes. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 336e8f105a741767aa4daed3e40906e4a68abea1 +Author: James Byrne <jbyrne@aminocom.com> +Date: Mon Apr 22 12:38:52 2013 +0100 + + Finish cleanup of byteswap code. + + Commit 9ba8992 left three references to the old CT_LE_W macro. + Remove these since no conversion was needed as the value being + converted was zero. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 64b6227186d08a0a1c339fb0b894ca9c0050ffac +Author: Daniel Baumann <mail@daniel-baumann.ch> +Date: Thu Apr 4 08:08:00 2013 +0200 + + Shortening links to upstream homepage. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 76304bef84f8aa5e99128b982d5c9dc5b90c09e5 +Author: Cristian RodrÃguez <crrodriguez@opensuse.org> +Date: Fri Mar 1 08:23:34 2013 +0100 + + Fix offsetof definition. + + * include stddef.h to get the correct offsetof definition. + * remove local offsetof definition, systems not having it on stddef.h + are in violation of C89, C99, POSIX.1-2001. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 9ba8992e2e889d19b479a5f62ed41bb93bad8bb5 +Author: Cristian RodrÃguez <crrodriguez@opensuse.org> +Date: Fri Mar 1 08:58:36 2013 +0100 + + Cleanup byteswap code. + + Remove all duplicate macro definitions for byteswapping routines + and replace them for proper usage of userspace endian(3). + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit 8733e12a3eb24bfbb56f3a40863053e1197039a6 (tag: v3.0.16) +Author: Daniel Baumann <mail@daniel-baumann.ch> +Date: Wed May 29 10:06:01 2013 +0200 + + Releasing version 3.0.16. + + Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> + +commit a9fa87e758291fa2b4143ad6db07aa4a2ee72eb6 Author: Petr Gajdos <pgajdos@suse.cz> Date: Fri Mar 1 08:34:12 2013 +0100 @@ -10,7 +123,7 @@ Date: Fri Mar 1 08:34:12 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 7963bda123aa3bc6e4525a69b8fb82c4e92f7a52 +commit 92057f1731557ee90ad793567b3164478ac46106 Author: Petr Gajdos <pgajdos@suse.cz> Date: Fri Mar 1 08:33:18 2013 +0100 @@ -21,7 +134,7 @@ Date: Fri Mar 1 08:33:18 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 23fd2911267f73ea8dd6b5e6cc7ffb60223063e5 +commit 5e265c42aab04a906f2dd8a570c5c26519860cb4 Author: Petr Gajdos <pgajdos@suse.cz> Date: Fri Mar 1 08:32:02 2013 +0100 @@ -32,7 +145,7 @@ Date: Fri Mar 1 08:32:02 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit dbf11935d610b3b8d50480fc6c6257f8d8508635 +commit 5cec53c43cb453a0e1c1adc0369fdc5d45356384 Author: Petr Gajdos <pgajdos@suse.cz> Date: Fri Mar 1 08:30:21 2013 +0100 @@ -41,7 +154,7 @@ Date: Fri Mar 1 08:30:21 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 6de7543008fb5b37017560448c45270dafb62ab8 +commit 63938f0606f896d979ccb7d8056e9a1275b961ef Author: Petr Gajdos <pgajdos@suse.cz> Date: Fri Mar 1 08:29:00 2013 +0100 @@ -52,8 +165,8 @@ Date: Fri Mar 1 08:29:00 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit feb90914727acd92e4518881a07c3d80d6d6ccfa -Author: Daniel Baumann <daniel.baumann@progress-linux.org> +commit 10c1c41fd8e2813fe42b279e5a3c6261da8d318c +Author: Petr Gajdos <pgajdos@suse.cz> Date: Fri Mar 1 08:58:15 2013 +0100 Write uppercase letters in label. @@ -63,7 +176,7 @@ Date: Fri Mar 1 08:58:15 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit a75fb1c838a47b8f54ff567ca2eb71e98ccb691c +commit a75fb1c838a47b8f54ff567ca2eb71e98ccb691c (tag: v3.0.15) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Thu Feb 21 15:06:52 2013 +0100 @@ -113,7 +226,7 @@ Date: Thu Feb 21 14:40:25 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 7a756385ed6bce393396c699e068b5f239053db6 +commit 7a756385ed6bce393396c699e068b5f239053db6 (tag: v3.0.14) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Wed Jan 23 13:22:01 2013 +0100 @@ -171,7 +284,7 @@ Date: Wed Jan 23 12:17:20 2013 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 13cdb4d262b4042ec2d94d706e30f45a63f1c029 +commit 13cdb4d262b4042ec2d94d706e30f45a63f1c029 (tag: v3.0.13) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sat Jun 30 19:10:44 2012 +0200 @@ -189,7 +302,7 @@ Date: Sat Jun 30 19:09:11 2012 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit e243612ccd10ec10a9877fe32524acc8b7f3d2a4 +commit e243612ccd10ec10a9877fe32524acc8b7f3d2a4 (tag: v3.0.12) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sat Oct 29 08:40:53 2011 +0200 @@ -276,7 +389,7 @@ Date: Sun Jan 2 15:39:03 2011 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 66d55cd07420a7f6da3c96412b9159439823ff97 +commit 66d55cd07420a7f6da3c96412b9159439823ff97 (tag: v3.0.11) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Fri Dec 24 17:58:29 2010 +0100 @@ -305,7 +418,7 @@ Date: Fri Oct 8 13:38:16 2010 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 5ef7f1f78a13207fd4317a73dd0308c95faeaa44 +commit 5ef7f1f78a13207fd4317a73dd0308c95faeaa44 (tag: v3.0.10) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sun Sep 12 09:35:47 2010 +0200 @@ -373,7 +486,7 @@ Date: Sun Mar 14 16:05:32 2010 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 5b6849dc6268dfdede6e57c50d28f4179416b127 +commit 5b6849dc6268dfdede6e57c50d28f4179416b127 (tag: v3.0.9) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sun Jan 31 08:31:32 2010 +0100 @@ -390,7 +503,7 @@ Date: Sun Jan 31 00:11:41 2010 -0500 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 2a3bef84fbee41ba055ecd57b6ded334e80b9b7f +commit 2a3bef84fbee41ba055ecd57b6ded334e80b9b7f (tag: v3.0.8) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sat Jan 23 10:16:18 2010 +0100 @@ -499,7 +612,7 @@ Date: Wed Jan 6 11:18:55 2010 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 171bc07b0c3eff0eec01d899326ac2a34ea51e72 +commit 171bc07b0c3eff0eec01d899326ac2a34ea51e72 (tag: v3.0.7) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Thu Dec 24 10:53:36 2009 +0100 @@ -541,7 +654,7 @@ Date: Thu Dec 24 09:31:41 2009 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 0657e018980f46932f7c438b4b1593c0ed10ccca +commit 0657e018980f46932f7c438b4b1593c0ed10ccca (tag: v3.0.6) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sun Oct 4 10:59:33 2009 +0200 @@ -578,7 +691,7 @@ Date: Sun Oct 4 08:32:30 2009 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 16ba63f98a310d9743e5b9dbd0f9d7a4f4717455 +commit 16ba63f98a310d9743e5b9dbd0f9d7a4f4717455 (tag: v3.0.5) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Mon Jul 27 14:26:11 2009 +0200 @@ -606,7 +719,7 @@ Date: Sun Jul 26 22:12:06 2009 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit dd0f0b53926fbd3b0c262cc09b5d3e0fc19c7ec8 +commit dd0f0b53926fbd3b0c262cc09b5d3e0fc19c7ec8 (tag: v3.0.4) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Tue Jul 21 08:10:52 2009 +0200 @@ -634,7 +747,7 @@ Date: Tue May 19 10:37:52 2009 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 7c16098be2b04ab791a520bf4ca2319233f4bd73 +commit 7c16098be2b04ab791a520bf4ca2319233f4bd73 (tag: v3.0.3) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Mon May 18 15:12:04 2009 +0200 @@ -670,7 +783,7 @@ Date: Thu Mar 5 07:03:36 2009 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit b54a8a46ef08e1993796673cfe6c732fe238f74d +commit b54a8a46ef08e1993796673cfe6c732fe238f74d (tag: v3.0.2) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sat Feb 28 09:48:04 2009 +0100 @@ -710,7 +823,7 @@ Date: Fri Jan 30 14:05:12 2009 +0100 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit df2d2f17898cb5e13e9017aef1ccaae3b11a201b +commit df2d2f17898cb5e13e9017aef1ccaae3b11a201b (tag: v3.0.1) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sun Nov 23 22:45:45 2008 +0100 @@ -756,7 +869,7 @@ Date: Tue Sep 30 07:25:19 2008 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit 21e9ba0a43ed34e8424cac4fdb1d1d8d02e43336 +commit 21e9ba0a43ed34e8424cac4fdb1d1d8d02e43336 (tag: v3.0.0) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Sun Sep 28 11:43:19 2008 +0200 @@ -1140,7 +1253,7 @@ Date: Fri Sep 26 13:40:47 2008 +0200 Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch> -commit ba6774ae1dd5199a733dfaeaf438dff095284de7 +commit ba6774ae1dd5199a733dfaeaf438dff095284de7 (tag: v2.11) Author: Daniel Baumann <mail@daniel-baumann.ch> Date: Thu Jun 26 12:45:36 2008 +0200 @@ -26,9 +26,9 @@ DOCDIR = $(PREFIX)/share/doc MANDIR = $(PREFIX)/share/man #OPTFLAGS = -O2 -fomit-frame-pointer -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -OPTFLAGS = -O2 -fomit-frame-pointer $(shell getconf LFS_CFLAGS) +OPTFLAGS = -O2 -fomit-frame-pointer -D_GNU_SOURCE $(shell getconf LFS_CFLAGS) #WARNFLAGS = -Wall -pedantic -std=c99 -WARNFLAGS = -Wall +WARNFLAGS = -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wmissing-prototypes -Wstrict-prototypes DEBUGFLAGS = -g CFLAGS += $(OPTFLAGS) $(WARNFLAGS) $(DEBUGFLAGS) diff --git a/man/dosfsck.8 b/man/dosfsck.8 index 50f5232..8395fa8 100644 --- a/man/dosfsck.8 +++ b/man/dosfsck.8 @@ -129,7 +129,7 @@ Does not create . and .. files where necessary. Does not remove entirely empty d \fBmkdosfs\fR(8) .SH HOMEPAGE -More information about \fBdosfsck\fR and \fBdosfstools\fR can be found at <\fIhttp://www.daniel\-baumann.ch/software/dosfstools/\fR>. +More information about \fBdosfsck\fR and \fBdosfstools\fR can be found at <\fIhttp://daniel\-baumann.ch/software/dosfstools/\fR>. .SH AUTHORS \fBdosfstools\fR were written by Werner Almesberger <\fIwerner.almesberger@lrc.di.epfl.ch\fR>, Roman Hodek <\fIRoman.Hodek@informatik.uni-erlangen.de\fR>, and others. The current maintainer is Daniel Baumann <\fImail@daniel-baumann.ch\fR>. diff --git a/man/dosfslabel.8 b/man/dosfslabel.8 index e217ad6..f1c3a0d 100644 --- a/man/dosfslabel.8 +++ b/man/dosfslabel.8 @@ -30,7 +30,7 @@ .SH DESCRIPTION \fBdosfslabel\fR set or gets a MS\-DOS filesystem label from a given device. .PP -If the label is omitted, then the label name of the specified device is written on the standard output. A label can't be longer than 11 characters. +If the label is omitted, then the label name of the specified device is written on the standard output. A label can't be longer than 11 bytes. .SH OPTIONS .IP "\fB\-h\fR, \fB\-\-help\fR" 4 @@ -44,7 +44,7 @@ Shows version. \fBmkdosfs\fR(8) .SH HOMEPAGE -More information about \fBdosfsck\fR and \fBdosfstools\fR can be found at <\fIhttp://www.daniel\-baumann.ch/software/dosfstools/\fR>. +More information about \fBdosfsck\fR and \fBdosfstools\fR can be found at <\fIhttp://daniel\-baumann.ch/software/dosfstools/\fR>. .SH AUTHORS \fBdosfstools\fR were written by Werner Almesberger <\fIwerner.almesberger@lrc.di.epfl.ch\fR>, Roman Hodek <\fIRoman.Hodek@informatik.uni-erlangen.de\fR>, and others. The current maintainer is Daniel Baumann <\fImail@daniel-baumann.ch\fR>. @@ -60,18 +60,9 @@ static struct { 0xfe, "5.25\" 160k floppy 1s/40tr/8sec"}, { 0xff, "5.25\" 320k floppy 2s/40tr/8sec"},}; -#if defined __alpha || defined __arm || defined __arm__ || defined __ia64__ || defined __x86_64__ \ - || defined __ppc64__ || defined __bfin__ || defined __MICROBLAZE__ -/* Unaligned fields must first be copied byte-wise */ +/* Unaligned fields must first be accessed byte-wise */ #define GET_UNALIGNED_W(f) \ - ({ \ - unsigned short __v; \ - memcpy( &__v, &f, sizeof(__v) ); \ - CF_LE_W( *(unsigned short *)&__v ); \ - }) -#else -#define GET_UNALIGNED_W(f) CF_LE_W( *(unsigned short *)&f ) -#endif + le16toh( (__u16)f[0] | ((__u16)f[1]<<8) ) static char *get_media_descr(unsigned char media) { @@ -104,8 +95,8 @@ static void dump_boot(DOS_FS * fs, struct boot_sector *b, unsigned lss) printf("Media byte 0x%02x (%s)\n", b->media, get_media_descr(b->media)); printf("%10d bytes per logical sector\n", GET_UNALIGNED_W(b->sector_size)); printf("%10d bytes per cluster\n", fs->cluster_size); - printf("%10d reserved sector%s\n", CF_LE_W(b->reserved), - CF_LE_W(b->reserved) == 1 ? "" : "s"); + printf("%10d reserved sector%s\n", le16toh(b->reserved), + le16toh(b->reserved) == 1 ? "" : "s"); printf("First FAT starts at byte %llu (sector %llu)\n", (unsigned long long)fs->fat_start, (unsigned long long)fs->fat_start / lss); @@ -126,14 +117,14 @@ static void dump_boot(DOS_FS * fs, struct boot_sector *b, unsigned lss) (unsigned long long)fs->data_start / lss); printf("%10lu data clusters (%llu bytes)\n", fs->clusters, (unsigned long long)fs->clusters * fs->cluster_size); - printf("%u sectors/track, %u heads\n", CF_LE_W(b->secs_track), - CF_LE_W(b->heads)); + printf("%u sectors/track, %u heads\n", le16toh(b->secs_track), + le16toh(b->heads)); printf("%10u hidden sectors\n", atari_format ? /* On Atari, the hidden field is only 16 bit wide and unused */ (((unsigned char *)&b->hidden)[0] | - ((unsigned char *)&b->hidden)[1] << 8) : CF_LE_L(b->hidden)); + ((unsigned char *)&b->hidden)[1] << 8) : le32toh(b->hidden)); sectors = GET_UNALIGNED_W(b->sectors); - printf("%10u sectors total\n", sectors ? sectors : CF_LE_L(b->total_sect)); + printf("%10u sectors total\n", sectors ? sectors : le32toh(b->total_sect)); } static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, int lss) @@ -142,7 +133,7 @@ static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, int lss) if (!fs->backupboot_start) { printf("There is no backup boot sector.\n"); - if (CF_LE_W(b->reserved) < 3) { + if (le16toh(b->reserved) < 3) { printf("And there is no space for creating one!\n"); return; } @@ -154,15 +145,15 @@ static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, int lss) int bbs; /* The usual place for the backup boot sector is sector 6. Choose * that or the last reserved sector. */ - if (CF_LE_W(b->reserved) >= 7 && CF_LE_W(b->info_sector) != 6) + if (le16toh(b->reserved) >= 7 && le16toh(b->info_sector) != 6) bbs = 6; else { - bbs = CF_LE_W(b->reserved) - 1; - if (bbs == CF_LE_W(b->info_sector)) + bbs = le16toh(b->reserved) - 1; + if (bbs == le16toh(b->info_sector)) --bbs; /* this is never 0, as we checked reserved >= 3! */ } fs->backupboot_start = bbs * lss; - b->backup_boot = CT_LE_W(bbs); + b->backup_boot = htole16(bbs); fs_write(fs->backupboot_start, sizeof(*b), b); fs_write((loff_t) offsetof(struct boot_sector, backup_boot), sizeof(b->backup_boot), &b->backup_boot); @@ -216,11 +207,11 @@ static void check_backup_boot(DOS_FS * fs, struct boot_sector *b, int lss) static void init_fsinfo(struct info_sector *i) { - i->magic = CT_LE_L(0x41615252); - i->signature = CT_LE_L(0x61417272); - i->free_clusters = CT_LE_L(-1); - i->next_cluster = CT_LE_L(2); - i->boot_sign = CT_LE_W(0xaa55); + i->magic = htole32(0x41615252); + i->signature = htole32(0x61417272); + i->free_clusters = htole32(-1); + i->next_cluster = htole32(2); + i->boot_sign = htole16(0xaa55); } static void read_fsinfo(DOS_FS * fs, struct boot_sector *b, int lss) @@ -237,13 +228,13 @@ static void read_fsinfo(DOS_FS * fs, struct boot_sector *b, int lss) /* search for a free reserved sector (not boot sector and not * backup boot sector) */ __u32 s; - for (s = 1; s < CF_LE_W(b->reserved); ++s) - if (s != CF_LE_W(b->backup_boot)) + for (s = 1; s < le16toh(b->reserved); ++s) + if (s != le16toh(b->backup_boot)) break; - if (s > 0 && s < CF_LE_W(b->reserved)) { + if (s > 0 && s < le16toh(b->reserved)) { init_fsinfo(&i); fs_write((loff_t) s * lss, sizeof(i), &i); - b->info_sector = CT_LE_W(s); + b->info_sector = htole16(s); fs_write((loff_t) offsetof(struct boot_sector, info_sector), sizeof(b->info_sector), &b->info_sector); if (fs->backupboot_start) @@ -259,24 +250,24 @@ static void read_fsinfo(DOS_FS * fs, struct boot_sector *b, int lss) return; } - fs->fsinfo_start = CF_LE_W(b->info_sector) * lss; + fs->fsinfo_start = le16toh(b->info_sector) * lss; fs_read(fs->fsinfo_start, sizeof(i), &i); - if (i.magic != CT_LE_L(0x41615252) || - i.signature != CT_LE_L(0x61417272) || i.boot_sign != CT_LE_W(0xaa55)) { + if (i.magic != htole32(0x41615252) || + i.signature != htole32(0x61417272) || i.boot_sign != htole16(0xaa55)) { printf("FSINFO sector has bad magic number(s):\n"); - if (i.magic != CT_LE_L(0x41615252)) + if (i.magic != htole32(0x41615252)) printf(" Offset %llu: 0x%08x != expected 0x%08x\n", (unsigned long long)offsetof(struct info_sector, magic), - CF_LE_L(i.magic), 0x41615252); - if (i.signature != CT_LE_L(0x61417272)) + le32toh(i.magic), 0x41615252); + if (i.signature != htole32(0x61417272)) printf(" Offset %llu: 0x%08x != expected 0x%08x\n", (unsigned long long)offsetof(struct info_sector, signature), - CF_LE_L(i.signature), 0x61417272); - if (i.boot_sign != CT_LE_W(0xaa55)) + le32toh(i.signature), 0x61417272); + if (i.boot_sign != htole16(0xaa55)) printf(" Offset %llu: 0x%04x != expected 0x%04x\n", (unsigned long long)offsetof(struct info_sector, boot_sign), - CF_LE_W(i.boot_sign), 0xaa55); + le16toh(i.boot_sign), 0xaa55); if (interactive) printf("1) Correct\n2) Don't correct (FSINFO invalid then)\n"); else @@ -289,7 +280,7 @@ static void read_fsinfo(DOS_FS * fs, struct boot_sector *b, int lss) } if (fs->fsinfo_start) - fs->free_clusters = CF_LE_L(i.free_clusters); + fs->free_clusters = le32toh(i.free_clusters); } static char print_fat_dirty_state(void) @@ -358,16 +349,16 @@ void read_boot(DOS_FS * fs) die("Currently, only 1 or 2 FATs are supported, not %d.\n", b.fats); fs->nfats = b.fats; sectors = GET_UNALIGNED_W(b.sectors); - total_sectors = sectors ? sectors : CF_LE_L(b.total_sect); + total_sectors = sectors ? sectors : le32toh(b.total_sect); if (verbose) printf("Checking we can access the last sector of the filesystem\n"); /* Can't access last odd sector anyway, so round down */ fs_test((loff_t) ((total_sectors & ~1) - 1) * (loff_t) logical_sector_size, logical_sector_size); - fat_length = CF_LE_W(b.fat_length) ? - CF_LE_W(b.fat_length) : CF_LE_L(b.fat32_length); - fs->fat_start = (loff_t) CF_LE_W(b.reserved) * logical_sector_size; - fs->root_start = ((loff_t) CF_LE_W(b.reserved) + b.fats * fat_length) * + fat_length = le16toh(b.fat_length) ? + le16toh(b.fat_length) : le32toh(b.fat32_length); + fs->fat_start = (loff_t) le16toh(b.reserved) * logical_sector_size; + fs->root_start = ((loff_t) le16toh(b.reserved) + b.fats * fat_length) * logical_sector_size; fs->root_entries = GET_UNALIGNED_W(b.dir_entries); fs->data_start = fs->root_start + ROUND_TO_MULTIPLE(fs->root_entries << @@ -380,7 +371,7 @@ void read_boot(DOS_FS * fs) fs->free_clusters = -1; /* unknown */ if (!b.fat_length && b.fat32_length) { fs->fat_bits = 32; - fs->root_cluster = CF_LE_L(b.root_cluster); + fs->root_cluster = le32toh(b.root_cluster); if (!fs->root_cluster && fs->root_entries) /* M$ hasn't specified this, but it looks reasonable: If * root_cluster is 0 but there is a separate root dir @@ -404,7 +395,7 @@ void read_boot(DOS_FS * fs) fs->clusters, FAT16_THRESHOLD); check_fat_state_bit(fs, &b); - fs->backupboot_start = CF_LE_W(b.backup_boot) * logical_sector_size; + fs->backupboot_start = le16toh(b.backup_boot) * logical_sector_size; check_backup_boot(fs, &b, logical_sector_size); read_fsinfo(fs, &b, logical_sector_size); @@ -473,29 +464,32 @@ void read_boot(DOS_FS * fs) static void write_boot_label(DOS_FS * fs, char *label) { - struct boot_sector b; - struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b; - - fs_read(0, sizeof(b), &b); if (fs->fat_bits == 12 || fs->fat_bits == 16) { - if (b16->extended_sig != 0x29) { - b16->extended_sig = 0x29; - b16->serial = 0; - memmove(b16->fs_type, fs->fat_bits == 12 ? "FAT12 " : "FAT16 ", + struct boot_sector_16 b16; + + fs_read(0, sizeof(b16), &b16); + if (b16.extended_sig != 0x29) { + b16.extended_sig = 0x29; + b16.serial = 0; + memmove(b16.fs_type, fs->fat_bits == 12 ? "FAT12 " : "FAT16 ", 8); } - memmove(b16->label, label, 11); + memmove(b16.label, label, 11); + fs_write(0, sizeof(b16), &b16); } else if (fs->fat_bits == 32) { + struct boot_sector b; + + fs_read(0, sizeof(b), &b); if (b.extended_sig != 0x29) { b.extended_sig = 0x29; b.serial = 0; memmove(b.fs_type, "FAT32 ", 8); } memmove(b.label, label, 11); + fs_write(0, sizeof(b), &b); + if (fs->backupboot_start) + fs_write(fs->backupboot_start, sizeof(b), &b); } - fs_write(0, sizeof(b), &b); - if (fs->fat_bits == 32 && fs->backupboot_start) - fs_write(fs->backupboot_start, sizeof(b), &b); } loff_t find_volume_de(DOS_FS * fs, DIR_ENT * de) @@ -544,10 +538,10 @@ static void write_volume_label(DOS_FS * fs, char *label) offset = alloc_rootdir_entry(fs, &de, label); } memcpy(de.name, label, 11); - de.time = CT_LE_W((unsigned short)((mtime->tm_sec >> 1) + + de.time = htole16((unsigned short)((mtime->tm_sec >> 1) + (mtime->tm_min << 5) + (mtime->tm_hour << 11))); - de.date = CT_LE_W((unsigned short)(mtime->tm_mday + + de.date = htole16((unsigned short)(mtime->tm_mday + ((mtime->tm_mon + 1) << 5) + ((mtime->tm_year - 80) << 9))); if (created) @@ -557,9 +551,9 @@ static void write_volume_label(DOS_FS * fs, char *label) 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); + de.starthi = 0; + de.start = 0; + de.size = 0; } fs_write(offset, sizeof(DIR_ENT), &de); diff --git a/src/check.c b/src/check.c index 1ae91c6..a3fcc93 100644 --- a/src/check.c +++ b/src/check.c @@ -42,8 +42,8 @@ static DOS_FILE *root; /* get start field of a dir entry */ #define FSTART(p,fs) \ - ((unsigned long)CF_LE_W(p->dir_ent.start) | \ - (fs->fat_bits == 32 ? CF_LE_W(p->dir_ent.starthi) << 16 : 0)) + ((unsigned long)le16toh(p->dir_ent.start) | \ + (fs->fat_bits == 32 ? le16toh(p->dir_ent.starthi) << 16 : 0)) #define MODIFY(p,i,v) \ do { \ @@ -61,17 +61,17 @@ static DOS_FILE *root; /* writing to fake entry for FAT32 root dir */ \ if (!__v) die("Oops, deleting FAT32 root dir!"); \ fs->root_cluster = __v; \ - p->dir_ent.start = CT_LE_W(__v&0xffff); \ - p->dir_ent.starthi = CT_LE_W(__v>>16); \ - __v = CT_LE_L(__v); \ + p->dir_ent.start = htole16(__v&0xffff); \ + p->dir_ent.starthi = htole16(__v>>16); \ + __v = htole32(__v); \ fs_write((loff_t)offsetof(struct boot_sector,root_cluster), \ sizeof(((struct boot_sector *)0)->root_cluster), \ &__v); \ } \ else { \ - MODIFY(p,start,CT_LE_W((__v)&0xffff)); \ + MODIFY(p,start,htole16((__v)&0xffff)); \ if (fs->fat_bits == 32) \ - MODIFY(p,starthi,CT_LE_W((__v)>>16)); \ + MODIFY(p,starthi,htole16((__v)>>16)); \ } \ } while(0) @@ -230,7 +230,7 @@ static int day_n[] = /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */ -time_t date_dos2unix(unsigned short time, unsigned short date) +static time_t date_dos2unix(unsigned short time, unsigned short date) { int month, year; time_t secs; @@ -253,18 +253,19 @@ static char *file_stat(DOS_FILE * file) time_t date; date = - date_dos2unix(CF_LE_W(file->dir_ent.time), CF_LE_W(file->dir_ent.date)); + date_dos2unix(le16toh(file->dir_ent.time), le16toh(file->dir_ent.date)); tm = localtime(&date); strftime(tmp, 99, "%H:%M:%S %b %d %Y", tm); - sprintf(temp, " Size %u bytes, date %s", CF_LE_L(file->dir_ent.size), tmp); + sprintf(temp, " Size %u bytes, date %s", le32toh(file->dir_ent.size), tmp); return temp; } static int bad_name(DOS_FILE * file) { int i, spc, suspicious = 0; - char *bad_chars = atari_format ? "*?\\/:" : "*?<>|\"\\/:"; - unsigned char *name = file->dir_ent.name; + const char *bad_chars = atari_format ? "*?\\/:" : "*?<>|\"\\/:"; + const unsigned char *name = file->dir_ent.name; + const unsigned char *ext = file->dir_ent.ext; /* Do not complain about (and auto-correct) the extended attribute files * of OS/2. */ @@ -286,12 +287,12 @@ static int bad_name(DOS_FILE * file) return 1; } - for (i = 8; i < 11; i++) { - if (name[i] < ' ' || name[i] == 0x7f) + for (i = 0; i < 3; i++) { + if (ext[i] < ' ' || ext[i] == 0x7f) return 1; - if (name[i] > 0x7f) + if (ext[i] > 0x7f) ++suspicious; - if (strchr(bad_chars, name[i])) + if (strchr(bad_chars, ext[i])) return 1; } @@ -306,11 +307,11 @@ static int bad_name(DOS_FILE * file) } spc = 0; - for (i = 8; i < 11; i++) { - if (name[i] == ' ') + for (i = 0; i < 3; i++) { + if (ext[i] == ' ') spc = 1; else if (spc) - /* non-space after a space not allowed, space terminates the name + /* non-space after a space not allowed, space terminates the ext * part */ return 1; } @@ -466,7 +467,7 @@ static int handle_dot(DOS_FS * fs, DOS_FILE * file, int dots) rename_file(file); return 0; case '4': - MODIFY(file, size, CT_LE_L(0)); + MODIFY(file, size, htole32(0)); MODIFY(file, attr, file->dir_ent.attr | ATTR_DIR); break; } @@ -486,10 +487,10 @@ static int check_file(DOS_FS * fs, DOS_FILE * file) unsigned long expect, curr, this, clusters, prev, walk, clusters2; if (file->dir_ent.attr & ATTR_DIR) { - if (CF_LE_L(file->dir_ent.size)) { + if (le32toh(file->dir_ent.size)) { printf("%s\n Directory has non-zero size. Fixing it.\n", path_name(file)); - MODIFY(file, size, CT_LE_L(0)); + MODIFY(file, size, htole32(0)); } if (file->parent && !strncmp((const char *)file->dir_ent.name, MSDOS_DOT, @@ -548,14 +549,14 @@ static int check_file(DOS_FS * fs, DOS_FILE * file) MODIFY_START(file, 0, fs); break; } - if (!(file->dir_ent.attr & ATTR_DIR) && CF_LE_L(file->dir_ent.size) <= + if (!(file->dir_ent.attr & ATTR_DIR) && le32toh(file->dir_ent.size) <= (unsigned long long)clusters * fs->cluster_size) { printf ("%s\n File size is %u bytes, cluster chain length is > %llu " "bytes.\n Truncating file to %u bytes.\n", path_name(file), - CF_LE_L(file->dir_ent.size), + le32toh(file->dir_ent.size), (unsigned long long)clusters * fs->cluster_size, - CF_LE_L(file->dir_ent.size)); + le32toh(file->dir_ent.size)); truncate_file(fs, file, clusters); break; } @@ -603,7 +604,7 @@ static int check_file(DOS_FS * fs, DOS_FILE * file) else MODIFY_START(owner, 0, fs); MODIFY(owner, size, - CT_LE_L((unsigned long long)clusters * + htole32((unsigned long long)clusters * fs->cluster_size)); if (restart) return 1; @@ -632,16 +633,16 @@ static int check_file(DOS_FS * fs, DOS_FILE * file) clusters++; prev = curr; } - if (!(file->dir_ent.attr & ATTR_DIR) && CF_LE_L(file->dir_ent.size) > + if (!(file->dir_ent.attr & ATTR_DIR) && le32toh(file->dir_ent.size) > (unsigned long long)clusters * fs->cluster_size) { printf ("%s\n File size is %u bytes, cluster chain length is %llu bytes." "\n Truncating file to %llu bytes.\n", path_name(file), - CF_LE_L(file->dir_ent.size), + le32toh(file->dir_ent.size), (unsigned long long)clusters * fs->cluster_size, (unsigned long long)clusters * fs->cluster_size); MODIFY(file, size, - CT_LE_L((unsigned long long)clusters * fs->cluster_size)); + htole32((unsigned long long)clusters * fs->cluster_size)); } return 0; } @@ -869,7 +870,7 @@ static void undelete(DOS_FS * fs, DOS_FILE * file) { unsigned long clusters, left, prev, walk; - clusters = left = (CF_LE_L(file->dir_ent.size) + fs->cluster_size - 1) / + clusters = left = (le32toh(file->dir_ent.size) + fs->cluster_size - 1) / fs->cluster_size; prev = 0; @@ -931,8 +932,8 @@ static void add_file(DOS_FS * fs, DOS_FILE *** chain, DOS_FILE * parent, memcpy(de.name, " ", MSDOS_NAME); de.attr = ATTR_DIR; de.size = de.time = de.date = 0; - de.start = CT_LE_W(fs->root_cluster & 0xffff); - de.starthi = CT_LE_W((fs->root_cluster >> 16) & 0xffff); + de.start = htole16(fs->root_cluster & 0xffff); + de.starthi = htole16((fs->root_cluster >> 16) & 0xffff); } if ((type = file_type(cp, (char *)de.name)) != fdt_none) { if (type == fdt_undelete && (de.attr & ATTR_DIR)) diff --git a/src/dosfsck.c b/src/dosfsck.c index 84ecdbb..f7c1f4f 100644 --- a/src/dosfsck.c +++ b/src/dosfsck.c @@ -104,7 +104,7 @@ int main(int argc, char **argv) DOS_FS fs; int salvage_files, verify, c; unsigned n_files_check = 0, n_files_verify = 0; - unsigned long free_clusters; + unsigned long free_clusters = 0; memset(&fs, 0, sizeof(fs)); rw = salvage_files = verify = 0; @@ -217,8 +217,9 @@ exit: printf("Leaving file system unchanged.\n"); } - printf("%s: %u files, %lu/%lu clusters\n", argv[optind], - n_files, fs.clusters - free_clusters, fs.clusters); + if (!boot_only) + printf("%s: %u files, %lu/%lu clusters\n", argv[optind], + n_files, fs.clusters - free_clusters, fs.clusters); return fs_close(rw) ? 1 : 0; } diff --git a/src/dosfsck.h b/src/dosfsck.h index 9fe103a..e53bf31 100644 --- a/src/dosfsck.h +++ b/src/dosfsck.h @@ -37,23 +37,8 @@ #include <linux/msdos_fs.h> -#undef CF_LE_W -#undef CF_LE_L -#undef CT_LE_W -#undef CT_LE_L - -#if __BYTE_ORDER == __BIG_ENDIAN -#include <byteswap.h> -#define CF_LE_W(v) bswap_16(v) -#define CF_LE_L(v) bswap_32(v) -#define CT_LE_W(v) CF_LE_W(v) -#define CT_LE_L(v) CF_LE_L(v) -#else -#define CF_LE_W(v) (v) -#define CF_LE_L(v) (v) -#define CT_LE_W(v) (v) -#define CT_LE_L(v) (v) -#endif /* __BIG_ENDIAN */ +#include <stddef.h> +#include <endian.h> #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME) @@ -188,9 +173,6 @@ typedef struct { char *label; } DOS_FS; -#ifndef offsetof -#define offsetof(t,e) ((int)&(((t *)0)->e)) -#endif extern int interactive, rw, list, verbose, test, write_immed; extern int atari_format; diff --git a/src/dosfslabel.c b/src/dosfslabel.c index dd8d36a..edfb60c 100644 --- a/src/dosfslabel.c +++ b/src/dosfslabel.c @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) int i; char *device = NULL; - char *label = NULL; + char label[12] = {0}; loff_t offset; DIR_ENT de; @@ -109,8 +109,8 @@ int main(int argc, char *argv[]) device = argv[1]; if (argc == 3) { - label = argv[2]; - if (strlen(label) > 11) { + strncpy(label, argv[2], 11); + if (strlen(argv[2]) > 11) { fprintf(stderr, "dosfslabel: labels can be no longer than 11 characters\n"); exit(1); @@ -54,13 +54,13 @@ void get_fat(FAT_ENTRY * entry, void *fat, unsigned long cluster, DOS_FS * fs) (ptr[0] | ptr[1] << 8)); break; case 16: - entry->value = CF_LE_W(((unsigned short *)fat)[cluster]); + entry->value = le16toh(((unsigned short *)fat)[cluster]); break; case 32: /* According to M$, the high 4 bits of a FAT32 entry are reserved and * are not part of the cluster number. So we cut them off. */ { - unsigned long e = CF_LE_L(((unsigned int *)fat)[cluster]); + unsigned long e = le32toh(((unsigned int *)fat)[cluster]); entry->value = e & 0xfffffff; entry->reserved = e >> 28; } @@ -207,7 +207,7 @@ void set_fat(DOS_FS * fs, unsigned long cluster, unsigned long new) case 16: data = fs->fat + cluster * 2; offs = fs->fat_start + cluster * 2; - *(unsigned short *)data = CT_LE_W(new); + *(unsigned short *)data = htole16(new); size = 2; break; case 32: @@ -219,7 +219,7 @@ void set_fat(DOS_FS * fs, unsigned long cluster, unsigned long new) offs = fs->fat_start + cluster * 4; /* According to M$, the high 4 bits of a FAT32 entry are reserved and * are not part of the cluster number. So we never touch them. */ - *(unsigned long *)data = CT_LE_L((new & 0xfffffff) | + *(unsigned long *)data = htole32((new & 0xfffffff) | (curEntry.reserved << 28)); size = 4; } @@ -478,12 +478,12 @@ void reclaim_file(DOS_FS * fs) loff_t offset; files++; offset = alloc_rootdir_entry(fs, &de, "FSCK%04dREC"); - de.start = CT_LE_W(i & 0xffff); + de.start = htole16(i & 0xffff); if (fs->fat_bits == 32) - de.starthi = CT_LE_W(i >> 16); + de.starthi = htole16(i >> 16); for (walk = i; walk > 0 && walk != -1; walk = next_cluster(fs, walk)) { - de.size = CT_LE_L(CF_LE_L(de.size) + fs->cluster_size); + de.size = htole32(le32toh(de.size) + fs->cluster_size); reclaimed++; } fs_write(offset, sizeof(DIR_ENT), &de); @@ -540,7 +540,7 @@ unsigned long update_free(DOS_FS * fs) } if (do_set) { - unsigned long le_free = CT_LE_L(free); + unsigned long le_free = htole32(free); fs->free_clusters = free; fs_write(fs->fsinfo_start + offsetof(struct info_sector, free_clusters), sizeof(le_free), &le_free); @@ -124,7 +124,7 @@ static char *cnv_unicode(const unsigned char *uni, int maxlen, int use_q) cp = out = use_q ? qalloc(&mem_queue, len + 1) : alloc(len + 1); for (up = uni; (up - uni) / 2 < maxlen && (up[0] || up[1]); up += 2) { - if ((x = wctombs(cp, BYTES_TO_WCHAR(up[0], up[1]))) != (size_t) - 1) + if ((x = wctombs((char *)cp, BYTES_TO_WCHAR(up[0], up[1]))) != (size_t) - 1) cp += x; else if (UNICODE_CONVERTABLE(up[0], up[1])) *cp++ = up[0]; @@ -388,7 +388,7 @@ void lfn_add_slot(DIR_ENT * de, loff_t dir_offset) sizeof(lfn->reserved), &lfn->reserved); } } - if (lfn->start != CT_LE_W(0)) { + if (lfn->start != htole16(0)) { printf("Start cluster field in VFAT long filename slot is not 0 " "(but 0x%04x).\n", lfn->start); if (interactive) @@ -396,7 +396,7 @@ void lfn_add_slot(DIR_ENT * de, loff_t dir_offset) else printf("Auto-setting to 0.\n"); if (!interactive || get_key("12", "?") == '1') { - lfn->start = CT_LE_W(0); + lfn->start = htole16(0); fs_write(dir_offset + offsetof(LFN_ENT, start), sizeof(lfn->start), &lfn->start); } @@ -462,8 +462,10 @@ char *lfn_get(DIR_ENT * de, loff_t * lfn_offset) } } - for (sum = 0, i = 0; i < 11; i++) + for (sum = 0, i = 0; i < 8; i++) sum = (((sum & 1) << 7) | ((sum & 0xfe) >> 1)) + de->name[i]; + for (i = 0; i < 3; i++) + sum = (((sum & 1) << 7) | ((sum & 0xfe) >> 1)) + de->ext[i]; if (sum != lfn_checksum) { /* checksum doesn't match, long name doesn't apply to this alias */ /* Causes: 1) alias renamed */ diff --git a/src/mkdosfs.c b/src/mkdosfs.c index d7c94f5..4142052 100644 --- a/src/mkdosfs.c +++ b/src/mkdosfs.c @@ -64,35 +64,10 @@ #include <time.h> #include <errno.h> #include <ctype.h> +#include <endian.h> #include <asm/types.h> -#if __BYTE_ORDER == __BIG_ENDIAN - -#include <asm/byteorder.h> -#ifdef __le16_to_cpu -/* ++roman: 2.1 kernel headers define these function, they're probably more - * efficient then coding the swaps machine-independently. */ -#define CF_LE_W __le16_to_cpu -#define CF_LE_L __le32_to_cpu -#define CT_LE_W __cpu_to_le16 -#define CT_LE_L __cpu_to_le32 -#else -#define CF_LE_W(v) ((((v) & 0xff) << 8) | (((v) >> 8) & 0xff)) -#define CF_LE_L(v) (((unsigned)(v)>>24) | (((unsigned)(v)>>8)&0xff00) | \ - (((unsigned)(v)<<8)&0xff0000) | ((unsigned)(v)<<24)) -#define CT_LE_W(v) CF_LE_W(v) -#define CT_LE_L(v) CF_LE_L(v) -#endif /* defined(__le16_to_cpu) */ - -#else - -#define CF_LE_W(v) (v) -#define CF_LE_L(v) (v) -#define CT_LE_W(v) (v) -#define CT_LE_L(v) (v) - -#endif /* __BIG_ENDIAN */ /* In earlier versions, an own llseek() was used, but glibc lseek() is * sufficient (or even better :) for 64 bit offsets in the meantime */ @@ -121,7 +96,7 @@ /* Compute ceil(a/b) */ -inline int cdiv(int a, int b) +static inline int cdiv(int a, int b) { return (a + b - 1) / b; } @@ -416,6 +391,8 @@ static long do_check(char *buffer, int try, off_t current_block) static void alarm_intr(int alnum) { + (void)alnum; + if (currently_testing >= blocks) return; @@ -601,8 +578,8 @@ static void establish_params(int device_num, int size) if (ioctl(dev, FDGETPRM, ¶m)) /* Can we get the diskette geometry? */ die("unable to get diskette geometry for '%s'"); } - bs.secs_track = CT_LE_W(param.sect); /* Set up the geometry information */ - bs.heads = CT_LE_W(param.head); + bs.secs_track = htole16(param.sect); /* Set up the geometry information */ + bs.heads = htole16(param.head); switch (param.size) { /* Set up the media descriptor byte */ case 720: /* 5.25", 2, 9, 40 - 360K */ bs.media = (char)0xfd; @@ -647,32 +624,32 @@ floppy_default: switch (loop_size) { /* Assuming the loop device -> floppy later */ case 720: /* 5.25", 2, 9, 40 - 360K */ - bs.secs_track = CF_LE_W(9); - bs.heads = CF_LE_W(2); + bs.secs_track = le16toh(9); + bs.heads = le16toh(2); bs.media = (char)0xfd; bs.cluster_size = (char)2; def_root_dir_entries = 112; break; case 1440: /* 3.5", 2, 9, 80 - 720K */ - bs.secs_track = CF_LE_W(9); - bs.heads = CF_LE_W(2); + bs.secs_track = le16toh(9); + bs.heads = le16toh(2); bs.media = (char)0xf9; bs.cluster_size = (char)2; def_root_dir_entries = 112; break; case 2400: /* 5.25", 2, 15, 80 - 1200K */ - bs.secs_track = CF_LE_W(15); - bs.heads = CF_LE_W(2); + bs.secs_track = le16toh(15); + bs.heads = le16toh(2); bs.media = (char)0xf9; bs.cluster_size = (char)(atari_format ? 2 : 1); def_root_dir_entries = 224; break; case 5760: /* 3.5", 2, 36, 80 - 2880K */ - bs.secs_track = CF_LE_W(36); - bs.heads = CF_LE_W(2); + bs.secs_track = le16toh(36); + bs.heads = le16toh(2); bs.media = (char)0xf0; bs.cluster_size = (char)2; bs.dir_entries[0] = (char)224; @@ -680,8 +657,8 @@ floppy_default: break; case 2880: /* 3.5", 2, 18, 80 - 1440K */ - bs.secs_track = CF_LE_W(18); - bs.heads = CF_LE_W(2); + bs.secs_track = le16toh(18); + bs.heads = le16toh(2); bs.media = (char)0xf0; bs.cluster_size = (char)(atari_format ? 2 : 1); def_root_dir_entries = 224; @@ -690,8 +667,8 @@ floppy_default: default: /* Anything else: default hd setup */ printf("Loop device does not match a floppy size, using " "default hd params\n"); - bs.secs_track = CT_LE_W(32); /* these are fake values... */ - bs.heads = CT_LE_W(64); + bs.secs_track = htole16(32); /* these are fake values... */ + bs.heads = htole16(64); goto def_hd_params; } } else @@ -702,11 +679,11 @@ floppy_default: if (ioctl(dev, HDIO_GETGEO, &geometry) || geometry.sectors == 0 || geometry.heads == 0) { printf("unable to get drive geometry, using default 255/63\n"); - bs.secs_track = CT_LE_W(63); - bs.heads = CT_LE_W(255); + bs.secs_track = htole16(63); + bs.heads = htole16(255); } else { - bs.secs_track = CT_LE_W(geometry.sectors); /* Set up the geometry information */ - bs.heads = CT_LE_W(geometry.heads); + bs.secs_track = htole16(geometry.sectors); /* Set up the geometry information */ + bs.heads = htole16(geometry.heads); } def_hd_params: bs.media = (char)0xf8; /* Set up the media descriptor for a hard drive */ @@ -761,11 +738,13 @@ static void setup_tables(void) struct msdos_volume_info *vi = (size_fat == 32 ? &bs.fat32.vi : &bs.oldfat.vi); - if (atari_format) + if (atari_format) { /* On Atari, the first few bytes of the boot sector are assigned * differently: The jump code is only 2 bytes (and m68k machine code * :-), then 6 bytes filler (ignored), then 3 byte serial number. */ - memcpy(bs.system_id - 1, "mkdosf", 6); + bs.boot_jump[2] = 'm'; + strcpy((char *)bs.system_id, "kdosf"); + } else strcpy((char *)bs.system_id, "mkdosfs"); if (sectors_per_cluster) @@ -808,7 +787,7 @@ static void setup_tables(void) } else { memcpy(bs.oldfat.boot_code, dummy_boot_code, BOOTCODE_SIZE); } - bs.boot_sign = CT_LE_W(BOOT_SIGN); + bs.boot_sign = htole16(BOOT_SIGN); } else { memcpy(bs.boot_jump, dummy_boot_jump_m68k, 2); } @@ -822,15 +801,15 @@ static void setup_tables(void) if (size_fat == 32 && reserved_sectors < 2) die("On FAT32 at least 2 reserved sectors are needed."); } - bs.reserved = CT_LE_W(reserved_sectors); + bs.reserved = htole16(reserved_sectors); if (verbose >= 2) printf("Using %d reserved sectors\n", reserved_sectors); bs.fats = (char)nr_fats; if (!atari_format || size_fat == 32) - bs.hidden = CT_LE_L(hidden_sectors); + bs.hidden = htole32(hidden_sectors); else { /* In Atari format, hidden is a 16 bit field */ - __u16 hidden = CT_LE_W(hidden_sectors); + __u16 hidden = htole16(hidden_sectors); if (hidden_sectors & ~0xffff) die("#hidden doesn't fit in 16bit field of Atari format\n"); memcpy(&bs.hidden, &hidden, 2); @@ -971,7 +950,7 @@ static void setup_tables(void) case 12: cluster_count = clust12; fat_length = fatlength12; - bs.fat_length = CT_LE_W(fatlength12); + bs.fat_length = htole16(fatlength12); memcpy(vi->fs_type, MSDOS_FAT12_SIGN, 8); break; @@ -995,7 +974,7 @@ static void setup_tables(void) } cluster_count = clust16; fat_length = fatlength16; - bs.fat_length = CT_LE_W(fatlength16); + bs.fat_length = htole16(fatlength16); memcpy(vi->fs_type, MSDOS_FAT16_SIGN, 8); break; @@ -1005,8 +984,8 @@ static void setup_tables(void) "WARNING: Not enough clusters for a 32 bit FAT!\n"); cluster_count = clust32; fat_length = fatlength32; - bs.fat_length = CT_LE_W(0); - bs.fat32.fat32_length = CT_LE_L(fatlength32); + bs.fat_length = htole16(0); + bs.fat32.fat32_length = htole32(fatlength32); memcpy(vi->fs_type, MSDOS_FAT32_SIGN, 8); root_dir_entries = 0; break; @@ -1017,7 +996,7 @@ static void setup_tables(void) /* Adjust the reserved number of sectors for alignment */ reserved_sectors = align_object(reserved_sectors, bs.cluster_size); - bs.reserved = CT_LE_W(reserved_sectors); + bs.reserved = htole16(reserved_sectors); /* Adjust the number of root directory entries to help enforce alignment */ if (align_structures) { @@ -1100,10 +1079,10 @@ static void setup_tables(void) cluster_count = clusters; if (size_fat != 32) - bs.fat_length = CT_LE_W(fat_length); + bs.fat_length = htole16(fat_length); else { bs.fat_length = 0; - bs.fat32.fat32_length = CT_LE_L(fat_length); + bs.fat32.fat32_length = htole32(fat_length); } } @@ -1115,11 +1094,11 @@ static void setup_tables(void) if (size_fat == 32) { /* set up additional FAT32 fields */ - bs.fat32.flags = CT_LE_W(0); + bs.fat32.flags = htole16(0); bs.fat32.version[0] = 0; bs.fat32.version[1] = 0; - bs.fat32.root_cluster = CT_LE_L(2); - bs.fat32.info_sector = CT_LE_W(1); + bs.fat32.root_cluster = htole32(2); + bs.fat32.info_sector = htole16(1); if (!backup_boot) backup_boot = (reserved_sectors >= 7) ? 6 : (reserved_sectors >= 2) ? reserved_sectors - 1 : 0; @@ -1132,7 +1111,7 @@ static void setup_tables(void) if (verbose >= 2) printf("Using sector %d as backup boot sector (0 = none)\n", backup_boot); - bs.fat32.backup_boot = CT_LE_W(backup_boot); + bs.fat32.backup_boot = htole16(backup_boot); memset(&bs.fat32.reserved2, 0, sizeof(bs.fat32.reserved2)); } @@ -1147,12 +1126,12 @@ static void setup_tables(void) if (num_sectors >= 65536) { bs.sectors[0] = (char)0; bs.sectors[1] = (char)0; - bs.total_sect = CT_LE_L(num_sectors); + bs.total_sect = htole32(num_sectors); } else { bs.sectors[0] = (char)(num_sectors & 0x00ff); bs.sectors[1] = (char)((num_sectors & 0xff00) >> 8); if (!atari_format) - bs.total_sect = CT_LE_L(0); + bs.total_sect = htole32(0); } if (!atari_format) @@ -1176,9 +1155,9 @@ static void setup_tables(void) if (verbose) { printf("%s has %d head%s and %d sector%s per track,\n", - device_name, CF_LE_W(bs.heads), - (CF_LE_W(bs.heads) != 1) ? "s" : "", CF_LE_W(bs.secs_track), - (CF_LE_W(bs.secs_track) != 1) ? "s" : ""); + device_name, le16toh(bs.heads), + (le16toh(bs.heads) != 1) ? "s" : "", le16toh(bs.secs_track), + (le16toh(bs.secs_track) != 1) ? "s" : ""); printf("logical sector size is %d,\n", sector_size); printf("using 0x%02x media descriptor, with %d sectors;\n", (int)(bs.media), num_sectors); @@ -1247,20 +1226,20 @@ static void setup_tables(void) memcpy(de->ext, volume_name + 8, 3); de->attr = ATTR_VOLUME; ctime = localtime(&create_time); - de->time = CT_LE_W((unsigned short)((ctime->tm_sec >> 1) + + de->time = htole16((unsigned short)((ctime->tm_sec >> 1) + (ctime->tm_min << 5) + (ctime->tm_hour << 11))); de->date = - CT_LE_W((unsigned short)(ctime->tm_mday + + htole16((unsigned short)(ctime->tm_mday + ((ctime->tm_mon + 1) << 5) + ((ctime->tm_year - 80) << 9))); 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); + de->starthi = htole16(0); + de->start = htole16(0); + de->size = htole32(0); } if (size_fat == 32) { @@ -1280,13 +1259,13 @@ static void setup_tables(void) info_sector[3] = 'A'; /* Magic for fsinfo structure */ - info->signature = CT_LE_L(0x61417272); + info->signature = htole32(0x61417272); /* We've allocated cluster 2 for the root dir. */ - info->free_clusters = CT_LE_L(cluster_count - 1); - info->next_cluster = CT_LE_L(2); + info->free_clusters = htole32(cluster_count - 1); + info->next_cluster = htole32(2); /* Info sector also must have boot sign */ - *(__u16 *) (info_sector + 0x1fe) = CT_LE_W(BOOT_SIGN); + *(__u16 *) (info_sector + 0x1fe) = htole16(BOOT_SIGN); } if (!(blank_sector = malloc(sector_size))) @@ -1324,7 +1303,7 @@ static void write_tables(void) int fat_length; fat_length = (size_fat == 32) ? - CF_LE_L(bs.fat32.fat32_length) : CF_LE_W(bs.fat_length); + le32toh(bs.fat32.fat32_length) : le16toh(bs.fat_length); seekto(0, "start of device"); /* clear all reserved sectors */ @@ -1335,7 +1314,7 @@ static void write_tables(void) writebuf((char *)&bs, sizeof(struct msdos_boot_sector), "boot sector"); /* on FAT32, write the info sector and backup boot sector */ if (size_fat == 32) { - seekto(CF_LE_W(bs.fat32.info_sector) * sector_size, "info sector"); + seekto(le16toh(bs.fat32.info_sector) * sector_size, "info sector"); writebuf(info_sector, 512, "info sector"); if (backup_boot != 0) { seekto(backup_boot * sector_size, "backup boot sector"); @@ -1366,7 +1345,7 @@ static void write_tables(void) /* Report the command usage and return a failure error code */ -void usage(void) +static void usage(void) { fatal_error("\ Usage: mkdosfs [-a][-A][-c][-C][-v][-I][-l bad-block-file][-b backup-boot-sector]\n\ diff --git a/src/version.h b/src/version.h index a7c41a0..6c5ab91 100644 --- a/src/version.h +++ b/src/version.h @@ -23,7 +23,7 @@ #ifndef _version_h #define _version_h -#define VERSION "3.0.16" -#define VERSION_DATE "01 Mar 2013" +#define VERSION "3.0.17" +#define VERSION_DATE "29 May 2013" #endif |