aboutsummaryrefslogtreecommitdiff
path: root/sbin/newfs_msdos
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/newfs_msdos')
-rw-r--r--sbin/newfs_msdos/Makefile2
-rw-r--r--sbin/newfs_msdos/mkfs_msdos.c30
-rw-r--r--sbin/newfs_msdos/newfs_msdos.821
-rw-r--r--sbin/newfs_msdos/newfs_msdos.c5
4 files changed, 34 insertions, 24 deletions
diff --git a/sbin/newfs_msdos/Makefile b/sbin/newfs_msdos/Makefile
index f4efc6490675..bd5b3486b6b6 100644
--- a/sbin/newfs_msdos/Makefile
+++ b/sbin/newfs_msdos/Makefile
@@ -1,4 +1,3 @@
-
.include <src.opts.mk>
PACKAGE=runtime
@@ -10,7 +9,6 @@ SRCS= newfs_msdos.c mkfs_msdos.c
.if ${MACHINE_CPUARCH} == "arm"
WARNS?= 3
.endif
-CSTD= c11
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
diff --git a/sbin/newfs_msdos/mkfs_msdos.c b/sbin/newfs_msdos/mkfs_msdos.c
index 13a804c82625..dcc2bb982efc 100644
--- a/sbin/newfs_msdos/mkfs_msdos.c
+++ b/sbin/newfs_msdos/mkfs_msdos.c
@@ -25,11 +25,6 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
#include <sys/param.h>
#ifdef MAKEFS
/* In the makefs case we only want struct disklabel */
@@ -254,7 +249,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
ssize_t n;
time_t now;
u_int fat, bss, rds, cls, dir, lsn, x, x1, x2;
- u_int extra_res, alignment, saved_x, attempts=0;
+ u_int extra_res, alignment, alignto, saved_x, attempts=0;
bool set_res, set_spf, set_spc;
int fd, fd1, rv;
struct msdos_options o = *op;
@@ -417,8 +412,12 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
}
bpb.bpbFATs = o.num_FAT;
}
- if (o.directory_entries)
- bpb.bpbRootDirEnts = o.directory_entries;
+ if (o.directory_entries) {
+ bpb.bpbRootDirEnts = roundup(o.directory_entries,
+ bpb.bpbBytesPerSec / sizeof(struct de));
+ if (bpb.bpbBytesPerSec == 0 || o.directory_entries >= MAXU16)
+ bpb.bpbRootDirEnts = MAXU16;
+ }
if (o.media_descriptor_set) {
if (o.media_descriptor < 0xf0) {
warnx("illegal media descriptor (%#x)", o.media_descriptor);
@@ -569,14 +568,17 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op)
x1 += (bpb.bpbBigFATsecs - 1) * bpb.bpbFATs;
}
if (set_res) {
- /* attempt to align root directory */
- alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs) %
- bpb.bpbSecPerClust;
- if (o.align)
- extra_res += bpb.bpbSecPerClust - alignment;
+ alignto = bpb.bpbSecPerClust;
+ if (alignto > 1) {
+ /* align data clusters */
+ alignment = (bpb.bpbResSectors + bpb.bpbBigFATsecs * bpb.bpbFATs + rds) %
+ alignto;
+ if (alignment != 0)
+ extra_res += alignto - alignment;
+ }
}
attempts++;
- } while (o.align && alignment != 0 && attempts < 2);
+ } while (alignment != 0 && attempts < 2);
if (o.align && alignment != 0)
warnx("warning: Alignment failed.");
diff --git a/sbin/newfs_msdos/newfs_msdos.8 b/sbin/newfs_msdos/newfs_msdos.8
index 278612548dc4..03dfbfced51f 100644
--- a/sbin/newfs_msdos/newfs_msdos.8
+++ b/sbin/newfs_msdos/newfs_msdos.8
@@ -23,7 +23,7 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd June 14, 2018
+.Dd June 6, 2024
.Dt NEWFS_MSDOS 8
.Os
.Sh NAME
@@ -91,7 +91,11 @@ A suffix s, k, m, g (lower or upper case)
appended to the offset specifies that the
number is in sectors, kilobytes, megabytes or gigabytes, respectively.
.It Fl A
-Attempt to cluster align root directory, useful for SD card.
+Attempt to cluster align the data area, useful for flash based storage.
+This option is enabled by default, unless a number of reserved sectors
+is specified using the
+.Fl r
+option.
.It Fl B Ar boot
Get bootstrap from file.
.It Fl C Ar create-size
@@ -134,7 +138,7 @@ File system block size (bytes per cluster).
This should resolve to an
acceptable number of sectors per cluster (see below).
.It Fl c Ar cluster-size
-Sectors per cluster.
+Sectors per cluster, also called allocation size.
Acceptable values are powers of 2 in the range
1 through 128.
If the block or cluster size are not specified, the code
@@ -167,6 +171,10 @@ is 2.
Number of hidden sectors.
.It Fl r Ar reserved
Number of reserved sectors.
+If the
+.Fl r
+option is not used, the number of reserved sectors is set to a value that
+aligns the start of the data area to a multiple of the cluster size.
.It Fl s Ar total
File system size.
.It Fl u Ar track-size
@@ -224,6 +232,12 @@ Create a file system, using default parameters, on
newfs_msdos /dev/ada0s1
.Ed
.Pp
+Create a FAT32 filesystem with a 32K allocation size on
+.Pa /dev/mmcsd0s1 :
+.Bd -literal -offset indent
+newfs_msdos -F 32 -A -c 64 /dev/mmcsd0s1
+.Ed
+.Pp
Create a standard 1.44M file system, with volume label
.Ar foo ,
on
@@ -238,6 +252,7 @@ Create a 30MB image file, with the FAT partition starting
newfs_msdos -C 30M -@63s ./somefile
.Ed
.Sh SEE ALSO
+.Xr msdosfs 4 ,
.Xr gpart 8 ,
.Xr newfs 8
.Sh HISTORY
diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c
index 1ba399fe447e..312a862d9113 100644
--- a/sbin/newfs_msdos/newfs_msdos.c
+++ b/sbin/newfs_msdos/newfs_msdos.c
@@ -27,11 +27,6 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
#include <sys/param.h>
#include <sys/stat.h>
#include <err.h>