xref: /freebsd/sbin/newfs_msdos/newfs_msdos.8 (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1.\" Copyright (c) 1998 Robert Nordier
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in
11.\"    the documentation and/or other materials provided with the
12.\"    distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
15.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
18.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.Dd January 12, 2024
27.Dt NEWFS_MSDOS 8
28.Os
29.Sh NAME
30.Nm newfs_msdos
31.Nd construct a new MS-DOS (FAT) file system
32.Sh SYNOPSIS
33.Nm
34.Op Fl N
35.Op Fl @ Ar offset
36.Op Fl A
37.Op Fl B Ar boot
38.Op Fl C Ar create-size
39.Op Fl F Ar FAT-type
40.Op Fl I Ar VolumeID
41.Op Fl L Ar label
42.Op Fl O Ar OEM
43.Op Fl S Ar sector-size
44.Op Fl T Ar timestamp
45.Op Fl a Ar FAT-size
46.Op Fl b Ar block-size
47.Op Fl c Ar cluster-size
48.Op Fl e Ar DirEnts
49.Op Fl f Ar format
50.Op Fl h Ar heads
51.Op Fl i Ar info
52.Op Fl k Ar backup
53.Op Fl m Ar media
54.Op Fl n Ar FATs
55.Op Fl o Ar hidden
56.Op Fl r Ar reserved
57.Op Fl s Ar total
58.Op Fl u Ar track-size
59.Ar special
60.Op Ar disktype
61.Sh DESCRIPTION
62The
63.Nm
64utility creates a FAT12, FAT16, or FAT32 file system on device or file named
65.Ar special ,
66using
67.Xr disktab 5
68entry
69.Ar disktype
70to determine geometry, if required.
71.Pp
72If
73.Ar special
74does not contain a
75.Ar /
76and
77.Fl C
78is not used, it is assumed to be a device name and
79.Ar /dev/
80is prepended to the name to construct the actual device name.
81To work a file in the current directory use
82.Ar ./filename
83.Pp
84The options are as follow:
85.Bl -tag -width indent
86.It Fl N
87Do not create a file system: just print out parameters.
88.It Fl @ Ar offset
89Build the filesystem at the specified offset in bytes in the device or file.
90A suffix s, k, m, g (lower or upper case)
91appended to the offset specifies that the
92number is in sectors, kilobytes, megabytes or gigabytes, respectively.
93.It Fl A
94Attempt to cluster align root directory, useful for SD card.
95.It Fl B Ar boot
96Get bootstrap from file.
97.It Fl C Ar create-size
98Create the image file with the specified size.
99A suffix character appended to the size is interpreted as for the
100.Fl @
101option.
102The file is created by truncating any existing file with the same name and
103resizing it to the requested size.
104If the file system supports sparse files, the space occupied on disk may be
105smaller than the size specified as parameter.
106.It Fl F Ar FAT-type
107FAT type (one of 12, 16, or 32).
108.It Fl I Ar VolumeID
109Volume ID, a 32 bit number in decimal or hexadecimal (0x...) format.
110.It Fl L Ar label
111Volume label (up to 11 characters).
112The label should consist of
113only those characters permitted in regular DOS (8+3) filenames.
114.It Fl O Ar OEM
115OEM string (up to 8 characters).
116The default is
117.Qq Li "BSD4.4  " .
118.It Fl S Ar sector-size
119Number of bytes per sector.
120Acceptable values are powers of 2
121in the range 512 through 32768, inclusive.
122.It Fl T Ar timestamp
123Create the filesystem as though the current time is
124.Ar timestamp .
125The default filesystem volume ID is derived from the time.
126.Ar timestamp
127can be a pathname (where the timestamp is derived from
128that file) or an integer value interpreted
129as the number of seconds since the Epoch.
130.It Fl a Ar FAT-size
131Number of sectors per FAT.
132.It Fl b Ar block-size
133File system block size (bytes per cluster).
134This should resolve to an
135acceptable number of sectors per cluster (see below).
136.It Fl c Ar cluster-size
137Sectors per cluster, also called allocation size.
138Acceptable values are powers of 2 in the range
1391 through 128.
140If the block or cluster size are not specified, the code
141uses a cluster between 512 bytes and 32K depending on
142the filesystem size.
143.It Fl e Ar DirEnts
144Number of root directory entries (FAT12 and FAT16 only).
145.It Fl f Ar format
146Specify a standard (floppy disk) format.
147The standard formats
148are (capacities in kilobytes): 160, 180, 320, 360, 640, 720, 1200,
1491232, 1440, 2880.
150.It Fl h Ar heads
151Number of drive heads.
152.It Fl i Ar info
153Location of the file system info sector (FAT32 only).
154A value of 0xffff signifies no info sector.
155.It Fl k Ar backup
156Location of the backup boot sector (FAT32 only).
157A value
158of 0xffff signifies no backup sector.
159.It Fl m Ar media
160Media descriptor (acceptable range 0xf0 to 0xff).
161.It Fl n Ar FATs
162Number of FATs.
163Acceptable values are 1 to 16 inclusive.
164The default
165is 2.
166.It Fl o Ar hidden
167Number of hidden sectors.
168.It Fl r Ar reserved
169Number of reserved sectors.
170.It Fl s Ar total
171File system size.
172.It Fl u Ar track-size
173Number of sectors per track.
174.El
175.Sh NOTES
176If some parameters (e.g., size, number of sectors, etc.) are not specified
177through options or disktype, the program tries to generate them automatically.
178In particular, the size is determined as the device or file size minus the
179offset specified with the
180.Fl @
181option.
182When the geometry is not available, it is assumed to be 63 sectors, 255 heads.
183The size is then rounded to become a multiple of the track size and avoid
184complaints by some filesystem code.
185.Pp
186FAT file system parameters occupy a "Boot Sector BPB (BIOS Parameter
187Block)" in the first of the "reserved" sectors which precede the actual
188file system.
189For reference purposes, this structure is presented
190below.
191.Bd -literal
192struct bsbpb {
193    uint16_t	bpbBytesPerSec;		/* [-S] bytes per sector */
194    uint8_t	bpbSecPerClust;		/* [-c] sectors per cluster */
195    uint16_t	bpbResSectors;		/* [-r] reserved sectors */
196    uint8_t	bpbFATs;		/* [-n] number of FATs */
197    uint16_t	bpbRootDirEnts;		/* [-e] root directory entries */
198    uint16_t	bpbSectors;		/* [-s] total sectors */
199    uint8_t	bpbMedia;		/* [-m] media descriptor */
200    uint16_t	bpbFATsecs;		/* [-a] sectors per FAT */
201    uint16_t	bpbSecPerTrack;		/* [-u] sectors per track */
202    uint16_t	bpbHeads;		/* [-h] drive heads */
203    uint32_t	bpbHiddenSecs;		/* [-o] hidden sectors */
204    uint32_t	bpbHugeSectors;		/* [-s] big total sectors */
205};
206/* FAT32 extensions */
207struct bsxbpb {
208    uint32_t	bpbBigFATsecs;		/* [-a] big sectors per FAT */
209    uint16_t	bpbExtFlags;		/* control flags */
210    uint16_t	bpbFSVers;		/* file system version */
211    uint32_t	bpbRootClust;		/* root directory start cluster */
212    uint16_t	bpbFSInfo;		/* [-i] file system info sector */
213    uint16_t	bpbBackup;		/* [-k] backup boot sector */
214};
215.Ed
216.Sh LIMITATION
217The maximum file size is 4GB, even if the file system itself is bigger.
218.Sh EXIT STATUS
219Exit status is 0 on success and 1 on error.
220.Sh EXAMPLES
221Create a file system, using default parameters, on
222.Pa /dev/ada0s1 :
223.Bd -literal -offset indent
224newfs_msdos /dev/ada0s1
225.Ed
226.Pp
227Create a FAT32 filesystem with a 32K allocation size on
228.Pa /dev/mmcsd0s1 :
229.Bd -literal -offset indent
230newfs_msdos -F 32 -A -c 64 /dev/mmcsd0s1
231.Ed
232.Pp
233Create a standard 1.44M file system, with volume label
234.Ar foo ,
235on
236.Pa /dev/fd0 :
237.Bd -literal -offset indent
238newfs_msdos -f 1440 -L foo fd0
239.Ed
240.Pp
241Create a 30MB image file, with the FAT partition starting
24263 sectors within the image file:
243.Bd -literal -offset indent
244newfs_msdos -C 30M -@63s ./somefile
245.Ed
246.Sh SEE ALSO
247.Xr gpart 8 ,
248.Xr newfs 8
249.Sh HISTORY
250The
251.Nm
252utility first appeared in
253.Fx 3.0 .
254.Sh AUTHORS
255.An Robert Nordier Aq Mt rnordier@FreeBSD.org
256