forked from Imagelibrary/rtems
dosfs: Use fs_info instead of mt_entry
This commit is contained in:
@@ -161,7 +161,7 @@ fat_buf_release(fat_fs_info_t *fs_info)
|
||||
* boundary; in this case assumed we want to read sequential sector(s))
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* start - sector num to start read from
|
||||
* offset - offset inside sector 'start'
|
||||
* count - count of bytes to read
|
||||
@@ -173,7 +173,7 @@ fat_buf_release(fat_fs_info_t *fs_info)
|
||||
*/
|
||||
ssize_t
|
||||
_fat_block_read(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t start,
|
||||
uint32_t offset,
|
||||
uint32_t count,
|
||||
@@ -181,7 +181,6 @@ _fat_block_read(
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
register fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
ssize_t cmpltd = 0;
|
||||
uint32_t blk = start;
|
||||
uint32_t ofs = offset;
|
||||
@@ -212,7 +211,7 @@ _fat_block_read(
|
||||
* boundary; in this case assumed we want to write sequential sector(s))
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* start - sector num to start read from
|
||||
* offset - offset inside sector 'start'
|
||||
* count - count of bytes to write
|
||||
@@ -224,14 +223,13 @@ _fat_block_read(
|
||||
*/
|
||||
ssize_t
|
||||
_fat_block_write(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t start,
|
||||
uint32_t offset,
|
||||
uint32_t count,
|
||||
const void *buff)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
ssize_t cmpltd = 0;
|
||||
uint32_t blk = start;
|
||||
uint32_t ofs = offset;
|
||||
@@ -263,13 +261,12 @@ _fat_block_write(
|
||||
|
||||
int
|
||||
_fat_block_zero(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t start,
|
||||
uint32_t offset,
|
||||
uint32_t count)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t blk = start;
|
||||
uint32_t ofs = offset;
|
||||
rtems_bdbuf_buffer *block = NULL;
|
||||
@@ -302,16 +299,14 @@ _fat_block_zero(
|
||||
* not release it.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 on success, or -1 if error occured and errno set appropriately
|
||||
*/
|
||||
int
|
||||
_fat_block_release(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
_fat_block_release(fat_fs_info_t *fs_info)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
return fat_buf_release(fs_info);
|
||||
}
|
||||
|
||||
@@ -319,7 +314,7 @@ _fat_block_release(
|
||||
* wrapper for reading a whole cluster at once
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* cln - number of cluster to read
|
||||
* buff - buffer provided by user
|
||||
*
|
||||
@@ -329,17 +324,16 @@ _fat_block_release(
|
||||
*/
|
||||
ssize_t
|
||||
fat_cluster_read(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
void *buff
|
||||
)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t fsec = 0;
|
||||
|
||||
fsec = fat_cluster_num_to_sector_num(mt_entry, cln);
|
||||
fsec = fat_cluster_num_to_sector_num(fs_info, cln);
|
||||
|
||||
return _fat_block_read(mt_entry, fsec, 0,
|
||||
return _fat_block_read(fs_info, fsec, 0,
|
||||
fs_info->vol.spc << fs_info->vol.sec_log2, buff);
|
||||
}
|
||||
|
||||
@@ -347,7 +341,7 @@ fat_cluster_read(
|
||||
* wrapper for writting a whole cluster at once
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* cln - number of cluster to write
|
||||
* buff - buffer provided by user
|
||||
*
|
||||
@@ -357,17 +351,16 @@ fat_cluster_read(
|
||||
*/
|
||||
ssize_t
|
||||
fat_cluster_write(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
const void *buff
|
||||
)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t fsec = 0;
|
||||
|
||||
fsec = fat_cluster_num_to_sector_num(mt_entry, cln);
|
||||
fsec = fat_cluster_num_to_sector_num(fs_info, cln);
|
||||
|
||||
return _fat_block_write(mt_entry, fsec, 0,
|
||||
return _fat_block_write(fs_info, fsec, 0,
|
||||
fs_info->vol.spc << fs_info->vol.sec_log2, buff);
|
||||
}
|
||||
|
||||
@@ -375,18 +368,17 @@ fat_cluster_write(
|
||||
* Get inforamtion about volume on which filesystem is mounted on
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
*
|
||||
* RETURNS:
|
||||
* RC_OK on success, or -1 if error occured
|
||||
* and errno set appropriately
|
||||
*/
|
||||
int
|
||||
fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
fat_init_volume_info(fat_fs_info_t *fs_info, const char *device)
|
||||
{
|
||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
register fat_vol_t *vol = &fs_info->vol;
|
||||
uint32_t data_secs = 0;
|
||||
char boot_rec[FAT_MAX_BPB_SIZE];
|
||||
@@ -396,7 +388,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
int i = 0;
|
||||
rtems_bdbuf_buffer *block = NULL;
|
||||
|
||||
vol->fd = open(mt_entry->dev, O_RDWR);
|
||||
vol->fd = open(device, O_RDWR);
|
||||
if (vol->fd < 0)
|
||||
{
|
||||
rtems_set_errno_and_return_minus_one(ENXIO);
|
||||
@@ -556,7 +548,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = _fat_block_read(mt_entry, vol->info_sec , 0,
|
||||
ret = _fat_block_read(fs_info, vol->info_sec , 0,
|
||||
FAT_FSI_LEADSIG_SIZE, fs_info_sector);
|
||||
if ( ret < 0 )
|
||||
{
|
||||
@@ -567,28 +559,28 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
if (FAT_GET_FSINFO_LEAD_SIGNATURE(fs_info_sector) !=
|
||||
FAT_FSINFO_LEAD_SIGNATURE_VALUE)
|
||||
{
|
||||
_fat_block_release(mt_entry);
|
||||
_fat_block_release(fs_info);
|
||||
close(vol->fd);
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = _fat_block_read(mt_entry, vol->info_sec , FAT_FSI_INFO,
|
||||
ret = _fat_block_read(fs_info, vol->info_sec , FAT_FSI_INFO,
|
||||
FAT_USEFUL_INFO_SIZE, fs_info_sector);
|
||||
if ( ret < 0 )
|
||||
{
|
||||
_fat_block_release(mt_entry);
|
||||
_fat_block_release(fs_info);
|
||||
close(vol->fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
vol->free_cls = FAT_GET_FSINFO_FREE_CLUSTER_COUNT(fs_info_sector);
|
||||
vol->next_cl = FAT_GET_FSINFO_NEXT_FREE_CLUSTER(fs_info_sector);
|
||||
rc = fat_fat32_update_fsinfo_sector(mt_entry, 0xFFFFFFFF,
|
||||
rc = fat_fat32_update_fsinfo_sector(fs_info, 0xFFFFFFFF,
|
||||
0xFFFFFFFF);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
_fat_block_release(mt_entry);
|
||||
_fat_block_release(fs_info);
|
||||
close(vol->fd);
|
||||
return rc;
|
||||
}
|
||||
@@ -604,7 +596,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
vol->next_cl = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
_fat_block_release(mt_entry);
|
||||
_fat_block_release(fs_info);
|
||||
|
||||
vol->afat_loc = vol->fat_loc + vol->fat_length * vol->afat;
|
||||
|
||||
@@ -657,22 +649,21 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
* Free all allocated resources and synchronize all necessary data
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
*
|
||||
* RETURNS:
|
||||
* RC_OK on success, or -1 if error occured
|
||||
* and errno set appropriately
|
||||
*/
|
||||
int
|
||||
fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
fat_shutdown_drive(fat_fs_info_t *fs_info)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
int i = 0;
|
||||
|
||||
if (fs_info->vol.type & FAT_FAT32)
|
||||
{
|
||||
rc = fat_fat32_update_fsinfo_sector(mt_entry, fs_info->vol.free_cls,
|
||||
rc = fat_fat32_update_fsinfo_sector(fs_info, fs_info->vol.free_cls,
|
||||
fs_info->vol.next_cl);
|
||||
if ( rc != RC_OK )
|
||||
rc = -1;
|
||||
@@ -717,7 +708,7 @@ fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
* Zeroing contents of all clusters in the chain
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* start_cluster_num - num of first cluster in the chain
|
||||
*
|
||||
* RETURNS:
|
||||
@@ -726,13 +717,12 @@ fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
*/
|
||||
int
|
||||
fat_init_clusters_chain(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t start_cln
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
ssize_t ret = 0;
|
||||
register fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cur_cln = start_cln;
|
||||
char *buf;
|
||||
|
||||
@@ -742,14 +732,14 @@ fat_init_clusters_chain(
|
||||
|
||||
while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
|
||||
{
|
||||
ret = fat_cluster_write(mt_entry, cur_cln, buf);
|
||||
ret = fat_cluster_write(fs_info, cur_cln, buf);
|
||||
if ( ret == -1 )
|
||||
{
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cur_cln, &cur_cln);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
free(buf);
|
||||
@@ -776,7 +766,7 @@ fat_init_clusters_chain(
|
||||
* Allocate unique ino from unique ino pool
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
*
|
||||
* RETURNS:
|
||||
* unique inode number on success, or 0 if there is no free unique inode
|
||||
@@ -787,9 +777,8 @@ fat_init_clusters_chain(
|
||||
*
|
||||
*/
|
||||
uint32_t
|
||||
fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
fat_get_unique_ino(fat_fs_info_t *fs_info)
|
||||
{
|
||||
register fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t j = 0;
|
||||
bool resrc_unsuff = false;
|
||||
|
||||
@@ -826,7 +815,7 @@ fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
* Return unique ino to unique ino pool
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* ino - inode number to free
|
||||
*
|
||||
* RETURNS:
|
||||
@@ -834,12 +823,10 @@ fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry)
|
||||
*/
|
||||
void
|
||||
fat_free_unique_ino(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t ino
|
||||
)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
|
||||
FAT_SET_UNIQ_INO_FREE((ino - fs_info->uino_base), fs_info->uino);
|
||||
}
|
||||
|
||||
@@ -847,7 +834,7 @@ fat_free_unique_ino(
|
||||
* Test whether ino is from unique ino pool
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* ino - ino to be tested
|
||||
*
|
||||
* RETURNS:
|
||||
@@ -855,11 +842,10 @@ fat_free_unique_ino(
|
||||
*/
|
||||
inline bool
|
||||
fat_ino_is_unique(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t ino
|
||||
)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
|
||||
return (ino >= fs_info->uino_base);
|
||||
}
|
||||
@@ -868,7 +854,7 @@ fat_ino_is_unique(
|
||||
* Synchronize fsinfo sector for FAT32 volumes
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* free_count - count of free clusters
|
||||
* next_free - the next free cluster num
|
||||
*
|
||||
@@ -877,26 +863,25 @@ fat_ino_is_unique(
|
||||
*/
|
||||
int
|
||||
fat_fat32_update_fsinfo_sector(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t free_count,
|
||||
uint32_t next_free
|
||||
)
|
||||
{
|
||||
ssize_t ret1 = 0, ret2 = 0;
|
||||
register fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t le_free_count = 0;
|
||||
uint32_t le_next_free = 0;
|
||||
|
||||
le_free_count = CT_LE_L(free_count);
|
||||
le_next_free = CT_LE_L(next_free);
|
||||
|
||||
ret1 = _fat_block_write(mt_entry,
|
||||
ret1 = _fat_block_write(fs_info,
|
||||
fs_info->vol.info_sec,
|
||||
FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET,
|
||||
4,
|
||||
(char *)(&le_free_count));
|
||||
|
||||
ret2 = _fat_block_write(mt_entry,
|
||||
ret2 = _fat_block_write(fs_info,
|
||||
fs_info->vol.info_sec,
|
||||
FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET,
|
||||
4,
|
||||
|
||||
@@ -407,12 +407,10 @@ fat_dir_pos_init(
|
||||
|
||||
static inline uint32_t
|
||||
fat_cluster_num_to_sector_num(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
const fat_fs_info_t *fs_info,
|
||||
uint32_t cln
|
||||
)
|
||||
{
|
||||
register fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
|
||||
if ( (cln == 0) && (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)) )
|
||||
return fs_info->vol.rdir_loc;
|
||||
|
||||
@@ -422,16 +420,14 @@ fat_cluster_num_to_sector_num(
|
||||
|
||||
static inline uint32_t
|
||||
fat_cluster_num_to_sector512_num(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
const fat_fs_info_t *fs_info,
|
||||
uint32_t cln
|
||||
)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
|
||||
if (cln == 1)
|
||||
return 1;
|
||||
|
||||
return (fat_cluster_num_to_sector_num(mt_entry, cln) <<
|
||||
return (fat_cluster_num_to_sector_num(fs_info, cln) <<
|
||||
fs_info->vol.sec_mul);
|
||||
}
|
||||
|
||||
@@ -449,67 +445,63 @@ int
|
||||
fat_buf_release(fat_fs_info_t *fs_info);
|
||||
|
||||
ssize_t
|
||||
_fat_block_read(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
_fat_block_read(fat_fs_info_t *fs_info,
|
||||
uint32_t start,
|
||||
uint32_t offset,
|
||||
uint32_t count,
|
||||
void *buff);
|
||||
|
||||
ssize_t
|
||||
_fat_block_write(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
_fat_block_write(fat_fs_info_t *fs_info,
|
||||
uint32_t start,
|
||||
uint32_t offset,
|
||||
uint32_t count,
|
||||
const void *buff);
|
||||
|
||||
int
|
||||
_fat_block_zero(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
_fat_block_zero(fat_fs_info_t *fs_info,
|
||||
uint32_t start,
|
||||
uint32_t offset,
|
||||
uint32_t count);
|
||||
|
||||
int
|
||||
_fat_block_release(rtems_filesystem_mount_table_entry_t *mt_entry);
|
||||
_fat_block_release(fat_fs_info_t *fs_info);
|
||||
|
||||
ssize_t
|
||||
fat_cluster_read(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_cluster_read(fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
void *buff);
|
||||
|
||||
ssize_t
|
||||
fat_cluster_write(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_cluster_write(fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
const void *buff);
|
||||
|
||||
int
|
||||
fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry);
|
||||
fat_init_volume_info(fat_fs_info_t *fs_info, const char *device);
|
||||
|
||||
int
|
||||
fat_init_clusters_chain(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_init_clusters_chain(fat_fs_info_t *fs_info,
|
||||
uint32_t start_cln);
|
||||
|
||||
uint32_t
|
||||
fat_cluster_num_to_sector_num(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
uint32_t cln);
|
||||
|
||||
int
|
||||
fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry);
|
||||
fat_shutdown_drive(fat_fs_info_t *fs_info);
|
||||
|
||||
|
||||
uint32_t
|
||||
fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry);
|
||||
fat_get_unique_ino(fat_fs_info_t *fs_info);
|
||||
|
||||
bool
|
||||
fat_ino_is_unique(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_ino_is_unique(fat_fs_info_t *fs_info,
|
||||
uint32_t ino);
|
||||
|
||||
void
|
||||
fat_free_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_free_unique_ino(fat_fs_info_t *fs_info,
|
||||
uint32_t ino);
|
||||
|
||||
int
|
||||
fat_fat32_update_fsinfo_sector(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t free_count,
|
||||
uint32_t next_free
|
||||
);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* Allocate chain of free clusters from Files Allocation Table
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* chain - the number of the first allocated cluster (first cluster
|
||||
* in the chain)
|
||||
* count - count of clusters to allocate (chain length)
|
||||
@@ -40,7 +40,7 @@
|
||||
*/
|
||||
int
|
||||
fat_scan_fat_for_free_clusters(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t *chain,
|
||||
uint32_t count,
|
||||
uint32_t *cls_added,
|
||||
@@ -49,7 +49,6 @@ fat_scan_fat_for_free_clusters(
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cl4find = 2;
|
||||
uint32_t next_cln = 0;
|
||||
uint32_t save_cln = 0;
|
||||
@@ -71,11 +70,11 @@ fat_scan_fat_for_free_clusters(
|
||||
*/
|
||||
while (i < data_cls_val)
|
||||
{
|
||||
rc = fat_get_fat_cluster(mt_entry, cl4find, &next_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cl4find, &next_cln);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
if (*cls_added != 0)
|
||||
fat_free_fat_clusters_chain(mt_entry, (*chain));
|
||||
fat_free_fat_clusters_chain(fs_info, (*chain));
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ fat_scan_fat_for_free_clusters(
|
||||
if (*cls_added == 0)
|
||||
{
|
||||
*chain = cl4find;
|
||||
rc = fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_EOC);
|
||||
rc = fat_set_fat_cluster(fs_info, cl4find, FAT_GENFAT_EOC);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
/*
|
||||
@@ -102,24 +101,24 @@ fat_scan_fat_for_free_clusters(
|
||||
else
|
||||
{
|
||||
/* set EOC value to new allocated cluster */
|
||||
rc = fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_EOC);
|
||||
rc = fat_set_fat_cluster(fs_info, cl4find, FAT_GENFAT_EOC);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
/* cleanup activity */
|
||||
fat_free_fat_clusters_chain(mt_entry, (*chain));
|
||||
fat_free_fat_clusters_chain(fs_info, (*chain));
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = fat_set_fat_cluster(mt_entry, save_cln, cl4find);
|
||||
rc = fat_set_fat_cluster(fs_info, save_cln, cl4find);
|
||||
if ( rc != RC_OK )
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (zero_fill) {
|
||||
uint32_t sec = fat_cluster_num_to_sector_num(mt_entry,
|
||||
uint32_t sec = fat_cluster_num_to_sector_num(fs_info,
|
||||
cl4find);
|
||||
|
||||
rc = _fat_block_zero(mt_entry, sec, 0, fs_info->vol.bpc);
|
||||
rc = _fat_block_zero(fs_info, sec, 0, fs_info->vol.bpc);
|
||||
if ( rc != RC_OK )
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -155,9 +154,9 @@ fat_scan_fat_for_free_clusters(
|
||||
cleanup:
|
||||
|
||||
/* cleanup activity */
|
||||
fat_free_fat_clusters_chain(mt_entry, (*chain));
|
||||
fat_free_fat_clusters_chain(fs_info, (*chain));
|
||||
/* trying to save last allocated cluster for future use */
|
||||
fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_FREE);
|
||||
fat_set_fat_cluster(fs_info, cl4find, FAT_GENFAT_FREE);
|
||||
fat_buf_release(fs_info);
|
||||
return rc;
|
||||
}
|
||||
@@ -166,7 +165,7 @@ cleanup:
|
||||
* Free chain of clusters in Files Allocation Table.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* chain - number of the first cluster in the chain
|
||||
*
|
||||
* RETURNS:
|
||||
@@ -174,19 +173,18 @@ cleanup:
|
||||
*/
|
||||
int
|
||||
fat_free_fat_clusters_chain(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t chain
|
||||
)
|
||||
{
|
||||
int rc = RC_OK, rc1 = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cur_cln = chain;
|
||||
uint32_t next_cln = 0;
|
||||
uint32_t freed_cls_cnt = 0;
|
||||
|
||||
while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
|
||||
{
|
||||
rc = fat_get_fat_cluster(mt_entry, cur_cln, &next_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cur_cln, &next_cln);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
if(fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)
|
||||
@@ -196,7 +194,7 @@ fat_free_fat_clusters_chain(
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = fat_set_fat_cluster(mt_entry, cur_cln, FAT_GENFAT_FREE);
|
||||
rc = fat_set_fat_cluster(fs_info, cur_cln, FAT_GENFAT_FREE);
|
||||
if ( rc != RC_OK )
|
||||
rc1 = rc;
|
||||
|
||||
@@ -220,7 +218,7 @@ fat_free_fat_clusters_chain(
|
||||
* from Files Allocation Table.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* cln - number of cluster to fetch the contents from
|
||||
* ret_val - contents of the cluster 'cln' (link to next cluster in
|
||||
* the chain)
|
||||
@@ -231,13 +229,12 @@ fat_free_fat_clusters_chain(
|
||||
*/
|
||||
int
|
||||
fat_get_fat_cluster(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
uint32_t *ret_val
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
register fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
rtems_bdbuf_buffer *block0 = NULL;
|
||||
uint32_t sec = 0;
|
||||
uint32_t ofs = 0;
|
||||
@@ -305,7 +302,7 @@ fat_get_fat_cluster(
|
||||
* from Files Allocation Table.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* cln - number of cluster to set contents to
|
||||
* in_val - value to set
|
||||
*
|
||||
@@ -315,13 +312,12 @@ fat_get_fat_cluster(
|
||||
*/
|
||||
int
|
||||
fat_set_fat_cluster(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
uint32_t in_val
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t sec = 0;
|
||||
uint32_t ofs = 0;
|
||||
uint16_t fat16_clv = 0;
|
||||
|
||||
@@ -26,18 +26,18 @@ extern "C" {
|
||||
#include "fat.h"
|
||||
|
||||
int
|
||||
fat_get_fat_cluster(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_get_fat_cluster(fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
uint32_t *ret_val);
|
||||
|
||||
int
|
||||
fat_set_fat_cluster(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_set_fat_cluster(fat_fs_info_t *fs_info,
|
||||
uint32_t cln,
|
||||
uint32_t in_val);
|
||||
|
||||
int
|
||||
fat_scan_fat_for_free_clusters(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t *chain,
|
||||
uint32_t count,
|
||||
uint32_t *cls_added,
|
||||
@@ -47,7 +47,7 @@ fat_scan_fat_for_free_clusters(
|
||||
|
||||
int
|
||||
fat_free_fat_clusters_chain(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
uint32_t chain
|
||||
);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ _hash_delete(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
|
||||
|
||||
static inline int
|
||||
_hash_search(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
const fat_fs_info_t *fs_info,
|
||||
rtems_chain_control *hash,
|
||||
uint32_t key1,
|
||||
uint32_t key2,
|
||||
@@ -49,7 +49,7 @@ _hash_search(
|
||||
|
||||
static off_t
|
||||
fat_file_lseek(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t file_cln,
|
||||
uint32_t *disk_cln
|
||||
@@ -72,7 +72,7 @@ fat_file_lseek(
|
||||
* of second key fields) value.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* pos - cluster and offset of the node
|
||||
* fat_fd - placeholder for returned fat-file descriptor
|
||||
*
|
||||
@@ -82,21 +82,20 @@ fat_file_lseek(
|
||||
*/
|
||||
int
|
||||
fat_file_open(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_dir_pos_t *dir_pos,
|
||||
fat_file_fd_t **fat_fd
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
fat_file_fd_t *lfat_fd = NULL;
|
||||
uint32_t key = 0;
|
||||
|
||||
/* construct key */
|
||||
key = fat_construct_key(mt_entry, &dir_pos->sname);
|
||||
key = fat_construct_key(fs_info, &dir_pos->sname);
|
||||
|
||||
/* access "valid" hash table */
|
||||
rc = _hash_search(mt_entry, fs_info->vhash, key, 0, &lfat_fd);
|
||||
rc = _hash_search(fs_info, fs_info->vhash, key, 0, &lfat_fd);
|
||||
if ( rc == RC_OK )
|
||||
{
|
||||
/* return pointer to fat_file_descriptor allocated before */
|
||||
@@ -106,7 +105,7 @@ fat_file_open(
|
||||
}
|
||||
|
||||
/* access "removed-but-still-open" hash table */
|
||||
rc = _hash_search(mt_entry, fs_info->rhash, key, key, &lfat_fd);
|
||||
rc = _hash_search(fs_info, fs_info->rhash, key, key, &lfat_fd);
|
||||
|
||||
lfat_fd = (*fat_fd) = (fat_file_fd_t*)malloc(sizeof(fat_file_fd_t));
|
||||
if ( lfat_fd == NULL )
|
||||
@@ -124,7 +123,7 @@ fat_file_open(
|
||||
lfat_fd->ino = key;
|
||||
else
|
||||
{
|
||||
lfat_fd->ino = fat_get_unique_ino(mt_entry);
|
||||
lfat_fd->ino = fat_get_unique_ino(fs_info);
|
||||
|
||||
if ( lfat_fd->ino == 0 )
|
||||
{
|
||||
@@ -176,7 +175,7 @@ fat_file_reopen(fat_file_fd_t *fat_fd)
|
||||
* memory allocated by the descriptor
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* fat_fd - fat-file descriptor
|
||||
*
|
||||
* RETURNS:
|
||||
@@ -184,12 +183,11 @@ fat_file_reopen(fat_file_fd_t *fat_fd)
|
||||
*/
|
||||
int
|
||||
fat_file_close(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t key = 0;
|
||||
|
||||
/*
|
||||
@@ -202,24 +200,24 @@ fat_file_close(
|
||||
return rc;
|
||||
}
|
||||
|
||||
key = fat_construct_key(mt_entry, &fat_fd->dir_pos.sname);
|
||||
key = fat_construct_key(fs_info, &fat_fd->dir_pos.sname);
|
||||
|
||||
if (fat_fd->flags & FAT_FILE_REMOVED)
|
||||
{
|
||||
rc = fat_file_truncate(mt_entry, fat_fd, 0);
|
||||
rc = fat_file_truncate(fs_info, fat_fd, 0);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
|
||||
_hash_delete(fs_info->rhash, key, fat_fd->ino, fat_fd);
|
||||
|
||||
if ( fat_ino_is_unique(mt_entry, fat_fd->ino) )
|
||||
fat_free_unique_ino(mt_entry, fat_fd->ino);
|
||||
if ( fat_ino_is_unique(fs_info, fat_fd->ino) )
|
||||
fat_free_unique_ino(fs_info, fat_fd->ino);
|
||||
|
||||
free(fat_fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fat_ino_is_unique(mt_entry, fat_fd->ino))
|
||||
if (fat_ino_is_unique(fs_info, fat_fd->ino))
|
||||
{
|
||||
fat_fd->links_num = 0;
|
||||
}
|
||||
@@ -243,7 +241,7 @@ fat_file_close(
|
||||
* linear file
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* fat_fd - fat-file descriptor
|
||||
* start - offset in fat-file (in bytes) to read from
|
||||
* count - count of bytes to read
|
||||
@@ -255,7 +253,7 @@ fat_file_close(
|
||||
*/
|
||||
ssize_t
|
||||
fat_file_read(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t start,
|
||||
uint32_t count,
|
||||
@@ -264,7 +262,6 @@ fat_file_read(
|
||||
{
|
||||
int rc = RC_OK;
|
||||
ssize_t ret = 0;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cmpltd = 0;
|
||||
uint32_t cur_cln = 0;
|
||||
uint32_t cl_start = 0;
|
||||
@@ -293,11 +290,11 @@ fat_file_read(
|
||||
if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
|
||||
(fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
|
||||
{
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->cln);
|
||||
sec = fat_cluster_num_to_sector_num(fs_info, fat_fd->cln);
|
||||
sec += (start >> fs_info->vol.sec_log2);
|
||||
byte = start & (fs_info->vol.bps - 1);
|
||||
|
||||
ret = _fat_block_read(mt_entry, sec, byte, count, buf);
|
||||
ret = _fat_block_read(fs_info, sec, byte, count, buf);
|
||||
if ( ret < 0 )
|
||||
return -1;
|
||||
|
||||
@@ -307,7 +304,7 @@ fat_file_read(
|
||||
cl_start = start >> fs_info->vol.bpc_log2;
|
||||
save_ofs = ofs = start & (fs_info->vol.bpc - 1);
|
||||
|
||||
rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
|
||||
rc = fat_file_lseek(fs_info, fat_fd, cl_start, &cur_cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -315,18 +312,18 @@ fat_file_read(
|
||||
{
|
||||
c = MIN(count, (fs_info->vol.bpc - ofs));
|
||||
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
|
||||
sec = fat_cluster_num_to_sector_num(fs_info, cur_cln);
|
||||
sec += (ofs >> fs_info->vol.sec_log2);
|
||||
byte = ofs & (fs_info->vol.bps - 1);
|
||||
|
||||
ret = _fat_block_read(mt_entry, sec, byte, c, buf + cmpltd);
|
||||
ret = _fat_block_read(fs_info, sec, byte, c, buf + cmpltd);
|
||||
if ( ret < 0 )
|
||||
return -1;
|
||||
|
||||
count -= c;
|
||||
cmpltd += c;
|
||||
save_cln = cur_cln;
|
||||
rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cur_cln, &cur_cln);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
|
||||
@@ -348,7 +345,7 @@ fat_file_read(
|
||||
* of fat-file, represents it as linear file
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* fat_fd - fat-file descriptor
|
||||
* start - offset(in bytes) to write from
|
||||
* count - count
|
||||
@@ -360,7 +357,7 @@ fat_file_read(
|
||||
*/
|
||||
ssize_t
|
||||
fat_file_write(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t start,
|
||||
uint32_t count,
|
||||
@@ -369,7 +366,6 @@ fat_file_write(
|
||||
{
|
||||
int rc = 0;
|
||||
ssize_t ret = 0;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cmpltd = 0;
|
||||
uint32_t cur_cln = 0;
|
||||
uint32_t save_cln = 0; /* FIXME: This might be incorrect, cf. below */
|
||||
@@ -390,7 +386,7 @@ fat_file_write(
|
||||
if (count > fat_fd->size_limit - start)
|
||||
count = fat_fd->size_limit - start;
|
||||
|
||||
rc = fat_file_extend(mt_entry, fat_fd, zero_fill, start + count, &c);
|
||||
rc = fat_file_extend(fs_info, fat_fd, zero_fill, start + count, &c);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -404,11 +400,11 @@ fat_file_write(
|
||||
if ((FAT_FD_OF_ROOT_DIR(fat_fd)) &&
|
||||
(fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)))
|
||||
{
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->cln);
|
||||
sec = fat_cluster_num_to_sector_num(fs_info, fat_fd->cln);
|
||||
sec += (start >> fs_info->vol.sec_log2);
|
||||
byte = start & (fs_info->vol.bps - 1);
|
||||
|
||||
ret = _fat_block_write(mt_entry, sec, byte, count, buf);
|
||||
ret = _fat_block_write(fs_info, sec, byte, count, buf);
|
||||
if ( ret < 0 )
|
||||
return -1;
|
||||
|
||||
@@ -418,7 +414,7 @@ fat_file_write(
|
||||
cl_start = start >> fs_info->vol.bpc_log2;
|
||||
save_ofs = ofs = start & (fs_info->vol.bpc - 1);
|
||||
|
||||
rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
|
||||
rc = fat_file_lseek(fs_info, fat_fd, cl_start, &cur_cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -426,18 +422,18 @@ fat_file_write(
|
||||
{
|
||||
c = MIN(count, (fs_info->vol.bpc - ofs));
|
||||
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
|
||||
sec = fat_cluster_num_to_sector_num(fs_info, cur_cln);
|
||||
sec += (ofs >> fs_info->vol.sec_log2);
|
||||
byte = ofs & (fs_info->vol.bps - 1);
|
||||
|
||||
ret = _fat_block_write(mt_entry, sec, byte, c, buf + cmpltd);
|
||||
ret = _fat_block_write(fs_info, sec, byte, c, buf + cmpltd);
|
||||
if ( ret < 0 )
|
||||
return -1;
|
||||
|
||||
count -= c;
|
||||
cmpltd += c;
|
||||
save_cln = cur_cln;
|
||||
rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cur_cln, &cur_cln);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
|
||||
@@ -460,7 +456,7 @@ fat_file_write(
|
||||
* existing clusters chain.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* fat_fd - fat-file descriptor
|
||||
* new_length - new length
|
||||
* a_length - placeholder for result - actual new length of file
|
||||
@@ -471,7 +467,7 @@ fat_file_write(
|
||||
*/
|
||||
int
|
||||
fat_file_extend(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
bool zero_fill,
|
||||
uint32_t new_length,
|
||||
@@ -479,7 +475,6 @@ fat_file_extend(
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t chain = 0;
|
||||
uint32_t bytes2add = 0;
|
||||
uint32_t cls2add = 0;
|
||||
@@ -516,15 +511,15 @@ fat_file_extend(
|
||||
uint32_t sec;
|
||||
uint32_t byte;
|
||||
|
||||
rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
|
||||
rc = fat_file_lseek(fs_info, fat_fd, cl_start, &cur_cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln);
|
||||
sec = fat_cluster_num_to_sector_num(fs_info, cur_cln);
|
||||
sec += ofs >> fs_info->vol.sec_log2;
|
||||
byte = ofs & (fs_info->vol.bps - 1);
|
||||
|
||||
rc = _fat_block_zero(mt_entry, sec, byte, bytes_remain);
|
||||
rc = _fat_block_zero(fs_info, sec, byte, bytes_remain);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
}
|
||||
@@ -539,7 +534,7 @@ fat_file_extend(
|
||||
|
||||
cls2add = ((bytes2add - 1) >> fs_info->vol.bpc_log2) + 1;
|
||||
|
||||
rc = fat_scan_fat_for_free_clusters(mt_entry, &chain, cls2add,
|
||||
rc = fat_scan_fat_for_free_clusters(fs_info, &chain, cls2add,
|
||||
&cls_added, &last_cl, zero_fill);
|
||||
|
||||
/* this means that low level I/O error occured */
|
||||
@@ -571,19 +566,19 @@ fat_file_extend(
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
|
||||
rc = fat_file_ioctl(fs_info, fat_fd, F_CLU_NUM,
|
||||
(fat_fd->fat_file_size - 1), &old_last_cl);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
fat_free_fat_clusters_chain(mt_entry, chain);
|
||||
fat_free_fat_clusters_chain(fs_info, chain);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
rc = fat_set_fat_cluster(mt_entry, old_last_cl, chain);
|
||||
rc = fat_set_fat_cluster(fs_info, old_last_cl, chain);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
fat_free_fat_clusters_chain(mt_entry, chain);
|
||||
fat_free_fat_clusters_chain(fs_info, chain);
|
||||
return rc;
|
||||
}
|
||||
fat_buf_release(fs_info);
|
||||
@@ -595,10 +590,10 @@ fat_file_extend(
|
||||
fat_fd->map.last_cln = last_cl;
|
||||
if (fat_fd->fat_file_type == FAT_DIRECTORY)
|
||||
{
|
||||
rc = fat_init_clusters_chain(mt_entry, chain);
|
||||
rc = fat_init_clusters_chain(fs_info, chain);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
fat_free_fat_clusters_chain(mt_entry, chain);
|
||||
fat_free_fat_clusters_chain(fs_info, chain);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -616,7 +611,7 @@ fat_file_extend(
|
||||
* in the chain starting from this cluster.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* fat_fd - fat-file descriptor
|
||||
* new_length - new length
|
||||
*
|
||||
@@ -625,13 +620,12 @@ fat_file_extend(
|
||||
*/
|
||||
int
|
||||
fat_file_truncate(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t new_length
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cur_cln = 0;
|
||||
uint32_t cl_start = 0;
|
||||
uint32_t new_last_cln = FAT_UNDEFINED_VALUE;
|
||||
@@ -649,23 +643,23 @@ fat_file_truncate(
|
||||
|
||||
if (cl_start != 0)
|
||||
{
|
||||
rc = fat_file_lseek(mt_entry, fat_fd, cl_start - 1, &new_last_cln);
|
||||
rc = fat_file_lseek(fs_info, fat_fd, cl_start - 1, &new_last_cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
|
||||
rc = fat_file_lseek(fs_info, fat_fd, cl_start, &cur_cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
rc = fat_free_fat_clusters_chain(mt_entry, cur_cln);
|
||||
rc = fat_free_fat_clusters_chain(fs_info, cur_cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
if (cl_start != 0)
|
||||
{
|
||||
rc = fat_set_fat_cluster(mt_entry, new_last_cln, FAT_GENFAT_EOC);
|
||||
rc = fat_set_fat_cluster(fs_info, new_last_cln, FAT_GENFAT_EOC);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
fat_fd->map.file_cln = cl_start - 1;
|
||||
@@ -682,7 +676,7 @@ fat_file_truncate(
|
||||
*
|
||||
* PARAMETERS:
|
||||
* fat_fd - fat-file descriptor
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* cmd - command
|
||||
* ...
|
||||
*
|
||||
@@ -691,13 +685,12 @@ fat_file_truncate(
|
||||
*/
|
||||
int
|
||||
fat_file_ioctl(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
int cmd,
|
||||
...)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cur_cln = 0;
|
||||
uint32_t cl_start = 0;
|
||||
uint32_t pos = 0;
|
||||
@@ -729,7 +722,7 @@ fat_file_ioctl(
|
||||
|
||||
cl_start = pos >> fs_info->vol.bpc_log2;
|
||||
|
||||
rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln);
|
||||
rc = fat_file_lseek(fs_info, fat_fd, cl_start, &cur_cln);
|
||||
if ( rc != RC_OK )
|
||||
break;
|
||||
|
||||
@@ -751,21 +744,20 @@ fat_file_ioctl(
|
||||
*
|
||||
* PARAMETERS:
|
||||
* fat_fd - fat-file descriptor
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
*
|
||||
* RETURNS:
|
||||
* None
|
||||
*/
|
||||
void
|
||||
fat_file_mark_removed(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd
|
||||
)
|
||||
{
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t key = 0;
|
||||
|
||||
key = fat_construct_key(mt_entry, &fat_fd->dir_pos.sname);
|
||||
key = fat_construct_key(fs_info, &fat_fd->dir_pos.sname);
|
||||
|
||||
_hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd);
|
||||
|
||||
@@ -784,7 +776,7 @@ fat_file_mark_removed(
|
||||
* descriptor.
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* fat_fd - fat-file descriptor
|
||||
*
|
||||
* RETURNS:
|
||||
@@ -792,12 +784,11 @@ fat_file_mark_removed(
|
||||
*/
|
||||
int
|
||||
fat_file_size(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd
|
||||
)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
fat_fs_info_t *fs_info = mt_entry->fs_info;
|
||||
uint32_t cur_cln = fat_fd->cln;
|
||||
uint32_t save_cln = 0;
|
||||
|
||||
@@ -814,7 +805,7 @@ fat_file_size(
|
||||
while ((cur_cln & fs_info->vol.mask) < fs_info->vol.eoc_val)
|
||||
{
|
||||
save_cln = cur_cln;
|
||||
rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cur_cln, &cur_cln);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
|
||||
@@ -870,7 +861,7 @@ _hash_delete(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
|
||||
* is returned
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
* hash - hash element will be removed from
|
||||
* key1 - search key
|
||||
* key2 - search key
|
||||
@@ -881,7 +872,7 @@ _hash_delete(rtems_chain_control *hash, uint32_t key1, uint32_t key2,
|
||||
*/
|
||||
static inline int
|
||||
_hash_search(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
const fat_fs_info_t *fs_info,
|
||||
rtems_chain_control *hash,
|
||||
uint32_t key1,
|
||||
uint32_t key2,
|
||||
@@ -894,7 +885,7 @@ _hash_search(
|
||||
for ( ; !rtems_chain_is_tail((hash) + mod, the_node) ; )
|
||||
{
|
||||
fat_file_fd_t *ffd = (fat_file_fd_t *)the_node;
|
||||
uint32_t ck = fat_construct_key(mt_entry, &ffd->dir_pos.sname);
|
||||
uint32_t ck = fat_construct_key(fs_info, &ffd->dir_pos.sname);
|
||||
|
||||
if ( (key1) == ck)
|
||||
{
|
||||
@@ -911,7 +902,7 @@ _hash_search(
|
||||
|
||||
static off_t
|
||||
fat_file_lseek(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t file_cln,
|
||||
uint32_t *disk_cln
|
||||
@@ -941,7 +932,7 @@ fat_file_lseek(
|
||||
/* skip over the clusters */
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln);
|
||||
rc = fat_get_fat_cluster(fs_info, cur_cln, &cur_cln);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -111,24 +111,24 @@ typedef struct fat_file_fd_s
|
||||
* PARAMETERS:
|
||||
* cl - cluster number
|
||||
* ofs - offset inside cluster 'cl'
|
||||
* mt_entry - mount table entry
|
||||
* fs_info - FS info
|
||||
*
|
||||
* RETURNS:
|
||||
* constructed key
|
||||
*/
|
||||
static inline uint32_t
|
||||
fat_construct_key(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
const fat_fs_info_t *fs_info,
|
||||
fat_pos_t *pos)
|
||||
{
|
||||
return ( ((fat_cluster_num_to_sector512_num(mt_entry, pos->cln) +
|
||||
return ( ((fat_cluster_num_to_sector512_num(fs_info, pos->cln) +
|
||||
(pos->ofs >> FAT_SECTOR512_BITS)) << 4) +
|
||||
((pos->ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) );
|
||||
}
|
||||
|
||||
/* Prototypes for "fat-file" operations */
|
||||
int
|
||||
fat_file_open(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_open(fat_fs_info_t *fs_info,
|
||||
fat_dir_pos_t *dir_pos,
|
||||
fat_file_fd_t **fat_fd);
|
||||
|
||||
@@ -136,47 +136,47 @@ int
|
||||
fat_file_reopen(fat_file_fd_t *fat_fd);
|
||||
|
||||
int
|
||||
fat_file_close(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_close(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd);
|
||||
|
||||
ssize_t
|
||||
fat_file_read(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_read(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t start,
|
||||
uint32_t count,
|
||||
uint8_t *buf);
|
||||
|
||||
ssize_t
|
||||
fat_file_write(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_write(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t start,
|
||||
uint32_t count,
|
||||
const uint8_t *buf);
|
||||
|
||||
int
|
||||
fat_file_extend(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_extend(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
bool zero_fill,
|
||||
uint32_t new_length,
|
||||
uint32_t *a_length);
|
||||
|
||||
int
|
||||
fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_truncate(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
uint32_t new_length);
|
||||
|
||||
int
|
||||
fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_ioctl(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd,
|
||||
int cmd,
|
||||
...);
|
||||
|
||||
int
|
||||
fat_file_size(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_size(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd);
|
||||
|
||||
void
|
||||
fat_file_mark_removed(rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
fat_file_mark_removed(fat_fs_info_t *fs_info,
|
||||
fat_file_fd_t *fat_fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -122,12 +122,12 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
|
||||
/*
|
||||
* read the original directory entry
|
||||
*/
|
||||
sec = fat_cluster_num_to_sector_num(parent_loc->mt_entry,
|
||||
sec = fat_cluster_num_to_sector_num(&fs_info->fat,
|
||||
link_fd->dir_pos.sname.cln);
|
||||
sec += (link_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
|
||||
byte = (link_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1));
|
||||
|
||||
ret = _fat_block_read(parent_loc->mt_entry,
|
||||
ret = _fat_block_read(&fs_info->fat,
|
||||
sec, byte, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE,
|
||||
link_node);
|
||||
if (ret < 0) {
|
||||
@@ -175,7 +175,7 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
|
||||
if (type == MSDOS_DIRECTORY)
|
||||
{
|
||||
/* open new directory as fat-file */
|
||||
rc = fat_file_open(parent_loc->mt_entry, &dir_pos, &fat_fd);
|
||||
rc = fat_file_open(&fs_info->fat, &dir_pos, &fat_fd);
|
||||
if (rc != RC_OK)
|
||||
goto err;
|
||||
|
||||
@@ -225,7 +225,7 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
|
||||
* correspondes to a new node is zero length, so it will be extended
|
||||
* by one cluster and entries will be written
|
||||
*/
|
||||
ret = fat_file_write(parent_loc->mt_entry, fat_fd, 0,
|
||||
ret = fat_file_write(&fs_info->fat, fat_fd, 0,
|
||||
MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2,
|
||||
(uint8_t *)dot_dotdot);
|
||||
if (ret < 0)
|
||||
@@ -244,7 +244,7 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
|
||||
CT_LE_W((uint16_t )(((fat_fd->cln) & 0xFFFF0000) >> 16));
|
||||
|
||||
/* rewrite dot entry */
|
||||
ret = fat_file_write(parent_loc->mt_entry, fat_fd, 0,
|
||||
ret = fat_file_write(&fs_info->fat, fat_fd, 0,
|
||||
MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE,
|
||||
(uint8_t *)DOT_NODE_P(dot_dotdot));
|
||||
if (ret < 0)
|
||||
@@ -258,12 +258,12 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
|
||||
if (rc != RC_OK)
|
||||
goto error;
|
||||
|
||||
fat_file_close(parent_loc->mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
}
|
||||
return RC_OK;
|
||||
|
||||
error:
|
||||
fat_file_close(parent_loc->mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
|
||||
err:
|
||||
/* mark the used 32bytes structure on the disk as free */
|
||||
|
||||
@@ -170,7 +170,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
|
||||
* directories feature :( - we should count elements currently
|
||||
* present in the directory because there may be holes :)
|
||||
*/
|
||||
ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, (j * bts2rd),
|
||||
ret = fat_file_read(&fs_info->fat, fat_fd, (j * bts2rd),
|
||||
bts2rd, fs_info->cl_buf);
|
||||
if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)
|
||||
{
|
||||
@@ -314,7 +314,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
|
||||
*/
|
||||
|
||||
/* get number of cluster we are working with */
|
||||
rc = fat_file_ioctl(iop->pathinfo.mt_entry, fat_fd, F_CLU_NUM,
|
||||
rc = fat_file_ioctl(&fs_info->fat, fat_fd, F_CLU_NUM,
|
||||
j * bts2rd, &cur_cln);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
@@ -325,7 +325,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
|
||||
fat_dir_pos_init(&dir_pos);
|
||||
dir_pos.sname.cln = cur_cln;
|
||||
dir_pos.sname.ofs = i;
|
||||
rc = fat_file_open(iop->pathinfo.mt_entry, &dir_pos, &tmp_fat_fd);
|
||||
rc = fat_file_open(&fs_info->fat, &dir_pos, &tmp_fat_fd);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
rtems_semaphore_release(fs_info->vol_sema);
|
||||
@@ -377,7 +377,7 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
|
||||
count -= (sizeof(struct dirent));
|
||||
|
||||
/* inode number extracted, close fat-file */
|
||||
rc = fat_file_close(iop->pathinfo.mt_entry, tmp_fat_fd);
|
||||
rc = fat_file_close(&fs_info->fat, tmp_fat_fd);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
rtems_semaphore_release(fs_info->vol_sema);
|
||||
|
||||
@@ -115,7 +115,7 @@ msdos_file_read(rtems_libio_t *iop, void *buffer, size_t count)
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_set_errno_and_return_minus_one(EIO);
|
||||
|
||||
ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, iop->offset, count,
|
||||
ret = fat_file_read(&fs_info->fat, fat_fd, iop->offset, count,
|
||||
buffer);
|
||||
if (ret > 0)
|
||||
iop->offset += ret;
|
||||
@@ -153,7 +153,7 @@ msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count)
|
||||
if ((iop->flags & LIBIO_FLAGS_APPEND) != 0)
|
||||
iop->offset = fat_fd->fat_file_size;
|
||||
|
||||
ret = fat_file_write(iop->pathinfo.mt_entry, fat_fd, iop->offset, count,
|
||||
ret = fat_file_write(&fs_info->fat, fat_fd, iop->offset, count,
|
||||
buffer);
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -236,17 +236,17 @@ msdos_file_ftruncate(rtems_libio_t *iop, off_t length)
|
||||
|
||||
old_length = fat_fd->fat_file_size;
|
||||
if (length < old_length) {
|
||||
rc = fat_file_truncate(iop->pathinfo.mt_entry, fat_fd, length);
|
||||
rc = fat_file_truncate(&fs_info->fat, fat_fd, length);
|
||||
} else {
|
||||
uint32_t new_length;
|
||||
|
||||
rc = fat_file_extend(iop->pathinfo.mt_entry,
|
||||
rc = fat_file_extend(&fs_info->fat,
|
||||
fat_fd,
|
||||
true,
|
||||
length,
|
||||
&new_length);
|
||||
if (rc == RC_OK && length != new_length) {
|
||||
fat_file_truncate(iop->pathinfo.mt_entry, fat_fd, old_length);
|
||||
fat_file_truncate(&fs_info->fat, fat_fd, old_length);
|
||||
errno = ENOSPC;
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
@@ -31,5 +31,7 @@
|
||||
void
|
||||
msdos_free_node_info(const rtems_filesystem_location_info_t *pathloc)
|
||||
{
|
||||
fat_file_close(pathloc->mt_entry, pathloc->node_access);
|
||||
msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
|
||||
|
||||
fat_file_close(&fs_info->fat, pathloc->node_access);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry)
|
||||
fat_file_fd_t *fat_fd = temp_mt_entry->mt_fs_root->location.node_access;
|
||||
|
||||
/* close fat-file which correspondes to root directory */
|
||||
fat_file_close(temp_mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
|
||||
fat_shutdown_drive(temp_mt_entry);
|
||||
fat_shutdown_drive(&fs_info->fat);
|
||||
|
||||
rtems_semaphore_delete(fs_info->vol_sema);
|
||||
free(fs_info->cl_buf);
|
||||
|
||||
@@ -63,7 +63,7 @@ msdos_initialize_support(
|
||||
|
||||
temp_mt_entry->fs_info = fs_info;
|
||||
|
||||
rc = fat_init_volume_info(temp_mt_entry);
|
||||
rc = fat_init_volume_info(&fs_info->fat, temp_mt_entry->dev);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
free(fs_info);
|
||||
@@ -79,10 +79,10 @@ msdos_initialize_support(
|
||||
*/
|
||||
fat_dir_pos_init(&root_pos);
|
||||
root_pos.sname.cln = FAT_ROOTDIR_CLUSTER_NUM;
|
||||
rc = fat_file_open(temp_mt_entry, &root_pos, &fat_fd);
|
||||
rc = fat_file_open(&fs_info->fat, &root_pos, &fat_fd);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_shutdown_drive(temp_mt_entry);
|
||||
fat_shutdown_drive(&fs_info->fat);
|
||||
free(fs_info);
|
||||
return rc;
|
||||
}
|
||||
@@ -105,11 +105,11 @@ msdos_initialize_support(
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = fat_file_size(temp_mt_entry, fat_fd);
|
||||
rc = fat_file_size(&fs_info->fat, fat_fd);
|
||||
if ( rc != RC_OK )
|
||||
{
|
||||
fat_file_close(temp_mt_entry, fat_fd);
|
||||
fat_shutdown_drive(temp_mt_entry);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
fat_shutdown_drive(&fs_info->fat);
|
||||
free(fs_info);
|
||||
return rc;
|
||||
}
|
||||
@@ -119,8 +119,8 @@ msdos_initialize_support(
|
||||
fs_info->cl_buf = (uint8_t *)calloc(cl_buf_size, sizeof(char));
|
||||
if (fs_info->cl_buf == NULL)
|
||||
{
|
||||
fat_file_close(temp_mt_entry, fat_fd);
|
||||
fat_shutdown_drive(temp_mt_entry);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
fat_shutdown_drive(&fs_info->fat);
|
||||
free(fs_info);
|
||||
rtems_set_errno_and_return_minus_one(ENOMEM);
|
||||
}
|
||||
@@ -132,8 +132,8 @@ msdos_initialize_support(
|
||||
&fs_info->vol_sema);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
{
|
||||
fat_file_close(temp_mt_entry, fat_fd);
|
||||
fat_shutdown_drive(temp_mt_entry);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
fat_shutdown_drive(&fs_info->fat);
|
||||
free(fs_info->cl_buf);
|
||||
free(fs_info);
|
||||
rtems_set_errno_and_return_minus_one( EIO );
|
||||
|
||||
@@ -306,7 +306,7 @@ msdos_find_name(
|
||||
return MSDOS_NAME_NOT_FOUND_ERR;
|
||||
|
||||
/* open fat-file corresponded to the found node */
|
||||
rc = fat_file_open(parent_loc->mt_entry, &dir_pos, &fat_fd);
|
||||
rc = fat_file_open(&fs_info->fat, &dir_pos, &fat_fd);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -333,10 +333,10 @@ msdos_find_name(
|
||||
fat_fd->fat_file_type = FAT_DIRECTORY;
|
||||
fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
|
||||
|
||||
rc = fat_file_size(parent_loc->mt_entry, fat_fd);
|
||||
rc = fat_file_size(&fs_info->fat, fat_fd);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(parent_loc->mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -363,10 +363,10 @@ msdos_find_name(
|
||||
}
|
||||
|
||||
/* close fat-file corresponded to the node we searched in */
|
||||
rc = fat_file_close(parent_loc->mt_entry, parent_loc->node_access);
|
||||
rc = fat_file_close(&fs_info->fat, parent_loc->node_access);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(parent_loc->mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
/*
|
||||
* open fat-file corresponded to ".."
|
||||
*/
|
||||
rc = fat_file_open(mt_entry, dir_pos, &fat_fd);
|
||||
rc = fat_file_open(&fs_info->fat, dir_pos, &fat_fd);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -528,10 +528,10 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
fat_fd->map.file_cln = 0;
|
||||
fat_fd->map.disk_cln = fat_fd->cln;
|
||||
|
||||
rc = fat_file_size(mt_entry, fat_fd);
|
||||
rc = fat_file_size(&fs_info->fat, fat_fd);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -556,14 +556,14 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
cl4find = MSDOS_EXTRACT_CLUSTER_NUM(dot_node);
|
||||
|
||||
/* close fat-file corresponded to ".." directory */
|
||||
rc = fat_file_close(mt_entry, fat_fd);
|
||||
rc = fat_file_close(&fs_info->fat, fat_fd);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
|
||||
@@ -578,7 +578,7 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
}
|
||||
|
||||
/* open fat-file corresponded to second ".." */
|
||||
rc = fat_file_open(mt_entry, dir_pos, &fat_fd);
|
||||
rc = fat_file_open(&fs_info->fat, dir_pos, &fat_fd);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -593,10 +593,10 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
fat_fd->map.file_cln = 0;
|
||||
fat_fd->map.disk_cln = fat_fd->cln;
|
||||
|
||||
rc = fat_file_size(mt_entry, fat_fd);
|
||||
rc = fat_file_size(&fs_info->fat, fat_fd);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -605,10 +605,10 @@ msdos_get_dotdot_dir_info_cluster_num_and_offset(
|
||||
dir_pos, dir_entry);
|
||||
if (rc != RC_OK)
|
||||
{
|
||||
fat_file_close(mt_entry, fat_fd);
|
||||
fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
rc = fat_file_close(mt_entry, fat_fd);
|
||||
rc = fat_file_close(&fs_info->fat, fat_fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -644,18 +644,18 @@ msdos_set_dir_wrt_time_and_date(
|
||||
* calculate input for _fat_block_write: convert (cluster num, offset) to
|
||||
* (sector num, new offset)
|
||||
*/
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->dir_pos.sname.cln);
|
||||
sec = fat_cluster_num_to_sector_num(&fs_info->fat, fat_fd->dir_pos.sname.cln);
|
||||
sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
|
||||
/* byte points to start of 32bytes structure */
|
||||
byte = fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1);
|
||||
|
||||
time_val = CT_LE_W(time_val);
|
||||
ret1 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_WTIME_OFFSET,
|
||||
ret1 = _fat_block_write(&fs_info->fat, sec, byte + MSDOS_FILE_WTIME_OFFSET,
|
||||
2, (char *)(&time_val));
|
||||
date = CT_LE_W(date);
|
||||
ret2 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_WDATE_OFFSET,
|
||||
ret2 = _fat_block_write(&fs_info->fat, sec, byte + MSDOS_FILE_WDATE_OFFSET,
|
||||
2, (char *)(&date));
|
||||
ret3 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_ADATE_OFFSET,
|
||||
ret3 = _fat_block_write(&fs_info->fat, sec, byte + MSDOS_FILE_ADATE_OFFSET,
|
||||
2, (char *)(&date));
|
||||
|
||||
if ( (ret1 < 0) || (ret2 < 0) || (ret3 < 0) )
|
||||
@@ -694,17 +694,17 @@ msdos_set_first_cluster_num(
|
||||
* calculate input for _fat_block_write: convert (cluster num, offset) to
|
||||
* (sector num, new offset)
|
||||
*/
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->dir_pos.sname.cln);
|
||||
sec = fat_cluster_num_to_sector_num(&fs_info->fat, fat_fd->dir_pos.sname.cln);
|
||||
sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
|
||||
/* byte from points to start of 32bytes structure */
|
||||
byte = fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1);
|
||||
|
||||
le_cl_low = CT_LE_W((uint16_t )(new_cln & 0x0000FFFF));
|
||||
ret1 = _fat_block_write(mt_entry, sec,
|
||||
ret1 = _fat_block_write(&fs_info->fat, sec,
|
||||
byte + MSDOS_FIRST_CLUSTER_LOW_OFFSET, 2,
|
||||
(char *)(&le_cl_low));
|
||||
le_cl_hi = CT_LE_W((uint16_t )((new_cln & 0xFFFF0000) >> 16));
|
||||
ret2 = _fat_block_write(mt_entry, sec,
|
||||
ret2 = _fat_block_write(&fs_info->fat, sec,
|
||||
byte + MSDOS_FIRST_CLUSTER_HI_OFFSET, 2,
|
||||
(char *)(&le_cl_hi));
|
||||
if ( (ret1 < 0) || (ret2 < 0) )
|
||||
@@ -737,12 +737,12 @@ msdos_set_file_size(
|
||||
uint32_t sec = 0;
|
||||
uint32_t byte = 0;
|
||||
|
||||
sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->dir_pos.sname.cln);
|
||||
sec = fat_cluster_num_to_sector_num(&fs_info->fat, fat_fd->dir_pos.sname.cln);
|
||||
sec += (fat_fd->dir_pos.sname.ofs >> fs_info->fat.vol.sec_log2);
|
||||
byte = (fat_fd->dir_pos.sname.ofs & (fs_info->fat.vol.bps - 1));
|
||||
|
||||
le_new_length = CT_LE_L((fat_fd->fat_file_size));
|
||||
ret = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_SIZE_OFFSET, 4,
|
||||
ret = _fat_block_write(&fs_info->fat, sec, byte + MSDOS_FILE_SIZE_OFFSET, 4,
|
||||
(char *)(&le_new_length));
|
||||
if ( ret < 0 )
|
||||
return -1;
|
||||
@@ -798,12 +798,12 @@ msdos_set_first_char4file_name(
|
||||
*/
|
||||
while (true)
|
||||
{
|
||||
uint32_t sec = (fat_cluster_num_to_sector_num(mt_entry, start.cln) +
|
||||
uint32_t sec = (fat_cluster_num_to_sector_num(&fs_info->fat, start.cln) +
|
||||
(start.ofs >> fs_info->fat.vol.sec_log2));
|
||||
uint32_t byte = (start.ofs & (fs_info->fat.vol.bps - 1));
|
||||
|
||||
ret = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_NAME_OFFSET, 1,
|
||||
&fchar);
|
||||
ret = _fat_block_write(&fs_info->fat, sec, byte + MSDOS_FILE_NAME_OFFSET,
|
||||
1, &fchar);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
@@ -817,7 +817,7 @@ msdos_set_first_char4file_name(
|
||||
if ((end.cln == fs_info->fat.vol.rdir_cl) &&
|
||||
(fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16)))
|
||||
break;
|
||||
rc = fat_get_fat_cluster(mt_entry, start.cln, &start.cln);
|
||||
rc = fat_get_fat_cluster(&fs_info->fat, start.cln, &start.cln);
|
||||
if ( rc != RC_OK )
|
||||
return rc;
|
||||
start.ofs = 0;
|
||||
@@ -854,7 +854,7 @@ msdos_dir_is_empty(
|
||||
/* dir is not empty */
|
||||
*ret_val = false;
|
||||
|
||||
while ((ret = fat_file_read(mt_entry, fat_fd, j * fs_info->fat.vol.bps,
|
||||
while ((ret = fat_file_read(&fs_info->fat, fat_fd, j * fs_info->fat.vol.bps,
|
||||
fs_info->fat.vol.bps,
|
||||
fs_info->cl_buf)) != FAT_EOF)
|
||||
{
|
||||
@@ -998,7 +998,7 @@ int msdos_find_name_in_fat_file(
|
||||
* doing this see if a suitable location can be found to
|
||||
* create the entry if the name is not found.
|
||||
*/
|
||||
while ((ret = fat_file_read(mt_entry, fat_fd, (dir_offset * bts2rd),
|
||||
while ((ret = fat_file_read(&fs_info->fat, fat_fd, (dir_offset * bts2rd),
|
||||
bts2rd, fs_info->cl_buf)) != FAT_EOF)
|
||||
{
|
||||
bool remainder_empty = false;
|
||||
@@ -1282,7 +1282,7 @@ int msdos_find_name_in_fat_file(
|
||||
* We get the entry we looked for - fill the position
|
||||
* structure and the 32 bytes of the short entry
|
||||
*/
|
||||
int rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
|
||||
int rc = fat_file_ioctl(&fs_info->fat, fat_fd, F_CLU_NUM,
|
||||
dir_offset * bts2rd,
|
||||
&dir_pos->sname.cln);
|
||||
if (rc != RC_OK)
|
||||
@@ -1292,7 +1292,7 @@ int msdos_find_name_in_fat_file(
|
||||
|
||||
if (lfn_start.cln != FAT_FILE_SHORT_NAME)
|
||||
{
|
||||
rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
|
||||
rc = fat_file_ioctl(&fs_info->fat, fat_fd, F_CLU_NUM,
|
||||
lfn_start.cln * bts2rd,
|
||||
&lfn_start.cln);
|
||||
if (rc != RC_OK)
|
||||
@@ -1397,7 +1397,7 @@ int msdos_find_name_in_fat_file(
|
||||
#if MSDOS_FIND_PRINT
|
||||
printf ("MSFS:[9.1] eso:%li\n", empty_space_offset);
|
||||
#endif
|
||||
ret = fat_file_read(mt_entry, fat_fd,
|
||||
ret = fat_file_read(&fs_info->fat, fat_fd,
|
||||
(empty_space_offset * bts2rd), bts2rd,
|
||||
fs_info->cl_buf);
|
||||
|
||||
@@ -1409,7 +1409,7 @@ int msdos_find_name_in_fat_file(
|
||||
#if MSDOS_FIND_PRINT
|
||||
printf ("MSFS:[9.2] extending file:%li\n", empty_space_offset);
|
||||
#endif
|
||||
ret = fat_file_extend (mt_entry, fat_fd, false,
|
||||
ret = fat_file_extend (&fs_info->fat, fat_fd, false,
|
||||
empty_space_offset * bts2rd, &new_length);
|
||||
|
||||
if (ret != RC_OK)
|
||||
@@ -1423,7 +1423,7 @@ int msdos_find_name_in_fat_file(
|
||||
|
||||
memset(fs_info->cl_buf, 0, bts2rd);
|
||||
|
||||
ret = fat_file_write(mt_entry, fat_fd,
|
||||
ret = fat_file_write(&fs_info->fat, fat_fd,
|
||||
empty_space_offset * bts2rd,
|
||||
bts2rd, fs_info->cl_buf);
|
||||
#if MSDOS_FIND_PRINT
|
||||
@@ -1464,7 +1464,7 @@ int msdos_find_name_in_fat_file(
|
||||
if (lfn_entry == (lfn_entries + 1))
|
||||
{
|
||||
/* get current cluster number */
|
||||
int rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
|
||||
int rc = fat_file_ioctl(&fs_info->fat, fat_fd, F_CLU_NUM,
|
||||
empty_space_offset * bts2rd,
|
||||
&dir_pos->sname.cln);
|
||||
if (rc != RC_OK)
|
||||
@@ -1474,7 +1474,7 @@ int msdos_find_name_in_fat_file(
|
||||
|
||||
if (lfn_start.cln != FAT_FILE_SHORT_NAME)
|
||||
{
|
||||
rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM,
|
||||
rc = fat_file_ioctl(&fs_info->fat, fat_fd, F_CLU_NUM,
|
||||
lfn_start.cln * bts2rd,
|
||||
&lfn_start.cln);
|
||||
if (rc != RC_OK)
|
||||
@@ -1546,7 +1546,7 @@ int msdos_find_name_in_fat_file(
|
||||
*MSDOS_DIR_ATTR(entry) |= MSDOS_ATTR_LFN;
|
||||
}
|
||||
|
||||
ret = fat_file_write(mt_entry, fat_fd,
|
||||
ret = fat_file_write(&fs_info->fat, fat_fd,
|
||||
(empty_space_offset * bts2rd) + empty_space_entry,
|
||||
length, fs_info->cl_buf + empty_space_entry);
|
||||
if (ret == -1)
|
||||
@@ -1600,7 +1600,7 @@ int msdos_find_node_by_cluster_num_in_fat_file(
|
||||
else
|
||||
bts2rd = fs_info->fat.vol.bpc;
|
||||
|
||||
while ((ret = fat_file_read(mt_entry, fat_fd, j * bts2rd, bts2rd,
|
||||
while ((ret = fat_file_read(&fs_info->fat, fat_fd, j * bts2rd, bts2rd,
|
||||
fs_info->cl_buf)) != FAT_EOF)
|
||||
{
|
||||
if ( ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE )
|
||||
@@ -1626,7 +1626,7 @@ int msdos_find_node_by_cluster_num_in_fat_file(
|
||||
if (MSDOS_EXTRACT_CLUSTER_NUM(entry) == cl4find)
|
||||
{
|
||||
/* on success fill aux structure and copy all 32 bytes */
|
||||
rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM, j * bts2rd,
|
||||
rc = fat_file_ioctl(&fs_info->fat, fat_fd, F_CLU_NUM, j * bts2rd,
|
||||
&dir_pos->sname.cln);
|
||||
if (rc != RC_OK)
|
||||
return rc;
|
||||
|
||||
@@ -20,6 +20,7 @@ msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
|
||||
const rtems_filesystem_location_info_t *pathloc)
|
||||
{
|
||||
int rc = RC_OK;
|
||||
msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info;
|
||||
fat_file_fd_t *fat_fd = pathloc->node_access;
|
||||
|
||||
if (fat_fd->fat_file_type == MSDOS_DIRECTORY)
|
||||
@@ -71,7 +72,7 @@ msdos_rmnod(const rtems_filesystem_location_info_t *parent_pathloc,
|
||||
return rc;
|
||||
}
|
||||
|
||||
fat_file_mark_removed(pathloc->mt_entry, fat_fd);
|
||||
fat_file_mark_removed(&fs_info->fat, fat_fd);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user