1e6865dcdSopenharmony_ci<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2e6865dcdSopenharmony_ci<html lang="en">
3e6865dcdSopenharmony_ci<head>
4e6865dcdSopenharmony_ci<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5e6865dcdSopenharmony_ci<meta http-equiv="Content-Style-Type" content="text/css">
6e6865dcdSopenharmony_ci<link rel="up" title="FatFs" href="../00index_e.html">
7e6865dcdSopenharmony_ci<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/getfree.html">
8e6865dcdSopenharmony_ci<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
9e6865dcdSopenharmony_ci<title>FatFs - f_getfree</title>
10e6865dcdSopenharmony_ci</head>
11e6865dcdSopenharmony_ci
12e6865dcdSopenharmony_ci<body>
13e6865dcdSopenharmony_ci
14e6865dcdSopenharmony_ci<div class="para func">
15e6865dcdSopenharmony_ci<h2>f_getfree</h2>
16e6865dcdSopenharmony_ci<p>The f_getfree function gets number of the free clusters on the volume.</p>
17e6865dcdSopenharmony_ci<pre>
18e6865dcdSopenharmony_ciFRESULT f_getfree (
19e6865dcdSopenharmony_ci  const TCHAR* <span class="arg">path</span>,  <span class="c">/* [IN] Logical drive number */</span>
20e6865dcdSopenharmony_ci  DWORD* <span class="arg">nclst</span>,       <span class="c">/* [OUT] Number of free clusters */</span>
21e6865dcdSopenharmony_ci  FATFS** <span class="arg">fatfs</span>       <span class="c">/* [OUT] Corresponding filesystem object */</span>
22e6865dcdSopenharmony_ci);
23e6865dcdSopenharmony_ci</pre>
24e6865dcdSopenharmony_ci</div>
25e6865dcdSopenharmony_ci
26e6865dcdSopenharmony_ci<div class="para arg">
27e6865dcdSopenharmony_ci<h4>Parameters</h4>
28e6865dcdSopenharmony_ci<dl class="par">
29e6865dcdSopenharmony_ci<dt>path</dt>
30e6865dcdSopenharmony_ci<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. A null-string means the default drive.</dd>
31e6865dcdSopenharmony_ci<dt>nclst</dt>
32e6865dcdSopenharmony_ci<dd>Pointer to the <tt>DWORD</tt> variable to store number of free clusters.</dd>
33e6865dcdSopenharmony_ci<dt>fatfs</dt>
34e6865dcdSopenharmony_ci<dd>Pointer to pointer that to store a pointer to the corresponding filesystem object.</dd>
35e6865dcdSopenharmony_ci</dl>
36e6865dcdSopenharmony_ci</div>
37e6865dcdSopenharmony_ci
38e6865dcdSopenharmony_ci
39e6865dcdSopenharmony_ci<div class="para ret">
40e6865dcdSopenharmony_ci<h4>Return Values</h4>
41e6865dcdSopenharmony_ci<p>
42e6865dcdSopenharmony_ci<a href="rc.html#ok">FR_OK</a>,
43e6865dcdSopenharmony_ci<a href="rc.html#de">FR_DISK_ERR</a>,
44e6865dcdSopenharmony_ci<a href="rc.html#ie">FR_INT_ERR</a>,
45e6865dcdSopenharmony_ci<a href="rc.html#nr">FR_NOT_READY</a>,
46e6865dcdSopenharmony_ci<a href="rc.html#id">FR_INVALID_DRIVE</a>,
47e6865dcdSopenharmony_ci<a href="rc.html#ne">FR_NOT_ENABLED</a>,
48e6865dcdSopenharmony_ci<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
49e6865dcdSopenharmony_ci<a href="rc.html#tm">FR_TIMEOUT</a>
50e6865dcdSopenharmony_ci</p>
51e6865dcdSopenharmony_ci</div>
52e6865dcdSopenharmony_ci
53e6865dcdSopenharmony_ci
54e6865dcdSopenharmony_ci<div class="para desc">
55e6865dcdSopenharmony_ci<h4>Descriptions</h4>
56e6865dcdSopenharmony_ci<p>The <tt>f_getfree</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. In case of FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt><a href="config.html#fs_nofsinfo">FF_FS_NOFSINFO</a></tt> option.</p>
57e6865dcdSopenharmony_ci</div>
58e6865dcdSopenharmony_ci
59e6865dcdSopenharmony_ci
60e6865dcdSopenharmony_ci<div class="para comp">
61e6865dcdSopenharmony_ci<h4>QuickInfo</h4>
62e6865dcdSopenharmony_ci<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
63e6865dcdSopenharmony_ci</div>
64e6865dcdSopenharmony_ci
65e6865dcdSopenharmony_ci
66e6865dcdSopenharmony_ci<div class="para use">
67e6865dcdSopenharmony_ci<h4>Example</h4>
68e6865dcdSopenharmony_ci<pre>
69e6865dcdSopenharmony_ci    FATFS *fs;
70e6865dcdSopenharmony_ci    DWORD fre_clust, fre_sect, tot_sect;
71e6865dcdSopenharmony_ci
72e6865dcdSopenharmony_ci
73e6865dcdSopenharmony_ci    <span class="c">/* Get volume information and free clusters of drive 1 */</span>
74e6865dcdSopenharmony_ci    res = <em>f_getfree</em>("1:", &amp;fre_clust, &amp;fs);
75e6865dcdSopenharmony_ci    if (res) die(res);
76e6865dcdSopenharmony_ci
77e6865dcdSopenharmony_ci    <span class="c">/* Get total sectors and free sectors */</span>
78e6865dcdSopenharmony_ci    tot_sect = (fs->n_fatent - 2) * fs->csize;
79e6865dcdSopenharmony_ci    fre_sect = fre_clust * fs->csize;
80e6865dcdSopenharmony_ci
81e6865dcdSopenharmony_ci    <span class="c">/* Print the free space (assuming 512 bytes/sector) */</span>
82e6865dcdSopenharmony_ci    printf("%10lu KiB total drive space.\n%10lu KiB available.\n", tot_sect / 2, fre_sect / 2);
83e6865dcdSopenharmony_ci</pre>
84e6865dcdSopenharmony_ci</div>
85e6865dcdSopenharmony_ci
86e6865dcdSopenharmony_ci
87e6865dcdSopenharmony_ci<div class="para ref">
88e6865dcdSopenharmony_ci<h4>See Also</h4>
89e6865dcdSopenharmony_ci<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
90e6865dcdSopenharmony_ci</div>
91e6865dcdSopenharmony_ci
92e6865dcdSopenharmony_ci<p class="foot"><a href="../00index_e.html">Return</a></p>
93e6865dcdSopenharmony_ci</body>
94e6865dcdSopenharmony_ci</html>
95