1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
\r
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
\r
5 <meta http-equiv="Content-Style-Type" content="text/css">
\r
6 <link rel="up" title="FatFs" href="../00index_e.html">
\r
7 <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
\r
8 <title>FatFs - f_getfree</title>
\r
15 <p>The f_getfree function gets number of the free clusters.</p>
\r
18 const XCHAR* <em>Path</em>, /* Root directory of the drive */
\r
19 DWORD* <em>Clusters</em>, /* Pointer to the variable to store number of free clusters */
\r
20 FATFS** <em>FileSystemObject</em> /* Pointer to pointer to file system object */
\r
29 <dd>Pinter to the null-terminated string that specifies the <a href="filename.html">root directory</a> of the logical drive.</dd>
\r
31 <dd>Pointer to the DWORD variable to store number of free clusters.</dd>
\r
32 <dt>FileSystemObject</dt>
\r
33 <dd>Pointer to pointer that to store a pointer to the corresponding file system object.</dd>
\r
39 <h4>Return Values</h4>
\r
42 <dd>The function succeeded. The <tt><em>*Clusters</em></tt> has number of free clusters and <tt><em>*FileSystemObject</em></tt> points the file system object.</dd>
\r
43 <dt>FR_INVALID_DRIVE</dt>
\r
44 <dd>The drive number is invalid.</dd>
\r
45 <dt>FR_NOT_READY</dt>
\r
46 <dd>The disk drive cannot work due to no medium in the drive or any other reason.</dd>
\r
47 <dt>FR_DISK_ERR</dt>
\r
48 <dd>The function failed due to an error in the disk function.</dd>
\r
50 <dd>The function failed due to a wrong FAT structure or an internal error.</dd>
\r
51 <dt>FR_NOT_ENABLED</dt>
\r
52 <dd>The logical drive has no work area.</dd>
\r
53 <dt>FR_NO_FILESYSTEM</dt>
\r
54 <dd>There is no valid FAT partition on the disk.</dd>
\r
60 <h4>Descriptions</h4>
\r
61 <p>The f_getfree function gets number of free clusters on the drive. The member <tt>csize</tt> in the file system object is refrecting number of sectors per cluster, so that the free space in unit of sector can be calcurated with this. When FSInfo structure on FAT32 volume is not in sync, this function can return an incorrect free cluster count.</p>
\r
67 <p>Available when <tt>_FS_READONLY == 0</tt> and <tt>_FS_MINIMIZE == 0</tt>.</p>
\r
75 DWORD fre_clust, fre_sect, tot_sect;
\r
78 /* Get drive information and free clusters */
\r
79 res = f_getfree("/", &fre_clust, &fs);
\r
82 /* Get total sectors and free sectors */
\r
83 tot_sect = (fs->max_clust - 2) * fs->csize;
\r
84 fre_sect = fre_clust * fs->csize;
\r
86 /* Print free space in unit of KB (assuming 512B/sector) */
\r
87 printf("%lu KB total drive space.\n"
\r
88 "%lu KB available.\n",
\r
89 fre_sect / 2, tot_sect / 2);
\r
96 <p><tt><a href="sfatfs.html">FATFS</a></tt></p>
\r
99 <p class="foot"><a href="../00index_e.html">Return</a></p>
\r