rpms/dosfstools/devel dosfstools-2.11-label.patch, NONE, 1.1 dosfstools.spec, 1.28, 1.29

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Tue Apr 3 19:15:11 UTC 2007


Author: katzj

Update of /cvs/dist/rpms/dosfstools/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv1191

Modified Files:
	dosfstools.spec 
Added Files:
	dosfstools-2.11-label.patch 
Log Message:
* Tue Apr  3 2007 Jeremy Katz <katzj at redhat.com> - 2.11-8
- add dosfslabel (originally by Peter Jones)


dosfstools-2.11-label.patch:
 Makefile     |   14 +++++--
 boot.c       |   46 ++++++++++++++++++++++++
 boot.h       |    1 
 dosfsck.h    |   42 +++++++++++++++++++++-
 dosfslabel.c |  110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 207 insertions(+), 6 deletions(-)

--- NEW FILE dosfstools-2.11-label.patch ---
--- dosfstools-2.11/dosfsck/Makefile.label	1999-07-06 10:23:11.000000000 -0400
+++ dosfstools-2.11/dosfsck/Makefile	2007-01-11 16:33:54.000000000 -0500
@@ -1,9 +1,12 @@
 
-OBJECTS = boot.o check.o common.o dosfsck.o fat.o file.o io.o lfn.o
+OBJECTS = boot.o check.o common.o fat.o file.o io.o lfn.o
 
-all: dosfsck
+all: dosfsck dosfslabel
 
-dosfsck: $(OBJECTS)
+dosfsck: $(OBJECTS) dosfsck.o
+	$(CC) -o $@ $(LDFLAGS) $^
+
+dosfslabel : $(OBJECTS) dosfslabel.o
 	$(CC) -o $@ $(LDFLAGS) $^
 
 .c.o:
@@ -15,8 +18,10 @@
 	install -m 644 dosfsck.8 $(MANDIR)
 	rm -f $(SBINDIR)/fsck.msdos
 	rm -f $(SBINDIR)/fsck.vfat
+	rm -f $(SBINDIR)/dosfslabel
 	ln -s dosfsck $(SBINDIR)/fsck.msdos
 	ln -s dosfsck $(SBINDIR)/fsck.vfat
+	ln -s dosfslabel $(SBINDIR)/dosfslabel
 	rm -f $(MANDIR)/fsck.msdos.8
 	ln -s dosfsck.8 $(MANDIR)/fsck.msdos.8
 	ln -s dosfsck.8 $(MANDIR)/fsck.vfat.8
@@ -25,7 +30,7 @@
 	rm -f *.o *.s *.i *~ \#*# tmp_make .#* .new*
 
 distclean: clean
-	rm -f *.a dosfsck
+	rm -f *.a dosfsck dosfslabel
 
 dep:
 	sed '/\#\#\# Dependencies/q' <Makefile >tmp_make
@@ -38,6 +43,7 @@
 common.o: common.c common.h
 dosfsck.o: dosfsck.c common.h dosfsck.h io.h boot.h fat.h file.h \
  check.h
+dosfslabel.o: dosfslabel.c common.h dosfsck.h io.h boot.h fat.h file.h check.h
 fat.o: fat.c common.h dosfsck.h io.h check.h fat.h
 file.o: file.c common.h file.h
 io.o: io.c dosfsck.h common.h io.h
--- dosfstools-2.11/dosfsck/dosfsck.h.label	2007-01-11 16:33:54.000000000 -0500
+++ dosfstools-2.11/dosfsck/dosfsck.h	2007-01-11 16:33:54.000000000 -0500
@@ -65,10 +65,47 @@
     __u32	root_cluster;	/* first cluster in root directory */
     __u16	info_sector;	/* filesystem info sector */
     __u16	backup_boot;	/* backup boot sector */
-    __u16	reserved2[6];	/* Unused */
+    __u8 	reserved2[12];	/* Unused */
+
+    __u8        drive_number;   /* Logical Drive Number */
+    __u8        reserved3;      /* Unused */
+
+    __u8        extended_sig;   /* Extended Signature (0x29) */
+    __u32       serial;         /* Serial number */
+    __u8        label[11];      /* FS label */
+    __u8        fs_type[8];     /* FS Type */
+
+    /* fill up to 512 bytes */
+    __u8	junk[422];
+} __attribute__ ((packed));
+
+struct boot_sector_16 {
+    __u8	ignored[3];	/* Boot strap short or near jump */
+    __u8	system_id[8];	/* Name - can be used to special case
+				   partition manager volumes */
+    __u8	sector_size[2];	/* bytes per logical sector */
+    __u8	cluster_size;	/* sectors/cluster */
+    __u16	reserved;	/* reserved sectors */
+    __u8	fats;		/* number of FATs */
+    __u8	dir_entries[2];	/* root directory entries */
+    __u8	sectors[2];	/* number of sectors */
+    __u8	media;		/* media code (unused) */
+    __u16	fat_length;	/* sectors/FAT */
+    __u16	secs_track;	/* sectors per track */
+    __u16	heads;		/* number of heads */
+    __u32	hidden;		/* hidden sectors (unused) */
+    __u32	total_sect;	/* number of sectors (if sectors == 0) */
+    
+    __u8        drive_number;   /* Logical Drive Number */
+    __u8        reserved2;      /* Unused */
+
+    __u8        extended_sig;   /* Extended Signature (0x29) */
+    __u32       serial;         /* Serial number */
+    __u8        label[11];      /* FS label */
+    __u8        fs_type[8];     /* FS Type */
 
     /* fill up to 512 bytes */
-    __u8	junk[448];
+    __u8	junk[450];
 } __attribute__ ((packed));
 
 struct info_sector {
@@ -128,6 +165,7 @@
     long free_clusters;
     loff_t backupboot_start; /* 0 if not present */
     FAT_ENTRY *fat;
+    char *label;
 } DOS_FS;
 
 #ifndef offsetof
--- /dev/null	2006-12-18 18:52:37.519428789 -0500
+++ dosfstools-2.11/dosfsck/dosfslabel.c	2007-01-11 16:35:00.000000000 -0500
@@ -0,0 +1,110 @@
+/* dosfslabel.c  -  User interface */
+
+/* Copyright 2007 Red Hat, Inc.
+ * Portions copyright 1998 Roman Hodek.
+ * Portions copyright 1993 Werner Almesberger.
+ */
+
+#include "../version.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+
+#include "common.h"
+#include "dosfsck.h"
+#include "io.h"
+#include "boot.h"
+#include "fat.h"
+#include "file.h"
+#include "check.h"
+
+
+int interactive = 0,list = 0,test = 0,verbose = 0,write_immed = 0;
+int atari_format = 0;
+unsigned n_files = 0;
+void *mem_queue = NULL;
+
+
+static void usage(int error)
+{
+    FILE *f = error ? stderr : stdout;
+    int status = error ? 1 : 0;
+
+    fprintf(f,"usage: dosfslabel device [label]\n");
+    exit(status);
+}
+
+/*
+ * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
+ * of MS-DOS filesystem by default.
+ */
+static void check_atari( void )
+{
+#ifdef __mc68000__
+    FILE *f;
+    char line[128], *p;
+
+    if (!(f = fopen( "/proc/hardware", "r" ))) {
+	perror( "/proc/hardware" );
+	return;
+    }
+
+    while( fgets( line, sizeof(line), f ) ) {
+	if (strncmp( line, "Model:", 6 ) == 0) {
+	    p = line + 6;
+	    p += strspn( p, " \t" );
+	    if (strncmp( p, "Atari ", 6 ) == 0)
+		atari_format = 1;
+	    break;
+	}
+    }
+    fclose( f );
+#endif
+}
+
+
+int main(int argc, char *argv[])
+{
+    DOS_FS fs;
+    int rw = 0;
+
+    char *device = NULL;
+    char *label = NULL;
+    
+    check_atari();
+
+    if (argc < 2 || argc > 3)
+        usage(1);
+
+    if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
+        usage(0);
+    else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
+        printf( "dosfslabel " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
+        exit(0);
+    }
+
+    device = argv[1];
+    if (argc == 3) {
+        label = argv[2];
+        if (strlen(label) > 11) {
+            fprintf(stderr,
+                    "dosfslabel: labels can be no longer than 11 characters\n");
+            exit(1);
+        }
+        rw = 1;
+    }
+
+    fs_open(device, rw);
+    read_boot(&fs);
+    if (!rw) {
+        fprintf(stdout, "%s\n", fs.label);
+        exit(0);
+    }
+
+    write_label(&fs, label);
+    return fs_close(rw) ? 1 : 0;
+}
--- dosfstools-2.11/dosfsck/boot.h.label	1997-06-18 06:09:38.000000000 -0400
+++ dosfstools-2.11/dosfsck/boot.h	2007-01-11 16:33:54.000000000 -0500
@@ -7,6 +7,7 @@
 #define _BOOT_H
 
 void read_boot(DOS_FS *fs);
+void write_label(DOS_FS *fs, char *label);
 
 /* Reads the boot sector from the currently open device and initializes *FS */
 
--- dosfstools-2.11/dosfsck/boot.c.label	2005-03-12 09:16:22.000000000 -0500
+++ dosfstools-2.11/dosfsck/boot.c	2007-01-11 16:33:54.000000000 -0500
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
+#include <stdlib.h>
 
 #include "common.h"
 #include "dosfsck.h"
@@ -348,6 +349,21 @@
     /* On FAT32, the high 4 bits of a FAT entry are reserved */
     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 (__u8));
+    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;
+    }
+
     if (fs->clusters > ((unsigned long long)fs->fat_size*8/fs->fat_bits)-2)
 	die("File system has %d clusters but only space for %d FAT entries.",
 	  fs->clusters,((unsigned long long)fs->fat_size*8/fs->fat_bits)-2);
@@ -365,6 +381,36 @@
     if (verbose) dump_boot(fs,&b,logical_sector_size);
 }
 
+void write_label(DOS_FS *fs, char *label)
+{
+    struct boot_sector b;
+    struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b;
+    int l = strlen(label);
+
+    while (l < 11)
+        label[l++] = ' ';
+
+    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   ", 8);
+        }
+        memmove(b16->label, label, 11);
+    } else if (fs->fat_bits == 32) {
+        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->fat_bits == 32 && fs->backupboot_start)
+        fs_write(fs->backupboot_start, sizeof(b), &b);
+}
+
 /* Local Variables: */
 /* tab-width: 8     */
 /* End:             */


Index: dosfstools.spec
===================================================================
RCS file: /cvs/dist/rpms/dosfstools/devel/dosfstools.spec,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- dosfstools.spec	21 Feb 2007 13:06:00 -0000	1.28
+++ dosfstools.spec	3 Apr 2007 19:15:09 -0000	1.29
@@ -1,7 +1,7 @@
 Name: dosfstools
 Summary: Utilities for making and checking MS-DOS FAT filesystems on Linux
 Version: 2.11
-Release: 7%{?dist}
+Release: 8%{?dist}
 License: GPL
 Group: Applications/System
 Source: ftp://ftp.uni-erlangen.de/pub/Linux/LOCAL/dosfstools/dosfstools-%{version}.src.tar.gz
@@ -9,6 +9,7 @@
 Patch1: dosfstools-2.7-argfix.patch
 Patch2: dosfstools-2.11-assumeKernel26.patch
 Patch4: dosfstools-2.11-fortify.patch
+Patch5: dosfstools-2.11-label.patch
 Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 Obsoletes: mkdosfs-ygg
 Provides: mkdosfs-ygg = %{version}
@@ -23,6 +24,7 @@
 %patch1 -p1 -b .argfix
 %patch2 -p1 -b .assumeKernel26
 %patch4 -p1 -b .fortify
+%patch5 -p1 -b .label
 
 %build
 make %{?_smp_mflags} CFLAGS="$RPM_OPT_FLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
@@ -47,6 +49,8 @@
 install -m 644 dosfsck/dosfsck.8 %{buildroot}%{_mandir}/man8
 ln -sf dosfsck.8.gz %{buildroot}%{_mandir}/man8/fsck.vfat.8.gz
 
+install -m755 dosfsck/dosfslabel %{buildroot}/sbin/dosfslabel
+
 %clean
 rm -rf %{buildroot}
 
@@ -56,6 +60,9 @@
 %{_mandir}/man8/*
 
 %changelog
+* Tue Apr  3 2007 Jeremy Katz <katzj at redhat.com> - 2.11-8
+- add dosfslabel (originally by Peter Jones)
+
 * Wed Feb 21 2007 Peter Vrabec <pvrabec at redhat.com> 2.11-7
 - fix debuginfo package (#225707)
 




More information about the fedora-cvs-commits mailing list