mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-08-30 06:07:13 +08:00
* libblock/src/bdbuf.c: Update comments.
* libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the
device from the rdev field of the stat buf.
* libcsupport/include/rtems/libio.h: Add a path length to evalpath
handler. Add parent locations to rmmod and unlink handlers.
* libcsupport/include/rtems/libio_.h: Add a path length to
rtems_filesystem_evaluate_path. Add
rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname,
and rtems_filesystem_prefix_separators. Remove
rtems_filesystem_evaluate_parent.
* libcsupport/src/base_fs.c, libcsupport/src/chdir.c,
libcsupport/src/chmod.c, libcsupport/src/chown.c,
libcsupport/src/chroot.c, libcsupport/src/fchdir.c,
libcsupport/src/link.c, libcsupport/src/mount.c,
libcsupport/src/open.c, libcsupport/src/privateenv.c,
libcsupport/src/readlink.c, libcsupport/src/unmount.c,
libcsupport/src/utime.c, libcsupport/src/unmount.c,
libcsupport/src/utime.c, libfs/src/devfs/devfs.h,
libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c,
libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c,
libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c,
libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c,
libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c,
libnetworking/lib/ftpfs.c: Add the length parameter to the eval
call.
* libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators,
rtems_filesystem_dirname,
rtems_filesystem_evaluate_relative_path. Add the length parameter
to the eval call.
* libcsupport/src/rmdir.c: Find the parent pathloc then the node
pathloc from that node. Remove the call to find the parent given
the node pathloc.
* libcsupport/src/stat.c: Add the length parameter to the eval
call. Set the device into the rdev field.
* libcsupport/src/unlink.c: Find the parent pathloc then the node
pathloc from that node. Remove the call to find the parent given
the node pathloc.
* libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the
disk device number from the stat rdev field.
* libfs/src/dosfs/msdos.h: Add the length parameter to the eval
call. Add the parent pathloc to the rmnod handler.
* libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod
handler.
* libfs/src/dosfs/msdos_eval.c: Add the length parameter to the
eval and token call.
* libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the
rmnod handler.
* libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for
only the allowed flags. Add the missing flags spec'ed in the POSIX
standard.
* libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c,
libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the
parent node. Currently ignored in the IMFS.
* libfs/src/imfs/imfs_stat.c: Return the device number in the rdev
field.
* libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add
the length parameter to the token call.
* libfs/src/nfsclient/src/nfs.c: Add the length parameter to the
eval call and parent node to the rmnod and unlink command.
* libmisc/shell/internal.h: Remove the libc mounter decl to make
public.
* libmisc/shell/main_mount.c: Add support for hooking external
mount support for new file systems.
* libmisc/shell/shell.h: Add helper functions for the mount
command.
208 lines
6.9 KiB
C
208 lines
6.9 KiB
C
/**
|
|
* @file
|
|
*
|
|
* File system mount functions.
|
|
*/
|
|
|
|
/*===============================================================*\
|
|
| 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.rtems.com/license/LICENSE. |
|
|
| |
|
|
+-----------------------------------------------------------------+
|
|
| date history ID |
|
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
|
| 02.07.03 creation doe |
|
|
\*===============================================================*/
|
|
|
|
#ifndef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <rtems.h>
|
|
#include <rtems/fsmount.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <rtems/imfs.h>
|
|
#include <sys/stat.h>
|
|
|
|
/*=========================================================================*\
|
|
| Function: |
|
|
\*-------------------------------------------------------------------------*/
|
|
int rtems_fsmount_create_mount_point
|
|
(
|
|
/*-------------------------------------------------------------------------*\
|
|
| 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,strlen(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 rtems_fstab_entry *fstab_ptr,
|
|
size_t fstab_count,
|
|
size_t *fail_idx
|
|
)
|
|
/*-------------------------------------------------------------------------*\
|
|
| 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)) {
|
|
tmp_rc = 0;
|
|
/*
|
|
* create mount point
|
|
*/
|
|
if (tmp_rc == 0) {
|
|
tmp_rc = rtems_fsmount_create_mount_point(fstab_ptr->mount_point);
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
* 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);
|
|
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;
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
* proceed to next entry
|
|
*/
|
|
if (!terminate) {
|
|
fstab_ptr++;
|
|
fstab_idx++;
|
|
}
|
|
}
|
|
if (fail_idx != NULL) {
|
|
*fail_idx = fstab_idx;
|
|
}
|
|
return rc;
|
|
}
|