Module Name: src
Committed By: perseant
Date: Thu Jul 25 23:46:10 UTC 2024
Modified Files:
src/sbin/newfs_exfatfs [perseant-exfatfs]: make_exfatfs.c newfs.c
newfs_exfatfs.8
Log Message:
Actually use the partition offset alignment option.
Document all flags both in the man page and in usage().
To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/sbin/newfs_exfatfs/make_exfatfs.c
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sbin/newfs_exfatfs/newfs.c
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sbin/newfs_exfatfs/newfs_exfatfs.8
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/newfs_exfatfs/make_exfatfs.c
diff -u src/sbin/newfs_exfatfs/make_exfatfs.c:1.1.2.4 src/sbin/newfs_exfatfs/make_exfatfs.c:1.1.2.5
--- src/sbin/newfs_exfatfs/make_exfatfs.c:1.1.2.4 Wed Jul 24 00:46:18 2024
+++ src/sbin/newfs_exfatfs/make_exfatfs.c Thu Jul 25 23:46:10 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: make_exfatfs.c,v 1.1.2.4 2024/07/24 00:46:18 perseant Exp $ */
+/* $NetBSD: make_exfatfs.c,v 1.1.2.5 2024/07/25 23:46:10 perseant Exp $ */
/*-
* Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#if 0
static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
#else
-__RCSID("$NetBSD: make_exfatfs.c,v 1.1.2.4 2024/07/24 00:46:18 perseant Exp $");
+__RCSID("$NetBSD: make_exfatfs.c,v 1.1.2.5 2024/07/25 23:46:10 perseant Exp $");
#endif
#endif /* not lint */
@@ -475,9 +475,10 @@ uint16_t exfatfs_recommended_upcase_tabl
extern int Nflag; /* Don't write anything */
extern int Vflag; /* Verbose */
-extern uint32_t align;
+extern uint32_t fatalign;
extern uint32_t heapalign;
extern uint32_t fatlength;
+extern uint32_t partition_offset;
void pwarn(const char *, ...);
@@ -520,10 +521,10 @@ make_exfatfs(int devfd, uint secsize, st
++scshift;
/* Convert align and heapalign into sectors */
- align /= secsize;
+ fatalign /= secsize;
heapalign /= secsize;
if (heapalign == 0)
- heapalign = align;
+ heapalign = fatalign;
/* If no table given, use recommendation */
if (uctable == NULL || uctablesize == 0) {
@@ -556,11 +557,16 @@ make_exfatfs(int devfd, uint secsize, st
memcpy(fs->xf_JumpBoot, EXFAT_JUMPBOOT, sizeof(EXFAT_JUMPBOOT));
memcpy(fs->xf_FileSystemName, EXFAT_FSNAME, sizeof(EXFAT_FSNAME));
/* memset(fs->xf_MustBeZero, 0, sizeof(fs->xf_MustBeZero); */
- fs->xf_PartitionOffset = dkw->dkw_offset;
+ fs->xf_PartitionOffset = partition_offset;
fs->xf_VolumeLength = dkw->dkw_size;
- fs->xf_FatOffset = 24; /* Immediately following boot blocks */
- if (align)
- fs->xf_FatOffset = roundup(fs->xf_FatOffset, align);
+
+ /* The FAT immediately follows the boot blocks */
+ fs->xf_FatOffset = 24;
+ /* and some optional alignment padding */
+ if (fatalign) {
+ uint32_t falignoff = partition_offset % fatalign;
+ fs->xf_FatOffset = roundup(fs->xf_FatOffset + falignoff, fatalign);
+ }
/* Find the total number of "blocks" (clusters) on this volume */
/* This is an overestimate, not accounting for the FAT itself */
@@ -572,9 +578,11 @@ make_exfatfs(int devfd, uint secsize, st
nclust = fatlength * secsize / sizeof(uint32_t) - 2;
fs->xf_FatLength = fatlength;
fs->xf_ClusterHeapOffset = fs->xf_FatOffset + fs->xf_FatLength;
- if (heapalign)
- fs->xf_ClusterHeapOffset = roundup(fs->xf_ClusterHeapOffset,
- heapalign);
+ if (heapalign) {
+ uint32_t halignoff = partition_offset % heapalign;
+ fs->xf_ClusterHeapOffset = roundup(fs->xf_ClusterHeapOffset
+ + halignoff, heapalign);
+ }
/* Recalculate to take FATs into account */
nclust = (dkw->dkw_size - fs->xf_ClusterHeapOffset)
Index: src/sbin/newfs_exfatfs/newfs.c
diff -u src/sbin/newfs_exfatfs/newfs.c:1.1.2.2 src/sbin/newfs_exfatfs/newfs.c:1.1.2.3
--- src/sbin/newfs_exfatfs/newfs.c:1.1.2.2 Wed Jul 24 00:46:18 2024
+++ src/sbin/newfs_exfatfs/newfs.c Thu Jul 25 23:46:10 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs.c,v 1.1.2.2 2024/07/24 00:46:18 perseant Exp $ */
+/* $NetBSD: newfs.c,v 1.1.2.3 2024/07/25 23:46:10 perseant Exp $ */
/*-
* Copyright (c) 1989, 1992, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
#if 0
static char sccsid[] = "@(#)newfs.c 8.5 (Berkeley) 5/24/95";
#else
-__RCSID("$NetBSD: newfs.c,v 1.1.2.2 2024/07/24 00:46:18 perseant Exp $");
+__RCSID("$NetBSD: newfs.c,v 1.1.2.3 2024/07/25 23:46:10 perseant Exp $");
#endif
#endif /* not lint */
@@ -80,9 +80,9 @@ int Nflag = 0; /* run without writing f
int Vflag = 0; /* verbose */
uint64_t fssize; /* file system size */
uint32_t sectorsize; /* bytes/sector */
-uint32_t align = 0; /* fat alignment (bytes) */
+uint32_t fatalign = 0; /* fat alignment (sectors) */
uint32_t csize = 0; /* block size */
-uint32_t heapalign = 0; /* cluster heap alignment (bytes) */
+uint32_t heapalign = 0; /* cluster heap alignment (sectors) */
uint32_t serial = 0;
uint32_t partition_offset = 0;
uint32_t fatlength = 0;
@@ -134,59 +134,59 @@ main(int argc, char **argv)
memset(&dkw, 0, sizeof(dkw));
while ((ch = getopt(argc, argv, "a:b:c:Dh:FL:l:No:S:s:T:u:v#:")) != -1)
switch(ch) {
- case 'D':
+ case 'D': /* debug */
debug = 1;
break;
- case 'F':
+ case 'F': /* force create filesystem even on non disk */
force = 1;
break;
- case 'L':
+ case 'L': /* specify label */
label = optarg;
break;
- case 'N':
+ case 'N': /* dry run */
Nflag++;
break;
- case 'S':
+ case 'S': /* size in sectors */
secsize = strsuftoi64("sector size", optarg, 1,
INT64_MAX, NULL);
if (secsize <= 0 || (secsize & (secsize - 1)))
fatal("%s: bad sector size", optarg);
break;
- case 'T':
+ case 'T': /* specify disk type XXX */
disktype = optarg;
break;
- case 'a':
- align = strsuftoi64("alignment", optarg,
- MINBLOCKSIZE, INT64_MAX, NULL);
+ case 'a': /* FAT alignment */
+ fatalign = strsuftoi64("alignment", optarg,
+ MINBLOCKSIZE, INT64_MAX, NULL);
break;
- case 'b':
+ case 'b': /* take bootcode from file */
bootcodefile = optarg;
break;
- case 'c':
+ case 'c': /* cluster (block) size */
csize = strsuftoi64("cluster size", optarg,
MINBLOCKSIZE, INT64_MAX, NULL);
break;
- case 'h':
+ case 'h': /* cluster heap alignment */
heapalign = strsuftoi64("heap alignment", optarg,
MINBLOCKSIZE, INT64_MAX, NULL);
break;
- case 'l':
+ case 'l': /* FAT length in sectors */
fatlength = strtoul(optarg, NULL, 10);
break;
- case 'o':
- dkw.dkw_offset = strtoul(optarg, NULL, 10);
+ case 'o': /* partition offset */
+ partition_offset = strtoul(optarg, NULL, 10);
break;
- case 's':
+ case 's': /* size in DEV_BSIZE units */
fssize = strsuftoi64("file system size", optarg,
0, INT64_MAX, &byte_sized);
break;
- case 'u':
+ case 'u': /* take uctable from file */
uctablefile = optarg;
break;
- case 'v':
+ case 'v': /* verbose */
Vflag++;
break;
- case '#':
+ case '#': /* specify serial number */
serial = strtoul(optarg, NULL, 10);
break;
case '?':
@@ -271,6 +271,10 @@ main(int argc, char **argv)
fssize /= secsize;
}
+ /* If not specified, use partition offset from wedge */
+ if (partition_offset <= 0)
+ partition_offset = dkw.dkw_offset;
+
/* If force, make the partition look like EXFAT */
if (force) {
(void)strcpy(dkw.dkw_ptype, DKW_PTYPE_EXFAT);
@@ -300,7 +304,7 @@ main(int argc, char **argv)
printf("Using Windows default cluster size %d"
" for filesystem size %lld\n",
(int)csize, (unsigned long long)diskbytes);
-#else /* SD Card Association recommendations */
+#else /* SD Association recommendations */
if (diskbytes <= 8 * MEGABYTE)
csize = 8 * KILOBYTE;
else if (diskbytes <= 1 * GIGABYTE)
@@ -314,7 +318,7 @@ main(int argc, char **argv)
else
csize = 512 * KILOBYTE;
if (Vflag)
- printf("Using SD Card Association recommended"
+ printf("Using SD Association recommended"
" cluster size %d"
" for filesystem size %lld\n",
(int)csize, (unsigned long long)diskbytes);
@@ -324,28 +328,31 @@ main(int argc, char **argv)
printf("Using specified cluster size %d", (int)csize);
}
- if (align <= 0) {
+ if (fatalign <= 0) {
#ifdef USE_WINDOWS_DEFAULTS
- align = 0;
-#else /* SD Card Association recommendations */
+ fatalign = 0;
+#else /* SD Association recommendations */
if (diskbytes <= 8 * MEGABYTE)
- align = 8 * KILOBYTE;
+ fatalign = 8 * KILOBYTE;
else if (diskbytes <= 64 * MEGABYTE)
- align = 16 * KILOBYTE;
+ fatalign = 16 * KILOBYTE;
else if (diskbytes <= 256 * MEGABYTE)
- align = 32 * KILOBYTE;
+ fatalign = 32 * KILOBYTE;
else if (diskbytes <= 2 * GIGABYTE)
- align = 64 * KILOBYTE;
+ fatalign = 64 * KILOBYTE;
else if (diskbytes <= 32 * GIGABYTE)
- align = 4 * MEGABYTE;
+ fatalign = 4 * MEGABYTE;
else if (diskbytes <= 128 * GIGABYTE)
- align = 16 * MEGABYTE;
+ fatalign = 16 * MEGABYTE;
else if (diskbytes <= 512 * GIGABYTE)
- align = 32 * MEGABYTE;
+ fatalign = 32 * MEGABYTE;
else
- align = 64 * MEGABYTE;
+ fatalign = 64 * MEGABYTE;
#endif
}
+ /* Convert to sectors */
+ fatalign /= secsize;
+ heapalign /= secsize;
/* Convert given label from UTF8 into UCS2 */
uclabellen = exfatfs_utf8ucs2str((const uint8_t *)label,
@@ -439,13 +446,22 @@ usage(void)
{
fprintf(stderr, "usage: newfs_exfatfs [ -fsoptions ] special-device\n");
fprintf(stderr, "where fsoptions are:\n");
+ fprintf(stderr, "\t-# serial number\n");
fprintf(stderr, "\t-D (debug)\n");
fprintf(stderr, "\t-F (force)\n");
+ fprintf(stderr, "\t-L label\n");
fprintf(stderr,
"\t-N (do not create file system, just print out parameters)\n");
fprintf(stderr, "\t-S sector size\n");
- fprintf(stderr, "\t-a alignment in bytes\n");
+ fprintf(stderr, "\t-T disk type\n");
+ fprintf(stderr, "\t-a FAT alignment in bytes\n");
+ fprintf(stderr, "\t-b bootcode file\n");
fprintf(stderr, "\t-c cluster size in bytes\n");
+ fprintf(stderr, "\t-h cluster heap alignment in bytes\n");
+ fprintf(stderr, "\t-l FAT length in sectors\n");
+ fprintf(stderr, "\t-o partition offset in sectors\n");
fprintf(stderr, "\t-s file system size in sectors\n");
+ fprintf(stderr, "\t-u upcase table file\n");
+ fprintf(stderr, "\t-v (verbose)\n");
exit(1);
}
Index: src/sbin/newfs_exfatfs/newfs_exfatfs.8
diff -u src/sbin/newfs_exfatfs/newfs_exfatfs.8:1.1.2.1 src/sbin/newfs_exfatfs/newfs_exfatfs.8:1.1.2.2
--- src/sbin/newfs_exfatfs/newfs_exfatfs.8:1.1.2.1 Sat Jun 29 19:43:25 2024
+++ src/sbin/newfs_exfatfs/newfs_exfatfs.8 Thu Jul 25 23:46:10 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: newfs_exfatfs.8,v 1.1.2.1 2024/06/29 19:43:25 perseant Exp $
+.\" $NetBSD: newfs_exfatfs.8,v 1.1.2.2 2024/07/25 23:46:10 perseant Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -46,20 +46,38 @@ device basing its defaults on the inform
Before running
.Nm
the disk must be labeled using
-.Xr disklabel 8 ,
-the proper fstype is exFAT.
+.Xr disklabel 8 .
+The proper fstype is exFAT.
.Pp
The following options define the general layout policies.
.Bl -tag -width Fl
-.It Fl b Ar cluster-size
+.It Fl # Ar serial-number
+Use the given serial number, rather than generating one at random.
+.It Fl a Ar fat-alignment
+The alignment of the File Allocation Table in bytes.
+If not specified, the alignment is made according to XXX.
+.It Fl b Ar bootcode-file
+Use the bootcode contained in the given file.
+If not specified, the bootcode field will be filled with NUL (0x00).
+.It Fl c Ar cluster-size
The cluster size of the file system in bytes.
If not specified, the block size is generated based on the file system size.
+.It Fl D
+Print debugging information to stdout.
.It Fl F
Force creation of a file system even on a partition labeled as another type.
+.It Fl h Ar heap-alignment
+The alignment of the cluster heap, in bytes.
+If not specified, the FAT alignment will be used.
.It Fl L Ar label
Specify the file system label. The default label is "NONE GIVEN".
+.It Fl l Ar fat-length
+The length of the File Allocation Table, in sectors.
.It Fl N
Do not actually create the filesystem.
+.It Fl o Ar partition-offset
+The offset of this partition from the beginning of the disk, in sectors.
+The default value is taken from the disklabel.
.It Fl S Ar sector-size
Use this as the size of filesystem sectors, in bytes. The default is to
use the sector size from the disk label.
@@ -67,6 +85,12 @@ use the sector size from the disk label.
The size of the file system in sectors.
.It Fl T Ar type
Use the given disk type when there is no disk label.
+.It Fl u Ar upcase-file
+Use the given file for the filesystem's upcase table.
+The default is to use the recommended upcase table from
+section 7.2.5.1 of the specification.
+.It Fl v
+Be more verbose about what is being done.
.El
.Sh SEE ALSO
.Xr disktab 5 ,