From ce275cffd6ed98436ab689347d3b6db9ec047061 Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Wed, 6 Aug 2003 19:14:14 +0000 Subject: 2003-08-06 Thomas Doerfler PR 369/filesystem * Makefile.am, shell/cmds.c, wrapup/Makefile.am: sample application to show the use of the DOSFS functions * fsmount/Makefile.am, fsmount/README, fsmount/fsmount.c, fsmount/fsmount.h: New files. --- cpukit/libmisc/ChangeLog | 8 ++ cpukit/libmisc/Makefile.am | 2 +- cpukit/libmisc/fsmount/Makefile.am | 43 ++++++++ cpukit/libmisc/fsmount/README | 24 +++++ cpukit/libmisc/fsmount/fsmount.c | 196 +++++++++++++++++++++++++++++++++++++ cpukit/libmisc/fsmount/fsmount.h | 71 ++++++++++++++ cpukit/libmisc/shell/cmds.c | 2 +- cpukit/libmisc/wrapup/Makefile.am | 1 + 8 files changed, 345 insertions(+), 2 deletions(-) create mode 100644 cpukit/libmisc/fsmount/Makefile.am create mode 100644 cpukit/libmisc/fsmount/README create mode 100644 cpukit/libmisc/fsmount/fsmount.c create mode 100644 cpukit/libmisc/fsmount/fsmount.h (limited to 'cpukit') diff --git a/cpukit/libmisc/ChangeLog b/cpukit/libmisc/ChangeLog index 9c74dc4a22..759a2b6c5d 100644 --- a/cpukit/libmisc/ChangeLog +++ b/cpukit/libmisc/ChangeLog @@ -1,3 +1,11 @@ +2003-08-06 Thomas Doerfler + + PR 369/filesystem + * Makefile.am, shell/cmds.c, wrapup/Makefile.am: sample application to + show the use of the DOSFS functions + * fsmount/Makefile.am, fsmount/README, fsmount/fsmount.c, + fsmount/fsmount.h: New files. + 2003-08-05 Till Strauman PR 436/rtems_misc diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index fd45f3a725..fc8f64005e 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -3,7 +3,7 @@ ## SUBDIRS = capture cpuuse devnull dummy dumpbuf monitor mw-fb shell \ - rtmonuse serdbg stackchk untar wrapup + rtmonuse serdbg stackchk untar fsmount wrapup EXTRA_DIST = README diff --git a/cpukit/libmisc/fsmount/Makefile.am b/cpukit/libmisc/fsmount/Makefile.am new file mode 100644 index 0000000000..12b0f6976b --- /dev/null +++ b/cpukit/libmisc/fsmount/Makefile.am @@ -0,0 +1,43 @@ +## +## Makefile.am,v 1.9 2002/08/11 05:51:17 ralf Exp +## + + +include_rtemsdir = $(includedir)/rtems + +LIBNAME = libfsmount +LIB = $(ARCH)/$(LIBNAME).a + +C_FILES = fsmount.c +C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.$(OBJEXT)) + +include_rtems_HEADERS = fsmount.h + +OBJS = $(C_O_FILES) + +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/lib.am + +$(PROJECT_INCLUDE)/rtems: + @$(mkinstalldirs) $@ +$(PROJECT_INCLUDE)/rtems/%.h: %.h + $(INSTALL_DATA) $< $@ + +# +# (OPTIONAL) Add local stuff here using += +# + +$(LIB): $(OBJS) + $(make-library) + +PREINSTALL_FILES = $(PROJECT_INCLUDE)/rtems \ + $(include_rtems_HEADERS:%=$(PROJECT_INCLUDE)/rtems/%) + +all-local: $(ARCH) $(PREINSTALL_FILES) $(OBJS) $(LIB) + +.PRECIOUS: $(LIB) + +EXTRA_DIST = README fsmount.c + +include $(top_srcdir)/../automake/local.am + diff --git a/cpukit/libmisc/fsmount/README b/cpukit/libmisc/fsmount/README new file mode 100644 index 0000000000..88bfda62e7 --- /dev/null +++ b/cpukit/libmisc/fsmount/README @@ -0,0 +1,24 @@ +# +# +# fsmount information +# +# Author: Thomas Doerfler 02/07/2003 +# +# README,v 1.1 1999/07/09 17:23:15 joel Exp +# + +fsmount.c contains the function fsmount. It processes the +fs table given as an parameter to create the listed mount points +and mount the corresponding file systems to their mount points. +See "c/src/tests/samples/fileio" for a sample on how to use this +function. + +The field "report_reasons" specifies, what results of the mount point +creation/mount operations should print to the console. + +The field "abort_reasons" specifies, what results of the mount point +creation/mount operations should abort the function. Do not set the +"abort_reasons" bit, unless you want to stop the processing of the +fsmount table after the first successful mount. + + diff --git a/cpukit/libmisc/fsmount/fsmount.c b/cpukit/libmisc/fsmount/fsmount.c new file mode 100644 index 0000000000..1d251199c0 --- /dev/null +++ b/cpukit/libmisc/fsmount/fsmount.c @@ -0,0 +1,196 @@ +/*===============================================================*\ +| Project: RTEMS fsmount | ++-----------------------------------------------------------------+ +| File: fsmount.c | ++-----------------------------------------------------------------+ +| Copyright (c) 2003 IMD | +| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler | +| | +| all rights reserved | ++-----------------------------------------------------------------+ +| this file contains the fsmount functions. These functions | +| are used to mount a list of filesystems (and create their mount | +| points before) | +| | +| The license and distribution terms for this file may be | +| found in the file LICENSE in this distribution or at | +| http://www.OARcorp.com/rtems/license.html. | +| | ++-----------------------------------------------------------------+ +| date history ID | +| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | +| 02.07.03 creation doe | +\*===============================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include + +/*=========================================================================*\ +| Function: | +\*-------------------------------------------------------------------------*/ +int rtems_fsmount_create_mountpoint +( +/*-------------------------------------------------------------------------*\ +| Purpose: | +| This function will create the mount point given | ++---------------------------------------------------------------------------+ +| Input Parameters: | +\*-------------------------------------------------------------------------*/ + const char *mount_point + ) +/*-------------------------------------------------------------------------*\ +| Return Value: | +| 0, if success, -1 and errno if failed | +\*=========================================================================*/ +{ + int rc = 0; + char *tok_buffer = NULL; + char *token = NULL; + int token_len; + size_t total_len; + IMFS_token_types token_type; + struct stat file_info; + /* + * allocate temp memory to rebuild path name + */ + tok_buffer = calloc(strlen(mount_point)+1,sizeof(char)); + token = tok_buffer; + total_len = 0; + do { + /* + * scan through given string, one segment at a time + */ + token_type = IMFS_get_token(mount_point+total_len,token,&token_len); + total_len += token_len; + strncpy(tok_buffer,mount_point,total_len); + tok_buffer[total_len] = '\0'; + + if ((token_type != IMFS_NO_MORE_PATH) && + (token_type != IMFS_CURRENT_DIR) && + (token_type != IMFS_INVALID_TOKEN)) { + /* + * check, whether segment exists + */ + if (0 != stat(tok_buffer,&file_info)) { + /* + * if not, create directory + */ + rc = mknod(tok_buffer,S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR,0); + } + } + } while ((rc == 0) && + (token_type != IMFS_NO_MORE_PATH) && + (token_type != IMFS_INVALID_TOKEN)); + + /* + * return token buffer to heap + */ + if (tok_buffer != NULL) { + free(tok_buffer); + } + return rc; +} + +/*=========================================================================*\ +| Function: | +\*-------------------------------------------------------------------------*/ +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 fstab_t *fstab_ptr, + int fstab_count, + int *fail_idx + ) +/*-------------------------------------------------------------------------*\ +| Return Value: | +| 0, if success, -1 and errno if failed | +\*=========================================================================*/ +{ + int rc = 0; + int tmp_rc; + int fstab_idx = 0; + rtems_filesystem_mount_table_entry_t *tmp_mt_entry; + boolean terminate = FALSE; + + /* + * scan through all fstab entries; + */ + while (!terminate && + (fstab_idx < fstab_count)) { + tmp_rc = 0; + /* + * create mount point + */ + if (tmp_rc == 0) { + tmp_rc = rtems_fsmount_create_mountpoint(fstab_ptr->mount_point); + if (tmp_rc != 0) { + if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNTPNT_CRTERR)) { + printf("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; + } + } + } + /* + * mount device to given mount point + */ + if (tmp_rc == RTEMS_SUCCESSFUL) { + tmp_rc = mount(&tmp_mt_entry, + fstab_ptr->fs_ops, + fstab_ptr->mount_options, + fstab_ptr->dev, + fstab_ptr->mount_point); + if (tmp_rc != RTEMS_SUCCESSFUL) { + if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_FAILED)) { + printf("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; + } + } + else { + if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_OK)) { + printf("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; + } + } + } + /* + * proceed to next entry + */ + if (!terminate) { + fstab_ptr++; + fstab_idx++; + } + } + if (fail_idx != NULL) { + *fail_idx = fstab_idx; + } + return rc; +} + diff --git a/cpukit/libmisc/fsmount/fsmount.h b/cpukit/libmisc/fsmount/fsmount.h new file mode 100644 index 0000000000..52346d6d88 --- /dev/null +++ b/cpukit/libmisc/fsmount/fsmount.h @@ -0,0 +1,71 @@ +/*===============================================================*\ +| Project: RTEMS fsmount | ++-----------------------------------------------------------------+ +| File: fsmount.h | ++-----------------------------------------------------------------+ +| Copyright (c) 2003 IMD | +| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler | +| | +| all rights reserved | ++-----------------------------------------------------------------+ +| this file contains the fsmount functions. These functions | +| are used to mount a list of filesystems (and create their mount | +| points before) | +| | +| The license and distribution terms for this file may be | +| found in the file LICENSE in this distribution or at | +| http://www.OARcorp.com/rtems/license.html. | +| | ++-----------------------------------------------------------------+ +| date history ID | +| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | +| 02.07.03 creation doe | +\*===============================================================*/ +#ifndef _FSMOUNT_H +#define _FSMOUNT_H +#include +#include +#include + +/* + * bits to define, what errors will cause reporting (via printf) and + * abort of mount processing + * Use a combination of these bits + * for the fields "report_reasons" and "abort_reasons" + */ +#define FSMOUNT_MNT_OK 0x0001 /* mounted ok */ +#define FSMOUNT_MNTPNT_CRTERR 0x0002 /* cannot create mount point */ +#define FSMOUNT_MNT_FAILED 0x0004 /* mounting failed */ + +typedef struct { + char *dev; + char *mount_point; + rtems_filesystem_operations_table *fs_ops; + rtems_filesystem_options_t mount_options; + unsigned16 report_reasons; + unsigned16 abort_reasons; +} fstab_t; + + +/*=========================================================================*\ +| Function: | +\*-------------------------------------------------------------------------*/ +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 fstab_t *fstab_ptr, /* Ptr to filesystem mount table */ + int fstab_count, /* number of entries in mount table*/ + int *fail_idx /* return: index of failed entry */ + ); +/*-------------------------------------------------------------------------*\ +| Return Value: | +| 0, if success, -1 and errno if failed | +\*=========================================================================*/ + +#endif /* _FSMOUNT_H */ diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c index cf2f252413..5cc630ef24 100644 --- a/cpukit/libmisc/shell/cmds.c +++ b/cpukit/libmisc/shell/cmds.c @@ -286,7 +286,7 @@ int main_ls(int argc, char *argv[]) strcat(nbuf,dp->d_name); /* always the fullpathname. Avoid ftpd problem.*/ if (stat(nbuf, &stat_buf) == 0) { /* AWFUL buts works...*/ - strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_atime)); + strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_mtime)); pwd=getpwuid(stat_buf.st_uid); user=pwd?pwd->pw_name:"nouser"; grp=getgrgid(stat_buf.st_gid); diff --git a/cpukit/libmisc/wrapup/Makefile.am b/cpukit/libmisc/wrapup/Makefile.am index 3b2e1d633c..5360ee5c35 100644 --- a/cpukit/libmisc/wrapup/Makefile.am +++ b/cpukit/libmisc/wrapup/Makefile.am @@ -28,6 +28,7 @@ TMP_LIBS += ../devnull/$(ARCH)/libdevnull.a TMP_LIBS += ../dummy/$(ARCH)/libdummy.a TMP_LIBS += ../mw-fb/$(ARCH)/libmw-fb.a TMP_LIBS += ../capture/$(ARCH)/libcapture.a +TMP_LIBS += ../fsmount/$(ARCH)/libfsmount.a # # (OPTIONAL) Add local stuff here using += -- cgit v1.2.3