]> cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/doc/en/mkfs.html
Version 0.6.8.2
[z180-stamp.git] / fatfs / doc / en / mkfs.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <link rel="up" title="FatFs" href="../00index_e.html">
7 <link rel="alternate" hreflang="ja" title="Japanese" href="../ja/mkfs.html">
8 <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
9 <title>FatFs - f_mkfs</title>
10 </head>
11
12 <body>
13
14 <div class="para func">
15 <h2>f_mkfs</h2>
16 <p>The f_mkfs fucntion creates an FAT file system on the logical drive.</p>
17 <pre>
18 FRESULT f_mkfs (
19 const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
20 BYTE <span class="arg">sfd</span>, <span class="c">/* [IN] Partitioning rule */</span>
21 UINT <span class="arg">au</span> <span class="c">/* [IN] Size of the allocation unit */</span>
22 );
23 </pre>
24 </div>
25
26 <div class="para arg">
27 <h4>Parameters</h4>
28 <dl class="par">
29 <dt>path</dt>
30 <dd>Pinter to the null-terminated string that specifies the <a href="filename.html">logical drive</a> to be formatted. If there is no drive number, it means the default drive.</dd>
31 <dt>sfd</dt>
32 <dd>Specifies partitioning rule (FDISK(0) or SFD(1)). This argument will be ignored on some case.</dd>
33 <dt>au</dt>
34 <dd>Specifies size of the allocation unit (cluter) in number of bytes or sectors. When the value is from 1 to 128, it specifies number of sectors. When the value is <tt>&gt;= _MIN_SS</tt>, it specifies number of bytes. If any invalid value, zero or not power of 2, is given, the cluster size is automatically determined depends on the volume size.</dd>
35 </dl>
36 </div>
37
38 <div class="para ret">
39 <h4>Return Values</h4>
40 <p>
41 <a href="rc.html#ok">FR_OK</a>,
42 <a href="rc.html#de">FR_DISK_ERR</a>,
43 <a href="rc.html#nr">FR_NOT_READY</a>,
44 <a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
45 <a href="rc.html#id">FR_INVALID_DRIVE</a>,
46 <a href="rc.html#ne">FR_NOT_ENABLED</a>,
47 <a href="rc.html#ma">FR_MKFS_ABORTED</a>,
48 <a href="rc.html#ip">FR_INVALID_PARAMETER</a>
49 </p>
50 </div>
51
52 <div class="para desc">
53 <h4>Description</h4>
54 <p>The <tt>f_mkfs()</tt> function creates an FAT volume on the specified logical drive. When FDISK format is specified, a primary partition occupies entire space of the physical drive is created and then an FAT volume is created on the partition. When SFD format is specified, the FAT volume starts from the first sector of the physical drive.</p>
55 <p>If the logical drive is bound to the specific partition (1-4) by multiple partition feature (<tt>_MULTI_PARTITION</tt>), the FAT volume is created into the partition. In this case, the second argument <tt class="arg">sfd</tt> is ignored. The physical drive must have been partitioned with <tt>f_fdisk()</tt> function or any other partitioning tools prior to create the FAT volume with this function.</p>
56 <p>Note that there are two partitioning rules, FDISK and SFD. The FDISK partitioning is usually used for harddisk, MMC, SDC, CFC and U Disk. It can divide a physical drive into one or more partitions with a partition table on the MBR. However Windows does not support multiple partition on the removable disk. The SFD is non-partitioned method. The FAT volume starts from the first sector on the physical drive without partition table. It is usually used for floppy disk, Microdrive, optical disk and any type of super-floppy media.</p>
57 <p>The FAT sub-type, FAT12/FAT16/FAT32, is determined by number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus which FAT sub-type is selected, is depends on the volume size and the specified cluster size. The cluster size affects read/write throughput and space usage efficiency. Larger cluster size increases the read/write throughput and decreases the space usage efficiency of the volume.</p>
58 <p>In case of the number of clusters gets near the FAT sub-type boundaries, the function can fail with <tt>FR_MKFS_ABORTED</tt>.</p>
59 </div>
60
61 <div class="para comp">
62 <h4>QuickInfo</h4>
63 <p>Available when <tt>_FS_READOLNY == 0</tt> and <tt>_USE_MKFS == 1</tt>.</p>
64 </div>
65
66 <div class="para use">
67 <h4>Example</h4>
68 <pre>
69 <span class="c">/* Format the default drive */</span>
70 int main (void)
71 {
72 FATFS fs; <span class="c">/* File system object (volume work area) */</span>
73 FIL fil; <span class="c">/* File object */</span>
74 FRESULT res; <span class="c">/* API result code */</span>
75 UINT bw; <span class="c">/* Bytes written */</span>
76
77
78 <span class="c">/* Register work area */</span>
79 f_mount(&amp;fs, "", 0);
80
81 <span class="c">/* Create FAT volume with default cluster size */</span>
82 res = f_mkfs("", 0, 0);
83 if (res) ...
84
85 <span class="c">/* Create a file as new */</span>
86 res = f_open(&fil, "hello.txt", FA_CREATE_NEW | FA_WRITE);
87 if (res) ...
88
89 <span class="c">/* Write a message */</span>
90 f_write(&fil, "Hello, World!\r\n", 15, &bw);
91 if (bw != 15) ...
92
93 <span class="c">/* Close the file */</span>
94 f_close(&fil);
95
96 <span class="c">/* Unregister work area */</span>
97 f_mount(0, "", 0);
98
99 </pre>
100 </div>
101
102 <div class="para ref">
103 <h4>See Also</h4>
104 <p><tt><a href="filename.html#vol">Volume management</a>, <a href="fdisk.html">f_fdisk</a></tt></p>
105 </div>
106
107 <p class="foot"><a href="../00index_e.html">Return</a></p>
108 </body>
109 </html>