From 29e92b090c8bc35745aa5c89231ce806bcb11e57 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Mon, 31 May 2010 13:56:37 +0000 Subject: 2010-05-31 Chris Johns * libcsupport/Makefile.am: Add mount-mgr.c. * libcsupport/src/mount-mgr.c: New. * include/rtems/fs.h: Added rtems_filesystem_location_mount. * libcsupport/include/rtems/libio.h, libcsupport/src/mount.c: New mount interface. It is similar to Linux. * libcsupport/include/rtems/libio_.h: Remove the init_fs_mount_table call. * libcsupport/src/base_fs.c: Remove init_fs_mount_table_call. Use the new mount call. Remove setting the root node in the global pathloc. Mount does this now. * libcsupport/src/privateenv.c: Remove the hack to set the root mount table entry in the environment. * libcsupport/src/unmount.cL Free the target string. * libblock/src/bdpart-mount.c: New mount API. * libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_init.c, libfs/src/dosfs/dosfs.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c, libfs/src/imfs/miniimfs_init.c, libfs/src/nfsclient/src/librtemsNfs.h, libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs.h, libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h, libnetworking/rtems/tftp.h: New mount_h API. * libfs/src/devfs/devfs_eval.c: Local include of extern ops. * libfs/src/nfsclient/src/nfs.c: New mount API. Removed the mount me call and fixed the initialisation to happen when mounting. * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Remove mount filesystem files. * libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h: Updated to the new mount table values. * libmisc/shell/main_mount_ftp.c, libmisc/shell/main_mount_msdos.c, libmisc/shell/main_mount_rfs.c, libmisc/shell/main_mount_tftp.c: Removed. * libmisc/shell/main_mount.c: Use the new mount API. Also access the file system table for the file system types. * libnetworking/lib/tftpDriver.c: Updated to the new mount API. Fixed to allow mounting from any mount point. Also can now have more than file system mounted. * sapi/include/confdefs.h: Add file system configuration support. --- cpukit/ChangeLog | 50 +++ cpukit/include/rtems/fs.h | 5 + cpukit/libblock/src/bdpart-mount.c | 9 +- cpukit/libcsupport/Makefile.am | 2 +- cpukit/libcsupport/include/rtems/libio.h | 138 ++++++-- cpukit/libcsupport/include/rtems/libio_.h | 2 - cpukit/libcsupport/src/base_fs.c | 8 +- cpukit/libcsupport/src/mount.c | 287 +++++++++------- cpukit/libcsupport/src/privateenv.c | 14 +- cpukit/libcsupport/src/unmount.c | 1 + cpukit/libfs/src/devfs/devfs.h | 22 +- cpukit/libfs/src/devfs/devfs_eval.c | 14 + cpukit/libfs/src/devfs/devfs_init.c | 3 +- cpukit/libfs/src/dosfs/dosfs.h | 3 +- cpukit/libfs/src/dosfs/msdos.h | 2 - cpukit/libfs/src/dosfs/msdos_init.c | 8 +- cpukit/libfs/src/imfs/imfs.h | 6 +- cpukit/libfs/src/imfs/imfs_eval.c | 74 ++-- cpukit/libfs/src/imfs/imfs_init.c | 3 +- cpukit/libfs/src/imfs/miniimfs_init.c | 3 +- cpukit/libfs/src/nfsclient/src/librtemsNfs.h | 35 +- cpukit/libfs/src/nfsclient/src/nfs.c | 55 ++- cpukit/libfs/src/rfs/rtems-rfs-rtems.c | 8 +- cpukit/libfs/src/rfs/rtems-rfs.h | 7 +- cpukit/libmisc/Makefile.am | 9 +- cpukit/libmisc/fsmount/fsmount.c | 97 +++--- cpukit/libmisc/fsmount/fsmount.h | 31 +- cpukit/libmisc/shell/main_mount.c | 149 +++----- cpukit/libmisc/shell/main_mount_ftp.c | 37 -- cpukit/libmisc/shell/main_mount_msdos.c | 35 -- cpukit/libmisc/shell/main_mount_rfs.c | 36 -- cpukit/libmisc/shell/main_mount_tftp.c | 37 -- cpukit/libmisc/shell/shellconfig.h | 39 --- cpukit/libnetworking/lib/ftpfs.c | 23 +- cpukit/libnetworking/lib/tftpDriver.c | 489 +++++++++++++++------------ cpukit/libnetworking/rtems/ftpfs.h | 19 +- cpukit/libnetworking/rtems/tftp.h | 8 +- cpukit/sapi/include/confdefs.h | 258 ++++++++++++-- 38 files changed, 1125 insertions(+), 901 deletions(-) delete mode 100644 cpukit/libmisc/shell/main_mount_ftp.c delete mode 100644 cpukit/libmisc/shell/main_mount_msdos.c delete mode 100644 cpukit/libmisc/shell/main_mount_rfs.c delete mode 100644 cpukit/libmisc/shell/main_mount_tftp.c diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 4b31b254e9..8767213c2a 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,53 @@ +2010-05-31 Chris Johns + + * libcsupport/Makefile.am: Add mount-mgr.c. + * libcsupport/src/mount-mgr.c: New. + * include/rtems/fs.h: Added rtems_filesystem_location_mount. + * libcsupport/include/rtems/libio.h, libcsupport/src/mount.c: New + mount interface. It is similar to Linux. + * libcsupport/include/rtems/libio_.h: Remove the + init_fs_mount_table call. + * libcsupport/src/base_fs.c: Remove init_fs_mount_table_call. Use + the new mount call. Remove setting the root node in the global + pathloc. Mount does this now. + * libcsupport/src/privateenv.c: Remove the hack to set the root + mount table entry in the environment. + * libcsupport/src/unmount.cL Free the target string. + * libblock/src/bdpart-mount.c: New mount API. + + * libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_init.c, + libfs/src/dosfs/dosfs.h, libfs/src/dosfs/msdos.h, + libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs.h, + libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c, + libfs/src/imfs/miniimfs_init.c, + libfs/src/nfsclient/src/librtemsNfs.h, + libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs.h, + libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h, + libnetworking/rtems/tftp.h: New mount_h API. + + * libfs/src/devfs/devfs_eval.c: Local include of extern ops. + * libfs/src/nfsclient/src/nfs.c: New mount API. Removed the mount + me call and fixed the initialisation to happen when mounting. + + * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Remove mount + filesystem files. + + * libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h: Updated to + the new mount table values. + + * libmisc/shell/main_mount_ftp.c, + libmisc/shell/main_mount_msdos.c, libmisc/shell/main_mount_rfs.c, + libmisc/shell/main_mount_tftp.c: Removed. + + * libmisc/shell/main_mount.c: Use the new mount API. Also access + the file system table for the file system types. + + * libnetworking/lib/tftpDriver.c: Updated to the new mount + API. Fixed to allow mounting from any mount point. Also can now + have more than file system mounted. + + * sapi/include/confdefs.h: Add file system configuration support. + 2010-05-29 Ralf Corsépius PR 1531/newlib: diff --git a/cpukit/include/rtems/fs.h b/cpukit/include/rtems/fs.h index e86ca5dafe..cd8a8d5457 100644 --- a/cpukit/include/rtems/fs.h +++ b/cpukit/include/rtems/fs.h @@ -52,6 +52,11 @@ struct rtems_filesystem_location_info_tt rtems_filesystem_mount_table_entry_t *mt_entry; }; +/* + * Return the mount table entry for a path location. + */ +#define rtems_filesystem_location_mount(_pl) ((_pl)->mt_entry) + #ifdef __cplusplus } #endif diff --git a/cpukit/libblock/src/bdpart-mount.c b/cpukit/libblock/src/bdpart-mount.c index 9c871d2f88..8f2e051c61 100644 --- a/cpukit/libblock/src/bdpart-mount.c +++ b/cpukit/libblock/src/bdpart-mount.c @@ -29,7 +29,6 @@ #include #include -#include #include rtems_status_code rtems_bdpart_mount( @@ -99,11 +98,11 @@ rtems_status_code rtems_bdpart_mount( /* Mount */ rv = mount( - NULL, - &msdos_ops, - 0, logical_disk_name, - mount_point + mount_point, + "msdos", + 0, + NULL ); if (rv != 0) { rmdir( mount_point); diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index c802c36de6..c9729c289b 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -44,7 +44,7 @@ ASSOCIATION_C_FILES = src/assoclocalbyname.c \ src/assocremotebylocal.c src/assocremotebyname.c BASE_FS_C_FILES = src/base_fs.c src/mount.c src/unmount.c src/libio.c \ - src/libio_init.c \ + src/mount-mgr.c src/libio_init.c \ src/libio_sockets.c src/eval.c src/fs_null_handlers.c src/privateenv.c \ src/open_dev_console.c src/__usrenv.c diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h index fb96e07b22..4f45ee47ac 100644 --- a/cpukit/libcsupport/include/rtems/libio.h +++ b/cpukit/libcsupport/include/rtems/libio.h @@ -209,23 +209,24 @@ typedef int (*rtems_filesystem_freenode_t)( ); typedef int (* rtems_filesystem_mount_t ) ( - rtems_filesystem_mount_table_entry_t *mt_entry /* in */ + rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ ); typedef int (* rtems_filesystem_fsmount_me_t )( - rtems_filesystem_mount_table_entry_t *mt_entry + rtems_filesystem_mount_table_entry_t *mt_entry, /* IN */ + const void *data /* IN */ ); typedef int (* rtems_filesystem_unmount_t ) ( - rtems_filesystem_mount_table_entry_t *mt_entry /* in */ + rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ ); typedef int (* rtems_filesystem_fsunmount_me_t ) ( - rtems_filesystem_mount_table_entry_t *mt_entry /* in */ + rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ ); typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) ( - rtems_filesystem_location_info_t *pathloc /* in */ + rtems_filesystem_location_info_t *pathloc /* IN */ ); typedef int (* rtems_filesystem_utime_t)( @@ -291,6 +292,62 @@ struct _rtems_filesystem_operations_table { rtems_filesystem_statvfs_t statvfs_h; }; +/* + * File system table used by mount to manage file systems. + */ +typedef struct _rtems_filesystem_table { + const char *type; + rtems_filesystem_fsmount_me_t mount_h; +} rtems_filesystem_table_t; + +/* + * File system table runtime loaded nodes. + */ +typedef struct _rtems_filesystem_table_node { + rtems_chain_node node; + rtems_filesystem_table_t entry; +} rtems_filesystem_table_node_t; + +/* + * Get the first entry in the filesystem table. + */ +const rtems_filesystem_table_t* rtems_filesystem_table_first( void ); + +/* + * Get the next entry in the file system table. + */ +const rtems_filesystem_table_t* +rtems_filesystem_table_next( rtems_filesystem_table_t *entry ); + +/* + * Get the first entry in the mount table. + */ +rtems_filesystem_mount_table_entry_t* +rtems_filesystem_mounts_first( void ); + +/* + * Get the next entry in the mount table. + */ +rtems_filesystem_mount_table_entry_t* +rtems_filesystem_mounts_next( rtems_filesystem_mount_table_entry_t *entry ); + +/* + * Register a file system. + */ +int +rtems_filesystem_register( + const char *type, + rtems_filesystem_fsmount_me_t mount_h +); + +/* + * Unregister a file system. + */ +int +rtems_filesystem_unregister( + const char *type +); + #if 0 /* Now in exec/include/rtems/fs.h */ @@ -313,20 +370,25 @@ struct rtems_filesystem_location_info_tt */ typedef struct { - int link_max; - int max_canon; - int max_input; - int name_max; - int path_max; - int pipe_buf; - int posix_async_io; - int posix_chown_restrictions; - int posix_no_trunc; - int posix_prio_io; - int posix_sync_io; - int posix_vdisable; + int link_max; /* count */ + int max_canon; /* max formatted input line size */ + int max_input; /* max input line size */ + int name_max; /* max name length */ + int path_max; /* max path */ + int pipe_buf; /* pipe buffer size */ + int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */ + int posix_chown_restrictions; /* can chown: 0=no, 1=yes */ + int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */ + int posix_prio_io; /* priority IO, 0=no, 1=yes */ + int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */ + int posix_vdisable; /* special char processing, 0=no, 1=yes */ } rtems_filesystem_limits_and_options_t; +/* + * Default pathconf settings. Override in a filesystem. + */ +extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf; + /* * Structure for a mount table entry. */ @@ -340,6 +402,16 @@ struct rtems_filesystem_mount_table_entry_tt { rtems_filesystem_limits_and_options_t pathconf_limits_and_options; + /* + * The target or mount point of the file system. + */ + const char *target; + + /* + * The type of filesystem or the name of the filesystem. + */ + const char *type; + /* * When someone adds a mounted filesystem on a real device, * this will need to be used. @@ -350,6 +422,26 @@ struct rtems_filesystem_mount_table_entry_tt { char *dev; }; +/** + * The pathconf setting for a file system. + */ +#define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) + +/** + * The type of file system. Its name. + */ +#define rtems_filesystem_type(_mte) ((_mte)->type) + +/** + * The mount point of a file system. + */ +#define rtems_filesystem_mount_point(_mte) ((_mte)->target) + +/** + * The device entry of a file system. + */ +#define rtems_filesystem_mount_device(_mte) ((_mte)->dev) + /* * Valid RTEMS file systems options */ @@ -637,11 +729,11 @@ int unmount( ); int mount( - rtems_filesystem_mount_table_entry_t **mt_entry, - const rtems_filesystem_operations_table *fs_ops, - rtems_filesystem_options_t fsoptions, - const char *device, - const char *mount_point + const char *source, + const char *target, + const char *filesystemtype, + rtems_filesystem_options_t options, + const void *data ); /* @@ -649,7 +741,7 @@ int mount( */ typedef struct { - const rtems_filesystem_operations_table *fs_ops; + const char *type; rtems_filesystem_options_t fsoptions; const char *device; const char *mount_point; diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h index 248357a4ef..22f498b98a 100644 --- a/cpukit/libcsupport/include/rtems/libio_.h +++ b/cpukit/libcsupport/include/rtems/libio_.h @@ -271,8 +271,6 @@ int rtems_filesystem_prefix_separators( void rtems_filesystem_initialize(void); -int init_fs_mount_table(void); - #ifdef __cplusplus } #endif diff --git a/cpukit/libcsupport/src/base_fs.c b/cpukit/libcsupport/src/base_fs.c index 819456434f..e552769577 100644 --- a/cpukit/libcsupport/src/base_fs.c +++ b/cpukit/libcsupport/src/base_fs.c @@ -36,7 +36,6 @@ void rtems_filesystem_initialize( void ) { int status; - rtems_filesystem_mount_table_entry_t *entry; const rtems_filesystem_mount_table_t *mt; rtems_filesystem_location_info_t loc; @@ -46,9 +45,6 @@ void rtems_filesystem_initialize( void ) rtems_filesystem_umask = 022; - - init_fs_mount_table(); - /* * mount the first filesystem. */ @@ -58,8 +54,7 @@ void rtems_filesystem_initialize( void ) mt = &rtems_filesystem_mount_table[0]; - status = mount( - &entry, mt->fs_ops, mt->fsoptions, mt->device, mt->mount_point ); + status = mount( mt->device, mt->mount_point, mt->type, mt->fsoptions, NULL ); if ( status == -1 ) rtems_fatal_error_occurred( 0xABCD0002 ); @@ -86,7 +81,6 @@ void rtems_filesystem_initialize( void ) * * Till Straumann, 10/25/2002 */ - rtems_filesystem_root = entry->mt_fs_root; /* Clone the root pathloc */ rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); rtems_filesystem_root = loc; diff --git a/cpukit/libcsupport/src/mount.c b/cpukit/libcsupport/src/mount.c index d21a084be0..3e3c47166d 100644 --- a/cpukit/libcsupport/src/mount.c +++ b/cpukit/libcsupport/src/mount.c @@ -33,24 +33,72 @@ #include -rtems_chain_control rtems_filesystem_mount_table_control; +/* + * External defined by confdefs.h or the user. + */ +extern const rtems_filesystem_table_t configuration_filesystem_table[]; /* - * Prototypes that probably should be somewhere else. + * Points to a list of filesystems added at runtime. */ +rtems_chain_control *rtems_filesystem_table; -int init_fs_mount_table( void ); -static bool Is_node_fs_root( - rtems_filesystem_location_info_t *loc -); +/* + * Mount table list. + */ +rtems_chain_control rtems_filesystem_mount_table_control; +bool rtems_filesystem_mount_table_control_init; +/* + * Default pathconfs. + */ +const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf = { + 5, /* link_max: count */ + 128, /* max_canon: max formatted input line size */ + 7, /* max_input: max input line size */ + 255, /* name_max: max name */ + 255, /* path_max: max path */ + 1024, /* pipe_buf: pipe buffer size */ + 0, /* posix_async_io: async IO supported on fs, 0=no, 1=yes */ + 0 , /* posix_chown_restrictions: can chown: 0=no, 1=yes */ + 1, /* posix_no_trunc: error on filenames > max name, 0=no, 1=yes */ + 0, /* posix_prio_io: priority IO, 0=no, 1=yes */ + 0, /* posix_sync_io: file can be sync'ed, 0=no, 1=yes */ + 0 /* posix_vdisable: special char processing, 0=no, 1=yes */ +}; /* - * XXX + * Is_node_fs_root + * + * This routine will run through the entries that currently exist in the + * mount table chain. For each entry in the mount table chain it will + * compare the mount tables root node to the node describing the selected + * mount point. If any match is found true is returned else false is + * returned. + * */ -#define FOUND 0 -#define NOT_FOUND -1 +static bool Is_node_fs_root( + rtems_filesystem_location_info_t *loc +) +{ + rtems_chain_node *the_node; + rtems_filesystem_mount_table_entry_t *the_mount_entry; + + /* + * For each mount table entry + */ + if ( rtems_filesystem_mount_table_control_init ) { + for ( the_node = rtems_chain_first( &rtems_filesystem_mount_table_control ); + !rtems_chain_is_tail( &rtems_filesystem_mount_table_control, the_node ); + the_node = rtems_chain_next( the_node ) ) { + the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node; + if ( the_mount_entry->mt_fs_root.node_access == loc->node_access ) + return true; + } + } + return false; +} /* * mount @@ -68,27 +116,25 @@ static bool Is_node_fs_root( */ int mount( - rtems_filesystem_mount_table_entry_t **mt_entry, - const rtems_filesystem_operations_table *fs_ops, - rtems_filesystem_options_t options, - const char *device, - const char *mount_point -) + const char *source, + const char *target, + const char *filesystemtype, + rtems_filesystem_options_t options, + const void *data + ) { + const rtems_filesystem_table_t *entry; rtems_filesystem_location_info_t loc; - rtems_filesystem_mount_table_entry_t *temp_mt_entry = NULL; + rtems_filesystem_mount_table_entry_t *mt_entry = NULL; rtems_filesystem_location_info_t *loc_to_free = NULL; size_t size; -/* XXX add code to check for required operations */ - /* - * Is there a file system operations table? + * If mount is ever called we allocate the mount table control structure. */ - - if ( fs_ops == NULL ) { - errno = EINVAL; - return -1; + if ( !rtems_filesystem_mount_table_control_init ) { + rtems_filesystem_mount_table_control_init = true; + rtems_chain_initialize_empty ( &rtems_filesystem_mount_table_control ); } /* @@ -101,45 +147,88 @@ int mount( return -1; } - /* Do they support being mounted at all ? */ - if ( !fs_ops->fsmount_me_h ) { - errno = ENOTSUP; - goto cleanup_and_bail; + /* + * Check the type. + */ + if (!filesystemtype) { + errno = EINVAL; + return -1; } + if (strlen(filesystemtype) >= 128) { + errno = EINVAL; + return -1; + } + + /* + * Check the configuration table filesystems then check any runtime added + * file systems. + */ + entry = &configuration_filesystem_table[0]; + while (entry->type) { + if (strcmp (filesystemtype, entry->type) == 0) + break; + ++entry; + } + + if (!entry->type) { + entry = NULL; + if (rtems_filesystem_table) { + rtems_chain_node *the_node; + for (the_node = rtems_chain_first(rtems_filesystem_table); + !rtems_chain_is_tail(rtems_filesystem_table, the_node); + the_node = rtems_chain_next(the_node)) { + entry = &(((rtems_filesystem_table_node_t*) the_node)->entry); + if (strcmp (filesystemtype, entry->type) == 0) + break; + entry = NULL; + } + } + } + if (!entry) + { + errno = EINVAL; + return -1; + } + /* * Allocate a mount table entry */ - size = sizeof(rtems_filesystem_mount_table_entry_t); - if ( device ) - size += strlen( device ) + 1; - temp_mt_entry = malloc( size ); - - if ( !temp_mt_entry ) { - errno = ENOMEM; - return -1; - } - - temp_mt_entry->mt_fs_root.mt_entry = temp_mt_entry; - temp_mt_entry->options = options; - if ( device ) { - temp_mt_entry->dev = - (char *)temp_mt_entry + sizeof( rtems_filesystem_mount_table_entry_t ); - strcpy( temp_mt_entry->dev, device ); - } else - temp_mt_entry->dev = 0; + size = sizeof(rtems_filesystem_mount_table_entry_t); + if ( source ) + size += strlen( source ) + 1; + + mt_entry = malloc( size ); + if ( !mt_entry ) { + errno = ENOMEM; + return -1; + } + + memset( mt_entry, 0, size ); + + mt_entry->mt_fs_root.mt_entry = mt_entry; + mt_entry->type = entry->type; + mt_entry->options = options; + mt_entry->pathconf_limits_and_options = rtems_filesystem_default_pathconf; + + if ( source ) { + mt_entry->dev = + (char *)mt_entry + sizeof( rtems_filesystem_mount_table_entry_t ); + strcpy( mt_entry->dev, source ); + } else + mt_entry->dev = 0; /* * The mount_point should be a directory with read/write/execute * permissions in the existing tree. */ - if ( mount_point ) { + if ( target ) { if ( rtems_filesystem_evaluate_path( - mount_point, strlen( mount_point ), RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 ) + target, strlen( target ), RTEMS_LIBIO_PERMS_RWX, &loc, true ) == -1 ) goto cleanup_and_bail; loc_to_free = &loc; @@ -179,11 +268,11 @@ int mount( * traverse the tree. */ - temp_mt_entry->mt_point_node.node_access = loc.node_access; - temp_mt_entry->mt_point_node.handlers = loc.handlers; - temp_mt_entry->mt_point_node.ops = loc.ops; - temp_mt_entry->mt_point_node.mt_entry = loc.mt_entry; - + mt_entry->mt_point_node.node_access = loc.node_access; + mt_entry->mt_point_node.handlers = loc.handlers; + mt_entry->mt_point_node.ops = loc.ops; + mt_entry->mt_point_node.mt_entry = loc.mt_entry; + /* * This link to the parent is only done when we are dealing with system * below the base file system @@ -194,31 +283,45 @@ int mount( goto cleanup_and_bail; } - if ( loc.ops->mount_h( temp_mt_entry ) ) { + if ( loc.ops->mount_h( mt_entry ) ) { goto cleanup_and_bail; } + + mt_entry->target = strdup( target ); } else { + /* + * Do we already have a base file system ? + */ + if ( !rtems_chain_is_empty( &rtems_filesystem_mount_table_control ) ) { + errno = EINVAL; + goto cleanup_and_bail; + } + /* * This is a mount of the base file system --> The * mt_point_node.node_access will be set to null to indicate that this * is the root of the entire file system. */ - temp_mt_entry->mt_fs_root.node_access = NULL; - temp_mt_entry->mt_fs_root.handlers = NULL; - temp_mt_entry->mt_fs_root.ops = NULL; + mt_entry->mt_fs_root.node_access = NULL; + mt_entry->mt_fs_root.handlers = NULL; + mt_entry->mt_fs_root.ops = NULL; + + mt_entry->mt_point_node.node_access = NULL; + mt_entry->mt_point_node.handlers = NULL; + mt_entry->mt_point_node.ops = NULL; + mt_entry->mt_point_node.mt_entry = NULL; - temp_mt_entry->mt_point_node.node_access = NULL; - temp_mt_entry->mt_point_node.handlers = NULL; - temp_mt_entry->mt_point_node.ops = NULL; - temp_mt_entry->mt_point_node.mt_entry = NULL; + mt_entry->target = "/"; } - if ( fs_ops->fsmount_me_h( temp_mt_entry ) ) { - /* try to undo the mount operation */ - if ( loc.ops->unmount_h ) { - loc.ops->unmount_h( temp_mt_entry ); + if ( entry->mount_h( mt_entry, data ) ) { + /* + * Try to undo the mount operation + */ + if ( loc.ops->unmount_h ) { + loc.ops->unmount_h( mt_entry ); } goto cleanup_and_bail; } @@ -226,18 +329,18 @@ int mount( /* * Add the mount table entry to the mount table chain */ - rtems_chain_append( &rtems_filesystem_mount_table_control, - &temp_mt_entry->Node ); + &mt_entry->Node ); - if ( mt_entry ) - *mt_entry = temp_mt_entry; + if ( !target ) + rtems_filesystem_root = mt_entry->mt_fs_root; return 0; cleanup_and_bail: - free( temp_mt_entry ); + free( (void*) mt_entry->target ); + free( mt_entry ); if ( loc_to_free ) rtems_filesystem_freenode( loc_to_free ); @@ -245,49 +348,3 @@ cleanup_and_bail: return -1; } - - -/* - * init_fs_mount_table - * - * This routine will initialize the chain control element that manages the - * mount table chain. - */ - -int init_fs_mount_table(void) -{ - rtems_chain_initialize_empty ( &rtems_filesystem_mount_table_control ); - return 0; -} - -/* - * Is_node_fs_root - * - * This routine will run through the entries that currently exist in the - * mount table chain. For each entry in the mount table chain it will - * compare the mount tables root node to the node describing the selected - * mount point. If any match is found true is returned else false is - * returned. - * - */ - -static bool Is_node_fs_root( - rtems_filesystem_location_info_t *loc -) -{ - rtems_chain_node *the_node; - rtems_filesystem_mount_table_entry_t *the_mount_entry; - - /* - * For each mount table entry - */ - - for ( the_node = rtems_filesystem_mount_table_control.first; - !rtems_chain_is_tail( &rtems_filesystem_mount_table_control, the_node ); - the_node = the_node->next ) { - the_mount_entry = (rtems_filesystem_mount_table_entry_t *) the_node; - if ( the_mount_entry->mt_fs_root.node_access == loc->node_access ) - return true; - } - return false; -} diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index d61f9013a9..3d31cf55e2 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -1,5 +1,5 @@ /* - * Instantatiate a private user environment for the calling thread. + * Instantiate a private user environment for the calling thread. * * Submitted by: fernando.ruiz@ctv.es (correo@fernando-ruiz.com) * @@ -24,12 +24,6 @@ #include #include -extern rtems_chain_control rtems_filesystem_mount_table_control; - -#define THE_ROOT_FS_LOC \ - (((rtems_filesystem_mount_table_entry_t*)\ - rtems_filesystem_mount_table_control.first)->mt_fs_root) - /* cleanup a user environment * NOTE: this must be called with * thread dispatching disabled! @@ -82,13 +76,11 @@ rtems_status_code rtems_libio_set_private_env(void) { *rtems_current_user_env = rtems_global_user_env; /* get the global values*/ rtems_current_user_env->task_id=task_id; /* mark the local values*/ - /* get a clean root */ - rtems_filesystem_root = THE_ROOT_FS_LOC; - /* Clone the pathlocs. In contrast to most other * code we must _not_ free the original locs because * what we are trying to do here is forking off - * clones. + * clones. The reason is a pathloc can be allocated by the + * file system and needs to be freed when deleting the environment. */ rtems_filesystem_evaluate_path("/", 1, 0, &loc, 0); diff --git a/cpukit/libcsupport/src/unmount.c b/cpukit/libcsupport/src/unmount.c index 60cfd12416..164cf6ef69 100644 --- a/cpukit/libcsupport/src/unmount.c +++ b/cpukit/libcsupport/src/unmount.c @@ -213,6 +213,7 @@ int unmount( */ rtems_filesystem_freenode( fs_mount_loc ); + free( (void*) mt_entry->target ); free( mt_entry ); return 0; diff --git a/cpukit/libfs/src/devfs/devfs.h b/cpukit/libfs/src/devfs/devfs.h index 6b1daa1a0c..80f67e8450 100644 --- a/cpukit/libfs/src/devfs/devfs.h +++ b/cpukit/libfs/src/devfs/devfs.h @@ -50,22 +50,6 @@ extern int rtems_deviceio_errno(rtems_status_code code); extern uint32_t rtems_device_table_size; - -/** - * The following defines the device-only filesystem operating - * handlers. - */ - -extern rtems_filesystem_operations_table devFS_ops; - -/** - * The following defines the device-only filesystem operating - * handlers. - */ - -extern rtems_filesystem_file_handlers_r devFS_file_handlers; - - /** * This handler maps open operation to rtems_io_open. * @param iop This is the RTEMS's internal representation of file. @@ -257,14 +241,16 @@ extern int devFS_mknod( * initializing it to a known state, and set device file operation * handlers. After this, the device-only filesytem is ready for use * - * @param temp_mt_entry + * @param mt_entry The filesystem mount table entry. + * @param data Filesystem specific data. * @retval upon success, this routine returns 0; otherwise it returns * -1 and errno is set to proper value. The only error is when malloc * failed, and errno is set to NOMEM. */ extern int devFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry + rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data ); diff --git a/cpukit/libfs/src/devfs/devfs_eval.c b/cpukit/libfs/src/devfs/devfs_eval.c index 28e867c4ce..0df5754ad5 100644 --- a/cpukit/libfs/src/devfs/devfs_eval.c +++ b/cpukit/libfs/src/devfs/devfs_eval.c @@ -15,6 +15,20 @@ #include #include "devfs.h" +/** + * The following defines the device-only filesystem operating + * handlers. + */ + +extern rtems_filesystem_operations_table devFS_ops; + +/** + * The following defines the device-only filesystem operating + * handlers. + */ + +extern rtems_filesystem_file_handlers_r devFS_file_handlers; + int devFS_evaluate_path( const char *pathname, size_t pathnamelen, diff --git a/cpukit/libfs/src/devfs/devfs_init.c b/cpukit/libfs/src/devfs/devfs_init.c index 3a64ddc27a..4ce616ebb2 100644 --- a/cpukit/libfs/src/devfs/devfs_init.c +++ b/cpukit/libfs/src/devfs/devfs_init.c @@ -59,7 +59,8 @@ rtems_filesystem_file_handlers_r devFS_file_handlers = int devFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry + rtems_filesystem_mount_table_entry_t *temp_mt_entry, + const void *data ) { rtems_device_name_t *device_name_table; diff --git a/cpukit/libfs/src/dosfs/dosfs.h b/cpukit/libfs/src/dosfs/dosfs.h index eb99411993..5b6cdec2bf 100644 --- a/cpukit/libfs/src/dosfs/dosfs.h +++ b/cpukit/libfs/src/dosfs/dosfs.h @@ -25,7 +25,8 @@ extern "C" { #endif -extern rtems_filesystem_operations_table msdos_ops; +int rtems_dosfs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data); #define MSDOS_FMT_FATANY 0 #define MSDOS_FMT_FAT12 1 diff --git a/cpukit/libfs/src/dosfs/msdos.h b/cpukit/libfs/src/dosfs/msdos.h index 53c0e7340f..03ea5a5a88 100644 --- a/cpukit/libfs/src/dosfs/msdos.h +++ b/cpukit/libfs/src/dosfs/msdos.h @@ -223,8 +223,6 @@ typedef enum msdos_token_types_e #define MSDOS_DPS512_NUM 16 /* Prototypes */ -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( diff --git a/cpukit/libfs/src/dosfs/msdos_init.c b/cpukit/libfs/src/dosfs/msdos_init.c index 1e17bf9545..20d45764ec 100644 --- a/cpukit/libfs/src/dosfs/msdos_init.c +++ b/cpukit/libfs/src/dosfs/msdos_init.c @@ -16,6 +16,7 @@ #endif #include +#include "dosfs.h" #include "msdos.h" const rtems_filesystem_operations_table msdos_ops = { @@ -28,7 +29,7 @@ const rtems_filesystem_operations_table msdos_ops = { .chown_h = NULL, .freenod_h = msdos_free_node_info, .mount_h = NULL, - .fsmount_me_h = msdos_initialize, + .fsmount_me_h = rtems_dosfs_initialize, .unmount_h = NULL, .fsunmount_me_h = msdos_shut_down, .utime_h = NULL, @@ -50,11 +51,12 @@ const rtems_filesystem_operations_table msdos_ops = { * RC_OK on success, or -1 if error occured (errno set apropriately). * */ -int msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry) +int rtems_dosfs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data) { int rc; - rc = msdos_initialize_support(temp_mt_entry, + rc = msdos_initialize_support(mt_entry, &msdos_ops, &msdos_file_handlers, &msdos_dir_handlers); diff --git a/cpukit/libfs/src/imfs/imfs.h b/cpukit/libfs/src/imfs/imfs.h index 666d35a9a5..33d41e9988 100644 --- a/cpukit/libfs/src/imfs/imfs.h +++ b/cpukit/libfs/src/imfs/imfs.h @@ -255,11 +255,13 @@ extern const rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS; */ extern int IMFS_initialize( - rtems_filesystem_mount_table_entry_t *mt_entry + rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data ); extern int miniIMFS_initialize( - rtems_filesystem_mount_table_entry_t *mt_entry + rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data ); extern int IMFS_initialize_support( diff --git a/cpukit/libfs/src/imfs/imfs_eval.c b/cpukit/libfs/src/imfs/imfs_eval.c index 7547c6a0e4..b282e7c9a4 100644 --- a/cpukit/libfs/src/imfs/imfs_eval.c +++ b/cpukit/libfs/src/imfs/imfs_eval.c @@ -490,7 +490,7 @@ int IMFS_eval_path( size_t pathnamelen, /* IN */ int flags, /* IN */ rtems_filesystem_location_info_t *pathloc /* IN/OUT */ -) + ) { int i = 0; int len; @@ -531,40 +531,40 @@ int IMFS_eval_path( if ( type != IMFS_NO_MORE_PATH ) if ( node->type == IMFS_DIRECTORY ) if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) - rtems_set_errno_and_return_minus_one( EACCES ); + rtems_set_errno_and_return_minus_one( EACCES ); node = pathloc->node_access; switch( type ) { case IMFS_UP_DIR: - /* - * Am I at the root of all filesystems? (chroot'ed?) - */ + /* + * Am I at the root of all filesystems? (chroot'ed?) + */ - if ( pathloc->node_access == rtems_filesystem_root.node_access ) - break; /* Throw out the .. in this case */ + if ( pathloc->node_access == rtems_filesystem_root.node_access ) + break; /* Throw out the .. in this case */ - /* - * Am I at the root of this mounted filesystem? - */ + /* + * Am I at the root of this mounted filesystem? + */ if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access) { /* - * Am I at the root of all filesystems? - */ + * Am I at the root of all filesystems? + */ if ( pathloc->node_access == rtems_filesystem_root.node_access ) { break; /* Throw out the .. in this case */ - } else { + } else { newloc = pathloc->mt_entry->mt_point_node; *pathloc = newloc; return (*pathloc->ops->evalpath_h)(&(pathname[i-len]), pathnamelen+len, flags,pathloc); - } - } else { + } + } else { if ( !node->Parent ) rtems_set_errno_and_return_minus_one( ENOENT ); @@ -572,17 +572,17 @@ int IMFS_eval_path( node = node->Parent; pathloc->node_access = node; - } + } pathloc->node_access = node; break; case IMFS_NAME: - /* - * If we are at a link follow it. - */ + /* + * If we are at a link follow it. + */ - if ( node->type == IMFS_HARD_LINK ) { + if ( node->type == IMFS_HARD_LINK ) { IMFS_evaluate_hard_link( pathloc, 0 ); @@ -590,26 +590,26 @@ int IMFS_eval_path( if ( !node ) rtems_set_errno_and_return_minus_one( ENOTDIR ); - } else if ( node->type == IMFS_SYM_LINK ) { + } else if ( node->type == IMFS_SYM_LINK ) { result = IMFS_evaluate_sym_link( pathloc, 0 ); node = pathloc->node_access; if ( result == -1 ) return -1; - } + } - /* - * Only a directory can be decended into. - */ + /* + * Only a directory can be decended into. + */ - if ( node->type != IMFS_DIRECTORY ) + if ( node->type != IMFS_DIRECTORY ) rtems_set_errno_and_return_minus_one( ENOTDIR ); - /* - * 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 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; @@ -617,19 +617,19 @@ int IMFS_eval_path( return (*pathloc->ops->evalpath_h)( &pathname[i-len], pathnamelen+len, flags, pathloc ); - } + } - /* - * Otherwise find the token name in the present location. - */ + /* + * 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 ); - /* - * Set the node access to the point we have found. - */ + /* + * Set the node access to the point we have found. + */ pathloc->node_access = node; break; diff --git a/cpukit/libfs/src/imfs/imfs_init.c b/cpukit/libfs/src/imfs/imfs_init.c index 9dae7cc690..c7e6069d35 100644 --- a/cpukit/libfs/src/imfs/imfs_init.c +++ b/cpukit/libfs/src/imfs/imfs_init.c @@ -59,7 +59,8 @@ const rtems_filesystem_operations_table IMFS_ops = { */ int IMFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry + rtems_filesystem_mount_table_entry_t *temp_mt_entry, + const void *data ) { return IMFS_initialize_support( diff --git a/cpukit/libfs/src/imfs/miniimfs_init.c b/cpukit/libfs/src/imfs/miniimfs_init.c index 2244dfde7d..6bad5e29a2 100644 --- a/cpukit/libfs/src/imfs/miniimfs_init.c +++ b/cpukit/libfs/src/imfs/miniimfs_init.c @@ -59,7 +59,8 @@ const rtems_filesystem_operations_table miniIMFS_ops = { */ int miniIMFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry + rtems_filesystem_mount_table_entry_t *temp_mt_entry, + const void *data ) { return IMFS_initialize_support( diff --git a/cpukit/libfs/src/nfsclient/src/librtemsNfs.h b/cpukit/libfs/src/nfsclient/src/librtemsNfs.h index 8afdb6c60f..01ef9a3a76 100644 --- a/cpukit/libfs/src/nfsclient/src/librtemsNfs.h +++ b/cpukit/libfs/src/nfsclient/src/librtemsNfs.h @@ -70,6 +70,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* RPCIO driver interface. * If you need RPCIO for other purposes than NFS * you may want to include @@ -82,7 +86,9 @@ */ extern rtems_task_priority rpciodPriority; -/* Initialize the driver +/* Initialize the driver. + * + * Note, called in nfsfs initialise when mount is called. * * RETURNS: 0 on success, -1 on failure */ @@ -103,6 +109,8 @@ rpcUdpCleanup(void); * NOTE: The RPCIO driver must have been initialized prior to * calling this. * + * Note, called in nfsfs initialise when mount is called with defaults. + * * ARGS: depth of the small and big * transaction pools, i.e. how * many transactions (buffers) @@ -131,22 +139,12 @@ nfsCleanup(void); int nfsMountsShow(FILE *f); -/* convenience wrapper - * - * NOTE: this routine calls NON-REENTRANT - * gethostbyname() if the host is - * not in 'dot' notation. - */ -int -nfsMount(char *uidhost, char *path, char *mntpoint); - -/* Alternatively, a pointer to the filesystem operations - * table can be supplied to the native RTEMS (NON-POSIX!) - * 'mount()' call. - * Supply a ":" string - * for 'device' argument to 'mount()'. +/* + * Filesystem mount table mount handler. Do not call, use the mount call. */ -extern struct _rtems_filesystem_operations_table nfs_fs_ops; +int +rtems_nfsfs_initialize(rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data); /* A utility routine to find the path leading to a * rtems_filesystem_location_info_t node. @@ -174,4 +172,9 @@ nfsSetTimeout(uint32_t timeout_ms); /* Read current timeout (in milliseconds) */ uint32_t nfsGetTimeout(void); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c index 4444848f0e..de902cbbad 100644 --- a/cpukit/libfs/src/nfsclient/src/nfs.c +++ b/cpukit/libfs/src/nfsclient/src/nfs.c @@ -4,6 +4,8 @@ /* Author: Till Straumann 2002 */ +/* Hacked on by others. */ + /* * Authorship * ---------- @@ -1193,8 +1195,7 @@ updateAttr(NfsNode node, int force) } /* - * IP address helper. Note that we avoid - * gethostbyname() since it's not reentrant. + * IP address helper. * * initialize a sockaddr_in from a * ['.''@']':'" string and let @@ -1211,7 +1212,8 @@ buildIpAddr(u_long *puid, u_long *pgid, char **pHost, struct sockaddr_in *psa, char **pPath) { -char host[30]; +struct hostent *h; +char host[64]; char *chpt = *pPath; char *path; int len; @@ -1238,7 +1240,7 @@ int len; /* split the device name which is in the form * - * ':' + * ':' * * into its components using a local buffer */ @@ -1254,11 +1256,19 @@ int len; strncpy(host, chpt, len); host[len]=0; - if ( ! inet_pton(AF_INET, host, &psa->sin_addr) ) { - errno = ENXIO; + /* BEGIN OF NON-THREAD SAFE REGION */ + + h = gethostbyname(host); + + if ( !h ) { + errno = EINVAL; return -1; } + memcpy(&psa->sin_addr, h->h_addr, sizeof (struct in_addr)); + + /* END OF NON-THREAD SAFE REGION */ + psa->sin_family = AF_INET; psa->sin_port = 0; *pPath = path; @@ -1898,9 +1908,9 @@ struct rtems_filesystem_mount_table_entry_tt { #endif -/* This op is called as the last step of mounting this FS */ -STATIC int nfs_fsmount_me( - rtems_filesystem_mount_table_entry_t *mt_entry +int rtems_nfsfs_initialize( + rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data ) { char *host; @@ -1917,11 +1927,20 @@ RpcUdpServer nfsServer = 0; int e = -1; char *path = mt_entry->dev; + if (rpcUdpInit () < 0) { + fprintf (stderr, "error: initialising RPC\n"); + return -1; + } + + nfsInit(0, 0); +#if 0 + printf("Trying to mount %s on %s\n",path,mntpoint); +#endif + if ( buildIpAddr(&uid, &gid, &host, &saddr, &path) ) return -1; - #ifdef NFS_V2_PORT /* if the portmapper fails, retry a fixed port */ for (retry = 1, saddr.sin_port = 0, stat = RPC_FAILED; @@ -2460,7 +2479,7 @@ struct _rtems_filesystem_operations_table nfs_fs_ops = { nfs_chown, /* OPTIONAL; may be NULL */ nfs_freenode, /* OPTIONAL; may be NULL; (release node_access) */ nfs_mount, /* OPTIONAL; may be NULL */ - nfs_fsmount_me, /* OPTIONAL; may be NULL -- but this makes NO SENSE */ + rtems_nfsfs_initialize, /* OPTIONAL; may be NULL -- not used anymore */ nfs_unmount, /* OPTIONAL; may be NULL */ nfs_fsunmount_me, /* OPTIONAL; may be NULL */ nfs_utime, /* OPTIONAL; may be NULL */ @@ -3228,6 +3247,8 @@ Nfs nfs; return 0; } +#if 0 +CCJ_REMOVE_MOUNT /* convenience wrapper * * NOTE: this routine calls NON-REENTRANT @@ -3237,7 +3258,6 @@ Nfs nfs; int nfsMount(char *uidhost, char *path, char *mntpoint) { -rtems_filesystem_mount_table_entry_t *mtab; struct stat st; int devl; char *host; @@ -3310,11 +3330,11 @@ char *dev = 0; printf("Trying to mount %s on %s\n",dev,mntpoint); - if (mount(&mtab, - &nfs_fs_ops, - RTEMS_FILESYSTEM_READ_WRITE, - dev, - mntpoint)) { + if (mount(dev, + mntpoint, + "nfs", + RTEMS_FILESYSTEM_READ_WRITE, + NULL)) { perror("nfsMount - mount"); goto cleanup; } @@ -3325,6 +3345,7 @@ cleanup: free(dev); return rval; } +#endif /* HERE COMES A REALLY UGLY HACK */ diff --git a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c index f50af413fa..afa68d415d 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs-rtems.c +++ b/cpukit/libfs/src/rfs/rtems-rfs-rtems.c @@ -120,7 +120,7 @@ rtems_rfs_rtems_eval_path (const char* path, node_len = 0; while (!rtems_filesystem_is_separator (*path) && (*path != '\0') && pathlen && - (node_len + 1 < rtems_rfs_fs_max_name (fs))) + ((node_len + 1) < rtems_rfs_fs_max_name (fs))) { path++; pathlen--; @@ -1214,7 +1214,8 @@ const rtems_filesystem_file_handlers_r rtems_rfs_rtems_link_handlers = * Forward decl for the ops table. */ -int rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t *mt_entry); +int rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data); int rtems_rfs_rtems_shutdown (rtems_filesystem_mount_table_entry_t *mt_entry); /** @@ -1247,7 +1248,8 @@ const rtems_filesystem_operations_table rtems_rfs_ops = */ int -rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t* mt_entry) +rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t* mt_entry, + const void* data) { rtems_rfs_rtems_private* rtems; rtems_rfs_file_system* fs; diff --git a/cpukit/libfs/src/rfs/rtems-rfs.h b/cpukit/libfs/src/rfs/rtems-rfs.h index b0e5a6c5e2..ca5a6f3051 100644 --- a/cpukit/libfs/src/rfs/rtems-rfs.h +++ b/cpukit/libfs/src/rfs/rtems-rfs.h @@ -22,14 +22,9 @@ #include #include -/** - * File ops table for the RFS file system. - */ -const rtems_filesystem_operations_table rtems_rfs_ops; - /** * Initialise the RFS File system. */ -int rtems_rfs_initialise (rtems_filesystem_mount_table_entry_t *mt_entry); +int rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t *mt_entry); #endif diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index f69c627f48..2fc0464500 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -76,7 +76,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \ shell/main_id.c shell/main_logoff.c shell/main_ln.c shell/main_ls.c \ shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \ shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \ - shell/main_mount_msdos.c shell/main_mmove.c shell/main_msdosfmt.c \ + shell/main_mmove.c shell/main_msdosfmt.c \ shell/main_mv.c shell/main_mwdump.c shell/main_perioduse.c \ shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \ shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \ @@ -95,14 +95,13 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \ shell/dd-misc.c shell/dd-position.c \ shell/main_hexdump.c shell/hexdump-conv.c shell/hexdump-display.c \ shell/hexdump-odsyntax.c shell/hexdump-parse.c shell/hexsyntax.c \ - shell/main_time.c shell/main_mknod.c shell/main_mount_rfs.c \ + shell/main_time.c shell/main_mknod.c \ shell/main_setenv.c shell/main_getenv.c shell/main_unsetenv.c \ shell/main_mkrfs.c shell/main_debugrfs.c if LIBNETWORKING -libshell_a_SOURCES += shell/main_mount_ftp.c shell/main_mount_tftp.c \ - shell/main_ifconfig.c shell/main_route.c shell/main_netstats.c \ - shell/main_mount_nfs.c +libshell_a_SOURCES += \ + shell/main_ifconfig.c shell/main_route.c shell/main_netstats.c endif endif diff --git a/cpukit/libmisc/fsmount/fsmount.c b/cpukit/libmisc/fsmount/fsmount.c index 2adfcb5d09..5fa52e99f2 100644 --- a/cpukit/libmisc/fsmount/fsmount.c +++ b/cpukit/libmisc/fsmount/fsmount.c @@ -118,82 +118,81 @@ int rtems_fsmount_create_mount_point int rtems_fsmount ( /*-------------------------------------------------------------------------*\ -| Purpose: | -| This function will create the mount points listed and mount the file | -| systems listed in the calling parameters | -+---------------------------------------------------------------------------+ -| Input Parameters: | -\*-------------------------------------------------------------------------*/ - const rtems_fstab_entry *fstab_ptr, - size_t fstab_count, - size_t *fail_idx + | Purpose: | + | This function will create the mount points listed and mount the file | + | systems listed in the calling parameters | + +---------------------------------------------------------------------------+ + | Input Parameters: | + \*-------------------------------------------------------------------------*/ + const rtems_fstab_entry *fstab_ptr, + size_t fstab_count, + size_t *fail_idx ) /*-------------------------------------------------------------------------*\ -| Return Value: | -| 0, if success, -1 and errno if failed | -\*=========================================================================*/ + | Return Value: | + | 0, if success, -1 and errno if failed | + \*=========================================================================*/ { int rc = 0; int tmp_rc; size_t fstab_idx = 0; - rtems_filesystem_mount_table_entry_t *tmp_mt_entry; bool terminate = false; /* * scan through all fstab entries; */ while (!terminate && - (fstab_idx < fstab_count)) { + (fstab_idx < fstab_count)) { tmp_rc = 0; /* * create mount point */ if (tmp_rc == 0) { - tmp_rc = rtems_fsmount_create_mount_point(fstab_ptr->mount_point); + tmp_rc = rtems_fsmount_create_mount_point(fstab_ptr->target); if (tmp_rc != 0) { - if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNTPNT_CRTERR)) { - fprintf(stdout,"fsmount: creation of mount point \"%s\" failed: %s\n", - fstab_ptr->mount_point, - strerror(errno)); - } - if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNTPNT_CRTERR)) { - terminate = true; - rc = tmp_rc; - } + if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNTPNT_CRTERR)) { + fprintf(stdout,"fsmount: creation of mount point \"%s\" failed: %s\n", + fstab_ptr->target, + strerror(errno)); + } + if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNTPNT_CRTERR)) { + terminate = true; + rc = tmp_rc; + } } } /* * mount device to given mount point */ if (tmp_rc == 0) { - tmp_rc = mount(&tmp_mt_entry, - fstab_ptr->fs_ops, - fstab_ptr->mount_options, - fstab_ptr->dev, - fstab_ptr->mount_point); + tmp_rc = mount(fstab_ptr->source, + fstab_ptr->target, + fstab_ptr->type, + fstab_ptr->options, + NULL); if (tmp_rc != 0) { - if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_FAILED)) { - fprintf(stdout,"fsmount: mounting of \"%s\" to" - " \"%s\" failed: %s\n", - fstab_ptr->dev, - fstab_ptr->mount_point, - strerror(errno)); - } - if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_FAILED)) { - terminate = true; - rc = tmp_rc; - } + if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_FAILED)) { + fprintf(stdout,"fsmount: mounting of \"%s\" to" + " \"%s\" failed: %s\n", + fstab_ptr->source, + fstab_ptr->target, + strerror(errno)); + } + if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_FAILED)) { + terminate = true; + rc = tmp_rc; + } } else { - if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_OK)) { - fprintf(stdout,"fsmount: mounting of \"%s\" to" - " \"%s\" succeeded\n", - fstab_ptr->dev, - fstab_ptr->mount_point); - } - if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_OK)) { - terminate = true; - } + if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_OK)) { + fprintf(stdout,"fsmount: mounting of \"%s\" to" + " \"%s\" succeeded\n", + fstab_ptr->source, + fstab_ptr->target); + } + if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_OK)) { + terminate = true; + } } } /* diff --git a/cpukit/libmisc/fsmount/fsmount.h b/cpukit/libmisc/fsmount/fsmount.h index 0841a6fe49..15597c31ff 100644 --- a/cpukit/libmisc/fsmount/fsmount.h +++ b/cpukit/libmisc/fsmount/fsmount.h @@ -90,24 +90,24 @@ typedef enum { */ typedef struct { /** - * Device file path. + * Source for the mount. */ - const char *dev; + const char *source; /** - * Mount point path. + * Target for the mount. */ - const char *mount_point; + const char *target; /** * File system operations. */ - const rtems_filesystem_operations_table *fs_ops; + const char *type; /** * File system mount options. */ - rtems_filesystem_options_t mount_options; + rtems_filesystem_options_t options; /** * Report @ref rtems_fstab_conditions "condition flags". @@ -128,7 +128,7 @@ typedef struct { * * @see rtems_fsmount(). */ -int rtems_fsmount_create_mount_point( const char *mount_point); +int rtems_fsmount_create_mount_point(const char *mount_point); /** * Mounts the file systems listed in the file system mount table @a fstab of @@ -160,23 +160,22 @@ int rtems_fsmount_create_mount_point( const char *mount_point); * * #include * #include - * #include * #include * #include * * static const rtems_fstab_entry fstab [] = { * { - * .dev = "/dev/sd-card-a", - * .mount_point = "/mnt", - * .fs_ops = &msdos_ops, - * .mount_options = RTEMS_FILESYSTEM_READ_WRITE, + * .source = "/dev/sd-card-a", + * .target = "/mnt", + * .type = "dosfs", + * .options = RTEMS_FILESYSTEM_READ_WRITE, * .report_reasons = RTEMS_FSTAB_ANY, * .abort_reasons = RTEMS_FSTAB_OK * }, { - * .dev = "/dev/sd-card-a1", - * .mount_point = "/mnt", - * .fs_ops = &msdos_ops, - * .mount_options = RTEMS_FILESYSTEM_READ_WRITE, + * .source = "/dev/sd-card-a1", + * .target = "/mnt", + * .type = "dosfs", + * .options = RTEMS_FILESYSTEM_READ_WRITE, * .report_reasons = RTEMS_FSTAB_ANY, * .abort_reasons = RTEMS_FSTAB_NONE * } diff --git a/cpukit/libmisc/shell/main_mount.c b/cpukit/libmisc/shell/main_mount.c index 0fe569cc5b..8062001d6a 100644 --- a/cpukit/libmisc/shell/main_mount.c +++ b/cpukit/libmisc/shell/main_mount.c @@ -24,74 +24,24 @@ #include #include #include -#include -#include +#include #include "internal.h" -static rtems_chain_control filesystems; -static bool fs_init; - -static void rtems_shell_mount_fsys_init(void) -{ - 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, - rtems_shell_filesystems_t* fs, - rtems_filesystem_options_t options) -{ - rtems_filesystem_mount_table_entry_t* mt_entry; - /* - * Mount the disk. - */ - - if (mount (&mt_entry, fs->fs_ops, options, (char*) driver, (char*) path) < 0) - { - fprintf (stderr, "mount: mount failed: %s\n", strerror (errno)); - return 1; - } - - return 0; -} - -#define NUMOF(_i) (sizeof (_i) / sizeof (_i[0])) - int rtems_shell_main_mount( int argc, char *argv[] ) { rtems_filesystem_options_t options = RTEMS_FILESYSTEM_READ_WRITE; - rtems_shell_filesystems_t* fs = NULL; - char* driver = NULL; - char* mount_point = NULL; + char* type = NULL; + char* source = NULL; + char* target = NULL; + char* fsoptions = 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( @@ -101,71 +51,58 @@ int rtems_shell_main_mount( ); return 1; } - - for (a = rtems_shell_Mount_filesystems; *a; a++) { - if (strcmp (argv[arg], (*a)->name) == 0) { - fs = *a; - 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; - } - } + type = argv[arg]; } else if (argv[arg][1] == 'r') { options = RTEMS_FILESYSTEM_READ_ONLY; } else if (argv[arg][1] == 'L') { - rtems_shell_filesystems_t** a; - fprintf (stderr, "File systems: "); - for (a = rtems_shell_Mount_filesystems; *a; a++) - if (*a) - fprintf (stderr, "%s ", (*a)->name); - if (!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; - fprintf (stderr, "%s ", f->name); - node = node->next; - } + const rtems_filesystem_table_t* fs; + fs = rtems_filesystem_table_first(); + printf ("File systems: "); + while (fs) { + printf ("%s ", fs->type); + fs = rtems_filesystem_table_next(fs); } - fprintf (stderr, "\n"); - return 1; + printf ("\n"); + return 0; + } else if (argv[arg][1] == 'o') { + arg++; + if (arg == argc) { + fprintf( + stderr, + "%s: -o needs a list if filesystem options.\n", + argv[0] + ); + return 1; + } + fsoptions = argv[arg]; } else { fprintf (stderr, "unknown option: %s\n", argv[arg]); return 1; } } else { - if (!driver) - driver = argv[arg]; - else if (!mount_point) - mount_point = argv[arg]; + if (!source) + source = argv[arg]; + else if (!target) + target = argv[arg]; else { fprintf ( - stderr, "mount: driver and mount only require: %s\n", argv[arg]); + stderr, "mount: source and mount only require: %s\n", argv[arg]); return 1; } } } - if (fs == NULL) { + if (!type) { fprintf (stderr, "mount: no file-system; see the -L option\n"); return 1; } - if (fs->driver_needed && !driver) { - fprintf (stderr, "mount: no driver\n"); + if (!source) { + fprintf (stderr, "mount: no source\n"); return 1; } - if (!mount_point) { + if (!target) { fprintf (stderr, "mount: no mount point\n"); return 1; } @@ -174,19 +111,21 @@ int rtems_shell_main_mount( * Mount the disk. */ - if (fs->mounter (driver, mount_point, fs, options)) + if (mount (source, target, type, options, fsoptions) < 0) { + fprintf (stderr, "error: %s\n", strerror(errno)); return 1; + } - printf ("mounted %s -> %s\n", driver, mount_point); + printf ("mounted %s -> %s\n", source, target); return 0; } rtems_shell_cmd_t rtems_shell_MOUNT_Command = { - "mount", /* name */ - "mount [-t fstype] [-r] [-L] device path # mount disk", /* usage */ - "files", /* topic */ - rtems_shell_main_mount, /* command */ - NULL, /* alias */ - NULL /* next */ + "mount", /* name */ + "mount [-t type] [-r] [-L] source target", /* usage */ + "files", /* topic */ + rtems_shell_main_mount, /* command */ + NULL, /* alias */ + NULL /* next */ }; diff --git a/cpukit/libmisc/shell/main_mount_ftp.c b/cpukit/libmisc/shell/main_mount_ftp.c deleted file mode 100644 index 2712812fc0..0000000000 --- a/cpukit/libmisc/shell/main_mount_ftp.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Shell Command Implmentation - * - * Author: Fernando RUIZ CASAS - * Work: fernando.ruiz@ctv.es - * Home: correo@fernando-ruiz.com - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include -#include "internal.h" - -#include - -rtems_shell_filesystems_t rtems_shell_Mount_FTP = { - name: "ftp", - driver_needed: 1, - fs_ops: &rtems_ftpfs_ops, - mounter: rtems_shell_libc_mounter -}; diff --git a/cpukit/libmisc/shell/main_mount_msdos.c b/cpukit/libmisc/shell/main_mount_msdos.c deleted file mode 100644 index 67c87d984a..0000000000 --- a/cpukit/libmisc/shell/main_mount_msdos.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Shell Command Implmentation - * - * Author: Fernando RUIZ CASAS - * Work: fernando.ruiz@ctv.es - * Home: correo@fernando-ruiz.com - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include -#include "internal.h" - -rtems_shell_filesystems_t rtems_shell_Mount_MSDOS = { - name: "msdos", - driver_needed: 1, - fs_ops: &msdos_ops, - mounter: rtems_shell_libc_mounter -}; diff --git a/cpukit/libmisc/shell/main_mount_rfs.c b/cpukit/libmisc/shell/main_mount_rfs.c deleted file mode 100644 index 674556afce..0000000000 --- a/cpukit/libmisc/shell/main_mount_rfs.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Shell Command Implmentation - * - * Author: Fernando RUIZ CASAS - * Work: fernando.ruiz@ctv.es - * Home: correo@fernando-ruiz.com - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include -#include "internal.h" - -rtems_shell_filesystems_t rtems_shell_Mount_RFS = { - name: "rfs", - driver_needed: 1, - fs_ops: &rtems_rfs_ops, - mounter: rtems_shell_libc_mounter -}; - diff --git a/cpukit/libmisc/shell/main_mount_tftp.c b/cpukit/libmisc/shell/main_mount_tftp.c deleted file mode 100644 index 1efeb7b229..0000000000 --- a/cpukit/libmisc/shell/main_mount_tftp.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Shell Command Implmentation - * - * Author: Fernando RUIZ CASAS - * Work: fernando.ruiz@ctv.es - * Home: correo@fernando-ruiz.com - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include "internal.h" - -#include -#include - -rtems_shell_filesystems_t rtems_shell_Mount_TFTP = { - name: "tftp", - driver_needed: 0, - fs_ops: &rtems_tftp_ops, - mounter: rtems_shell_libc_mounter -}; diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h index 65428ea164..cfc475095e 100644 --- a/cpukit/libmisc/shell/shellconfig.h +++ b/cpukit/libmisc/shell/shellconfig.h @@ -91,17 +91,6 @@ extern rtems_shell_alias_t rtems_shell_EXIT_Alias; extern rtems_shell_alias_t *rtems_shell_Initial_aliases[]; -/* - * Externs for mount command helpers - */ -extern rtems_shell_filesystems_t rtems_shell_Mount_RFS; -extern rtems_shell_filesystems_t rtems_shell_Mount_MSDOS; -extern rtems_shell_filesystems_t rtems_shell_Mount_TFTP; -extern rtems_shell_filesystems_t rtems_shell_Mount_FTP; -extern rtems_shell_filesystems_t rtems_shell_Mount_NFS; - -extern rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[]; - /* * If we are configured to alias a command, then make sure the underlying * command is configured. @@ -444,34 +433,6 @@ extern rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[]; NULL }; - /* - * The mount command's support file system types. - */ - #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \ - !defined(CONFIGURE_SHELL_COMMAND_NO_MOUNT)) || \ - defined(CONFIGURE_SHELL_COMMAND_MOUNT) - rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[] = { - #if defined(CONFIGURE_SHELL_MOUNT_RFS) - &rtems_shell_Mount_RFS, - #endif - #if defined(CONFIGURE_SHELL_MOUNT_MSDOS) - &rtems_shell_Mount_MSDOS, - #endif - #if RTEMS_NETWORKING - #if defined(CONFIGURE_SHELL_MOUNT_TFTP) - &rtems_shell_Mount_TFTP, - #endif - #if defined(CONFIGURE_SHELL_MOUNT_FTP) - &rtems_shell_Mount_FTP, - #endif - #if defined(CONFIGURE_SHELL_MOUNT_NFS) - &rtems_shell_Mount_NFS, - #endif - #endif - NULL - }; - #endif - #endif #endif diff --git a/cpukit/libnetworking/lib/ftpfs.c b/cpukit/libnetworking/lib/ftpfs.c index fb7b0d32b2..5e7f520990 100644 --- a/cpukit/libnetworking/lib/ftpfs.c +++ b/cpukit/libnetworking/lib/ftpfs.c @@ -130,6 +130,8 @@ static int rtems_ftpfs_set_connection_timeout( return 0; } +#if 0 +CCJ_REMOVE_MOUNT rtems_status_code rtems_ftpfs_mount(const char *mount_point) { int rv = 0; @@ -156,6 +158,7 @@ rtems_status_code rtems_ftpfs_mount(const char *mount_point) return RTEMS_SUCCESSFUL; } +#endif static rtems_status_code rtems_ftpfs_do_ioctl( const char *mount_point, @@ -234,19 +237,6 @@ rtems_status_code rtems_ftpfs_set_timeout( ); } -int rtems_bsdnet_initialize_ftp_filesystem(void) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - - sc = rtems_ftpfs_mount(NULL); - - if (sc == RTEMS_SUCCESSFUL) { - return 0; - } else { - return -1; - } -} - typedef void (*rtems_ftpfs_reply_parser)( const char * /* reply fragment */, size_t /* reply fragment length */, @@ -1232,8 +1222,9 @@ static rtems_filesystem_node_types_t rtems_ftpfs_node_type( return RTEMS_FILESYSTEM_MEMORY_FILE; } -static int rtems_ftpfs_mount_me( - rtems_filesystem_mount_table_entry_t *e +int rtems_ftpfs_initialize( + rtems_filesystem_mount_table_entry_t *e, + const void *d ) { rtems_ftpfs_mount_entry *me = malloc(sizeof(rtems_ftpfs_mount_entry)); @@ -1337,7 +1328,7 @@ const rtems_filesystem_operations_table rtems_ftpfs_ops = { .chown_h = NULL, .freenod_h = rtems_ftpfs_free_node, .mount_h = NULL, - .fsmount_me_h = rtems_ftpfs_mount_me, + .fsmount_me_h = rtems_ftpfs_initialize, .unmount_h = NULL, .fsunmount_me_h = rtems_ftpfs_unmount_me, .utime_h = NULL, diff --git a/cpukit/libnetworking/lib/tftpDriver.c b/cpukit/libnetworking/lib/tftpDriver.c index c8740ce21a..63c2247844 100644 --- a/cpukit/libnetworking/lib/tftpDriver.c +++ b/cpukit/libnetworking/lib/tftpDriver.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef RTEMS_TFTP_DRIVER_DEBUG int rtems_tftp_driver_debug = 1; @@ -43,18 +44,6 @@ int rtems_tftp_driver_debug = 1; */ #define UDP_PORT_BASE 3180 -/* - * Pathname prefix - */ -#define TFTP_PATHNAME_PREFIX "/TFTP/" - -/* - * Root node_access value - * By using the address of a local static variable - * we ensure a unique value for this identifier. - */ -#define ROOT_NODE_ACCESS (&tftp_mutex) - /* * Default limits */ @@ -152,43 +141,49 @@ struct tftpStream { }; /* - * Number of streams open at the same time + * Flags for filesystem info. */ -static rtems_id tftp_mutex; -static int nStreams; -static struct tftpStream ** volatile tftpStreams; +#define TFTPFS_VERBOSE (1 << 0) -typedef const char *tftp_node; -extern rtems_filesystem_operations_table rtems_tftp_ops; -extern rtems_filesystem_file_handlers_r rtems_tftp_handlers; +/* + * Root node_access value + * By using the address of the file system + * we ensure a unique value for this identifier. + */ +#define ROOT_NODE_ACCESS(_fs) (_fs) /* - * Direct copy from the IMFS. Look at this. + * TFTP File system info. */ +typedef struct tftpfs_info_s { + uint32_t flags; + rtems_id tftp_mutex; + int nStreams; + struct tftpStream ** volatile tftpStreams; +} tftpfs_info_t; -rtems_filesystem_limits_and_options_t rtems_tftp_limits_and_options = { - 5, /* link_max */ - 6, /* max_canon */ - 7, /* max_input */ - 255, /* name_max */ - 255, /* path_max */ - 2, /* pipe_buf */ - 1, /* posix_async_io */ - 2, /* posix_chown_restrictions */ - 3, /* posix_no_trunc */ - 4, /* posix_prio_io */ - 5, /* posix_sync_io */ - 6 /* posix_vdisable */ -}; +#define tftpfs_info_mount_table(_mt) ((tftpfs_info_t*) ((_mt)->fs_info)) +#define tftpfs_info_pathloc(_pl) ((tftpfs_info_t*) ((_pl)->mt_entry->fs_info)) +#define tftpfs_info_iop(_iop) (tftpfs_info_pathloc (&((_iop)->pathinfo))) -static int rtems_tftp_mount_me( - rtems_filesystem_mount_table_entry_t *temp_mt_entry +/* + * Number of streams open at the same time + */ + +typedef const char *tftp_node; +extern rtems_filesystem_operations_table rtems_tftp_ops; +extern rtems_filesystem_file_handlers_r rtems_tftp_handlers; + +int rtems_tftpfs_initialize( + rtems_filesystem_mount_table_entry_t *mt_entry, + const void *data ) { + tftpfs_info_t *fs; rtems_status_code sc; - temp_mt_entry->mt_fs_root.handlers = &rtems_tftp_handlers; - temp_mt_entry->mt_fs_root.ops = &rtems_tftp_ops; + mt_entry->mt_fs_root.handlers = &rtems_tftp_handlers; + mt_entry->mt_fs_root.ops = &rtems_tftp_ops; /* * We have no tftp filesystem specific data to maintain. This @@ -197,16 +192,18 @@ static int rtems_tftp_mount_me( * And we maintain no real filesystem nodes, so there is no real root. */ - temp_mt_entry->fs_info = NULL; - temp_mt_entry->mt_fs_root.node_access = ROOT_NODE_ACCESS; - - /* - * These need to be looked at for full POSIX semantics. - */ - - temp_mt_entry->pathconf_limits_and_options = rtems_tftp_limits_and_options; - - + fs = malloc (sizeof (tftpfs_info_t)); + if (!fs) + rtems_set_errno_and_return_minus_one (ENOMEM); + + fs->flags = 0; + fs->nStreams = 0; + fs->tftpStreams = 0; + + mt_entry->fs_info = fs; + mt_entry->mt_fs_root.node_access = ROOT_NODE_ACCESS (fs); + mt_entry->mt_fs_root.node_access_2 = NULL; + /* * Now allocate a semaphore for mutual exclusion. * @@ -222,40 +219,51 @@ static int rtems_tftp_mount_me( RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0, - &tftp_mutex + &fs->tftp_mutex ); if (sc != RTEMS_SUCCESSFUL) - rtems_set_errno_and_return_minus_one( ENOMEM ); - + rtems_set_errno_and_return_minus_one (ENOMEM); + + if (data) { + char* config = (char*) data; + char* token; + char* saveptr; + token = strtok_r (config, " ", &saveptr); + while (token) { + if (strcmp (token, "verbose") == 0) + fs->flags |= TFTPFS_VERBOSE; + token = strtok_r (NULL, " ", &saveptr); + } + } + return 0; } /* - * Initialize the TFTP driver + * Release a stream and clear the pointer to it */ - -int rtems_bsdnet_initialize_tftp_filesystem (void) +static void +releaseStream (tftpfs_info_t *fs, int s) { - int status; - rtems_filesystem_mount_table_entry_t *entry; - - status = mkdir( TFTP_PATHNAME_PREFIX, S_IRWXU | S_IRWXG | S_IRWXO ); - if ( status == -1 ) - return status; - - status = mount( - &entry, - &rtems_tftp_ops, - RTEMS_FILESYSTEM_READ_WRITE, - NULL, - TFTP_PATHNAME_PREFIX - ); - - if ( status ) - perror( "TFTP mount failed" ); + if (fs->tftpStreams[s] && (fs->tftpStreams[s]->socket >= 0)) + close (fs->tftpStreams[s]->socket); + rtems_semaphore_obtain (fs->tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + free (fs->tftpStreams[s]); + fs->tftpStreams[s] = NULL; + rtems_semaphore_release (fs->tftp_mutex); +} - return status; +static int +rtems_tftpfs_shutdown (rtems_filesystem_mount_table_entry_t* mt_entry) +{ + tftpfs_info_t *fs = tftpfs_info_mount_table (mt_entry); + int s; + for (s = 0; s < fs->nStreams; s++) + releaseStream (fs, s); + rtems_semaphore_delete (fs->tftp_mutex); + free (fs); + return 0; } /* @@ -335,8 +343,8 @@ getPacket (struct tftpStream *tp, int retryCount) } from; socklen_t fromlen = sizeof from; len = recvfrom (tp->socket, &tp->pkbuf, - sizeof tp->pkbuf, 0, - &from.s, &fromlen); + sizeof tp->pkbuf, 0, + &from.s, &fromlen); if (len < 0) break; if (from.i.sin_addr.s_addr == tp->farAddress.sin_addr.s_addr) { @@ -410,18 +418,6 @@ sendAck (struct tftpStream *tp) return 0; } -/* - * Release a stream and clear the pointer to it - */ -static void -releaseStream (int s) -{ - rtems_semaphore_obtain (tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - free (tftpStreams[s]); - tftpStreams[s] = NULL; - rtems_semaphore_release (tftp_mutex); -} - static int rtems_tftp_evaluate_for_make( const char *path __attribute__((unused)), /* IN */ rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ @@ -429,7 +425,8 @@ static int rtems_tftp_evaluate_for_make( ) { pathloc->node_access = NULL; - rtems_set_errno_and_return_minus_one( EIO ); + pathloc->node_access_2 = NULL; + rtems_set_errno_and_return_minus_one (EIO); } /* @@ -493,46 +490,54 @@ static int rtems_tftp_eval_path( rtems_filesystem_location_info_t *pathloc /* IN/OUT */ ) { - pathloc->handlers = &rtems_tftp_handlers; + tftpfs_info_t *fs; + char *cp; + + /* + * Get the file system info. + */ + fs = tftpfs_info_pathloc (pathloc); + + pathloc->handlers = &rtems_tftp_handlers; /* * Hack to provide the illusion of directories inside the TFTP file system. * Paths ending in a / are assumed to be directories. */ if (pathname[strlen(pathname)-1] == '/') { - int isRelative = (pathloc->node_access != ROOT_NODE_ACCESS); - char *cp; + int nal = 0; + if (pathloc->node_access != ROOT_NODE_ACCESS (fs)) + nal = strlen(pathloc->node_access); + cp = malloc(nal + pathnamelen + 1); + if (cp == NULL) + rtems_set_errno_and_return_minus_one(ENOMEM); + if (nal) + memcpy (cp, pathloc->node_access, nal); + memcpy(cp + nal, pathname, pathnamelen); + cp[nal + pathnamelen] = '\0'; + fixPath (cp); + pathloc->node_access = cp; + } + else { + if (pathnamelen) { + /* + * Reject it if it's not read-only or write-only. + */ + flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE; + if ((flags != RTEMS_LIBIO_PERMS_READ) \ + && (flags != RTEMS_LIBIO_PERMS_WRITE)) + rtems_set_errno_and_return_minus_one(EINVAL); - /* - * Reject attempts to open() directories - */ - if (flags & RTEMS_LIBIO_PERMS_RDWR) - rtems_set_errno_and_return_minus_one( EISDIR ); - if (isRelative) { - cp = malloc (strlen(pathloc->node_access)+strlen(pathname)+1); - if (cp == NULL) - rtems_set_errno_and_return_minus_one( ENOMEM ); - strcpy (cp, pathloc->node_access); - strcat (cp, pathname); - } - else { - cp = strdup (pathname); + cp = malloc(pathnamelen + 1); if (cp == NULL) - rtems_set_errno_and_return_minus_one( ENOMEM ); + rtems_set_errno_and_return_minus_one(ENOMEM); + memcpy(cp, pathname, pathnamelen); + cp[pathnamelen] = '\0'; + fixPath (cp); + pathloc->node_access_2 = cp; } - fixPath (cp); - pathloc->node_access = cp; - return 0; } - if (pathloc->node_access != ROOT_NODE_ACCESS) - pathloc->node_access = 0; - /* - * Reject it if it's not read-only or write-only. - */ - flags &= RTEMS_LIBIO_PERMS_READ | RTEMS_LIBIO_PERMS_WRITE; - if ((flags != RTEMS_LIBIO_PERMS_READ) && (flags != RTEMS_LIBIO_PERMS_WRITE) ) - rtems_set_errno_and_return_minus_one( EINVAL ); return 0; } @@ -546,6 +551,7 @@ static int rtems_tftp_open_worker( uint32_t mode __attribute__((unused)) ) { + tftpfs_info_t *fs; struct tftpStream *tp; int retryCount; struct in_addr farAddress; @@ -558,72 +564,75 @@ static int rtems_tftp_open_worker( rtems_status_code sc; char *hostname; + /* + * Get the file system info. + */ + fs = tftpfs_info_iop (iop); + /* * Extract the host name component */ - cp2 = full_path_name; - while (*cp2 == '/') - cp2++; - hostname = cp2; - while (*cp2 != '/') { - if (*cp2 == '\0') - return ENOENT; - cp2++; + hostname = full_path_name; + cp1 = strchr (full_path_name, ':'); + if (!cp1) + hostname = "BOOTP_HOST"; + else { + *cp1 = '\0'; + ++cp1; } - *cp2++ = '\0'; /* * Convert hostname to Internet address */ if (strcmp (hostname, "BOOTP_HOST") == 0) farAddress = rtems_bsdnet_bootp_server_address; - else - farAddress.s_addr = inet_addr (hostname); - if ((farAddress.s_addr == INADDR_ANY) || (farAddress.s_addr == INADDR_BROADCAST)) + else if (inet_aton (hostname, &farAddress) == 0) { + struct hostent *he = gethostbyname(hostname); + if (he == NULL) + return ENOENT; + memcpy (&farAddress, he->h_addr, sizeof (farAddress)); + } else { return ENOENT; - + } + /* * Extract file pathname component */ - while (*cp2 == '/') - cp2++; - if (strcmp (cp2, "BOOTP_FILE") == 0) { - cp2 = rtems_bsdnet_bootp_boot_file_name; - while (*cp2 == '/') - cp2++; + if (strcmp (cp1, "BOOTP_FILE") == 0) { + cp1 = rtems_bsdnet_bootp_boot_file_name; } - if (*cp2 == '\0') + if (*cp1 == '\0') return ENOENT; - remoteFilename = cp2; + remoteFilename = cp1; if (strlen (remoteFilename) > (TFTP_BUFSIZE - 10)) return ENOENT; /* * Find a free stream */ - sc = rtems_semaphore_obtain (tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + sc = rtems_semaphore_obtain (fs->tftp_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) return EBUSY; - for (s = 0 ; s < nStreams ; s++) { - if (tftpStreams[s] == NULL) + for (s = 0 ; s < fs->nStreams ; s++) { + if (fs->tftpStreams[s] == NULL) break; } - if (s == nStreams) { + if (s == fs->nStreams) { /* * Reallocate stream pointers * Guard against the case where realloc() returns NULL. */ struct tftpStream **np; - np = realloc (tftpStreams, ++nStreams * sizeof *tftpStreams); + np = realloc (fs->tftpStreams, ++fs->nStreams * sizeof *fs->tftpStreams); if (np == NULL) { - rtems_semaphore_release (tftp_mutex); + rtems_semaphore_release (fs->tftp_mutex); return ENOMEM; } - tftpStreams = np; + fs->tftpStreams = np; } - tp = tftpStreams[s] = malloc (sizeof (struct tftpStream)); - rtems_semaphore_release (tftp_mutex); + tp = fs->tftpStreams[s] = malloc (sizeof (struct tftpStream)); + rtems_semaphore_release (fs->tftp_mutex); if (tp == NULL) return ENOMEM; iop->data0 = s; @@ -633,7 +642,7 @@ static int rtems_tftp_open_worker( * Create the socket */ if ((tp->socket = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { - releaseStream (s); + releaseStream (fs, s); return ENOMEM; } @@ -646,13 +655,12 @@ static int rtems_tftp_open_worker( int try = (now + retryCount) % 10; tp->myAddress.sin_family = AF_INET; - tp->myAddress.sin_port = htons (UDP_PORT_BASE + nStreams * try + s); + tp->myAddress.sin_port = htons (UDP_PORT_BASE + fs->nStreams * try + s); tp->myAddress.sin_addr.s_addr = htonl (INADDR_ANY); if (bind (tp->socket, (struct sockaddr *)&tp->myAddress, sizeof tp->myAddress) >= 0) break; if (++retryCount == 10) { - close (tp->socket); - releaseStream (s); + releaseStream (fs, s); return EBUSY; } } @@ -697,8 +705,7 @@ static int rtems_tftp_open_worker( if (sendto (tp->socket, (char *)&tp->pkbuf, len, 0, (struct sockaddr *)&tp->farAddress, sizeof tp->farAddress) < 0) { - close (tp->socket); - releaseStream (s); + releaseStream (fs, s); return EIO; } @@ -716,8 +723,7 @@ static int rtems_tftp_open_worker( tp->nleft = len - 2 * sizeof (uint16_t ); tp->eof = (tp->nleft < TFTP_BUFSIZE); if (sendAck (tp) != 0) { - close (tp->socket); - releaseStream (s); + releaseStream (fs, s); return EIO; } break; @@ -731,8 +737,7 @@ static int rtems_tftp_open_worker( } if (opcode == TFTP_OPCODE_ERROR) { int e = tftpErrno (tp); - close (tp->socket); - releaseStream (s); + releaseStream (fs, s); return e; } } @@ -741,8 +746,7 @@ static int rtems_tftp_open_worker( * Keep trying */ if (++retryCount >= OPEN_RETRY_LIMIT) { - close (tp->socket); - releaseStream (s); + releaseStream (fs, s); return EIO; } } @@ -759,36 +763,81 @@ static int rtems_tftp_open( uint32_t mode ) { - char *full_path_name; - char *s1; - int err; + tftpfs_info_t *fs; + const char *device; + char *full_path_name; + char *na; + char *na2; + int dlen; + int nalen; + int na2len; + int sep1; + int err; /* - * Tack the `current directory' on to relative paths. - * We know that the current directory ends in a / character. + * Get the file system info. */ - if (*new_name == '/') { - /* - * Skip the TFTP filesystem prefix. - */ - int len = strlen (TFTP_PATHNAME_PREFIX); - if (strncmp (new_name, TFTP_PATHNAME_PREFIX, len)) - return ENOENT; - new_name += len; - s1 = ""; - } + fs = tftpfs_info_iop (iop); + + /* + * Tack the prefix directory if one exists from the device name. + */ + device = + rtems_filesystem_mount_device (rtems_filesystem_location_mount (&iop->pathinfo)); + dlen = strlen (device); + if (dlen == 0) + rtems_set_errno_and_return_minus_one (ENOENT); + + if (iop->pathinfo.node_access_2 == NULL) + rtems_set_errno_and_return_minus_one (ENOENT); + + if (iop->pathinfo.node_access != ROOT_NODE_ACCESS (fs)) { + na = iop->pathinfo.node_access; + nalen = strlen (na); + } else { - s1 = rtems_filesystem_current.node_access; + na = NULL; + nalen = 0; + } + + na2 = iop->pathinfo.node_access_2; + + na2len = strlen (na2); + + if (nalen) { + sep1 = 1; + if (na[nalen] == '/') { + sep1 = 0; + if (na2[0] == '/') + ++na2; + } + else { + if (na2[0] == '/') + sep1 = 0; + else + sep1 = 1; + } } - full_path_name = malloc (strlen (s1) + strlen (new_name) + 1); + else + sep1 = 0; + + full_path_name = malloc (dlen + nalen + sep1 + na2len + 1); if (full_path_name == NULL) - return ENOMEM; - strcpy (full_path_name, s1); - strcat (full_path_name, new_name); + rtems_set_errno_and_return_minus_one(ENOMEM); + strcpy (full_path_name, device); + if (nalen) + strcat (full_path_name, na); + if (sep1) + strcat (full_path_name, "/"); + strcat (full_path_name, na2); fixPath (full_path_name); + + if (fs->flags & TFTPFS_VERBOSE) + printf ("TFTPFS: %s %s %s -> %s\n", device, na, na2, full_path_name); + err = rtems_tftp_open_worker (iop, full_path_name, flags, mode); free (full_path_name); - return err; + rtems_set_errno_and_return_minus_one(err); } /* @@ -805,7 +854,9 @@ static ssize_t rtems_tftp_read( int retryCount; int nwant; - + if (!tp) + rtems_set_errno_and_return_minus_one( EIO ); + /* * Read till user request is satisfied or EOF is reached */ @@ -841,24 +892,24 @@ static ssize_t rtems_tftp_read( if ((opcode == TFTP_OPCODE_DATA) && (ntohs (tp->pkbuf.tftpDATA.blocknum) == nextBlock)) { tp->nused = 0; - tp->nleft = len - 2 * sizeof (uint16_t ); + tp->nleft = len - 2 * sizeof (uint16_t); tp->eof = (tp->nleft < TFTP_BUFSIZE); tp->blocknum++; if (sendAck (tp) != 0) - rtems_set_errno_and_return_minus_one( EIO ); + rtems_set_errno_and_return_minus_one (EIO); break; } if (opcode == TFTP_OPCODE_ERROR) - rtems_set_errno_and_return_minus_one( tftpErrno (tp) ); + rtems_set_errno_and_return_minus_one (tftpErrno (tp)); } /* * Keep trying? */ if (++retryCount == IO_RETRY_LIMIT) - rtems_set_errno_and_return_minus_one( EIO ); + rtems_set_errno_and_return_minus_one (EIO); if (sendAck (tp) != 0) - rtems_set_errno_and_return_minus_one( EIO ); + rtems_set_errno_and_return_minus_one (EIO); } } return count - nwant; @@ -867,7 +918,7 @@ static ssize_t rtems_tftp_read( /* * Flush a write buffer and wait for acknowledgement */ -static int rtems_tftp_flush ( struct tftpStream *tp ) +static int rtems_tftp_flush (struct tftpStream *tp) { int wlen, rlen; int retryCount = 0; @@ -917,10 +968,20 @@ static int rtems_tftp_close( rtems_libio_t *iop ) { - struct tftpStream *tp = iop->data1;; - + tftpfs_info_t *fs; + struct tftpStream *tp = iop->data1; + int e = 0; + + /* + * Get the file system info. + */ + fs = tftpfs_info_iop (iop); + + if (!tp) + rtems_set_errno_and_return_minus_one (EIO); + if (tp->writing) - rtems_tftp_flush (tp); + e = rtems_tftp_flush (tp); if (!tp->eof && !tp->firstReply) { /* * Tell the other end to stop @@ -930,9 +991,8 @@ static int rtems_tftp_close( ticksPerSecond = rtems_clock_get_ticks_per_second(); rtems_task_wake_after (1 + ticksPerSecond / 10); } - close (tp->socket); - releaseStream (iop->data0); - return RTEMS_SUCCESSFUL; + releaseStream (fs, iop->data0); + rtems_set_errno_and_return_minus_one (e); } static ssize_t rtems_tftp_write( @@ -949,8 +1009,7 @@ static ssize_t rtems_tftp_write( * Bail out if an error has occurred */ if (!tp->writing) - return EIO; - + rtems_set_errno_and_return_minus_one (EIO); /* * Write till user request is satisfied @@ -997,8 +1056,10 @@ static rtems_filesystem_node_types_t rtems_tftp_node_type( rtems_filesystem_location_info_t *pathloc /* IN */ ) { + tftpfs_info_t *fs = tftpfs_info_pathloc (pathloc); if ((pathloc->node_access == NULL) - || (pathloc->node_access == ROOT_NODE_ACCESS)) + || (pathloc->node_access_2 != NULL) + || (pathloc->node_access == ROOT_NODE_ACCESS (fs))) return RTEMS_FILESYSTEM_MEMORY_FILE; return RTEMS_FILESYSTEM_DIRECTORY; } @@ -1007,10 +1068,16 @@ static int rtems_tftp_free_node_info( rtems_filesystem_location_info_t *pathloc /* IN */ ) { - if (pathloc->node_access && (pathloc->node_access != ROOT_NODE_ACCESS)) { + tftpfs_info_t *fs = tftpfs_info_pathloc (pathloc); + if (pathloc->node_access && \ + (pathloc->node_access != ROOT_NODE_ACCESS (fs))) { free (pathloc->node_access); pathloc->node_access = NULL; } + if (pathloc->node_access_2) { + free (pathloc->node_access_2); + pathloc->node_access_2 = NULL; + } return 0; } @@ -1025,9 +1092,9 @@ rtems_filesystem_operations_table rtems_tftp_ops = { NULL, /* chown */ rtems_tftp_free_node_info, /* freenodinfo */ NULL, /* mount */ - rtems_tftp_mount_me, /* initialize */ + rtems_tftpfs_initialize, /* initialize */ NULL, /* unmount */ - NULL, /* fsunmount */ + rtems_tftpfs_shutdown, /* fsunmount */ NULL, /* utime, */ NULL, /* evaluate_link */ NULL, /* symlink */ @@ -1035,18 +1102,18 @@ rtems_filesystem_operations_table rtems_tftp_ops = { }; rtems_filesystem_file_handlers_r rtems_tftp_handlers = { - rtems_tftp_open, /* open */ - rtems_tftp_close, /* close */ - rtems_tftp_read, /* read */ - rtems_tftp_write, /* write */ - NULL, /* ioctl */ - NULL, /* lseek */ - NULL, /* fstat */ - NULL, /* fchmod */ + rtems_tftp_open, /* open */ + rtems_tftp_close, /* close */ + rtems_tftp_read, /* read */ + rtems_tftp_write, /* write */ + NULL, /* ioctl */ + NULL, /* lseek */ + NULL, /* fstat */ + NULL, /* fchmod */ rtems_tftp_ftruncate, /* ftruncate */ - NULL, /* fpathconf */ - NULL, /* fsync */ - NULL, /* fdatasync */ - NULL, /* fcntl */ - NULL /* rmnod */ + NULL, /* fpathconf */ + NULL, /* fsync */ + NULL, /* fdatasync */ + NULL, /* fcntl */ + NULL /* rmnod */ }; diff --git a/cpukit/libnetworking/rtems/ftpfs.h b/cpukit/libnetworking/rtems/ftpfs.h index 0414f8e49d..a9d89d45ef 100644 --- a/cpukit/libnetworking/rtems/ftpfs.h +++ b/cpukit/libnetworking/rtems/ftpfs.h @@ -98,16 +98,6 @@ typedef enum { */ extern const rtems_filesystem_operations_table rtems_ftpfs_ops; -/** - * Creates the mount point @a mount_point and mounts the FTP file system. - * - * If @a mount_point is @c NULL the default mount point - * @ref RTEMS_FTPFS_MOUNT_POINT_DEFAULT will be used. - * - * It is mounted with read and write access. - */ -rtems_status_code rtems_ftpfs_mount( const char *mount_point); - /** * Returns in @a verbose if the verbose mode is enabled or disabled for the * file system at @a mount_point. @@ -160,15 +150,12 @@ rtems_status_code rtems_ftpfs_set_timeout( /** * Creates the default mount point @ref RTEMS_FTPFS_MOUNT_POINT_DEFAULT and - * mounts the FTP file system. + * mounts the FTP file system. Do not call directly, use mount.xs * * It is mounted with read and write access. - * - * On success, zero is returned. On error, -1 is returned. - * - * @deprecated Use rtems_ftpfs_mount() instead. */ -int rtems_bsdnet_initialize_ftp_filesystem( void); +int rtems_ftpfs_initialize(rtems_filesystem_mount_table_entry_t *e, + const void *d); #ifdef __cplusplus } diff --git a/cpukit/libnetworking/rtems/tftp.h b/cpukit/libnetworking/rtems/tftp.h index b6a1bb5e8f..7fb977ffa0 100644 --- a/cpukit/libnetworking/rtems/tftp.h +++ b/cpukit/libnetworking/rtems/tftp.h @@ -20,7 +20,8 @@ * To open `/bootfiles/image' on `hostname' for reading: * fd = open ("/TFTP/hostname/bootfiles/image", O_RDONLY); * - * The `hostname' must be four dot-separated decimal values. + * The 'TFTP' is the mount path and the `hostname' must be four dot-separated + * decimal values. */ #ifndef _RTEMS_TFTP_H @@ -32,6 +33,11 @@ extern "C" { #include +/* + * Filesystem Mount table entry. + */ +int rtems_tftpfs_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry); + /* * Filesystem initialization routine */ diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h index 50944b0f49..a65ec590f7 100644 --- a/cpukit/sapi/include/confdefs.h +++ b/cpukit/sapi/include/confdefs.h @@ -174,13 +174,192 @@ rtems_fs_init_functions_t rtems_fs_init_helper = extern int rtems_telnetd_maximum_ptys; #endif +/* + * Filesystems and Mount Table Configuration. + * + * Defines to control the file system: + * + * CONFIGURE_APPLICATION_DISABLE_FILESYSTEM: + * Disable the RTEMS filesystems. You get an empty DEVFS. + * + * CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM: + * Use the DEVFS as the root file system. Limited functions are + * provided when this is used. + * + * CONFIGURE_FILESYSTEM_ALL: + * Add file filesystems to the default filesystem table. + * + * List of available file systems. You can define as many as you like: + * CONFIGURE_FILESYSTEM_miniIMFS - MiniIMFS, use DEVFS now + * CONFIGURE_FILESYSTEM_IMFS - In Memory File System (IMFS) + * CONFIGURE_FILESYSTEM_DEVFS - Device File System (DSVFS) + * CONFIGURE_FILESYSTEM_TFTPFS - TFTP File System, networking enabled + * CONFIGURE_FILESYSTEM_FTPFS - FTP File System, networking enabled + * CONFIGURE_FILESYSTEM_NFSFS - Network File System, networking enabled + * CONFIGURE_FILESYSTEM_DOSFS - DOS File System, uses libblock + * CONFIGURE_FILESYSTEM_RFS - RTEMS File System (RFS), uses libblock + * + * Combinations: + * + * - If nothing is defined the base file system is the IMFS. + * + * - If CONFIGURE_APPLICATION_DISABLE_FILESYSTEM is defined all filesystem + * are disabled by force and an empty DEVFS is created. + * + * - If CONFIGURE_USE_DEV_AS_BASE_FILESYSTEM is defined all filesystem + * are disabled by force and DEVFS is defined. + */ + #ifdef CONFIGURE_INIT - #ifdef CONFIGURE_APPLICATION_DISABLE_FILESYSTEM - #if defined(RTEMS_COVERAGE) - uint32_t rtems_device_table_size = 0; + + /* + * Include all file systems. Do this before checking if the filesystem has + * been disabled. + */ + #ifdef CONFIGURE_FILESYSTEM_ALL + #define CONFIGURE_FILESYSTEM_miniIMFS + #define CONFIGURE_FILESYSTEM_IMFS + #define CONFIGURE_FILESYSTEM_DEVFS + #define CONFIGURE_FILESYSTEM_TFTPFS + #define CONFIGURE_FILESYSTEM_FTPFS + #define CONFIGURE_FILESYSTEM_NFSFS + #define CONFIGURE_FILESYSTEM_DOSFS + #define CONFIGURE_FILESYSTEM_RFS + #endif + + /* + * If disabling the file system undef everything. If DEVFS as the base + * filesystem undefine all other filesystems because you cannot mount other + * filesystems. + */ + #if defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM) || \ + defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM) + #if defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM) + #undef CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM #endif + #undef CONFIGURE_FILESYSTEM_miniIMFS + #undef CONFIGURE_FILESYSTEM_IMFS + #undef CONFIGURE_FILESYSTEM_DEVFS + #undef CONFIGURE_FILESYSTEM_TFTPFS + #undef CONFIGURE_FILESYSTEM_FTPFS + #undef CONFIGURE_FILESYSTEM_NFSFS + #undef CONFIGURE_FILESYSTEM_DOSFS + #undef CONFIGURE_FILESYSTEM_RFS + #endif + + /* + * If the base filesystem is DEVFS define it else define IMFS. + * We will have either DEVFS or IMFS defined after this. + */ + #if defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM) && \ + !defined(CONFIGURE_FILESYSTEM_DEVFS) + #define CONFIGURE_FILESYSTEM_DEVFS + #elif !defined(CONFIGURE_FILESYSTEM_IMFS) + #define CONFIGURE_FILESYSTEM_IMFS + #endif + +#endif + +/** + * IMFS + */ +#include + +/** + * This specifies the number of bytes per block for files within the IMFS. + * There are a maximum number of blocks per file so this dictates the maximum + * size of a file. This has to be balanced with the unused portion of each + * block that might be wasted. + */ +#ifndef CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK + #define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK \ + IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK +#endif + +#ifdef CONFIGURE_INIT + int imfs_rq_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK; +#endif /* CONFIGURE_INIT */ + +/** + * This defines the miniIMFS file system table entry. + */ +#if !defined(CONFIGURE_FILESYSTEM_ENTRY_miniIMFS) && \ + defined(CONFIGURE_FILESYSTEM_miniIMFS) +#define CONFIGURE_FILESYSTEM_ENTRY_miniIMFS { "mimfs", miniIMFS_initialize } +#endif + +/** + * This defines the IMFS file system table entry. + */ +#if !defined(CONFIGURE_FILESYSTEM_ENTRY_IMFS) && \ + defined(CONFIGURE_FILESYSTEM_IMFS) +#define CONFIGURE_FILESYSTEM_ENTRY_IMFS { "imfs", IMFS_initialize } +#endif + +/** + * DEVFS + */ +#if !defined(CONFIGURE_FILESYSTEM_ENTRY_DEVFS) && \ + defined(CONFIGURE_FILESYSTEM_DEVFS) +#include +#define CONFIGURE_FILESYSTEM_ENTRY_DEVFS { "devfs", devFS_initialize } +#endif + +#ifdef RTEMS_NETWORKING + /** + * FTPFS + */ + #if !defined(CONFIGURE_FILESYSTEM_ENTRY_FTPFS) && \ + defined(CONFIGURE_FILESYSTEM_FTPFS) + #include + #define CONFIGURE_FILESYSTEM_ENTRY_FTPFS { "ftpfs", rtems_ftpfs_initialize } + #endif + + /** + * TFTPFS + */ + #if !defined(CONFIGURE_FILESYSTEM_ENTRY_TFTPFS) && \ + defined(CONFIGURE_FILESYSTEM_TFTPFS) + #include + #define CONFIGURE_FILESYSTEM_ENTRY_TFTPFS { "tftpfs", rtems_tftpfs_initialize } + #endif + + /** + * NFSFS + */ + #if !defined(CONFIGURE_FILESYSTEM_ENTRY_NFSFS) && \ + defined(CONFIGURE_FILESYSTEM_NFSFS) + #include + #define CONFIGURE_FILESYSTEM_ENTRY_NFSFS { "nfs", rtems_nfsfs_initialize } + #endif +#endif + +/** + * DOSFS + */ +#if !defined(CONFIGURE_FILESYSTEM_ENTRY_DOSFS) && \ + defined(CONFIGURE_FILESYSTEM_DOSFS) + #include + #define CONFIGURE_FILESYSTEM_ENTRY_DOSFS { "dosfs", rtems_dosfs_initialize } +#endif + +/** + * RFS + */ +#if !defined(CONFIGURE_FILESYSTEM_ENTRY_RFS) && \ + defined(CONFIGURE_FILESYSTEM_RFS) + #include + #define CONFIGURE_FILESYSTEM_ENTRY_RFS { "rfs", rtems_rfs_rtems_initialise } +#endif + +#ifdef CONFIGURE_INIT + + /* + * DEVFS variables. + */ + #if defined(CONFIGURE_APPLICATION_DISABLE_FILESYSTEM) && !defined(RTEMS_COVERAGE) #define CONFIGURE_MEMORY_FOR_DEVFS 0 - #elif defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM) + #elif defined(CONFIGURE_FILESYSTEM_DEVFS) #ifndef CONFIGURE_MAXIMUM_DEVICES #define CONFIGURE_MAXIMUM_DEVICES 4 #endif @@ -195,28 +374,54 @@ rtems_fs_init_functions_t rtems_fs_init_helper = #else #define CONFIGURE_MEMORY_FOR_DEVFS 0 #endif -#endif -/* - * Mount Table Configuration - */ -#include + /** + * Table termination record. + */ + #define CONFIGURE_FILESYSTEM_NULL { NULL, NULL } -/** - * This specifies the number of bytes per block for files within - * the IMFS. There are a maximum number of blocks per file so - * this dictates the maximum size of a file. This has to be balanced - * with the unused portion of each block that might be wasted. - */ -#ifndef CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK - #define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK \ - IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK -#endif -#ifdef CONFIGURE_INIT - int imfs_rq_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK; -#endif /* CONFIGURE_INIT */ + /** + * The default file system table. Must be terminated with the NULL entry if + * you provide your own. + */ + #ifndef CONFIGURE_HAS_OWN_FILESYSTEM_TABLE + const rtems_filesystem_table_t configuration_filesystem_table[] = { + #if defined(CONFIGURE_FILESYSTEM_miniIMFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_miniIMFS) + CONFIGURE_FILESYSTEM_ENTRY_miniIMFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_IMFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_IMFS) + CONFIGURE_FILESYSTEM_ENTRY_IMFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_DEVFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_DEVFS) + CONFIGURE_FILESYSTEM_ENTRY_DEVFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_TFTPFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_TFTPFS) + CONFIGURE_FILESYSTEM_ENTRY_TFTPFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_FTPFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_FTPFS) + CONFIGURE_FILESYSTEM_ENTRY_FTPFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_NFSFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_NFSFS) + CONFIGURE_FILESYSTEM_ENTRY_NFSFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_DOSFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_DOSFS) + CONFIGURE_FILESYSTEM_ENTRY_DOSFS, + #endif + #if defined(CONFIGURE_FILESYSTEM_RFS) && \ + defined(CONFIGURE_FILESYSTEM_ENTRY_RFS) + CONFIGURE_FILESYSTEM_ENTRY_RFS, + #endif + CONFIGURE_FILESYSTEM_NULL + }; + #endif -#ifdef CONFIGURE_INIT /** * This disables the inclusion of pipe support in the full IMFS. * @@ -234,11 +439,11 @@ rtems_fs_init_functions_t rtems_fs_init_helper = #ifndef CONFIGURE_HAS_OWN_MOUNT_TABLE const rtems_filesystem_mount_table_t configuration_mount_table = { #ifdef CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM - &IMFS_ops, + "imfs", #elif defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM) - &devFS_ops, + "devfs", #else /* using miniIMFS as base filesystem */ - &miniIMFS_ops, + "mimfs", #endif RTEMS_FILESYSTEM_READ_WRITE, NULL, @@ -249,6 +454,7 @@ rtems_fs_init_functions_t rtems_fs_init_helper = *rtems_filesystem_mount_table = &configuration_mount_table; const int rtems_filesystem_mount_table_size = 1; #endif + #endif /* -- cgit v1.2.3