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.
This commit is contained in:
Jennifer Averett
2003-08-06 19:14:14 +00:00
parent 1d2dbec76d
commit ce275cffd6
8 changed files with 345 additions and 2 deletions
+8
View File
@@ -1,3 +1,11 @@
2003-08-06 Thomas Doerfler<Thomas.Doerfler@imd-systems.de>
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 <strauman@slac.stanford.edu>
PR 436/rtems_misc
+1 -1
View File
@@ -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
+43
View File
@@ -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
+24
View File
@@ -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.
+196
View File
@@ -0,0 +1,196 @@
/*===============================================================*\
| Project: RTEMS fsmount |
+-----------------------------------------------------------------+
| File: fsmount.c |
+-----------------------------------------------------------------+
| Copyright (c) 2003 IMD |
| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
| <Thomas.Doerfler@imd-systems.de> |
| 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 <rtems.h>
#include <rtems/fsmount.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <imfs.h>
#include <sys/stat.h>
/*=========================================================================*\
| 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;
}
+71
View File
@@ -0,0 +1,71 @@
/*===============================================================*\
| Project: RTEMS fsmount |
+-----------------------------------------------------------------+
| File: fsmount.h |
+-----------------------------------------------------------------+
| Copyright (c) 2003 IMD |
| Ingenieurbuero fuer Microcomputertechnik Th. Doerfler |
| <Thomas.Doerfler@imd-systems.de> |
| 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 <rtems.h>
#include <rtems/libio.h>
#include <rtems/libcsupport.h>
/*
* 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 */
+1 -1
View File
@@ -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);
+1
View File
@@ -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 +=