From 8851c0a5ef60f8ed98ceda73f9430e023e823a57 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 2 Aug 2010 18:27:23 +0000 Subject: 2010-08-02 Joel Sherrill * libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_readlink.c, libfs/src/pipe/fifo.c: Clean up for coverage improvements and formatting. --- cpukit/ChangeLog | 7 +++++ cpukit/libfs/src/imfs/imfs_creat.c | 50 +++++++++++++---------------------- cpukit/libfs/src/imfs/imfs_eval.c | 38 +++++++++----------------- cpukit/libfs/src/imfs/imfs_mknod.c | 17 +++--------- cpukit/libfs/src/imfs/imfs_readlink.c | 3 +-- cpukit/libfs/src/pipe/fifo.c | 21 ++++++++------- 6 files changed, 54 insertions(+), 82 deletions(-) diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 979f967b78..7a9160d4c6 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,10 @@ +2010-08-02 Joel Sherrill + + * libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_eval.c, + libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_readlink.c, + libfs/src/pipe/fifo.c: Clean up for coverage improvements and + formatting. + 2010-08-02 Joel Sherrill * libmisc/stackchk/check.c: If this port does not allocate the diff --git a/cpukit/libfs/src/imfs/imfs_creat.c b/cpukit/libfs/src/imfs/imfs_creat.c index a33f3c580b..e8e3ef10a0 100644 --- a/cpukit/libfs/src/imfs/imfs_creat.c +++ b/cpukit/libfs/src/imfs/imfs_creat.c @@ -64,42 +64,28 @@ IMFS_jnode_t *IMFS_create_node( /* * Set the type specific information */ - switch (type) { - case IMFS_DIRECTORY: - rtems_chain_initialize_empty(&node->info.directory.Entries); - break; - - case IMFS_HARD_LINK: - node->info.hard_link.link_node = info->hard_link.link_node; - break; - - case IMFS_SYM_LINK: - node->info.sym_link.name = info->sym_link.name; - break; - - case IMFS_DEVICE: - node->info.device.major = info->device.major; - node->info.device.minor = info->device.minor; - break; - - case IMFS_LINEAR_FILE: - node->info.linearfile.size = 0; - node->info.linearfile.direct = 0; - - case IMFS_MEMORY_FILE: + if ( type == IMFS_DIRECTORY ) { + rtems_chain_initialize_empty(&node->info.directory.Entries); + } else if ( type == IMFS_HARD_LINK ) { + node->info.hard_link.link_node = info->hard_link.link_node; + } else if ( type == IMFS_SYM_LINK ) { + node->info.sym_link.name = info->sym_link.name; + } else if ( type == IMFS_DEVICE ) { + node->info.device.major = info->device.major; + node->info.device.minor = info->device.minor; + } else if ( type == IMFS_LINEAR_FILE ) { + node->info.linearfile.size = 0; + node->info.linearfile.direct = 0; + if ( type == IMFS_MEMORY_FILE ) { node->info.file.size = 0; node->info.file.indirect = 0; node->info.file.doubly_indirect = 0; node->info.file.triply_indirect = 0; - break; - - case IMFS_FIFO: - node->info.fifo.pipe = NULL; - break; - - default: - IMFS_assert(0); - break; + } + } else if ( type == IMFS_FIFO ) { + node->info.fifo.pipe = NULL; + } else { + IMFS_assert(0); } /* diff --git a/cpukit/libfs/src/imfs/imfs_eval.c b/cpukit/libfs/src/imfs/imfs_eval.c index 8692024e14..c081953c8d 100644 --- a/cpukit/libfs/src/imfs/imfs_eval.c +++ b/cpukit/libfs/src/imfs/imfs_eval.c @@ -70,7 +70,6 @@ int IMFS_Set_handlers( * The following routine evaluates that we have permission * to do flags on the node. */ - int IMFS_evaluate_permission( rtems_filesystem_location_info_t *node, int flags @@ -136,14 +135,11 @@ int IMFS_evaluate_hard_link( /* * Check for things that should never happen. */ - - if ( jnode->type != IMFS_HARD_LINK ) - rtems_fatal_error_occurred (0xABCD0000); + IMFS_assert( jnode->type == IMFS_HARD_LINK ); /* * Set the hard link value and the handlers. */ - node->node_access = jnode->info.hard_link.link_node; IMFS_Set_handlers( node ); @@ -177,19 +173,13 @@ int IMFS_evaluate_sym_link( /* * Check for things that should never happen. */ - - if ( jnode->type != IMFS_SYM_LINK ) - rtems_fatal_error_occurred (0xABCD0000); - - if ( !jnode->Parent ) - rtems_fatal_error_occurred( 0xBAD00000 ); - + IMFS_assert( jnode->type == IMFS_SYM_LINK ) + IMFS_assert( jnode->Parent ) /* * Move the node_access to either the symbolic links parent or * root depending on the symbolic links path. */ - node->node_access = jnode->Parent; rtems_filesystem_get_sym_start_loc( @@ -201,7 +191,6 @@ int IMFS_evaluate_sym_link( /* * Use eval path to evaluate the path of the symbolic link. */ - result = IMFS_eval_path( &jnode->info.sym_link.name[i], strlen( &jnode->info.sym_link.name[i] ), @@ -214,7 +203,6 @@ int IMFS_evaluate_sym_link( /* * Verify we have the correct permissions for this node. */ - if ( !IMFS_evaluate_permission( node, flags ) ) rtems_set_errno_and_return_minus_one( EACCES ); @@ -226,7 +214,6 @@ int IMFS_evaluate_sym_link( * * The following routine returns the real node pointed to by a link. */ - int IMFS_evaluate_link( rtems_filesystem_location_info_t *node, /* IN/OUT */ int flags /* IN */ @@ -578,19 +565,23 @@ int IMFS_eval_path( /* * If we are at a link follow it. */ - if ( node->type == IMFS_HARD_LINK ) { - IMFS_evaluate_hard_link( pathloc, 0 ); - node = pathloc->node_access; - if ( !node ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); + + /* + * It would be a design error if we evaluated the link and + * was broken. + */ + IMFS_assert( node ); } else if ( node->type == IMFS_SYM_LINK ) { - result = IMFS_evaluate_sym_link( pathloc, 0 ); + /* + * In contrast to a hard link, it is possible to have a broken + * symbolic link. + */ node = pathloc->node_access; if ( result == -1 ) return -1; @@ -599,7 +590,6 @@ int IMFS_eval_path( /* * Only a directory can be decended into. */ - if ( node->type != IMFS_DIRECTORY ) rtems_set_errno_and_return_minus_one( ENOTDIR ); @@ -607,7 +597,6 @@ int IMFS_eval_path( * If we are at a node that is a mount point. Set loc to the * new fs root node and let them finish evaluating the path. */ - if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; @@ -619,7 +608,6 @@ int IMFS_eval_path( /* * Otherwise find the token name in the present location. */ - node = IMFS_find_match_in_dir( node, token ); if ( !node ) rtems_set_errno_and_return_minus_one( ENOENT ); diff --git a/cpukit/libfs/src/imfs/imfs_mknod.c b/cpukit/libfs/src/imfs/imfs_mknod.c index 28ca79e201..1a0175af0a 100644 --- a/cpukit/libfs/src/imfs/imfs_mknod.c +++ b/cpukit/libfs/src/imfs/imfs_mknod.c @@ -53,12 +53,10 @@ int IMFS_mknod( else if ( S_ISBLK(mode) || S_ISCHR(mode) ) { type = IMFS_DEVICE; rtems_filesystem_split_dev_t( dev, info.device.major, info.device.minor ); - } - else if (S_ISFIFO(mode)) + } else if (S_ISFIFO(mode)) type = IMFS_FIFO; - else { - rtems_set_errno_and_return_minus_one( EINVAL ); - } + else + IMFS_assert( 0 ); /* * Allocate and fill in an IMFS jnode @@ -70,14 +68,7 @@ int IMFS_mknod( * existed. The result was simpler code which should not have * this path. */ - new_node = IMFS_create_node( - pathloc, - type, - new_name, - mode, - &info - ); - + new_node = IMFS_create_node( pathloc, type, new_name, mode, &info ); if ( !new_node ) rtems_set_errno_and_return_minus_one( ENOMEM ); diff --git a/cpukit/libfs/src/imfs/imfs_readlink.c b/cpukit/libfs/src/imfs/imfs_readlink.c index 6b3d1acafe..3e5f0d943c 100644 --- a/cpukit/libfs/src/imfs/imfs_readlink.c +++ b/cpukit/libfs/src/imfs/imfs_readlink.c @@ -34,8 +34,7 @@ int IMFS_readlink( node = loc->node_access; - if ( node->type != IMFS_SYM_LINK ) - rtems_set_errno_and_return_minus_one( EINVAL ); + IMFS_assert( node->type == IMFS_SYM_LINK ); for( i=0; ((iinfo.sym_link.name[i] != '\0')); i++ ) buf[i] = node->info.sym_link.name[i]; diff --git a/cpukit/libfs/src/pipe/fifo.c b/cpukit/libfs/src/pipe/fifo.c index 38b90ed36e..a19ef617a3 100644 --- a/cpukit/libfs/src/pipe/fifo.c +++ b/cpukit/libfs/src/pipe/fifo.c @@ -190,10 +190,11 @@ static void pipe_unlock(void) rtems_status_code sc = RTEMS_SUCCESSFUL; sc = rtems_semaphore_release(pipe_semaphore); - if (sc != RTEMS_SUCCESSFUL) { - /* FIXME */ - rtems_fatal_error_occurred(0xdeadbeef); - } + #ifdef RTEMS_DEBUG + if (sc != RTEMS_SUCCESSFUL) { + rtems_fatal_error_occurred(0xdeadbeef); + } + #endif } /* @@ -248,15 +249,15 @@ int pipe_release( pipe_control_t *pipe = *pipep; uint32_t mode; - if (pipe_lock()) + #if defined(RTEMS_DEBUG) /* WARN pipe not freed and pipep not set to NULL! */ - /* FIXME */ - rtems_fatal_error_occurred(0xdeadbeef); + if (pipe_lock()) + rtems_fatal_error_occurred(0xdeadbeef); - if (!PIPE_LOCK(pipe)) /* WARN pipe not released! */ - /* FIXME */ - rtems_fatal_error_occurred(0xdeadbeef); + if (!PIPE_LOCK(pipe)) + rtems_fatal_error_occurred(0xdeadbeef); + #endif mode = LIBIO_ACCMODE(iop); if (mode & LIBIO_FLAGS_READ) -- cgit v1.2.3