Module Name:    src
Committed By:   perseant
Date:           Fri Aug  2 00:24:20 UTC 2024

Modified Files:
        src/usr.sbin/dumpexfatfs [perseant-exfatfs]: dumpexfatfs.8
            dumpexfatfs.c

Log Message:
Docuemnt options in the manual page.

Add -n flag to print a newfs_exfatfs invocation that would generate
this filesystem configuration.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/usr.sbin/dumpexfatfs/dumpexfatfs.8
cvs rdiff -u -r1.1.2.5 -r1.1.2.6 src/usr.sbin/dumpexfatfs/dumpexfatfs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/dumpexfatfs/dumpexfatfs.8
diff -u src/usr.sbin/dumpexfatfs/dumpexfatfs.8:1.1.2.1 src/usr.sbin/dumpexfatfs/dumpexfatfs.8:1.1.2.2
--- src/usr.sbin/dumpexfatfs/dumpexfatfs.8:1.1.2.1	Sat Jun 29 19:43:27 2024
+++ src/usr.sbin/dumpexfatfs/dumpexfatfs.8	Fri Aug  2 00:24:20 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: dumpexfatfs.8,v 1.1.2.1 2024/06/29 19:43:27 perseant Exp $
+.\"	$NetBSD: dumpexfatfs.8,v 1.1.2.2 2024/08/02 00:24:20 perseant Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -48,12 +48,35 @@ The listing is very long and detailed.
 This command is useful mostly for finding out certain file system
 information such as the file system block size.
 .Pp
-.\"The following flags are interpreted by
-.\".Nm .
-.\".Bl -tag -width indent
-.\".It Fl a
-.\"Dump the contents of all superblocks, not just the first.  Superblocks
-.\"appear in the dumplfs output with the segment containing them.
+The following flags are interpreted by
+.Nm .
+.Bl -tag -width indent
+.\""AaB:bcd:fnruv"
+.It Fl A
+This is equivalent to using flags -abfru.
+.It Fl a
+Dump the allocation bitmap.
+.It Fl B Ar bootcode-file
+Dump the filesystem's bootcode into a file suitable for use by
+.Xr newfs_exfatfs 8 .
+.It Fl c
+Print the current time, converted to and from DOS format time;
+and January 1st, 1980 in DOS format time.
+.It Fl d Ar inum
+Dump the contents of the directory with inode number
+.Ar inum .
+.It Fl f
+Dump the File Allocation Table.
+.It Fl n
+Show the invocation of
+.Xr newfs 8
+to duplicate this filesystem.
+.It Fl r
+Dump the contents of the root directory.
+.It Fl u
+Display the up-case table.
+.It Fl v
+Be more verbose.
 .El
 .Sh SEE ALSO
 .Xr disktab 5 ,

Index: src/usr.sbin/dumpexfatfs/dumpexfatfs.c
diff -u src/usr.sbin/dumpexfatfs/dumpexfatfs.c:1.1.2.5 src/usr.sbin/dumpexfatfs/dumpexfatfs.c:1.1.2.6
--- src/usr.sbin/dumpexfatfs/dumpexfatfs.c:1.1.2.5	Wed Jul 24 00:40:38 2024
+++ src/usr.sbin/dumpexfatfs/dumpexfatfs.c	Fri Aug  2 00:24:20 2024
@@ -35,6 +35,7 @@ void print_dir(struct exfatfs *fs, uint3
 
 void print_fat(struct exfatfs *fs);
 void print_bootblock(struct exfatfs *fs);
+void print_bootblock_newfs(struct exfatfs *fs, char *);
 void print_bitmap(struct exfatfs *fs);
 void print_upcase_table(struct exfatfs *fs, uint32_t clust, uint64_t len);
 uint32_t next_fat(struct exfatfs *fs, uint32_t fat);
@@ -49,6 +50,7 @@ int Bflag = 0;
 int Cflag = 0;
 int Dflag = 0;
 int Fflag = 0;
+int Nflag = 0;
 int Rflag = 0;
 int Uflag = 0;
 int verbose = 0;
@@ -56,6 +58,8 @@ int verbose = 0;
 static uint8_t PRIMARY_IGNORE[2] = { 2, 3 };
 static uint8_t PRIMARY_IGNORE_LEN = 2;
 
+#define NEWFS_EXFATFS "newfs_exfatfs"
+
 static void
 efun(int eval, const char *fmt, ...)
 {
@@ -83,8 +87,9 @@ int main(int argc, char **argv)
 	int devfd, c;
 	struct exfatfs *fs;
 	char *bootcodefile = NULL;
+	char *rdev;
 
-	while ((c = getopt(argc, argv, "AaB:bcd:fruv")) != -1) {
+	while ((c = getopt(argc, argv, "AaB:bcd:fnruv")) != -1) {
 		switch (c) {
 		case 'A':
 			Aflag = !Aflag;
@@ -111,6 +116,9 @@ int main(int argc, char **argv)
 		case 'f':
 			Fflag = !Fflag;
 			break;
+		case 'n':
+			Nflag = !Nflag;
+			break;
 		case 'r':
 			Rflag = !Rflag;
 			break;
@@ -127,6 +135,7 @@ int main(int argc, char **argv)
 	}
 	if (argc < optind)
 		usage();
+	rdev = argv[optind];
 
 	if (Cflag) {
 		struct timespec now;
@@ -149,12 +158,12 @@ int main(int argc, char **argv)
 		exit(0);
 	}
 
-	if (Aflag + Bflag + Dflag + Fflag + Rflag + Uflag == 0)
+	if (Aflag + Bflag + Dflag + Fflag + Nflag + Rflag + Uflag == 0)
 		Aflag = Bflag = Fflag = Rflag = Uflag = 1;
 	
-	devfd = open(argv[optind], O_RDONLY);
+	devfd = open(rdev, O_RDONLY);
 	if (devfd <= 0)
-		err(1, argv[optind]);
+		err(1, rdev);
 	
 	if (bootcodefile != NULL) {
 		/*
@@ -164,10 +173,10 @@ int main(int argc, char **argv)
 		FILE *fp;
 		char buf[390];
 		if (pread(devfd, buf, sizeof(buf), 120) < sizeof(buf))
-			err(1, argv[optind]);
+			err(1, rdev);
 		fp = fopen(bootcodefile, "wb");
 		if (fp == NULL || fwrite(buf, 390, 1, fp) < 1)
-			err(1, argv[optind]);	
+			err(1, rdev);
 		fclose(fp);
 	}
 	
@@ -185,6 +194,11 @@ int main(int argc, char **argv)
 
 	fs = exfatfs_init(devfd, verbose);
 
+	if (Nflag) {
+		print_bootblock_newfs(fs, rdev);
+		printf("\n");
+	}
+
 	if (Bflag) {
 		print_bootblock(fs);
 		printf("\n");
@@ -292,6 +306,19 @@ void print_bootblock(struct exfatfs *fs)
         printf("BootSignature: 0x%hx\n", fs->xf_BootSignature);
 }
 
+void print_bootblock_newfs(struct exfatfs *fs, char *rdev)
+{
+	printf("%s -# 0x%lx -a %lu -c %u -h %lu -S %u -s %lu %s\n",
+	       NEWFS_EXFATFS,
+	       (unsigned long)fs->xf_VolumeSerialNumber, /* -# */
+	       (unsigned long)fs->xf_FatOffset, /* -a */
+	       (unsigned)(1 << (fs->xf_SectorsPerClusterShift + fs->xf_BytesPerSectorShift)), /* -c */
+	       (unsigned long)fs->xf_ClusterHeapOffset, /* -h */
+	       (unsigned)(1 << fs->xf_BytesPerSectorShift), /* -S */
+	       (unsigned long)fs->xf_VolumeLength, /* -s */
+	       rdev);
+}
+
 /*
  * Return the next FAT entry after this one, or -1 if there is none.
  */

Reply via email to