Squashed commit of the following:

fs/mount:  Implements procfs /proc/fs/blocks and /proc/fs/usage files, replacing the NSH df command.
    fs/mount:  Implements procfs /proc/fs/mount file, replacing the NSH mount command when there are not arguments.
    fs/: Move prototype of foreach_mountpoint out of include/nuttx/fs/fs.h to fs/mount/mount.h.  Add framework for the mount procfs (initial commit is just a close of the net/route table procfs.
This commit is contained in:
Gregory Nutt 2017-10-26 13:33:08 -06:00
parent 4d344b36a3
commit 1ed816de4b
9 changed files with 875 additions and 36 deletions

1
TODO
View File

@ -636,7 +636,6 @@ o Kernel/Protected Build
COMMAND KERNEL INTERFACE(s)
-------- ----------------------------------------------
mkrd ramdisk_register()
mount foreach_mountpoint()
Status: Open
Priority: Medium/High -- the kernel build configuration is not fully fielded

View File

@ -44,9 +44,16 @@ ifeq ($(CONFIG_FS_AUTOMOUNTER),y)
CSRCS += fs_automount.c
endif
ifeq ($(CONFIG_FS_PROCFS),y)
ifneq ($(CONFIG_FS_PROCFS_EXCLUDE_MOUNT),y)
CSRCS += fs_procfs_mount.c fs_gettype.c
endif
endif
# Include mount build support
DEPPATH += --dep-path mount
VPATH += :mount
endif
endif

View File

@ -50,6 +50,7 @@
#include <nuttx/fs/fs.h>
#include "inode/inode.h"
#include "mount/mount.h"
#ifndef CONFIG_DISABLE_MOUNTPOINT

143
fs/mount/fs_gettype.c Normal file
View File

@ -0,0 +1,143 @@
/****************************************************************************
* fs/mount/fs_mount.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* 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/statfs.h>
#include "mount/mount.h"
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: fs_gettype
*
* Description:
* Given the result of statfs(), return a string representing the type of
* the file system.
*
* Input Parameters:
* statbuf - The result of a previouis statbuf statfs on the file system.
*
* Returned Value:
* A reference to a string representing the type of the file system.
*
****************************************************************************/
FAR const char *fs_gettype(FAR struct statfs *statbuf)
{
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
#ifdef CONFIG_FS_TMPFS
case TMPFS_MAGIC:
fstype = "tmpfs";
break;
#endif
#ifdef CONFIG_FS_BINFS
case BINFS_MAGIC:
fstype = "binfs";
break;
#endif
#ifdef CONFIG_FS_NXFFS
case NXFFS_MAGIC:
fstype = "nxffs";
break;
#endif
#ifdef CONFIG_NFS
case NFS_SUPER_MAGIC:
fstype = "nfs";
break;
#endif
#ifdef CONFIG_FS_SMARTFS
case SMARTFS_MAGIC:
fstype = "smartfs";
break;
#endif
#ifdef CONFIG_FS_PROCFS
case PROCFS_MAGIC:
fstype = "procfs";
break;
#endif
#ifdef CONFIG_FS_UNIONFS
case UNIONFS_MAGIC:
fstype = "unionfs";
break;
#endif
#ifdef CONFIG_FS_HOSTFS
case HOSTFS_MAGIC:
fstype = "hostfs";
break;
#endif
default:
fstype = "Unrecognized";
break;
}
return fstype;
}
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */

588
fs/mount/fs_procfs_mount.c Normal file
View File

@ -0,0 +1,588 @@
/****************************************************************************
* fs/mount/fs_procfs_mount.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* 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/statfs.h>
#include <sys/stat.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/procfs.h>
#include <nuttx/fs/dirent.h>
#include "mount/mount.h"
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
#if !defined(CONFIG_FS_PROCFS_EXCLUDE_MOUNT) || \
!defined(CONFIG_FS_PROCFS_EXCLUDE_BLOCKS) || \
!defined(CONFIG_FS_PROCFS_EXCLUDE_USAGE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Determines the size of an intermediate buffer that must be large enough
* to handle the longest line generated by this logic.
*/
#define MOUNT_LINELEN 64
/****************************************************************************
* Private Types
****************************************************************************/
enum mount_file_e
{
FS_MOUNT_FILE = 0, /* /proc/fs/mount */
FS_BLOCKS_FILE, /* /proc/fs/blocks */
FS_USAGE_FILE, /* /proc/fs/usage */
};
struct mount_file_s
{
struct procfs_file_s base; /* Base open file structure */
uint8_t id; /* See enum mount_file_e */
char line[MOUNT_LINELEN]; /* Pre-allocated buffer for formatted lines */
};
/* The structure is used when traversing routing tables */
struct mount_info_s
{
FAR char *line; /* Intermediate line buffer pointer */
FAR char *buffer; /* User buffer */
size_t linelen; /* Size of the intermediate buffer */
size_t buflen; /* Size of the user buffer */
size_t remaining; /* Bytes remaining in user buffer */
size_t totalsize; /* Accumulated size of the copy */
off_t offset; /* Skip offset */
bool header; /* True: header has been generated */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* Helpers */
static void mount_sprintf(FAR struct mount_info_s *info,
FAR const char *fmt, ...);
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
static int mount_entry(FAR const char *mountpoint,
FAR struct statfs *statbuf, FAR void *arg);
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
static int blocks_entry(FAR const char *mountpoint,
FAR struct statfs *statbuf, FAR void *arg);
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
static int usage_entry(FAR const char *mountpoint,
FAR struct statfs *statbuf, FAR void *arg);
#endif
/* File system methods */
static int mount_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode);
static int mount_close(FAR struct file *filep);
static ssize_t mount_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static int mount_dup(FAR const struct file *oldp,
FAR struct file *newp);
static int mount_stat(FAR const char *relpath, FAR struct stat *buf);
/****************************************************************************
* Public Data
****************************************************************************/
/* See fs_mount.c -- this structure is explicitly externed there.
* We use the old-fashioned kind of initializers so that this will compile
* with any compiler.
*/
const struct procfs_operations mount_procfsoperations =
{
mount_open, /* open */
mount_close, /* close */
mount_read, /* read */
NULL, /* write */
mount_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */
NULL, /* readdir */
NULL, /* rewinddir */
mount_stat /* stat */
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: mount_sprintf
*
* Description:
* Generate otuput from fs/mount, fs/blocks, or fs/usage, file read.
*
****************************************************************************/
static void mount_sprintf(FAR struct mount_info_s *info,
FAR const char *fmt, ...)
{
size_t linesize;
size_t copysize;
va_list ap;
/* Print the format and data to a line buffer */
va_start(ap, fmt);
linesize = vsnprintf(info->line, info->linelen, fmt, ap);
va_end(ap);
/* Copy the line buffer to the user buffer */
copysize = procfs_memcpy(info->line, linesize,
info->buffer, info->remaining,
&info->offset);
/* Update counts and pointers */
info->totalsize += copysize;
info->buffer += copysize;
info->remaining -= copysize;
}
/****************************************************************************
* Name: mount_entry
*
* Description:
* Output one fs/mount entry
*
* Format:
* <mountpoint> type <type>
*
****************************************************************************/
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
static int mount_entry(FAR const char *mountpoint, FAR struct statfs *statbuf,
FAR void *arg)
{
FAR struct mount_info_s *info = (FAR struct mount_info_s *)arg;
FAR const char *fstype;
DEBUGASSERT(mountpoint != NULL && statbuf != NULL && info != NULL);
/* Get the file system type */
fstype = fs_gettype(statbuf);
/* Generate mount list one line at a time */
mount_sprintf(info, " %s type %s\n", mountpoint, fstype);
return (info->totalsize >= info->buflen) ? 1 : 0;
}
#endif
/****************************************************************************
* Name: blocks_entry
*
* Description:
* Output one fs/blocks entry
*
* Format:
* <mountpoint> type <type>
*
****************************************************************************/
#ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
static int blocks_entry(FAR const char *mountpoint, FAR struct statfs *statbuf,
FAR void *arg)
{
FAR struct mount_info_s *info = (FAR struct mount_info_s *)arg;
DEBUGASSERT(mountpoint != NULL && statbuf != NULL && info != NULL);
/* Have we generated the header yet? */
if (!info->header)
{
mount_sprintf(info, " Block Number\n");
mount_sprintf(info, " Size Blocks Used Available Mounted on\n");
info->header = true;
}
/* Generate blocks list one line at a time */
mount_sprintf(info, "%6ld %8ld %8ld %8ld %s\n",
statbuf->f_bsize, statbuf->f_blocks,
statbuf->f_blocks - statbuf->f_bavail, statbuf->f_bavail,
mountpoint);
return (info->totalsize >= info->buflen) ? 1 : 0;
}
#endif
/****************************************************************************
* Name: blocks_entry
*
* Description:
* Output one fs/usage entry
*
* Format:
* <mountpoint> type <type>
*
****************************************************************************/
#ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
static int usage_entry(FAR const char *mountpoint, FAR struct statfs *statbuf,
FAR void *arg)
{
FAR struct mount_info_s *info = (FAR struct mount_info_s *)arg;
FAR const char *fstype;
uint32_t size;
uint32_t used;
uint32_t free;
int which;
char sizelabel;
char freelabel;
char usedlabel;
static const char labels[5] = { 'B', 'K', 'M', 'G', 'T' };
DEBUGASSERT(mountpoint != NULL && statbuf != NULL && info != NULL);
/* Have we generated the header yet? */
if (!info->header)
{
mount_sprintf(info, " Filesystem Size Used Available Mounted on\n");
info->header = true;
}
/* Get the file system type */
fstype = fs_gettype(statbuf);
size = statbuf->f_bsize * statbuf->f_blocks;
free = statbuf->f_bsize * statbuf->f_bavail;
used = size - free;
/* Find the label for size */
which = 0;
while (size >= 9999 || ((size & 0x3ff) == 0 && size != 0))
{
which++;
size >>= 10;
}
sizelabel = labels[which];
/* Find the label for free */
which = 0;
while (free >= 9999 || ((free & 0x3ff) == 0 && free != 0))
{
which++;
free >>= 10;
}
freelabel = labels[which];
/* Find the label for used */
which = 0;
while (used >= 9999 || ((used & 0x3ff) == 0 && used != 0))
{
which++;
used >>= 10;
}
usedlabel = labels[which];
/* Generate usage list one line at a time */
mount_sprintf(info, " %-10s %6ld%c %8ld%c %8ld%c %s\n", fstype,
size, sizelabel, used, usedlabel, free, freelabel,
mountpoint);
return (info->totalsize >= info->buflen) ? 1 : 0;
}
#endif
/****************************************************************************
* Name: mount_open
****************************************************************************/
static int mount_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode)
{
FAR struct mount_file_s *procfile;
uint8_t id;
finfo("Open '%s'\n", relpath);
/* PROCFS is read-only. Any attempt to open with any kind of write
* access is not permitted.
*
* REVISIT: Write-able proc files could be quite useful.
*/
if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
{
ferr("ERROR: Only O_RDONLY supported\n");
return -EACCES;
}
/* "fs/mount", "fs/block", and "fs/usage" are the only acceptable values
* for the relpath.
*/
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
if (strcmp(relpath, "fs/mount") == 0)
{
id = FS_MOUNT_FILE;
}
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
else if (strcmp(relpath, "fs/blocks") == 0)
{
id = FS_BLOCKS_FILE;
}
#endif
else if (strcmp(relpath, "fs/usage") == 0)
{
id = FS_USAGE_FILE;
}
else
{
ferr("ERROR: relpath is '%s'\n", relpath);
return -ENOENT;
}
/* Allocate a container to hold the task and node selection */
procfile = (FAR struct mount_file_s *)
kmm_zalloc(sizeof(struct mount_file_s));
if (!procfile)
{
ferr("ERROR: Failed to allocate file container\n");
return -ENOMEM;
}
/* Save the file ID */
procfile->id = id;
/* Save the open-specific state in filep->f_priv */
filep->f_priv = (FAR void *)procfile;
return OK;
}
/****************************************************************************
* Name: mount_close
****************************************************************************/
static int mount_close(FAR struct file *filep)
{
FAR struct mount_file_s *procfile;
/* Recover our private data from the struct file instance */
procfile = (FAR struct mount_file_s *)filep->f_priv;
DEBUGASSERT(procfile);
/* Release the file container structure */
kmm_free(procfile);
filep->f_priv = NULL;
return OK;
}
/****************************************************************************
* Name: mount_read
****************************************************************************/
static ssize_t mount_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct mount_file_s *procfile;
foreach_mountpoint_t handler;
ssize_t ret;
finfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
/* Recover our private data from the struct file instance */
procfile = (FAR struct mount_file_s *)filep->f_priv;
DEBUGASSERT(procfile);
/* Provide the requested data */
struct mount_info_s info;
memset(&info, 0, sizeof(struct mount_info_s));
info.line = procfile->line;
info.buffer = buffer;
info.linelen = MOUNT_LINELEN;
info.buflen = buflen;
info.remaining = buflen;
info.offset = filep->f_pos;
info.header = false;
switch (procfile->id)
{
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
case FS_MOUNT_FILE: /* /proc/fs/mount */
handler = mount_entry;
break;
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
case FS_BLOCKS_FILE: /* /proc/fs/blocks */
handler = blocks_entry;
break;
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
case FS_USAGE_FILE: /* /proc/fs/usage */
handler = usage_entry;
break;
#endif
default:
DEBUGPANIC();
return -EINVAL;
}
/* Generate each entry in the routing table */
(void)foreach_mountpoint(handler, &info);
ret = info.totalsize;
/* Update the file offset */
if (ret > 0)
{
filep->f_pos += ret;
}
return ret;
}
/****************************************************************************
* Name: mount_dup
*
* Description:
* Duplicate open file data in the new file structure.
*
****************************************************************************/
static int mount_dup(FAR const struct file *oldp, FAR struct file *newp)
{
FAR struct mount_file_s *oldfile;
FAR struct mount_file_s *newfile;
finfo("Dup %p->%p\n", oldp, newp);
/* Recover our private data from the old struct file instance */
oldfile = (FAR struct mount_file_s *)oldp->f_priv;
DEBUGASSERT(oldfile);
/* Allocate a new container to hold the task and node selection */
newfile = (FAR struct mount_file_s *)
kmm_malloc(sizeof(struct mount_file_s));
if (!newfile)
{
ferr("ERROR: Failed to allocate file container\n");
return -ENOMEM;
}
/* The copy the file information from the old container to the new */
memcpy(newfile, oldfile, sizeof(struct mount_file_s));
/* Save the new container in the new file structure */
newp->f_priv = (FAR void *)newfile;
return OK;
}
/****************************************************************************
* Name: mount_stat
*
* Description: Return information about a file or directory
*
****************************************************************************/
static int mount_stat(const char *relpath, struct stat *buf)
{
memset(buf, 0, sizeof(struct stat));
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* !CONFIG_FS_PROCFS_EXCLUDE_MOUNT || \
* !CONFIG_FS_PROCFS_EXCLUDE_BLOCKS || \
* !CONFIG_FS_PROCFS_EXCLUDE_USAGE */
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */

105
fs/mount/mount.h Normal file
View File

@ -0,0 +1,105 @@
/****************************************************************************
* fs/mount/mount.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* 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.
*
****************************************************************************/
#ifndef __FS_MOUNT_MOUNT_H
#define __FS_MOUNT_MOUNT_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef CONFIG_DISABLE_MOUNTPOINT
/****************************************************************************
* Public Types
****************************************************************************/
struct statfs; /* Forward reference */
/* Callback used by foreach_mountpoints to traverse all mountpoints in the
* pseudo-file system.
*/
typedef int (*foreach_mountpoint_t)(FAR const char *mountpoint,
FAR struct statfs *statbuf,
FAR void *arg);
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: foreach_mountpoint
*
* Description:
* Visit each mountpoint in the pseudo-file system. The traversal is
* terminated when the callback 'handler' returns a non-zero value, or when
* all of the mountpoints have been visited.
*
* This is just a front end "filter" to foreach_inode() that forwards only
* mountpoint inodes. It is intended to support the mount() command to
* when the mount command is used to enumerate mounts.
*
* NOTE 1: Use with caution... The pseudo-file system is locked throughout
* the traversal.
* NOTE 2: The search algorithm is recursive and could, in principle, use
* an indeterminant amount of stack space. This will not usually be a
* real work issue.
*
****************************************************************************/
int foreach_mountpoint(foreach_mountpoint_t handler, FAR void *arg);
/****************************************************************************
* Name: fs_gettype
*
* Description:
* Given the result of statfs(), return a string representing the type of
* the file system.
*
* Input Parameters:
* statbuf - The result of a previouis statbuf statfs on the file system.
*
* Returned Value:
* A reference to a string representing the type of the file system.
*
****************************************************************************/
FAR const char *fs_gettype(FAR struct statfs *statbuf);
#endif /* CONFIG_DISABLE_MOUNTPOINT */
#endif /* __FS_MOUNT_MOUNT_H */

View File

@ -39,6 +39,30 @@ config FS_PROCFS_EXCLUDE_MODULE
---help---
Causes the module information to be excluded from the procfs system.
config FS_PROCFS_EXCLUDE_BLOCKS
bool "Exclude fs/blocks information"
depends on !DISABLE_MOUNTPOINT
default n
---help---
Causes the fs block usage information to be excluded from the procfs
system.
config FS_PROCFS_EXCLUDE_MOUNT
bool "Exclude fs/mount information"
depends on !DISABLE_MOUNTPOINT
default n
---help---
Causes the mount point information to be excluded from the procfs
system.
config FS_PROCFS_EXCLUDE_USAGE
bool "Exclude fs/usage information"
depends on !DISABLE_MOUNTPOINT
default n
---help---
Causes the fs usage information to be excluded from the procfs
system.
config FS_PROCFS_EXCLUDE_UPTIME
bool "Exclude uptime"
default n

View File

@ -62,6 +62,8 @@
#include <nuttx/fs/dirent.h>
#include <nuttx/lib/regex.h>
#include "mount/mount.h"
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
/****************************************************************************
@ -90,6 +92,7 @@ extern const struct procfs_operations net_procfsoperations;
extern const struct procfs_operations net_procfs_routeoperations;
extern const struct procfs_operations mtd_procfsoperations;
extern const struct procfs_operations part_procfsoperations;
extern const struct procfs_operations mount_procfsoperations;
extern const struct procfs_operations smartfs_procfsoperations;
/* And even worse, this one is specific to the STM32. The solution to
@ -129,6 +132,10 @@ static const struct procfs_entry_s g_procfs_entries[] =
{ "modules", &module_operations, PROCFS_FILE_TYPE },
#endif
{ "fs/blocks", &mount_procfsoperations, PROCFS_FILE_TYPE },
{ "fs/mount", &mount_procfsoperations, PROCFS_FILE_TYPE },
{ "fs/usage", &mount_procfsoperations, PROCFS_FILE_TYPE },
#if defined(CONFIG_FS_SMARTFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
{ "fs/smartfs**", &smartfs_procfsoperations, PROCFS_UNKOWN_TYPE },
#endif

View File

@ -465,17 +465,6 @@ struct streamlist
};
#endif /* CONFIG_NFILE_STREAMS */
/* Callback used by foreach_mountpoints to traverse all mountpoints in the
* pseudo-file system.
*/
#ifndef CONFIG_DISABLE_MOUNTPOINT
struct statfs; /* Forward reference */
typedef int (*foreach_mountpoint_t)(FAR const char *mountpoint,
FAR struct statfs *statbuf,
FAR void *arg);
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@ -500,30 +489,6 @@ extern "C"
void fs_initialize(void);
/****************************************************************************
* Name: foreach_mountpoint
*
* Description:
* Visit each mountpoint in the pseudo-file system. The traversal is
* terminated when the callback 'handler' returns a non-zero value, or when
* all of the mountpoints have been visited.
*
* This is just a front end "filter" to foreach_inode() that forwards only
* mountpoint inodes. It is intended to support the mount() command to
* when the mount command is used to enumerate mounts.
*
* NOTE 1: Use with caution... The pseudo-file system is locked throughout
* the traversal.
* NOTE 2: The search algorithm is recursive and could, in principle, use
* an indeterminant amount of stack space. This will not usually be a
* real work issue.
*
****************************************************************************/
#ifndef CONFIG_DISABLE_MOUNTPOINT
int foreach_mountpoint(foreach_mountpoint_t handler, FAR void *arg);
#endif
/****************************************************************************
* Name: register_driver
*