From b489cd9610f953c13d75eb79d1c3b46df565aca2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 9 Oct 2015 15:17:32 -0600 Subject: [PATCH] TMFPS: Now basically functional although not heavily tested --- ChangeLog | 4 ++-- Documentation | 2 +- fs/tmpfs/Kconfig | 2 +- fs/tmpfs/fs_tmpfs.c | 27 +++++++++++++++++++-------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93e17112f5..887081c9b4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11019,5 +11019,5 @@ README file for more info (2015-10-08). * stm32 F4: Fix some TIM12 pin mappings. From Max Kriegleder (2015-10-9). - * fs/tmpfs: TMPFS file system is code complete, but not yet functional - (2015-10-9). + * fs/tmpfs: TMPFS file system is code complete and bascially functional + although it has not been heavilay tested (2015-10-9). diff --git a/Documentation b/Documentation index b705a3fefb..7a768453c1 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit b705a3fefb00ce13be249f47a17d80cdfa7bf71c +Subproject commit 7a768453c1ca9602d668c79d45db141b74d5c215 diff --git a/fs/tmpfs/Kconfig b/fs/tmpfs/Kconfig index c1f1220703..2d75fd11e6 100644 --- a/fs/tmpfs/Kconfig +++ b/fs/tmpfs/Kconfig @@ -6,7 +6,7 @@ config FS_TMPFS bool "TMPFS file system" default n - depends on !DISABLE_MOUNTPOINT && EXPERIMENTAL + depends on !DISABLE_MOUNTPOINT select FS_READABLE select FS_WRITABLE ---help--- diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 639177936c..2d28fa293d 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -667,6 +667,8 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, name = copy; parent = fs->tfs_root; + /* Lock the root directory to emulate the behavior of tmpfs_find_directory() */ + tmpfs_lock_directory(parent); parent->tdo_refs++; } @@ -677,7 +679,7 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, *name++ = '\0'; /* Locate the parent directory that should contain this name. - * On success, tmpfs_find_directory() will lockthe parent + * On success, tmpfs_find_directory() will lock the parent * directory and increment the reference count. */ @@ -724,6 +726,11 @@ static int tmpfs_create_file(FAR struct tmpfs_s *fs, goto errout_with_file; } + /* Release the reference and lock on the parent directory */ + + parent->tdo_refs--; + tmpfs_unlock_directory(parent); + /* Free the copy of the relpath and return success */ kmm_free(copy); @@ -856,8 +863,8 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, goto errout_with_parent; } - /* Allocate an empty directory object. There is no reference on the new - * directory and the object is not locked. + /* Allocate an empty directory object. NOTE that there is no reference on + * the new directory and the object is not locked. */ newtdo = tmpfs_alloc_directory(); @@ -883,7 +890,13 @@ static int tmpfs_create_directory(FAR struct tmpfs_s *fs, tmpfs_unlock_directory(parent); kmm_free(copy); - *tdo = newtdo; + /* Return the (unlocked, unreferenced) directory object to the caller */ + + if (tdo != NULL) + { + *tdo = newtdo; + } + return OK; /* Error exits */ @@ -1263,12 +1276,12 @@ static int tmpfs_foreach(FAR struct tmpfs_directory_s *tdo, { /* Lock the object and take a reference */ + to = tdo->tdo_entry[index].tde_object; tmpfs_lock_object(to); to->to_refs++; /* Is the next entry a directory? */ - to = tdo->tdo_entry[index].tde_object; if (to->to_type == TMPFS_DIRECTORY) { FAR struct tmpfs_directory_s *next = @@ -2159,9 +2172,7 @@ static int tmpfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, tmpfs_lock(fs); - /* Create the directory. This will lock the newly directory with a - * a reference count of one. - */ + /* Create the directory. */ ret = tmpfs_create_directory(fs, relpath, NULL); tmpfs_unlock(fs);