summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-14 08:13:07 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-03-21 16:14:53 +0100
commit201f3797b32033fc23c6448fe8f04c4e16344588 (patch)
tree83439d5d5d182592d74dbf115135061cd5db6684
parentc38f1fcf8f0fab90785b0aec4361d53673bbc864 (diff)
downloadrtems-201f3797b32033fc23c6448fe8f04c4e16344588.tar.bz2
dosfs: Simplify msdos_creat_node()
Update #2929.
-rw-r--r--cpukit/libfs/src/dosfs/msdos_create.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/cpukit/libfs/src/dosfs/msdos_create.c b/cpukit/libfs/src/dosfs/msdos_create.c
index 33bef0876f..344af6801a 100644
--- a/cpukit/libfs/src/dosfs/msdos_create.c
+++ b/cpukit/libfs/src/dosfs/msdos_create.c
@@ -179,6 +179,8 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
*/
if (type == FAT_DIRECTORY)
{
+ uint32_t unused;
+
/* open new directory as fat-file */
rc = fat_file_open(&fs_info->fat, &dir_pos, &fat_fd);
if (rc != RC_OK)
@@ -188,11 +190,19 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
* we opened fat-file for node we just created, so initialize fat-file
* descritor
*/
- fat_fd->fat_file_size = 0;
fat_fd->fat_file_type = FAT_DIRECTORY;
fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
fat_file_set_ctime_mtime(fat_fd, now);
+ /* extend it to contain exactly one cluster */
+ rc = fat_file_extend(&fs_info->fat,
+ fat_fd,
+ true,
+ fs_info->fat.vol.bpc,
+ &unused);
+ if (rc != RC_OK)
+ goto err;
+
/*
* dot and dotdot entries are identical to new node except the
* names
@@ -226,33 +236,16 @@ msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
CT_LE_W((uint16_t )(((parent_fat_fd->cln) & 0xFFFF0000)>>16));
}
- /*
- * write dot and dotdot entries to new fat-file: currently fat-file
- * 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(&fs_info->fat, fat_fd, 0,
- MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2,
- (uint8_t *)dot_dotdot);
- if (ret < 0)
- {
- rc = -1;
- goto error;
- }
-
- /* increment fat-file size by cluster size */
- fat_fd->fat_file_size += fs_info->fat.vol.bpc;
-
/* set up cluster num for dot entry */
*MSDOS_DIR_FIRST_CLUSTER_LOW(DOT_NODE_P(dot_dotdot)) =
CT_LE_W((uint16_t )((fat_fd->cln) & 0x0000FFFF));
*MSDOS_DIR_FIRST_CLUSTER_HI(DOT_NODE_P(dot_dotdot)) =
CT_LE_W((uint16_t )(((fat_fd->cln) & 0xFFFF0000) >> 16));
- /* rewrite dot entry */
+ /* write dot and dotdot entries */
ret = fat_file_write(&fs_info->fat, fat_fd, 0,
- MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE,
- (uint8_t *)DOT_NODE_P(dot_dotdot));
+ MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2,
+ (uint8_t *)dot_dotdot);
if (ret < 0)
{
rc = -1;