From 7baa484300d36a9ced34f6642501f91fd1428461 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Fri, 12 Jun 2009 01:53:33 +0000 Subject: 2009-06-12 Chris Johns * libblock/src/bdbuf.c: Update comments. * libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the device from the rdev field of the stat buf. * libcsupport/include/rtems/libio.h: Add a path length to evalpath handler. Add parent locations to rmmod and unlink handlers. * libcsupport/include/rtems/libio_.h: Add a path length to rtems_filesystem_evaluate_path. Add rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname, and rtems_filesystem_prefix_separators. Remove rtems_filesystem_evaluate_parent. * libcsupport/src/base_fs.c, libcsupport/src/chdir.c, libcsupport/src/chmod.c, libcsupport/src/chown.c, libcsupport/src/chroot.c, libcsupport/src/fchdir.c, libcsupport/src/link.c, libcsupport/src/mount.c, libcsupport/src/open.c, libcsupport/src/privateenv.c, libcsupport/src/readlink.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c, libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c, libnetworking/lib/ftpfs.c: Add the length parameter to the eval call. * libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators, rtems_filesystem_dirname, rtems_filesystem_evaluate_relative_path. Add the length parameter to the eval call. * libcsupport/src/rmdir.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc. * libcsupport/src/stat.c: Add the length parameter to the eval call. Set the device into the rdev field. * libcsupport/src/unlink.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc. * libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the disk device number from the stat rdev field. * libfs/src/dosfs/msdos.h: Add the length parameter to the eval call. Add the parent pathloc to the rmnod handler. * libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod handler. * libfs/src/dosfs/msdos_eval.c: Add the length parameter to the eval and token call. * libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the rmnod handler. * libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for only the allowed flags. Add the missing flags spec'ed in the POSIX standard. * libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c, libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the parent node. Currently ignored in the IMFS. * libfs/src/imfs/imfs_stat.c: Return the device number in the rdev field. * libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add the length parameter to the token call. * libfs/src/nfsclient/src/nfs.c: Add the length parameter to the eval call and parent node to the rmnod and unlink command. * libmisc/shell/internal.h: Remove the libc mounter decl to make public. * libmisc/shell/main_mount.c: Add support for hooking external mount support for new file systems. * libmisc/shell/shell.h: Add helper functions for the mount command. --- cpukit/ChangeLog | 68 +++++++++++++++++++++++++ cpukit/libblock/src/bdbuf.c | 25 +++++---- cpukit/libblock/src/bdpart.c | 5 +- cpukit/libblock/src/ide_part_table.c | 2 +- cpukit/libcsupport/include/rtems/libio.h | 8 ++- cpukit/libcsupport/include/rtems/libio_.h | 19 +++++-- cpukit/libcsupport/src/base_fs.c | 4 +- cpukit/libcsupport/src/chdir.c | 2 +- cpukit/libcsupport/src/chmod.c | 2 +- cpukit/libcsupport/src/chown.c | 2 +- cpukit/libcsupport/src/chroot.c | 2 +- cpukit/libcsupport/src/eval.c | 84 +++++++++++++++++++++++-------- cpukit/libcsupport/src/fchdir.c | 2 +- cpukit/libcsupport/src/link.c | 3 +- cpukit/libcsupport/src/mount.c | 2 +- cpukit/libcsupport/src/open.c | 4 +- cpukit/libcsupport/src/privateenv.c | 4 +- cpukit/libcsupport/src/readlink.c | 3 +- cpukit/libcsupport/src/rmdir.c | 44 ++++++++++++---- cpukit/libcsupport/src/stat.c | 3 +- cpukit/libcsupport/src/unlink.c | 48 ++++++++++++++---- cpukit/libcsupport/src/unmount.c | 2 +- cpukit/libcsupport/src/utime.c | 2 +- cpukit/libfs/src/devfs/devfs.h | 1 + cpukit/libfs/src/devfs/devfs_eval.c | 3 +- cpukit/libfs/src/devfs/devstat.c | 2 +- cpukit/libfs/src/dosfs/fat.c | 4 +- cpukit/libfs/src/dosfs/msdos.h | 14 ++++-- cpukit/libfs/src/dosfs/msdos_create.c | 2 +- cpukit/libfs/src/dosfs/msdos_dir.c | 3 +- cpukit/libfs/src/dosfs/msdos_eval.c | 7 ++- cpukit/libfs/src/dosfs/msdos_file.c | 3 +- cpukit/libfs/src/dosfs/msdos_format.c | 2 +- cpukit/libfs/src/dosfs/msdos_misc.c | 9 ++-- cpukit/libfs/src/imfs/imfs.h | 14 ++++-- cpukit/libfs/src/imfs/imfs_directory.c | 3 +- cpukit/libfs/src/imfs/imfs_eval.c | 29 ++++++++--- cpukit/libfs/src/imfs/imfs_fchmod.c | 6 +-- cpukit/libfs/src/imfs/imfs_fsunmount.c | 4 +- cpukit/libfs/src/imfs/imfs_gtkn.c | 5 +- cpukit/libfs/src/imfs/imfs_link.c | 2 +- cpukit/libfs/src/imfs/imfs_load_tar.c | 3 +- cpukit/libfs/src/imfs/imfs_mknod.c | 2 +- cpukit/libfs/src/imfs/imfs_rmnod.c | 3 +- cpukit/libfs/src/imfs/imfs_stat.c | 4 +- cpukit/libfs/src/imfs/imfs_symlink.c | 2 +- cpukit/libfs/src/imfs/imfs_unlink.c | 7 +-- cpukit/libfs/src/imfs/ioman.c | 2 +- cpukit/libfs/src/imfs/memfile.c | 3 +- cpukit/libfs/src/nfsclient/src/nfs.c | 28 +++++++---- cpukit/libfs/src/pipe/pipe.c | 2 +- cpukit/libmisc/fsmount/fsmount.c | 3 +- cpukit/libmisc/shell/internal.h | 7 --- cpukit/libmisc/shell/main_mount.c | 40 ++++++++++++++- cpukit/libmisc/shell/shell.h | 31 ++++++++++++ cpukit/libnetworking/lib/ftpfs.c | 6 +++ 56 files changed, 446 insertions(+), 150 deletions(-) diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index ca5845200d..9844271305 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,71 @@ +2009-06-12 Chris Johns + + * libblock/src/bdbuf.c: Update comments. + * libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the + device from the rdev field of the stat buf. + * libcsupport/include/rtems/libio.h: Add a path length to evalpath + handler. Add parent locations to rmmod and unlink handlers. + * libcsupport/include/rtems/libio_.h: Add a path length to + rtems_filesystem_evaluate_path. Add + rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname, + and rtems_filesystem_prefix_separators. Remove + rtems_filesystem_evaluate_parent. + * libcsupport/src/base_fs.c, libcsupport/src/chdir.c, + libcsupport/src/chmod.c, libcsupport/src/chown.c, + libcsupport/src/chroot.c, libcsupport/src/fchdir.c, + libcsupport/src/link.c, libcsupport/src/mount.c, + libcsupport/src/open.c, libcsupport/src/privateenv.c, + libcsupport/src/readlink.c, libcsupport/src/unmount.c, + libcsupport/src/utime.c, libcsupport/src/unmount.c, + libcsupport/src/utime.c, libfs/src/devfs/devfs.h, + libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c, + libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c, + libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, + libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c, + libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c, + libnetworking/lib/ftpfs.c: Add the length parameter to the eval + call. + * libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators, + rtems_filesystem_dirname, + rtems_filesystem_evaluate_relative_path. Add the length parameter + to the eval call. + * libcsupport/src/rmdir.c: Find the parent pathloc then the node + pathloc from that node. Remove the call to find the parent given + the node pathloc. + * libcsupport/src/stat.c: Add the length parameter to the eval + call. Set the device into the rdev field. + * libcsupport/src/unlink.c: Find the parent pathloc then the node + pathloc from that node. Remove the call to find the parent given + the node pathloc. + * libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the + disk device number from the stat rdev field. + * libfs/src/dosfs/msdos.h: Add the length parameter to the eval + call. Add the parent pathloc to the rmnod handler. + * libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod + handler. + * libfs/src/dosfs/msdos_eval.c: Add the length parameter to the + eval and token call. + * libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the + rmnod handler. + * libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for + only the allowed flags. Add the missing flags spec'ed in the POSIX + standard. + * libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c, + libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the + parent node. Currently ignored in the IMFS. + * libfs/src/imfs/imfs_stat.c: Return the device number in the rdev + field. + * libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add + the length parameter to the token call. + * libfs/src/nfsclient/src/nfs.c: Add the length parameter to the + eval call and parent node to the rmnod and unlink command. + * libmisc/shell/internal.h: Remove the libc mounter decl to make + public. + * libmisc/shell/main_mount.c: Add support for hooking external + mount support for new file systems. + * libmisc/shell/shell.h: Add helper functions for the mount + command. + 2009-06-11 Joel Sherrill * score/src/corespinlockwait.c: Mark timeout code which is not diff --git a/cpukit/libblock/src/bdbuf.c b/cpukit/libblock/src/bdbuf.c index 8be4bd8180..2bfa70efb1 100644 --- a/cpukit/libblock/src/bdbuf.c +++ b/cpukit/libblock/src/bdbuf.c @@ -1936,7 +1936,7 @@ rtems_bdbuf_swapout_modified_processing (rtems_bdpool_id pid, * a device at a time. The task level loop will repeat this operation while * there are buffers to be written. If the transfer fails place the buffers * back on the modified list and try again later. The pool is unlocked while - * the buffers are beign written to disk. + * the buffers are being written to disk. * * @param pid The pool id to process modified buffers on. * @param timer_delta It update_timers is true update the timers by this @@ -1965,14 +1965,14 @@ rtems_bdbuf_swapout_pool_processing (rtems_bdpool_id pid, /* * When the sync is for a device limit the sync to that device. If the sync - * is for a buffer handle the devices in the order on the sync list. This - * means the dev is -1. + * is for a buffer handle process the devices in the order on the sync + * list. This means the dev is -1. */ if (pool->sync_active) dev = pool->sync_device; /* - * If we have any buffers in the sync queue move then to the modified + * If we have any buffers in the sync queue move them to the modified * list. The first sync buffer will select the device we use. */ rtems_bdbuf_swapout_modified_processing (pid, &dev, @@ -1990,22 +1990,22 @@ rtems_bdbuf_swapout_pool_processing (rtems_bdpool_id pid, timer_delta); /* - * We have all the buffers that have been modified for this device so - * the pool can be unlocked because the state is set to TRANSFER. + * We have all the buffers that have been modified for this device so the + * pool can be unlocked because the state of each buffer has been set to + * TRANSFER. */ - rtems_bdbuf_unlock_pool (pool); /* - * If there are buffers to transfer to the media tranfer them. + * If there are buffers to transfer to the media transfer them. */ if (rtems_chain_is_empty (&transfer)) transfered_buffers = false; else { /* - * Obtain the disk device. Release the pool mutex to avoid a dead - * lock. + * Obtain the disk device. The pool's mutex has been released to avoid a + * dead lock. */ dd = rtems_disk_obtain (dev); if (dd == NULL) @@ -2020,14 +2020,13 @@ rtems_bdbuf_swapout_pool_processing (rtems_bdpool_id pid, /* * Take as many buffers as configured and pass to the driver. Note, the - * API to the drivers has the array of buffers and if a chain was passed + * API to the drivers has an array of buffers and if a chain was passed * we could have just passed the list. If the driver API is updated it * should be possible to make this change with little effect in this * code. The array that is passed is broken in design and should be - * removed. Merging to members of a struct into the first member is + * removed. Merging members of a struct into the first member is * trouble waiting to happen. */ - write_req->status = RTEMS_RESOURCE_IN_USE; write_req->error = 0; write_req->bufnum = 0; diff --git a/cpukit/libblock/src/bdpart.c b/cpukit/libblock/src/bdpart.c index 355bd8014d..5f005452fb 100644 --- a/cpukit/libblock/src/bdpart.c +++ b/cpukit/libblock/src/bdpart.c @@ -110,6 +110,9 @@ static void rtems_bdpart_type_to_string( uuid_unparse_lower( type, str); } +/* + * FIXME: This code should the deviceio interface and not the bdbug interface. + */ static rtems_status_code rtems_bdpart_get_disk_data( const char *disk_name, dev_t *disk, @@ -128,7 +131,7 @@ static rtems_status_code rtems_bdpart_get_disk_data( if (rv != 0) { return RTEMS_INVALID_NAME; } - *disk = st.st_dev; + *disk = st.st_rdev; /* Get disk begin, end and block size */ dd = rtems_disk_obtain( *disk); diff --git a/cpukit/libblock/src/ide_part_table.c b/cpukit/libblock/src/ide_part_table.c index 31edc31a41..026b5d05dc 100644 --- a/cpukit/libblock/src/ide_part_table.c +++ b/cpukit/libblock/src/ide_part_table.c @@ -467,7 +467,7 @@ rtems_ide_part_table_get(const char *dev_name, rtems_disk_desc_t *disk_desc) } strncpy (disk_desc->dev_name, dev_name, 15); - disk_desc->dev = dev_stat.st_dev; + disk_desc->dev = dev_stat.st_rdev; disk_desc->sector_size = (dev_stat.st_blksize) ? dev_stat.st_blksize : RTEMS_IDE_SECTOR_SIZE; diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h index 5f840647db..44e8b59267 100644 --- a/cpukit/libcsupport/include/rtems/libio.h +++ b/cpukit/libcsupport/include/rtems/libio.h @@ -128,6 +128,7 @@ typedef int (*rtems_filesystem_fcntl_t)( ); typedef int (*rtems_filesystem_rmnod_t)( + rtems_filesystem_location_info_t *parent_loc, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN */ ); @@ -174,6 +175,7 @@ typedef int (*rtems_filesystem_mknod_t)( typedef int (*rtems_filesystem_evalpath_t)( const char *pathname, /* IN */ + int pathnamelen, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */ ); @@ -191,7 +193,8 @@ typedef int (*rtems_filesystem_link_t)( ); typedef int (*rtems_filesystem_unlink_t)( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ); typedef int (*rtems_filesystem_chown_t)( @@ -326,7 +329,8 @@ struct rtems_filesystem_mount_table_entry_tt { * When someone adds a mounted filesystem on a real device, * this will need to be used. * - * The best option long term for this is probably an open file descriptor. + * The lower layers can manage how this is managed. Leave as a + * string. */ char *dev; }; diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h index f64fefb2e8..dfde83145d 100644 --- a/cpukit/libcsupport/include/rtems/libio_.h +++ b/cpukit/libcsupport/include/rtems/libio_.h @@ -234,16 +234,29 @@ int rtems_libio_is_file_open( * File System Routine Prototypes */ -int rtems_filesystem_evaluate_path( +int rtems_filesystem_evaluate_relative_path( const char *pathname, + int pathnamelen, int flags, rtems_filesystem_location_info_t *pathloc, int follow_link ); -int rtems_filesystem_evaluate_parent( +int rtems_filesystem_evaluate_path( + const char *pathname, + int pathnamelen, int flags, - rtems_filesystem_location_info_t *pathloc + rtems_filesystem_location_info_t *pathloc, + int follow_link +); + +int rtems_filesystem_dirname( + const char *pathname +); + +int rtems_filesystem_prefix_separators( + const char *pathname, + int pathnamelen ); void rtems_filesystem_initialize(void); diff --git a/cpukit/libcsupport/src/base_fs.c b/cpukit/libcsupport/src/base_fs.c index 91466a5b07..328bcce60a 100644 --- a/cpukit/libcsupport/src/base_fs.c +++ b/cpukit/libcsupport/src/base_fs.c @@ -89,10 +89,10 @@ void rtems_filesystem_initialize( void ) */ rtems_filesystem_root = entry->mt_fs_root; /* Clone the root pathloc */ - rtems_filesystem_evaluate_path("/", 0, &loc, 0); + rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); rtems_filesystem_root = loc; /* One more clone for the current node */ - rtems_filesystem_evaluate_path("/", 0, &loc, 0); + rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); rtems_filesystem_current = loc; /* Note: the global_env's refcnt doesn't matter diff --git a/cpukit/libcsupport/src/chdir.c b/cpukit/libcsupport/src/chdir.c index fb6f7e6497..ccc7a567ba 100644 --- a/cpukit/libcsupport/src/chdir.c +++ b/cpukit/libcsupport/src/chdir.c @@ -35,7 +35,7 @@ int chdir( */ result = rtems_filesystem_evaluate_path( - pathname, RTEMS_LIBIO_PERMS_SEARCH, &loc, true ); + pathname, strlen( pathname ), RTEMS_LIBIO_PERMS_SEARCH, &loc, true ); if ( result != 0 ) return -1; diff --git a/cpukit/libcsupport/src/chmod.c b/cpukit/libcsupport/src/chmod.c index a19302517d..459314f736 100644 --- a/cpukit/libcsupport/src/chmod.c +++ b/cpukit/libcsupport/src/chmod.c @@ -34,7 +34,7 @@ int chmod( rtems_filesystem_location_info_t loc; int result; - status = rtems_filesystem_evaluate_path( path, 0, &loc, true ); + status = rtems_filesystem_evaluate_path( path, strlen( path ), 0, &loc, true ); if ( status != 0 ) return -1; diff --git a/cpukit/libcsupport/src/chown.c b/cpukit/libcsupport/src/chown.c index 4784315d57..22d2a77127 100644 --- a/cpukit/libcsupport/src/chown.c +++ b/cpukit/libcsupport/src/chown.c @@ -33,7 +33,7 @@ int chown( rtems_filesystem_location_info_t loc; int result; - if ( rtems_filesystem_evaluate_path( path, 0x00, &loc, true ) ) + if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x00, &loc, true ) ) return -1; if ( !loc.ops->chown_h ) { diff --git a/cpukit/libcsupport/src/chroot.c b/cpukit/libcsupport/src/chroot.c index d3e1198d0a..ccda4d6d7a 100644 --- a/cpukit/libcsupport/src/chroot.c +++ b/cpukit/libcsupport/src/chroot.c @@ -44,7 +44,7 @@ int chroot( } /* clone the new root location */ - if (rtems_filesystem_evaluate_path(".", 0, &loc, 0)) { + if (rtems_filesystem_evaluate_path(".", 1, 0, &loc, 0)) { /* our cwd has changed, though - but there is no easy way of return :-( */ rtems_set_errno_and_return_minus_one( errno ); } diff --git a/cpukit/libcsupport/src/eval.c b/cpukit/libcsupport/src/eval.c index 7c9c0a7e47..5870155189 100644 --- a/cpukit/libcsupport/src/eval.c +++ b/cpukit/libcsupport/src/eval.c @@ -21,8 +21,9 @@ #include #include -int rtems_filesystem_evaluate_path( +int rtems_filesystem_evaluate_relative_path( const char *pathname, + int pathnamelen, int flags, rtems_filesystem_location_info_t *pathloc, int follow_link @@ -42,16 +43,10 @@ int rtems_filesystem_evaluate_path( if ( !pathloc ) rtems_set_errno_and_return_minus_one( EIO ); /* should never happen */ - /* - * Evaluate the path using the optable evalpath. - */ - - rtems_filesystem_get_start_loc( pathname, &i, pathloc ); - if ( !pathloc->ops->evalpath_h ) rtems_set_errno_and_return_minus_one( ENOTSUP ); - result = (*pathloc->ops->evalpath_h)( &pathname[i], flags, pathloc ); + result = (*pathloc->ops->evalpath_h)( &pathname[i], pathnamelen, flags, pathloc ); /* * Get the Node type and determine if you need to follow the link or @@ -90,34 +85,79 @@ int rtems_filesystem_evaluate_path( */ result = (*pathloc->ops->eval_link_h)( pathloc, flags ); - } } return result; } - -int rtems_filesystem_evaluate_parent( +int rtems_filesystem_evaluate_path( + const char *pathname, + int pathnamelen, int flags, - rtems_filesystem_location_info_t *pathloc + rtems_filesystem_location_info_t *pathloc, + int follow_link ) { - rtems_filesystem_location_info_t parent; - int result; + int i; + int result; + rtems_filesystem_node_types_t type; + + /* + * Verify Input parameters. + */ + + if ( !pathname ) + rtems_set_errno_and_return_minus_one( EFAULT ); if ( !pathloc ) rtems_set_errno_and_return_minus_one( EIO ); /* should never happen */ - if ( !pathloc->ops->evalpath_h ) - rtems_set_errno_and_return_minus_one( ENOTSUP ); + /* + * Evaluate the path using the optable evalpath. + */ + + rtems_filesystem_get_start_loc( pathname, &i, pathloc ); + + /* + * We evaluation the path relative to the start location we get got. + */ + return rtems_filesystem_evaluate_relative_path( pathname, + pathnamelen, + flags, + pathloc, + follow_link ); +} - parent = *pathloc; - result = (*pathloc->ops->evalpath_h)( "..", flags, &parent ); - if (result != 0){ - return -1; +int rtems_filesystem_dirname( + const char *pathname +) +{ + int len = strlen( pathname ); + + while ( len ) { + len--; + if ( rtems_filesystem_is_separator( pathname[len] ) ) + break; } - rtems_filesystem_freenode( &parent ); - return result; + return len; +} + +int rtems_filesystem_prefix_separators( + const char *pathname, + int pathnamelen +) +{ + /* + * Eat any separators at start of the path. + */ + int stripped = 0; + while ( *pathname && pathnamelen && rtems_filesystem_is_separator( *pathname ) ) + { + pathname++; + pathnamelen--; + stripped++; + } + return stripped; } diff --git a/cpukit/libcsupport/src/fchdir.c b/cpukit/libcsupport/src/fchdir.c index 603288614d..0f3cf9ebb3 100644 --- a/cpukit/libcsupport/src/fchdir.c +++ b/cpukit/libcsupport/src/fchdir.c @@ -76,7 +76,7 @@ int fchdir( rtems_filesystem_current = iop->pathinfo; /* clone the current node */ - if (rtems_filesystem_evaluate_path(".", 0, &loc, 0)) { + if (rtems_filesystem_evaluate_path(".", 1, 0, &loc, 0)) { /* cloning failed; restore original and bail out */ rtems_filesystem_current = saved; return -1; diff --git a/cpukit/libcsupport/src/link.c b/cpukit/libcsupport/src/link.c index c105a33742..bcad166182 100644 --- a/cpukit/libcsupport/src/link.c +++ b/cpukit/libcsupport/src/link.c @@ -37,7 +37,8 @@ int link( * Get the node we are linking to. */ - result = rtems_filesystem_evaluate_path( existing, 0, &existing_loc, true ); + result = rtems_filesystem_evaluate_path( existing, strlen( existing ), + 0, &existing_loc, true ); if ( result != 0 ) return -1; diff --git a/cpukit/libcsupport/src/mount.c b/cpukit/libcsupport/src/mount.c index 04264ad234..d21a084be0 100644 --- a/cpukit/libcsupport/src/mount.c +++ b/cpukit/libcsupport/src/mount.c @@ -139,7 +139,7 @@ int mount( if ( mount_point ) { if ( rtems_filesystem_evaluate_path( - mount_point, RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 ) + mount_point, strlen( mount_point ), RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 ) goto cleanup_and_bail; loc_to_free = &loc; diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c index 1bc83ed7bc..f45215ec0d 100644 --- a/cpukit/libcsupport/src/open.c +++ b/cpukit/libcsupport/src/open.c @@ -111,7 +111,7 @@ int open( */ status = rtems_filesystem_evaluate_path( - pathname, eval_flags, &loc, true ); + pathname, strlen( pathname ), eval_flags, &loc, true ); if ( status == -1 ) { if ( errno != ENOENT ) { @@ -133,7 +133,7 @@ int open( } /* Sanity check to see if the file name exists after the mknod() */ - status = rtems_filesystem_evaluate_path( pathname, 0x0, &loc, true ); + status = rtems_filesystem_evaluate_path( pathname, strlen( pathname ), 0x0, &loc, true ); if ( status != 0 ) { /* The file did not exist */ rc = EACCES; goto done; diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index 286a2f6733..d61f9013a9 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -91,9 +91,9 @@ rtems_status_code rtems_libio_set_private_env(void) { * clones. */ - rtems_filesystem_evaluate_path("/", 0, &loc, 0); + rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); rtems_filesystem_root = loc; - rtems_filesystem_evaluate_path("/", 0, &loc, 0); + rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); rtems_filesystem_current = loc; return RTEMS_SUCCESSFUL; diff --git a/cpukit/libcsupport/src/readlink.c b/cpukit/libcsupport/src/readlink.c index 957e27d1c8..9252871208 100644 --- a/cpukit/libcsupport/src/readlink.c +++ b/cpukit/libcsupport/src/readlink.c @@ -30,7 +30,8 @@ ssize_t readlink( if (!buf) rtems_set_errno_and_return_minus_one( EFAULT ); - result = rtems_filesystem_evaluate_path( pathname, 0, &loc, false ); + result = rtems_filesystem_evaluate_path( pathname, strlen( pathname ), + 0, &loc, false ); if ( result != 0 ) return -1; diff --git a/cpukit/libcsupport/src/rmdir.c b/cpukit/libcsupport/src/rmdir.c index 4b1de71c8a..ca0129fd3b 100644 --- a/cpukit/libcsupport/src/rmdir.c +++ b/cpukit/libcsupport/src/rmdir.c @@ -28,20 +28,42 @@ int rmdir( const char *pathname ) { + int parentpathlen; + const char *name; + rtems_filesystem_location_info_t parentloc; rtems_filesystem_location_info_t loc; + int i; int result; - + /* - * Get the node where we wish to go. + * Get the parent node of the node we wish to remove. Find the parent path. */ - result = rtems_filesystem_evaluate_path( pathname, 0, &loc, false ); - if ( result != 0 ) - return -1; + parentpathlen = rtems_filesystem_dirname ( pathname ); - result = rtems_filesystem_evaluate_parent(RTEMS_LIBIO_PERMS_WRITE, &loc ); - if (result != 0) { - rtems_filesystem_freenode( &loc ); + if ( parentpathlen == 0 ) + rtems_filesystem_get_start_loc( pathname, &i, &parentloc ); + else { + result = rtems_filesystem_evaluate_path(pathname, parentpathlen, + RTEMS_LIBIO_PERMS_WRITE, + &parentloc, + false ); + if ( result != 0 ) + return -1; + } + + /* + * Start from the parent to find the node that should be under it. + */ + + loc = parentloc; + name = pathname + parentpathlen; + name += rtems_filesystem_prefix_separators( name, strlen( name ) ); + + result = rtems_filesystem_evaluate_relative_path( name , strlen( name ), + 0, &loc, false ); + if ( result != 0 ) { + rtems_filesystem_freenode( &parentloc ); return -1; } @@ -51,11 +73,13 @@ int rmdir( if ( !loc.ops->node_type_h ){ rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); rtems_set_errno_and_return_minus_one( ENOTSUP ); } if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ){ rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); rtems_set_errno_and_return_minus_one( ENOTDIR ); } @@ -65,12 +89,14 @@ int rmdir( if ( !loc.handlers->rmnod_h ){ rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); rtems_set_errno_and_return_minus_one( ENOTSUP ); } - result = (*loc.handlers->rmnod_h)( &loc ); + result = (*loc.handlers->rmnod_h)( &parentloc, &loc ); rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); return result; } diff --git a/cpukit/libcsupport/src/stat.c b/cpukit/libcsupport/src/stat.c index c2f2badf22..5e26f94322 100644 --- a/cpukit/libcsupport/src/stat.c +++ b/cpukit/libcsupport/src/stat.c @@ -59,7 +59,8 @@ int _STAT_NAME( if ( !buf ) rtems_set_errno_and_return_minus_one( EFAULT ); - status = rtems_filesystem_evaluate_path( path, 0, &loc, _STAT_FOLLOW_LINKS ); + status = rtems_filesystem_evaluate_path( path, strlen( path ), + 0, &loc, _STAT_FOLLOW_LINKS ); if ( status != 0 ) return -1; diff --git a/cpukit/libcsupport/src/unlink.c b/cpukit/libcsupport/src/unlink.c index a441d4d6ec..43b1db5705 100644 --- a/cpukit/libcsupport/src/unlink.c +++ b/cpukit/libcsupport/src/unlink.c @@ -24,41 +24,67 @@ int unlink( const char *path ) { + int parentpathlen; + const char *name; + rtems_filesystem_location_info_t parentloc; rtems_filesystem_location_info_t loc; + int i; int result; /* - * Get the node to be unlinked. + * Get the node to be unlinked. Find the parent path first. */ - - result = rtems_filesystem_evaluate_path( path, 0, &loc, false ); - if ( result != 0 ) - return -1; - - result = rtems_filesystem_evaluate_parent(RTEMS_LIBIO_PERMS_WRITE, &loc ); - if (result != 0 && errno != ENOTSUP) { - rtems_filesystem_freenode( &loc ); + + parentpathlen = rtems_filesystem_dirname ( path ); + + if ( parentpathlen == 0 ) + rtems_filesystem_get_start_loc( path, &i, &parentloc ); + else { + result = rtems_filesystem_evaluate_path( path, parentpathlen, + RTEMS_LIBIO_PERMS_WRITE, + &parentloc, + false ); + if ( result != 0 ) + return -1; + } + + /* + * Start from the parent to find the node that should be under it. + */ + + loc = parentloc; + name = path + parentpathlen; + name += rtems_filesystem_prefix_separators( name, strlen( name ) ); + + result = rtems_filesystem_evaluate_relative_path( name , strlen( name ), + 0, &loc, false ); + if ( result != 0 ) { + rtems_filesystem_freenode( &parentloc ); return -1; } - + if ( !loc.ops->node_type_h ) { rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); rtems_set_errno_and_return_minus_one( ENOTSUP ); } if ( (*loc.ops->node_type_h)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) { rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); rtems_set_errno_and_return_minus_one( EISDIR ); } if ( !loc.ops->unlink_h ) { rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); rtems_set_errno_and_return_minus_one( ENOTSUP ); } - result = (*loc.ops->unlink_h)( &loc ); + result = (*loc.ops->unlink_h)( &parentloc, &loc ); rtems_filesystem_freenode( &loc ); + rtems_filesystem_freenode( &parentloc ); return result; } diff --git a/cpukit/libcsupport/src/unmount.c b/cpukit/libcsupport/src/unmount.c index e4ee7a74a4..774df9931d 100644 --- a/cpukit/libcsupport/src/unmount.c +++ b/cpukit/libcsupport/src/unmount.c @@ -113,7 +113,7 @@ int unmount( * The mount entry that is being refered to. */ - if ( rtems_filesystem_evaluate_path( path, 0x0, &loc, true ) ) + if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x0, &loc, true ) ) return -1; mt_entry = loc.mt_entry; diff --git a/cpukit/libcsupport/src/utime.c b/cpukit/libcsupport/src/utime.c index 5bd5060549..6cceea719f 100644 --- a/cpukit/libcsupport/src/utime.c +++ b/cpukit/libcsupport/src/utime.c @@ -30,7 +30,7 @@ int utime( rtems_filesystem_location_info_t temp_loc; int result; - if ( rtems_filesystem_evaluate_path( path, 0x00, &temp_loc, true ) ) + if ( rtems_filesystem_evaluate_path( path, strlen( path ), 0x00, &temp_loc, true ) ) return -1; if ( !temp_loc.ops->utime_h ){ diff --git a/cpukit/libfs/src/devfs/devfs.h b/cpukit/libfs/src/devfs/devfs.h index b065489455..2a666204d3 100644 --- a/cpukit/libfs/src/devfs/devfs.h +++ b/cpukit/libfs/src/devfs/devfs.h @@ -195,6 +195,7 @@ extern int devFS_node_type( extern int devFS_evaluate_path( const char *pathname, + int pathnamelen, int flags, rtems_filesystem_location_info_t *pathloc ); diff --git a/cpukit/libfs/src/devfs/devfs_eval.c b/cpukit/libfs/src/devfs/devfs_eval.c index 5d9423b007..dd69fd802d 100644 --- a/cpukit/libfs/src/devfs/devfs_eval.c +++ b/cpukit/libfs/src/devfs/devfs_eval.c @@ -17,6 +17,7 @@ int devFS_evaluate_path( const char *pathname, + int pathnamelen, int flags, rtems_filesystem_location_info_t *pathloc ) @@ -37,7 +38,7 @@ int devFS_evaluate_path( for (i = 0; i < rtems_device_table_size; i++){ if ((device_name_table[i].device_name) && - (strcmp(device_name_table[i].device_name, pathname) == 0)){ + (strncmp(pathname, device_name_table[i].device_name, pathnamelen) == 0)){ /* find the device, set proper values */ pathloc->node_access = (void *)&device_name_table[i]; pathloc->handlers = &devFS_file_handlers; diff --git a/cpukit/libfs/src/devfs/devstat.c b/cpukit/libfs/src/devfs/devstat.c index 6c6ee3e6b1..7bfdfec00c 100644 --- a/cpukit/libfs/src/devfs/devstat.c +++ b/cpukit/libfs/src/devfs/devstat.c @@ -30,7 +30,7 @@ int devFS_stat( if (!the_dev) rtems_set_errno_and_return_minus_one( EFAULT ); - buf->st_dev = rtems_filesystem_make_dev_t( the_dev->major, the_dev->minor ); + buf->st_rdev = rtems_filesystem_make_dev_t( the_dev->major, the_dev->minor ); buf->st_mode = the_dev->mode; diff --git a/cpukit/libfs/src/dosfs/fat.c b/cpukit/libfs/src/dosfs/fat.c index d5a3a7907d..0bf3d29d28 100644 --- a/cpukit/libfs/src/dosfs/fat.c +++ b/cpukit/libfs/src/dosfs/fat.c @@ -354,11 +354,11 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry) rtems_set_errno_and_return_minus_one(ENOTBLK); /* check that device is registred as block device and lock it */ - vol->dd = rtems_disk_obtain(stat_buf.st_dev); + vol->dd = rtems_disk_obtain(stat_buf.st_rdev); if (vol->dd == NULL) rtems_set_errno_and_return_minus_one(ENOTBLK); - vol->dev = stat_buf.st_dev; + vol->dev = stat_buf.st_rdev; /* Read boot record */ /* FIXME: Asserts FAT_MAX_BPB_SIZE < bdbuf block size */ diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h index 374210d9b7..1ea54d90c3 100644 --- a/cpukit/libfs/src/dosfs/msdos.h +++ b/cpukit/libfs/src/dosfs/msdos.h @@ -228,9 +228,10 @@ int msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry); int msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry); int msdos_eval_path( - const char *pathname, /* IN */ - int flags, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */ + const char *pathname, /* IN */ + int pathnamelen, /* IN */ + int flags, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN/OUT */ ); int msdos_eval4make( @@ -319,7 +320,8 @@ msdos_dir_chmod( mode_t mode /* IN */ ); -int msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */); +int msdos_file_rmnod(rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */); int msdos_file_link( rtems_filesystem_location_info_t *to_loc, @@ -354,7 +356,8 @@ msdos_file_chmod( mode_t mode /* IN */ ); -int msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */); +int msdos_dir_rmnod(rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */); int msdos_dir_sync(rtems_libio_t *iop); @@ -372,6 +375,7 @@ int msdos_creat_node(rtems_filesystem_location_info_t *parent_loc, /* Misc prototypes */ msdos_token_types_t msdos_get_token(const char *path, + int pathlen, const char **token, int *token_len); diff --git a/cpukit/libfs/src/dosfs/msdos_create.c b/cpukit/libfs/src/dosfs/msdos_create.c index bbdf137600..f7bd97196c 100644 --- a/cpukit/libfs/src/dosfs/msdos_create.c +++ b/cpukit/libfs/src/dosfs/msdos_create.c @@ -310,7 +310,7 @@ msdos_file_link(rtems_filesystem_location_info_t *to_loc, /* * check spelling and format new node name */ - if (MSDOS_NAME != msdos_get_token(name, &token, &len)) { + if (MSDOS_NAME != msdos_get_token(name, strlen(name), &token, &len)) { rtems_set_errno_and_return_minus_one(ENAMETOOLONG); } /* diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c index b897a192e3..43ff65291b 100644 --- a/cpukit/libfs/src/dosfs/msdos_dir.c +++ b/cpukit/libfs/src/dosfs/msdos_dir.c @@ -637,7 +637,8 @@ msdos_dir_chmod(rtems_filesystem_location_info_t *pathloc, * RC_OK on success, or -1 if error occured (errno set apropriately). */ int -msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc) +msdos_dir_rmnod(rtems_filesystem_location_info_t *parent_pathloc, + rtems_filesystem_location_info_t *pathloc) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; diff --git a/cpukit/libfs/src/dosfs/msdos_eval.c b/cpukit/libfs/src/dosfs/msdos_eval.c index 5eabedb2a4..a97c245ed0 100644 --- a/cpukit/libfs/src/dosfs/msdos_eval.c +++ b/cpukit/libfs/src/dosfs/msdos_eval.c @@ -72,6 +72,7 @@ msdos_set_handlers(rtems_filesystem_location_info_t *loc) int msdos_eval_path( const char *pathname, + int pathnamelen, int flags, rtems_filesystem_location_info_t *pathloc ) @@ -106,7 +107,8 @@ msdos_eval_path( while ((type != MSDOS_NO_MORE_PATH) && (type != MSDOS_INVALID_TOKEN)) { - type = msdos_get_token(&pathname[i], &token, &token_len); + type = msdos_get_token(&pathname[i], pathnamelen, &token, &token_len); + pathnamelen += token_len; i += token_len; fat_fd = pathloc->node_access; @@ -150,6 +152,7 @@ msdos_eval_path( rtems_semaphore_release(fs_info->vol_sema); return (*pathloc->ops->evalpath_h)(&(pathname[i-token_len]), + pathnamelen - token_len, flags, pathloc); } } @@ -288,7 +291,7 @@ msdos_eval4make( while (!done) { - type = msdos_get_token(&path[i], &token, &token_len); + type = msdos_get_token(&path[i], strlen(&path[i]), &token, &token_len); i += token_len; fat_fd = pathloc->node_access; diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c index 817897f845..8519412984 100644 --- a/cpukit/libfs/src/dosfs/msdos_file.c +++ b/cpukit/libfs/src/dosfs/msdos_file.c @@ -474,7 +474,8 @@ msdos_file_chmod(rtems_filesystem_location_info_t *pathloc, * RC_OK on success, or -1 if error occured (errno set appropriately) */ int -msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc) +msdos_file_rmnod(rtems_filesystem_location_info_t *parent_pathloc, + rtems_filesystem_location_info_t *pathloc) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; diff --git a/cpukit/libfs/src/dosfs/msdos_format.c b/cpukit/libfs/src/dosfs/msdos_format.c index 9319c87a87..af4a109892 100644 --- a/cpukit/libfs/src/dosfs/msdos_format.c +++ b/cpukit/libfs/src/dosfs/msdos_format.c @@ -916,7 +916,7 @@ int msdos_format /* check that device is registered as block device and lock it */ if (ret_val == 0) { - dd = rtems_disk_obtain(stat_buf.st_dev); + dd = rtems_disk_obtain(stat_buf.st_rdev); if (dd == NULL) { errno = ENOTBLK; ret_val = -1; diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c index 17928077e4..ef4f6c0e56 100644 --- a/cpukit/libfs/src/dosfs/msdos_misc.c +++ b/cpukit/libfs/src/dosfs/msdos_misc.c @@ -227,7 +227,10 @@ msdos_long_to_short(const char *lfn, int lfn_len, char* sfn, int sfn_len) * */ msdos_token_types_t -msdos_get_token(const char *path, const char **ret_token, int *ret_token_len) +msdos_get_token(const char *path, + int pathlen, + const char **ret_token, + int *ret_token_len) { msdos_token_types_t type = MSDOS_NAME; int i = 0; @@ -238,7 +241,7 @@ msdos_get_token(const char *path, const char **ret_token, int *ret_token_len) /* * Check for a separator. */ - while (!msdos_is_separator(path[i])) + while (!msdos_is_separator(path[i]) && (i < pathlen)) { if ( !msdos_is_valid_name_char(path[i]) ) return MSDOS_INVALID_TOKEN; @@ -254,7 +257,7 @@ msdos_get_token(const char *path, const char **ret_token, int *ret_token_len) */ if ( i == 0 ) { - if ( *path != '\0' ) + if ( (*path != '\0') && pathlen ) { i++; type = MSDOS_CURRENT_DIR; diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h index 355e494248..5345269dcb 100644 --- a/cpukit/libfs/src/imfs/imfs.h +++ b/cpukit/libfs/src/imfs/imfs.h @@ -277,6 +277,7 @@ extern int rtems_tarfs_load( */ extern IMFS_token_types IMFS_get_token( const char *path, + int pathlen, char *token, int *token_len ); @@ -316,6 +317,7 @@ extern int IMFS_evaluate_link( extern int IMFS_eval_path( const char *pathname, /* IN */ + int pathnamelen, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */ ); @@ -328,7 +330,8 @@ extern int IMFS_link( ); extern int IMFS_unlink( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ); extern int IMFS_chown( @@ -412,7 +415,8 @@ extern int imfs_dir_fstat( ); extern int imfs_dir_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ); extern int memfile_open( @@ -451,7 +455,8 @@ extern rtems_off64_t memfile_lseek( ); extern int memfile_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ); extern int device_open( @@ -527,7 +532,8 @@ extern int IMFS_fcntl( ); extern int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ); #ifdef __cplusplus diff --git a/cpukit/libfs/src/imfs/imfs_directory.c b/cpukit/libfs/src/imfs/imfs_directory.c index 1107da9221..71a6d4be41 100644 --- a/cpukit/libfs/src/imfs/imfs_directory.c +++ b/cpukit/libfs/src/imfs/imfs_directory.c @@ -282,7 +282,8 @@ int imfs_dir_fstat( */ int imfs_dir_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ) { IMFS_jnode_t *the_jnode; diff --git a/cpukit/libfs/src/imfs/imfs_eval.c b/cpukit/libfs/src/imfs/imfs_eval.c index 62d02f964e..5dcf7576a5 100644 --- a/cpukit/libfs/src/imfs/imfs_eval.c +++ b/cpukit/libfs/src/imfs/imfs_eval.c @@ -206,6 +206,7 @@ int IMFS_evaluate_sym_link( result = IMFS_eval_path( &jnode->info.sym_link.name[i], + strlen( &jnode->info.sym_link.name[i] ), flags, node ); @@ -294,6 +295,7 @@ int IMFS_evaluate_for_make( rtems_filesystem_location_info_t newloc; IMFS_jnode_t *node; bool done = false; + int pathlen; int result; /* @@ -302,13 +304,18 @@ int IMFS_evaluate_for_make( */ node = pathloc->node_access; + /* + * Get the path length. + */ + pathlen = strlen( path ); /* * Evaluate all tokens until we are done or an error occurs. */ - + while( !done ) { - type = IMFS_get_token( &path[i], token, &len ); + type = IMFS_get_token( &path[i], pathlen, token, &len ); + pathlen -= len; i += len; if ( !pathloc->node_access ) @@ -480,6 +487,7 @@ int IMFS_evaluate_for_make( int IMFS_eval_path( const char *pathname, /* IN */ + int pathnamelen, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */ ) @@ -510,8 +518,9 @@ int IMFS_eval_path( while( (type != IMFS_NO_MORE_PATH) && (type != IMFS_INVALID_TOKEN) ) { - type = IMFS_get_token( &pathname[i], token, &len ); - i += len; + type = IMFS_get_token( &pathname[i], pathnamelen, token, &len ); + pathnamelen -= len; + i += len; if ( !pathloc->node_access ) rtems_set_errno_and_return_minus_one( ENOENT ); @@ -551,7 +560,9 @@ int IMFS_eval_path( } else { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; - return (*pathloc->ops->evalpath_h)(&(pathname[i-len]),flags,pathloc); + return (*pathloc->ops->evalpath_h)(&(pathname[i-len]), + pathnamelen+len, + flags,pathloc); } } else { @@ -603,7 +614,9 @@ int IMFS_eval_path( if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; - return (*pathloc->ops->evalpath_h)( &pathname[i-len], flags, pathloc ); + return (*pathloc->ops->evalpath_h)( &pathname[i-len], + pathnamelen+len, + flags, pathloc ); } /* @@ -645,7 +658,9 @@ int IMFS_eval_path( if ( node->info.directory.mt_fs != NULL ) { newloc = node->info.directory.mt_fs->mt_fs_root; *pathloc = newloc; - return (*pathloc->ops->evalpath_h)( &pathname[i-len], flags, pathloc ); + return (*pathloc->ops->evalpath_h)( &pathname[i-len], + pathnamelen+len, + flags, pathloc ); } else { result = IMFS_Set_handlers( pathloc ); } diff --git a/cpukit/libfs/src/imfs/imfs_fchmod.c b/cpukit/libfs/src/imfs/imfs_fchmod.c index 6cb56aa629..54a093de2f 100644 --- a/cpukit/libfs/src/imfs/imfs_fchmod.c +++ b/cpukit/libfs/src/imfs/imfs_fchmod.c @@ -46,11 +46,9 @@ int IMFS_fchmod( /* * Change only the RWX permissions on the jnode to mode. */ - if ( mode & (~ (S_IRWXU | S_IRWXG | S_IRWXO ) ) ) - rtems_set_errno_and_return_minus_one( EPERM ); - jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); - jnode->st_mode |= mode; + jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX); + jnode->st_mode |= mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX); IMFS_update_ctime( jnode ); diff --git a/cpukit/libfs/src/imfs/imfs_fsunmount.c b/cpukit/libfs/src/imfs/imfs_fsunmount.c index c3a12efb14..19a26ffd04 100644 --- a/cpukit/libfs/src/imfs/imfs_fsunmount.c +++ b/cpukit/libfs/src/imfs/imfs_fsunmount.c @@ -74,12 +74,12 @@ int IMFS_fsunmount( IMFS_Set_handlers( &loc ); if ( jnode->type != IMFS_DIRECTORY ) { - result = IMFS_unlink( &loc ); + result = IMFS_unlink( NULL, &loc ); if (result != 0) return -1; jnode = next; } else if ( jnode_has_no_children( jnode ) ) { - result = IMFS_unlink( &loc ); + result = IMFS_unlink( NULL, &loc ); if (result != 0) return -1; jnode = next; diff --git a/cpukit/libfs/src/imfs/imfs_gtkn.c b/cpukit/libfs/src/imfs/imfs_gtkn.c index 09f1ab0174..b15b2f1136 100644 --- a/cpukit/libfs/src/imfs/imfs_gtkn.c +++ b/cpukit/libfs/src/imfs/imfs_gtkn.c @@ -26,6 +26,7 @@ IMFS_token_types IMFS_get_token( const char *path, + int pathlen, char *token, int *token_len ) @@ -38,7 +39,7 @@ IMFS_token_types IMFS_get_token( * Copy a name into token. (Remember NULL is a token.) */ c = path[i]; - while ( (!IMFS_is_separator(c)) && (i <= IMFS_NAME_MAX) ) { + while ( (!IMFS_is_separator(c)) && (i < pathlen) && (i <= IMFS_NAME_MAX) ) { token[i] = c; @@ -58,7 +59,7 @@ IMFS_token_types IMFS_get_token( if ( i == 0 ) { token[i] = c; - if ( token[i] != '\0' ) { + if ( (token[i] != '\0') && pathlen ) { i++; type = IMFS_CURRENT_DIR; } else { diff --git a/cpukit/libfs/src/imfs/imfs_link.c b/cpukit/libfs/src/imfs/imfs_link.c index 43c1613cfc..db8659db75 100644 --- a/cpukit/libfs/src/imfs/imfs_link.c +++ b/cpukit/libfs/src/imfs/imfs_link.c @@ -47,7 +47,7 @@ int IMFS_link( * Remove any separators at the end of the string. */ - IMFS_get_token( token, new_name, &i ); + IMFS_get_token( token, strlen( token ), new_name, &i ); /* * Create a new link node. diff --git a/cpukit/libfs/src/imfs/imfs_load_tar.c b/cpukit/libfs/src/imfs/imfs_load_tar.c index 0846f2e1ee..531359162e 100644 --- a/cpukit/libfs/src/imfs/imfs_load_tar.c +++ b/cpukit/libfs/src/imfs/imfs_load_tar.c @@ -92,7 +92,8 @@ rtems_tarfs_load( IMFS_jnode_t *node; int status; - status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0); + status = rtems_filesystem_evaluate_path(mountpoint, strlen(mountpoint), + 0, &root_loc, 0); if (status != 0) return(-1); diff --git a/cpukit/libfs/src/imfs/imfs_mknod.c b/cpukit/libfs/src/imfs/imfs_mknod.c index 9d35e61922..f7b8ac9998 100644 --- a/cpukit/libfs/src/imfs/imfs_mknod.c +++ b/cpukit/libfs/src/imfs/imfs_mknod.c @@ -41,7 +41,7 @@ int IMFS_mknod( char new_name[ IMFS_NAME_MAX + 1 ]; IMFS_types_union info; - IMFS_get_token( token, new_name, &result ); + IMFS_get_token( token, strlen( token ), new_name, &result ); /* * Figure out what type of IMFS node this is. diff --git a/cpukit/libfs/src/imfs/imfs_rmnod.c b/cpukit/libfs/src/imfs/imfs_rmnod.c index 85202b2c87..ed6001a691 100644 --- a/cpukit/libfs/src/imfs/imfs_rmnod.c +++ b/cpukit/libfs/src/imfs/imfs_rmnod.c @@ -31,7 +31,8 @@ */ int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ) { IMFS_jnode_t *the_jnode; diff --git a/cpukit/libfs/src/imfs/imfs_stat.c b/cpukit/libfs/src/imfs/imfs_stat.c index 76564811e9..533899e259 100644 --- a/cpukit/libfs/src/imfs/imfs_stat.c +++ b/cpukit/libfs/src/imfs/imfs_stat.c @@ -36,8 +36,8 @@ int IMFS_stat( switch ( the_jnode->type ) { case IMFS_DEVICE: - io = &the_jnode->info.device; - buf->st_dev = rtems_filesystem_make_dev_t( io->major, io->minor ); + io = &the_jnode->info.device; + buf->st_rdev = rtems_filesystem_make_dev_t( io->major, io->minor ); break; case IMFS_LINEAR_FILE: diff --git a/cpukit/libfs/src/imfs/imfs_symlink.c b/cpukit/libfs/src/imfs/imfs_symlink.c index e946f3dc66..36a52e50fb 100644 --- a/cpukit/libfs/src/imfs/imfs_symlink.c +++ b/cpukit/libfs/src/imfs/imfs_symlink.c @@ -41,7 +41,7 @@ int IMFS_symlink( * Remove any separators at the end of the string. */ - IMFS_get_token( node_name, new_name, &i ); + IMFS_get_token( node_name, strlen( node_name ), new_name, &i ); /* * Duplicate link name diff --git a/cpukit/libfs/src/imfs/imfs_unlink.c b/cpukit/libfs/src/imfs/imfs_unlink.c index b416a09b8e..0ec176ed03 100644 --- a/cpukit/libfs/src/imfs/imfs_unlink.c +++ b/cpukit/libfs/src/imfs/imfs_unlink.c @@ -25,7 +25,8 @@ #include int IMFS_unlink( - rtems_filesystem_location_info_t *loc /* IN */ + rtems_filesystem_location_info_t *parentloc, /* IN */ + rtems_filesystem_location_info_t *loc /* IN */ ) { IMFS_jnode_t *node; @@ -60,7 +61,7 @@ int IMFS_unlink( if ( node->info.hard_link.link_node->st_nlink == 1) { - result = (*the_link.handlers->rmnod_h)( &the_link ); + result = (*the_link.handlers->rmnod_h)( parentloc, &the_link ); if ( result != 0 ) return -1; } @@ -75,7 +76,7 @@ int IMFS_unlink( * Now actually free the node we were asked to free. */ - result = (*loc->handlers->rmnod_h)( loc ); + result = (*loc->handlers->rmnod_h)( parentloc, loc ); return result; } diff --git a/cpukit/libfs/src/imfs/ioman.c b/cpukit/libfs/src/imfs/ioman.c index ef5d4cf614..cbfcabb3a3 100644 --- a/cpukit/libfs/src/imfs/ioman.c +++ b/cpukit/libfs/src/imfs/ioman.c @@ -80,7 +80,7 @@ rtems_status_code rtems_io_lookup_name( int result; rtems_filesystem_node_types_t node_type; - result = rtems_filesystem_evaluate_path( name, 0x00, &loc, true ); + result = rtems_filesystem_evaluate_path( name, strlen( name ), 0x00, &loc, true ); the_jnode = loc.node_access; if ( !loc.ops->node_type_h ) { diff --git a/cpukit/libfs/src/imfs/memfile.c b/cpukit/libfs/src/imfs/memfile.c index e9b4d70f97..08c426d5da 100644 --- a/cpukit/libfs/src/imfs/memfile.c +++ b/cpukit/libfs/src/imfs/memfile.c @@ -1105,7 +1105,8 @@ fflush(stdout); */ int memfile_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parent_pathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ) { IMFS_jnode_t *the_jnode; diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c index daafac8c87..50c125ad28 100644 --- a/cpukit/libfs/src/nfsclient/src/nfs.c +++ b/cpukit/libfs/src/nfsclient/src/nfs.c @@ -1355,6 +1355,7 @@ struct rtems_filesystem_location_info_tt STATIC int nfs_do_evalpath( const char *pathname, /* IN */ + int pathnamelen, /* IN */ void *arg, rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ int forMake @@ -1375,7 +1376,8 @@ unsigned long niu,siu; e = ENOMEM; goto cleanup; } - strcpy(p, pathname); + memset(p, 0, MAXPATHLEN+1); + memcpy(p, pathname, pathnamelen); LOCK(nfsGlob.lock); node = nfsNodeClone(node); @@ -1510,7 +1512,7 @@ unsigned long niu,siu; if (forMake) rval = pathloc->ops->evalformake_h(part, pathloc, (const char**)arg); else - rval = pathloc->ops->evalpath_h(part, (int)arg, pathloc); + rval = pathloc->ops->evalpath_h(part, strlen(part), (int)arg, pathloc); free(p); return rval; @@ -1667,16 +1669,17 @@ static int nfs_evalformake( const char **pname /* OUT */ ) { - return nfs_do_evalpath(path, (void*)pname, pathloc, 1 /*forMake*/); + return nfs_do_evalpath(path, strlen(path), (void*)pname, pathloc, 1 /*forMake*/); } static int nfs_evalpath( const char *path, /* IN */ + int pathlen, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */ ) { - return nfs_do_evalpath(path, (void*)flags, pathloc, 0 /*not forMake*/); + return nfs_do_evalpath(path, pathlen, (void*)flags, pathloc, 0 /*not forMake*/); } @@ -1729,7 +1732,8 @@ NfsNode tNode = to_loc->node_access; } static int nfs_do_unlink( - rtems_filesystem_location_info_t *loc, /* IN */ + rtems_filesystem_location_info_t *parent_loc,/* IN */ + rtems_filesystem_location_info_t *loc, /* IN */ int proc ) { @@ -1768,10 +1772,11 @@ char *name = NFSPROC_REMOVE == proc ? } static int nfs_unlink( - rtems_filesystem_location_info_t *loc /* IN */ + rtems_filesystem_location_info_t *parent_loc, /* IN */ + rtems_filesystem_location_info_t *loc /* IN */ ) { - return nfs_do_unlink(loc, NFSPROC_REMOVE); + return nfs_do_unlink(parent_loc, loc, NFSPROC_REMOVE); } static int nfs_chown( @@ -2357,7 +2362,7 @@ int rval = RVAL_ERR_AND_DO_FREENODE; pathloc->handlers = &nfs_dir_file_handlers; - err = nfs_evalpath(buf, flags, pathloc); + err = nfs_evalpath(buf, strlen(buf), flags, pathloc); /* according to its semantics, * nfs_evalpath cloned the node attached @@ -2398,7 +2403,7 @@ int rval = RVAL_ERR_AND_DO_FREENODE; */ rtems_filesystem_freenode(pathloc); - if (rtems_filesystem_evaluate_path(buf, flags, pathloc, 1)) { + if (rtems_filesystem_evaluate_path(buf, strlen(buf), flags, pathloc, 1)) { /* If evalpath fails then there is no valid node * attached to pathloc; hence we must not attempt * to free the node @@ -3079,10 +3084,11 @@ static int nfs_file_fcntl( * call, though... */ static int nfs_dir_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ + rtems_filesystem_location_info_t *parentpathloc, /* IN */ + rtems_filesystem_location_info_t *pathloc /* IN */ ) { - return nfs_do_unlink(pathloc, NFSPROC_RMDIR); + return nfs_do_unlink(parentpathloc, pathloc, NFSPROC_RMDIR); } /* the file handlers table */ diff --git a/cpukit/libfs/src/pipe/pipe.c b/cpukit/libfs/src/pipe/pipe.c index 339aa42f4e..54628898ac 100644 --- a/cpukit/libfs/src/pipe/pipe.c +++ b/cpukit/libfs/src/pipe/pipe.c @@ -30,7 +30,7 @@ int pipe_create( int err = 0; /* Create /tmp if not exists */ - if (rtems_filesystem_evaluate_path("/tmp", RTEMS_LIBIO_PERMS_RWX, &loc, TRUE) + if (rtems_filesystem_evaluate_path("/tmp", 3, RTEMS_LIBIO_PERMS_RWX, &loc, TRUE) != 0) { if (errno != ENOENT) return -1; diff --git a/cpukit/libmisc/fsmount/fsmount.c b/cpukit/libmisc/fsmount/fsmount.c index 506c44aeb1..6e9ba263a7 100644 --- a/cpukit/libmisc/fsmount/fsmount.c +++ b/cpukit/libmisc/fsmount/fsmount.c @@ -76,7 +76,8 @@ int rtems_fsmount_create_mount_point /* * scan through given string, one segment at a time */ - token_type = IMFS_get_token(mount_point+total_len,token,&token_len); + token_type = IMFS_get_token(mount_point+total_len,strlen(mount_point+total_len), + token,&token_len); total_len += token_len; strncpy(tok_buffer,mount_point,total_len); tok_buffer[total_len] = '\0'; diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h index 1855d0b080..aadd346092 100644 --- a/cpukit/libmisc/shell/internal.h +++ b/cpukit/libmisc/shell/internal.h @@ -29,13 +29,6 @@ rtems_shell_topic_t * rtems_shell_lookup_topic(const char *topic); void rtems_shell_register_monitor_commands(void); void rtems_shell_initialize_command_set(void); -int rtems_shell_libc_mounter( - const char* driver, - const char* path, - rtems_shell_filesystems_t* fs, - rtems_filesystem_options_t options -); - void rtems_shell_print_heap_info( const char *c, Heap_Information *h diff --git a/cpukit/libmisc/shell/main_mount.c b/cpukit/libmisc/shell/main_mount.c index c949715313..43b6aaf36e 100644 --- a/cpukit/libmisc/shell/main_mount.c +++ b/cpukit/libmisc/shell/main_mount.c @@ -28,6 +28,30 @@ #include #include "internal.h" +static rtems_chain_control filesystems; +static bool fs_init; + +static void rtems_shell_mount_fsys_init() +{ + if (!fs_init) + { + rtems_chain_initialize_empty (&filesystems); + fs_init = true; + } +} + +void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs) +{ + rtems_shell_mount_fsys_init(); + rtems_chain_append (&filesystems, &fs->link); +} + +void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs) +{ + if (fs_init) + rtems_chain_extract (&fs->link); +} + int rtems_shell_libc_mounter( const char* driver, const char* path, @@ -60,12 +84,14 @@ int rtems_shell_main_mount( char* driver = NULL; char* mount_point = NULL; int arg; + + rtems_shell_mount_fsys_init(); for (arg = 1; arg < argc; arg++) { if (argv[arg][0] == '-') { if (argv[arg][1] == 't') { rtems_shell_filesystems_t** a; - + arg++; if (arg == argc) { fprintf( @@ -82,6 +108,18 @@ int rtems_shell_main_mount( break; } } + + if (!fs && !rtems_chain_is_empty(&filesystems)) { + rtems_chain_node* node = filesystems.first; + while (!rtems_chain_is_tail (&filesystems, node)) { + rtems_shell_filesystems_t* f = (rtems_shell_filesystems_t*)node; + if (strcmp (argv[arg], f->name) == 0) { + fs = f; + break; + } + node = node->next; + } + } } else if (argv[arg][1] == 'r') { options = RTEMS_FILESYSTEM_READ_ONLY; } else if (argv[arg][1] == 'L') { diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h index 333b03d977..a9782b846b 100644 --- a/cpukit/libmisc/shell/shell.h +++ b/cpukit/libmisc/shell/shell.h @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -232,6 +233,7 @@ typedef int (*rtems_shell_filesystems_mounter_t)( ); struct rtems_shell_filesystems_tt { + rtems_chain_node link; const char *name; int driver_needed; const rtems_filesystem_operations_table *fs_ops; @@ -257,6 +259,35 @@ void rtems_shell_get_prompt( size_t size ); +/** + * Helper for the mount command. + * + * @param[in] driver The path to the driver. + * @param[in] path The path to mount on. + * @param[in] fs The file system definition. + * @param[in] options Special file system options. + */ +int rtems_shell_libc_mounter( + const char* driver, + const char* path, + rtems_shell_filesystems_t* fs, + rtems_filesystem_options_t options +); + +/** + * Add a new file system mount configuration to the mount command. + * + * @param[in] fs The file system mount data. + */ +void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs); + +/** + * Delete file system mount configuration from the mount command. + * + * @param[in] fs The file system mount data to remove. + */ +void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs); + #ifdef __cplusplus } #endif diff --git a/cpukit/libnetworking/lib/ftpfs.c b/cpukit/libnetworking/lib/ftpfs.c index 65f651f5f5..46ce18b984 100644 --- a/cpukit/libnetworking/lib/ftpfs.c +++ b/cpukit/libnetworking/lib/ftpfs.c @@ -1183,6 +1183,7 @@ static int rtems_ftpfs_ftruncate( rtems_libio_t *iop, rtems_off64_t count) static int rtems_ftpfs_eval_path( const char *pathname, + int pathnamelen, int flags, rtems_filesystem_location_info_t *pathloc ) @@ -1192,6 +1193,11 @@ static int rtems_ftpfs_eval_path( * We need to store this path here or otherwise we would have to do this job * again. The path is used in rtems_ftpfs_open() via iop->file_info. */ + pathloc->node_access = malloc(pathnamelen + 1); + if (pathloc->node_access) { + memset(pathloc->node_access, 0, pathnamelen + 1); + memcpy(pathloc->node_access, pathname, pathnamelen); + } pathloc->node_access = strdup( pathname); return 0; -- cgit v1.2.3