]> cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/documents/doc/mkfs.html
Import fatfs R0.13b
[z180-stamp.git] / fatfs / documents / doc / 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=utf-8">
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/exFAT volume 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">opt</span>, <span class="c">/* [IN] Format options */</span>
21 DWORD <span class="arg">au</span>, <span class="c">/* [IN] Size of the allocation unit */</span>
22 void* <span class="arg">work</span>, <span class="c">/* [-] Working buffer */</span>
23 UINT <span class="arg">len</span> <span class="c">/* [IN] Size of working buffer */</span>
24 );
25 </pre>
26 </div>
27
28 <div class="para arg">
29 <h4>Parameters</h4>
30 <dl class="par">
31 <dt>path</dt>
32 <dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If it has no drive number in it, it means the default drive. The logical drive may or may not be mounted for the format process.</dd>
33 <dt>opt</dt>
34 <dd>Specifies the format option in combination of <tt>FM_FAT</tt>, <tt>FM_FAT32</tt>, <tt>FM_EXFAT</tt> and bitwise-or of these three, <tt>FM_ANY</tt>. <tt>FM_EXFAT</tt> is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size and <tt class="arg">au</tt>. The flag <tt>FM_SFD</tt> specifies to create the volume on the drive in SFD format.</dd>
35 <dt>au</dt>
36 <dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is <em>n</em> times the sector size. The <em>n</em> is power of 2 from 1 to 128 for FAT volume and upto 16MiB for exFAT volume. If zero is given, the default allocation unit size is selected depends on the volume size.</dd>
37 <dt>work</dt>
38 <dd>Pointer to the working buffer used for the format process. When a null pointer is given, the function allocates a memory block for the working buffer and <tt class="arg">len</tt> has no effect (at only <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>).</dd>
39 <dt>len</dt>
40 <dd>Size of the working buffer in unit of byte. It needs to be the sector size of the corresponding physical drive at least. Plenty of working buffer reduces number of write transactions to the drive and the format process will finish quickly.</dd>
41 </dl>
42 </div>
43
44 <div class="para ret">
45 <h4>Return Values</h4>
46 <p>
47 <a href="rc.html#ok">FR_OK</a>,
48 <a href="rc.html#de">FR_DISK_ERR</a>,
49 <a href="rc.html#nr">FR_NOT_READY</a>,
50 <a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
51 <a href="rc.html#id">FR_INVALID_DRIVE</a>,
52 <a href="rc.html#ma">FR_MKFS_ABORTED</a>,
53 <a href="rc.html#ip">FR_INVALID_PARAMETER</a>,
54 <a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
55 </p>
56 </div>
57
58 <div class="para desc">
59 <h4>Description</h4>
60 <p>The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument cannot be valid on the volume, the function will fail with <tt>FR_MKFS_ABORTED</tt>. The minimum drive size is 128 sectors with <tt>FM_SFD</tt> option.</p>
61 <p>The allocation unit, also called <em>cluster</em>, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases as the size of allocation unit. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger (this is automatically selected by default) is recommended for most case unless extremely many small files are created on a volume.</p>
62 <p>There are three disk partitioning formats, FDISK, SFD and GPT. The FDISK format is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table on the MBR (maser boot record, the first sector of the physical drive). The SFD (super-floppy disk) is non-partitioned disk format. The FAT volume starts at the first sector of the physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some systems support only either one of the two disk formats and the other is not supported. The GPT (GUID Partition Table) is a newly defined format for large storage devices. FatFs does not support the storages with GPT.</p>
63 <p>When the logical drive to be formatted is bound to a physical drive and <tt>FM_SFD</tt> is not specified, a primary partition occupies whole drive space is created in FDISK format, and then the FAT volume is created in the partition. When <tt>FM_SFD</tt> is specified, the FAT volume occupies from the first sector of the physical drive is created in SFD format.</p>
64 <p>When the logical drive to be formatted is bound to a specific partition (1-4) by support of multiple partition (<tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> == 1</tt>), the FAT volume is created on the partition and <tt>FM_SFD</tt> flag is ignored. The physical drive needs to be partitioned with <tt>f_fdisk</tt> function or any other partitioning tools prior to create the FAT volume with this function.</p>
65 </div>
66
67 <div class="para comp">
68 <h4>QuickInfo</h4>
69 <p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READOLNY</a> == 0</tt> and <tt><a href="config.html#use_mkfs">FF_USE_MKFS</a> == 1</tt>.</p>
70 </div>
71
72 <div class="para use">
73 <h4>Example</h4>
74 <pre>
75 <span class="c">/* Format default drive and create a file */</span>
76 int main (void)
77 {
78 FATFS fs; <span class="c">/* Filesystem object */</span>
79 FIL fil; <span class="c">/* File object */</span>
80 FRESULT res; <span class="c">/* API result code */</span>
81 UINT bw; <span class="c">/* Bytes written */</span>
82 BYTE work[FF_MAX_SS]; <span class="c">/* Work area (larger is better for processing time) */</span>
83
84
85 <span class="c">/* Create FAT volume */</span>
86 res = <em>f_mkfs</em>("", FM_ANY, 0, work, sizeof work);
87 if (res) ...
88
89 <span class="c">/* Register work area */</span>
90 f_mount(&amp;fs, "", 0);
91
92 <span class="c">/* Create a file as new */</span>
93 res = f_open(&amp;fil, "hello.txt", FA_CREATE_NEW | FA_WRITE);
94 if (res) ...
95
96 <span class="c">/* Write a message */</span>
97 f_write(&amp;fil, "Hello, World!\r\n", 15, &amp;bw);
98 if (bw != 15) ...
99
100 <span class="c">/* Close the file */</span>
101 f_close(&amp;fil);
102
103 <span class="c">/* Unregister work area */</span>
104 f_mount(0, "", 0);
105
106 ...
107 </pre>
108 </div>
109
110 <div class="para ref">
111 <h4>See Also</h4>
112 <p><a href="../res/mkfs.xls">Example of volume size and format parameters</a>, <a href="filename.html#vol">Volume management</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p>
113 </div>
114
115 <p class="foot"><a href="../00index_e.html">Return</a></p>
116 </body>
117 </html>