summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/dosfs/fat_file.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-07-07 15:46:33 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-07-11 17:14:51 +0200
commitc65afce4300a14c77dd8b7557e919af5afd8d18a (patch)
tree88c9d614ce67ac893d9800f3a145b5a877b1e039 /cpukit/libfs/src/dosfs/fat_file.c
parentbsps/lm32: PR2045: Add mic boost option (diff)
downloadrtems-c65afce4300a14c77dd8b7557e919af5afd8d18a.tar.bz2
dosfs: Use fs_info instead of mt_entry
Diffstat (limited to 'cpukit/libfs/src/dosfs/fat_file.c')
-rw-r--r--cpukit/libfs/src/dosfs/fat_file.c137
1 files changed, 64 insertions, 73 deletions
diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c
index 88f8e5b571..ddbe02ceb8 100644
--- a/cpukit/libfs/src/dosfs/fat_file.c
+++ b/cpukit/libfs/src/dosfs/fat_file.c
@@ -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;
}