Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:17

0001 /**
0002  * @file
0003  *
0004  * @ingroup libfs_msdos MSDOS FileSystem
0005  *
0006  * @brief Obtain MS-DOS filesystem information
0007  */
0008 
0009 /*
0010  *  Copyright (c) 2013 Andrey Mozzhuhin
0011  *  Copyright (c) 2013 Vitaly Belov
0012  *
0013  *  The license and distribution terms for this file may be
0014  *  found in the file LICENSE in this distribution or at
0015  *  http://www.rtems.org/license/LICENSE.
0016  */
0017 
0018 #include "fat.h"
0019 #include "fat_fat_operations.h"
0020 #include "msdos.h"
0021 
0022 int msdos_statvfs(
0023   const rtems_filesystem_location_info_t *__restrict root_loc,
0024   struct statvfs *__restrict sb)
0025 {
0026   msdos_fs_info_t *fs_info = root_loc->mt_entry->fs_info;
0027   fat_vol_t *vol = &fs_info->fat.vol;
0028 
0029   msdos_fs_lock(fs_info);
0030 
0031   sb->f_bsize = FAT_SECTOR512_SIZE;
0032   sb->f_frsize = vol->bpc;
0033   sb->f_blocks = vol->data_cls;
0034   sb->f_bfree = 0;
0035   sb->f_bavail = 0;
0036   sb->f_files = 0;    // FAT doesn't store inodes
0037   sb->f_ffree = 0;
0038   sb->f_favail = 0;
0039   sb->f_flag = 0;
0040   sb->f_namemax = MSDOS_NAME_MAX_LNF_LEN;
0041 
0042   if (vol->free_cls == FAT_UNDEFINED_VALUE)
0043   {
0044     int rc;
0045     uint32_t cur_cl = 2;
0046     uint32_t value = 0;
0047     uint32_t data_cls_val = vol->data_cls + 2;
0048 
0049     for (; cur_cl < data_cls_val; ++cur_cl)
0050     {
0051       rc = fat_get_fat_cluster(&fs_info->fat, cur_cl, &value);
0052       if (rc != RC_OK)
0053       {
0054         msdos_fs_unlock(fs_info);
0055         return rc;
0056       }
0057 
0058       if (value == FAT_GENFAT_FREE)
0059       {
0060         sb->f_bfree++;
0061         sb->f_bavail++;
0062       }
0063     }
0064   }
0065   else
0066   {
0067     sb->f_bfree = vol->free_cls;
0068     sb->f_bavail = vol->free_cls;
0069   }
0070 
0071   msdos_fs_unlock(fs_info);
0072   return RC_OK;
0073 }