source: rtems/cpukit/libfs/src/dosfs/msdos_statvfs.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * @file msdos_statvfs.c
3 *
4 * @brief Obtain MS-DOS filesystem information
5 * @ingroup libfs_msdos MSDOS FileSystem
6 */
7
8/*
9 *  Copyright (c) 2013 Andrey Mozzhuhin
10 *  Copyright (c) 2013 Vitaly Belov
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#include "fat.h"
18#include "fat_fat_operations.h"
19#include "msdos.h"
20
21int msdos_statvfs(
22  const rtems_filesystem_location_info_t *__restrict root_loc,
23  struct statvfs *__restrict sb)
24{
25  msdos_fs_info_t *fs_info = root_loc->mt_entry->fs_info;
26  fat_vol_t *vol = &fs_info->fat.vol;
27  rtems_status_code sc = RTEMS_SUCCESSFUL;
28
29  sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
30                              MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
31  if (sc != RTEMS_SUCCESSFUL)
32      rtems_set_errno_and_return_minus_one(EIO);
33
34  sb->f_bsize = FAT_SECTOR512_SIZE;
35  sb->f_frsize = vol->bpc;
36  sb->f_blocks = vol->data_cls;
37  sb->f_bfree = 0;
38  sb->f_bavail = 0;
39  sb->f_files = 0;    // FAT doesn't store inodes
40  sb->f_ffree = 0;
41  sb->f_favail = 0;
42  sb->f_flag = 0;
43  sb->f_namemax = MSDOS_NAME_MAX_LNF_LEN;
44
45  if (vol->free_cls == FAT_UNDEFINED_VALUE)
46  {
47    int rc;
48    uint32_t cur_cl = 2;
49    uint32_t value = 0;
50    uint32_t data_cls_val = vol->data_cls + 2;
51
52    for (; cur_cl < data_cls_val; ++cur_cl)
53    {
54      rc = fat_get_fat_cluster(&fs_info->fat, cur_cl, &value);
55      if (rc != RC_OK)
56      {
57        rtems_semaphore_release(fs_info->vol_sema);
58        return rc;
59      }
60
61      if (value == FAT_GENFAT_FREE)
62      {
63        sb->f_bfree++;
64        sb->f_bavail++;
65      }
66    }
67  }
68  else
69  {
70    sb->f_bfree = vol->free_cls;
71    sb->f_bavail = vol->free_cls;
72  }
73
74  rtems_semaphore_release(fs_info->vol_sema);
75  return RC_OK;
76}
Note: See TracBrowser for help on using the repository browser.