getfree.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/getfree.html">
  8. <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
  9. <title>FatFs - f_getfree</title>
  10. </head>
  11. <body>
  12. <div class="para func">
  13. <h2>f_getfree</h2>
  14. <p>The f_getfree function gets number of the free clusters on the volume.</p>
  15. <pre>
  16. FRESULT f_getfree (
  17. const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
  18. DWORD* <span class="arg">nclst</span>, <span class="c">/* [OUT] Number of free clusters */</span>
  19. FATFS** <span class="arg">fatfs</span> <span class="c">/* [OUT] Corresponding file system object */</span>
  20. );
  21. </pre>
  22. </div>
  23. <div class="para arg">
  24. <h4>Parameters</h4>
  25. <dl class="par">
  26. <dt>path</dt>
  27. <dd>Pinter to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. A null-string means the default drive.</dd>
  28. <dt>nclst</dt>
  29. <dd>Pointer to the <tt>DWORD</tt> variable to store number of free clusters.</dd>
  30. <dt>fatfs</dt>
  31. <dd>Pointer to pointer that to store a pointer to the corresponding file system object.</dd>
  32. </dl>
  33. </div>
  34. <div class="para ret">
  35. <h4>Return Values</h4>
  36. <p>
  37. <a href="rc.html#ok">FR_OK</a>,
  38. <a href="rc.html#de">FR_DISK_ERR</a>,
  39. <a href="rc.html#ie">FR_INT_ERR</a>,
  40. <a href="rc.html#nr">FR_NOT_READY</a>,
  41. <a href="rc.html#id">FR_INVALID_DRIVE</a>,
  42. <a href="rc.html#ne">FR_NOT_ENABLED</a>,
  43. <a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
  44. <a href="rc.html#tm">FR_TIMEOUT</a>
  45. </p>
  46. </div>
  47. <div class="para desc">
  48. <h4>Descriptions</h4>
  49. <p>The <tt>f_getfree()</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the file system object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. When 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>_FS_NOFSINFO</tt> option.</p>
  50. </div>
  51. <div class="para comp">
  52. <h4>QuickInfo</h4>
  53. <p>Available when <tt>_FS_READONLY == 0</tt> and <tt>_FS_MINIMIZE == 0</tt>.</p>
  54. </div>
  55. <div class="para use">
  56. <h4>Example</h4>
  57. <pre>
  58. FATFS *fs;
  59. DWORD fre_clust, fre_sect, tot_sect;
  60. <span class="c">/* Get volume information and free clusters of drive 1 */</span>
  61. res = f_getfree("1:", &amp;fre_clust, &amp;fs);
  62. if (res) die(res);
  63. <span class="c">/* Get total sectors and free sectors */</span>
  64. tot_sect = (fs->n_fatent - 2) * fs->csize;
  65. fre_sect = fre_clust * fs->csize;
  66. <span class="c">/* Print the free space (assuming 512 bytes/sector) */</span>
  67. printf("%10lu KiB total drive space.\n%10lu KiB available.\n",
  68. tot_sect / 2, fre_sect / 2);
  69. </pre>
  70. </div>
  71. <div class="para ref">
  72. <h4>See Also</h4>
  73. <p><tt><a href="sfatfs.html">FATFS</a></tt></p>
  74. </div>
  75. <p class="foot"><a href="../00index_e.html">Return</a></p>
  76. </body>
  77. </html>