From a43a34666e2124c24e86794206aa78d2ad5e910d Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sun, 15 Feb 2015 10:38:15 +0100 Subject: IMFS: Implement variable length node names This reduces the average node size and adds more flexibility. --- cpukit/libfs/src/imfs/imfs_rename.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'cpukit/libfs/src/imfs/imfs_rename.c') 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; } -- cgit v1.2.3