summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/imfs/imfs_rename.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-02-15 10:38:15 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-02-15 11:26:39 +0100
commita43a34666e2124c24e86794206aa78d2ad5e910d (patch)
tree9cee489e9763ab32904bad5eef921c3411d7ca3f /cpukit/libfs/src/imfs/imfs_rename.c
parentIMFS: Add CONFIGURE_IMFS_DISABLE_READDIR (diff)
downloadrtems-a43a34666e2124c24e86794206aa78d2ad5e910d.tar.bz2
IMFS: Implement variable length node names
This reduces the average node size and adds more flexibility.
Diffstat (limited to '')
-rw-r--r--cpukit/libfs/src/imfs/imfs_rename.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_rename.c b/cpukit/libfs/src/imfs/imfs_rename.c
index 46ef674075..b8f64c4ac1 100644
--- a/cpukit/libfs/src/imfs/imfs_rename.c
+++ b/cpukit/libfs/src/imfs/imfs_rename.c
@@ -30,31 +30,41 @@ int IMFS_rename(
size_t namelen
)
{
- int rv = 0;
IMFS_jnode_t *node = oldloc->node_access;
IMFS_jnode_t *new_parent = newparentloc->node_access;
+ char *allocated_name;
/*
* FIXME: Due to insufficient checks we can create inaccessible nodes with
* this operation.
*/
- if ( node->Parent != NULL ) {
- if ( namelen < IMFS_NAME_MAX ) {
- memcpy( node->name, name, namelen );
- node->name [namelen] = '\0';
-
- IMFS_remove_from_directory( node );
- IMFS_add_to_directory( new_parent, node );
- IMFS_update_ctime( node );
- } else {
- errno = ENAMETOOLONG;
- rv = -1;
- }
- } else {
- errno = EINVAL;
- rv = -1;
+ if ( node->Parent == NULL ) {
+ rtems_set_errno_and_return_minus_one( EINVAL );
}
- return rv;
+ if ( namelen >= IMFS_NAME_MAX ) {
+ rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
+ }
+
+ allocated_name = malloc( namelen );
+ if ( allocated_name == NULL ) {
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ memcpy( allocated_name, name, namelen );
+
+ if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
+ free( node->name );
+ }
+
+ node->name = allocated_name;
+ node->namelen = namelen;
+ node->flags |= IMFS_NODE_FLAG_NAME_ALLOCATED;
+
+ IMFS_remove_from_directory( node );
+ IMFS_add_to_directory( new_parent, node );
+ IMFS_update_ctime( node );
+
+ return 0;
}