2012-08-04 01:47:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_mntcmds.c
|
|
|
|
*
|
2013-03-07 02:52:30 +01:00
|
|
|
* Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
|
2012-08-04 01:47:32 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/statfs.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2012-12-24 18:49:58 +01:00
|
|
|
#include <string.h>
|
2012-08-04 01:47:32 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-12-24 18:49:58 +01:00
|
|
|
#include <nuttx/fs/nfs.h>
|
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
#include "nsh.h"
|
|
|
|
#include "nsh_console.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
/****************************************************************************
|
2013-05-01 02:03:04 +02:00
|
|
|
* Name: get_fstype
|
2012-08-04 01:47:32 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
|
2013-03-07 02:52:30 +01:00
|
|
|
#ifndef CONFIG_NUTTX_KERNEL
|
2013-05-01 02:03:04 +02:00
|
|
|
static const char* get_fstype(FAR struct statfs *statbuf)
|
2012-08-04 01:47:32 +02:00
|
|
|
{
|
|
|
|
FAR const char *fstype;
|
|
|
|
|
|
|
|
/* Get the file system type */
|
|
|
|
|
|
|
|
switch (statbuf->f_type)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_FS_FAT
|
|
|
|
case MSDOS_SUPER_MAGIC:
|
|
|
|
fstype = "vfat";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_FS_ROMFS
|
|
|
|
case ROMFS_MAGIC:
|
|
|
|
fstype = "romfs";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-01-16 16:41:27 +01:00
|
|
|
#ifdef CONFIG_FS_BINFS
|
2012-08-04 01:47:32 +02:00
|
|
|
case BINFS_MAGIC:
|
2013-01-16 20:08:23 +01:00
|
|
|
fstype = "binfs";
|
2012-08-04 01:47:32 +02:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_FS_NXFFS
|
|
|
|
case NXFFS_MAGIC:
|
|
|
|
fstype = "nxffs";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NFS
|
|
|
|
case NFS_SUPER_MAGIC:
|
|
|
|
fstype = "nfs";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-05-01 02:03:04 +02:00
|
|
|
#ifdef CONFIG_FS_SMARTFS
|
|
|
|
case SMARTFS_MAGIC:
|
|
|
|
fstype = "smartfs";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-11-17 19:30:04 +01:00
|
|
|
#ifdef CONFIG_FS_PROCFS
|
|
|
|
case PROCFS_MAGIC:
|
|
|
|
fstype = "procfs";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
default:
|
|
|
|
fstype = "Unrecognized";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-01 02:03:04 +02:00
|
|
|
return fstype;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: df_handler
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
|
|
|
|
static int df_handler(FAR const char *mountpoint,
|
|
|
|
FAR struct statfs *statbuf, FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpoint && statbuf && vtbl);
|
|
|
|
|
|
|
|
nsh_output(vtbl, "%6ld %8ld %8ld %8ld %s\n",
|
|
|
|
statbuf->f_bsize, statbuf->f_blocks,
|
|
|
|
statbuf->f_blocks - statbuf->f_bavail, statbuf->f_bavail,
|
|
|
|
mountpoint);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: df_man_readable_handler
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_CMDOPT_DF_H
|
|
|
|
static int df_man_readable_handler(FAR const char *mountpoint,
|
|
|
|
FAR struct statfs *statbuf, FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t used;
|
|
|
|
uint32_t free;
|
|
|
|
int which;
|
|
|
|
char sizelabel;
|
|
|
|
char freelabel;
|
|
|
|
char usedlabel;
|
|
|
|
const char labels[5] = { 'B', 'K', 'M', 'G', 'T' };
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpoint && statbuf && vtbl);
|
|
|
|
|
|
|
|
size = statbuf->f_bsize * statbuf->f_blocks;
|
|
|
|
free = statbuf->f_bsize * statbuf->f_bavail;
|
|
|
|
used = size - free;
|
|
|
|
|
|
|
|
/* Find the label for size */
|
|
|
|
|
|
|
|
which = 0;
|
2014-03-06 20:31:13 +01:00
|
|
|
while (size >= 9999 || ((size & 0x3ff) == 0 && size != 0))
|
2013-05-01 02:03:04 +02:00
|
|
|
{
|
|
|
|
which++;
|
|
|
|
size >>= 10;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-05-01 02:03:04 +02:00
|
|
|
sizelabel = labels[which];
|
|
|
|
|
|
|
|
/* Find the label for free */
|
|
|
|
|
|
|
|
which = 0;
|
2014-03-06 20:31:13 +01:00
|
|
|
while (free >= 9999 || ((free & 0x3ff) == 0 && free != 0))
|
2013-05-01 02:03:04 +02:00
|
|
|
{
|
|
|
|
which++;
|
|
|
|
free >>= 10;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-05-01 02:03:04 +02:00
|
|
|
freelabel = labels[which];
|
|
|
|
|
|
|
|
/* Find the label for used */
|
|
|
|
|
|
|
|
which = 0;
|
2014-03-06 20:31:13 +01:00
|
|
|
while (used >= 9999 || ((used & 0x3ff) == 0 && used != 0))
|
2013-05-01 02:03:04 +02:00
|
|
|
{
|
|
|
|
which++;
|
|
|
|
used >>= 10;
|
|
|
|
}
|
2013-12-12 16:21:55 +01:00
|
|
|
|
2013-05-01 02:03:04 +02:00
|
|
|
usedlabel = labels[which];
|
|
|
|
|
2013-11-17 19:30:04 +01:00
|
|
|
#ifndef CONFIG_NUTTX_KERNEL
|
2013-05-01 02:03:04 +02:00
|
|
|
nsh_output(vtbl, "%-10s %6ld%c %8ld%c %8ld%c %s\n", get_fstype(statbuf),
|
|
|
|
size, sizelabel, used, usedlabel, free, freelabel,
|
|
|
|
mountpoint);
|
2013-11-17 19:30:04 +01:00
|
|
|
#else
|
|
|
|
nsh_output(vtbl, "%6ld%c %8ld%c %8ld%c %s\n", size, sizelabel, used,
|
|
|
|
usedlabel, free, freelabel, mountpoint);
|
|
|
|
#endif
|
2013-05-01 02:03:04 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NSH_CMDOPT_DF_H */
|
|
|
|
|
2013-11-17 19:30:04 +01:00
|
|
|
#endif /* CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) &&
|
2013-05-01 02:03:04 +02:00
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF) */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mount_handler
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
|
|
|
|
#ifndef CONFIG_NUTTX_KERNEL
|
|
|
|
static int mount_handler(FAR const char *mountpoint,
|
|
|
|
FAR struct statfs *statbuf, FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg;
|
|
|
|
FAR const char *fstype;
|
|
|
|
|
|
|
|
DEBUGASSERT(mountpoint && statbuf && vtbl);
|
|
|
|
|
|
|
|
/* Get the file system type */
|
|
|
|
|
|
|
|
fstype = get_fstype(statbuf);
|
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
nsh_output(vtbl, " %s type %s\n", mountpoint, fstype);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-07 02:52:30 +01:00
|
|
|
#endif
|
2012-08-04 01:47:32 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mount_show
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
|
2013-03-07 02:52:30 +01:00
|
|
|
#ifndef CONFIG_NUTTX_KERNEL
|
2012-08-04 01:47:32 +02:00
|
|
|
static inline int mount_show(FAR struct nsh_vtbl_s *vtbl, FAR const char *progname)
|
|
|
|
{
|
|
|
|
return foreach_mountpoint(mount_handler, (FAR void *)vtbl);
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-07 02:52:30 +01:00
|
|
|
#endif
|
2012-08-04 01:47:32 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_df
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_DF)
|
|
|
|
int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
2013-05-01 02:03:04 +02:00
|
|
|
#ifdef CONFIG_NSH_CMDOPT_DF_H
|
|
|
|
if (argc > 1 && strcmp(argv[1], "-h") == 0)
|
|
|
|
{
|
2013-11-17 19:30:04 +01:00
|
|
|
#ifndef CONFIG_NUTTX_KERNEL
|
2013-05-01 02:03:04 +02:00
|
|
|
nsh_output(vtbl, "Filesystem Size Used Available Mounted on\n");
|
2013-11-17 19:30:04 +01:00
|
|
|
#else
|
|
|
|
nsh_output(vtbl, "Size Used Available Mounted on\n");
|
|
|
|
#endif
|
2013-05-01 02:03:04 +02:00
|
|
|
return foreach_mountpoint(df_man_readable_handler, (FAR void *)vtbl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, " Block Number\n");
|
|
|
|
nsh_output(vtbl, " Size Blocks Used Available Mounted on\n");
|
|
|
|
return foreach_mountpoint(df_handler, (FAR void *)vtbl);
|
|
|
|
}
|
2012-08-04 02:37:25 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mount
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
|
2012-08-04 01:47:32 +02:00
|
|
|
int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
2013-01-16 20:08:23 +01:00
|
|
|
FAR const char *source;
|
|
|
|
FAR char *fullsource;
|
|
|
|
FAR const char *target;
|
|
|
|
FAR char *fulltarget;
|
|
|
|
FAR const char *filesystem = NULL;
|
2012-08-04 01:47:32 +02:00
|
|
|
bool badarg = false;
|
2012-09-13 21:33:47 +02:00
|
|
|
int option;
|
2012-08-04 01:47:32 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* The mount command behaves differently if no parameters are provided */
|
|
|
|
|
2013-03-07 02:52:30 +01:00
|
|
|
#ifndef CONFIG_NUTTX_KERNEL
|
2012-08-04 01:47:32 +02:00
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
return mount_show(vtbl, argv[0]);
|
|
|
|
}
|
2013-03-07 02:52:30 +01:00
|
|
|
#endif
|
2012-08-04 01:47:32 +02:00
|
|
|
|
2012-09-08 15:56:21 +02:00
|
|
|
/* Get the mount options. NOTE: getopt() is not thread safe nor re-entrant.
|
|
|
|
* To keep its state proper for the next usage, it is necessary to parse to
|
|
|
|
* the end of the line even if an error occurs. If an error occurs, this
|
|
|
|
* logic just sets 'badarg' and continues.
|
|
|
|
*/
|
2012-08-04 01:47:32 +02:00
|
|
|
|
|
|
|
while ((option = getopt(argc, argv, ":t:")) != ERROR)
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case 't':
|
|
|
|
filesystem = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
|
|
|
badarg = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
|
|
|
badarg = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-08 15:56:21 +02:00
|
|
|
/* If a bad argument was encountered, then return without processing the
|
|
|
|
* command.
|
|
|
|
*/
|
2012-08-04 01:47:32 +02:00
|
|
|
|
|
|
|
if (badarg)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
/* There may be one or two required arguments after the options: the source
|
|
|
|
* and target paths. Some file systems do not require the source parameter
|
|
|
|
* so if there is only one parameter left, it must be the target.
|
2012-09-08 15:56:21 +02:00
|
|
|
*/
|
2012-08-04 01:47:32 +02:00
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
if (optind >= argc)
|
2012-08-04 01:47:32 +02:00
|
|
|
{
|
2013-01-16 20:08:23 +01:00
|
|
|
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
2012-08-04 01:47:32 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
2013-01-16 20:08:23 +01:00
|
|
|
|
|
|
|
source = NULL;
|
|
|
|
target = argv[optind];
|
|
|
|
optind++;
|
2013-11-17 19:30:04 +01:00
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
if (optind < argc)
|
2012-08-04 01:47:32 +02:00
|
|
|
{
|
2013-01-16 20:08:23 +01:00
|
|
|
source = target;
|
|
|
|
target = argv[optind];
|
|
|
|
optind++;
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
2012-08-04 01:47:32 +02:00
|
|
|
}
|
|
|
|
|
2012-09-08 15:56:21 +02:00
|
|
|
/* While the above parsing for the -t argument looks nice, the -t argument
|
|
|
|
* not really optional.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!filesystem)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
/* The source and target paths might be relative to the current
|
|
|
|
* working directory.
|
|
|
|
*/
|
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
fullsource = NULL;
|
|
|
|
fulltarget = NULL;
|
|
|
|
|
|
|
|
if (source)
|
2012-08-04 01:47:32 +02:00
|
|
|
{
|
2013-01-16 20:08:23 +01:00
|
|
|
fullsource = nsh_getfullpath(vtbl, source);
|
|
|
|
if (!fullsource)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
2012-08-04 01:47:32 +02:00
|
|
|
}
|
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
fulltarget = nsh_getfullpath(vtbl, target);
|
|
|
|
if (!fulltarget)
|
2012-08-04 01:47:32 +02:00
|
|
|
{
|
2013-01-16 20:08:23 +01:00
|
|
|
ret = ERROR;
|
|
|
|
goto errout;
|
2012-08-04 01:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform the mount */
|
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
ret = mount(fullsource, fulltarget, filesystem, 0, NULL);
|
2012-08-04 01:47:32 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
|
|
|
|
}
|
|
|
|
|
2013-01-16 20:08:23 +01:00
|
|
|
errout:
|
|
|
|
if (fullsource)
|
|
|
|
{
|
|
|
|
nsh_freefullpath(fullsource);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fulltarget)
|
|
|
|
{
|
|
|
|
nsh_freefullpath(fulltarget);
|
|
|
|
}
|
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_nfsmount
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_NET) && defined(CONFIG_NFS) && !defined(CONFIG_NSH_DISABLE_NFSMOUNT)
|
2012-08-04 01:47:32 +02:00
|
|
|
int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct nfs_args data;
|
|
|
|
FAR char *address;
|
|
|
|
FAR char *lpath;
|
|
|
|
FAR char *rpath;
|
|
|
|
bool badarg = false;
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
FAR struct sockaddr_in6 *sin;
|
|
|
|
struct in6_addr inaddr;
|
|
|
|
#else
|
|
|
|
FAR struct sockaddr_in *sin;
|
|
|
|
struct in_addr inaddr;
|
|
|
|
#endif
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* If a bad argument was encountered, then return without processing the
|
|
|
|
* command.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (badarg)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The fist argument on the command line should be the NFS server IP address
|
|
|
|
* in standard IPv4 (or IPv6) dot format.
|
|
|
|
*/
|
|
|
|
|
|
|
|
address = argv[1];
|
|
|
|
if (!address)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The local mount point path (lpath) might be relative to the current working
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lpath = nsh_getfullpath(vtbl, argv[2]);
|
|
|
|
if (!lpath)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the remote mount point path */
|
|
|
|
|
|
|
|
rpath = argv[3];
|
|
|
|
|
|
|
|
/* Convert the IP address string into its binary form */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
ret = inet_pton(AF_INET6, address, &inaddr);
|
|
|
|
#else
|
|
|
|
ret = inet_pton(AF_INET, address, &inaddr);
|
|
|
|
#endif
|
|
|
|
if (ret != 1)
|
|
|
|
{
|
|
|
|
nsh_freefullpath(lpath);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Place all of the NFS arguements into the nfs_args structure */
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
sin = (FAR struct sockaddr_in6 *)&data.addr;
|
|
|
|
sin->sin_family = AF_INET6;
|
|
|
|
sin->sin_port = htons(NFS_PMAPPORT);
|
|
|
|
memcpy(&sin->sin6_addr, &inaddr, sizeof(struct in6_addr));
|
|
|
|
data.addrlen = sizeof(struct sockaddr_in6);
|
|
|
|
#else
|
|
|
|
sin = (FAR struct sockaddr_in *)&data.addr;
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_port = htons(NFS_PMAPPORT);
|
|
|
|
sin->sin_addr = inaddr;
|
|
|
|
data.addrlen = sizeof(struct sockaddr_in);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
data.sotype = SOCK_DGRAM;
|
|
|
|
data.path = rpath;
|
|
|
|
data.flags = 0; /* 0=Use all defaults */
|
|
|
|
|
|
|
|
/* Perform the mount */
|
|
|
|
|
|
|
|
ret = mount(NULL, lpath, "nfs", 0, (FAR void *)&data);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We no longer need the allocated mount point path */
|
|
|
|
|
|
|
|
nsh_freefullpath(lpath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_umount
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-04 02:37:25 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_UMOUNT)
|
2012-08-04 01:47:32 +02:00
|
|
|
int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *fullpath = nsh_getfullpath(vtbl, argv[1]);
|
|
|
|
int ret = ERROR;
|
|
|
|
|
|
|
|
if (fullpath)
|
|
|
|
{
|
|
|
|
/* Perform the umount */
|
|
|
|
|
|
|
|
ret = umount(fullpath);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO);
|
|
|
|
}
|
|
|
|
nsh_freefullpath(fullpath);
|
|
|
|
}
|
2012-08-04 02:37:25 +02:00
|
|
|
|
2012-08-04 01:47:32 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|