summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-16 15:41:27 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-16 15:41:27 +0000
commitd904fafdf2f9f7ad686bd9d8b616aa310f5346eb (patch)
tree1a3a8a64fbe541877bc7ed69bc5757d6660e3172 /apps
parentf06a61ad2416526b0f9afddc0b42fb5c928b7093 (diff)
downloadpx4-nuttx-d904fafdf2f9f7ad686bd9d8b616aa310f5346eb.tar.gz
px4-nuttx-d904fafdf2f9f7ad686bd9d8b616aa310f5346eb.tar.bz2
px4-nuttx-d904fafdf2f9f7ad686bd9d8b616aa310f5346eb.zip
apps/builtin/binfs.c moved to nuttx/fs/binfs/fs_binfs.c
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5523 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rw-r--r--apps/ChangeLog.txt2
-rw-r--r--apps/builtin/Kconfig14
-rw-r--r--apps/builtin/Makefile4
-rw-r--r--apps/builtin/binfs.c448
-rw-r--r--apps/builtin/builtin.c2
-rw-r--r--apps/builtin/builtin.h77
-rw-r--r--apps/builtin/exec_builtin.c3
-rw-r--r--apps/include/apps.h17
-rw-r--r--apps/nshlib/nsh_mntcmds.c2
9 files changed, 6 insertions, 563 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index f91dc318b..5bc3b2149 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -473,3 +473,5 @@
very lightweight). Now supports open, close, and a new ioctl to recover
the builtin filename. The latter will be needed to support a binfs
binfmt.
+ * builtin/binfs.c: Move apps/builtin/binfs.c to fs/binfs/fs_binfs.c
+ CONFIG_APPS_BINDIR rename CONFIG_FS_BINFS
diff --git a/apps/builtin/Kconfig b/apps/builtin/Kconfig
index 1049712aa..37150e8a9 100644
--- a/apps/builtin/Kconfig
+++ b/apps/builtin/Kconfig
@@ -13,20 +13,6 @@ config BUILTIN
if BUILTIN
- config APPS_BINDIR
- bool "BINFS File System"
- default n
- ---help---
- The BINFS file system is current just a toy. The BINFS may, for example,
- be mount at /bin. Then all of the built-in applications will appear as
- executable file in /bin if you list them from NSH like:
-
- nsh> ls -l /bin
-
- At present, the BINFS supports nothing more than that. It is planned,
- however, to support execution of the builtin applications from BINFS as
- well (via a binfmt/ loader). However, that is down the road.
-
config BUILTIN_PROXY_STACKSIZE
int "Builtin Proxy Stack Size"
default 1024
diff --git a/apps/builtin/Makefile b/apps/builtin/Makefile
index 8c8928886..d77054f41 100644
--- a/apps/builtin/Makefile
+++ b/apps/builtin/Makefile
@@ -41,10 +41,6 @@ include $(APPDIR)/Make.defs
ASRCS =
CSRCS = builtin.c exec_builtin.c
-ifeq ($(CONFIG_APPS_BINDIR),y)
-CSRCS += binfs.c
-endif
-
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
diff --git a/apps/builtin/binfs.c b/apps/builtin/binfs.c
deleted file mode 100644
index 611e2b3bb..000000000
--- a/apps/builtin/binfs.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/****************************************************************************
- * apps/builtin/binfs.c
- *
- * Copyright (C) 2011-2013 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 <string.h>
-#include <fcntl.h>
-#include <assert.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/fs/fs.h>
-#include <nuttx/fs/binfs.h>
-#include <nuttx/fs/dirent.h>
-
-#include <apps/apps.h>
-
-#include "builtin.h"
-
-#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_APPS_BINDIR)
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int binfs_open(FAR struct file *filep, const char *relpath,
- int oflags, mode_t mode);
-static int binfs_close(FAR struct file *filep);
-static ssize_t binfs_read(FAR struct file *filep, char *buffer, size_t buflen);
-static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
-
-static int binfs_dup(FAR const struct file *oldp, FAR struct file *newp);
-
-static int binfs_opendir(struct inode *mountpt, const char *relpath,
- struct fs_dirent_s *dir);
-static int binfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
-static int binfs_rewinddir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
-
-static int binfs_bind(FAR struct inode *blkdriver, FAR const void *data,
- FAR void **handle);
-static int binfs_unbind(FAR void *handle, FAR struct inode **blkdriver);
-static int binfs_statfs(FAR struct inode *mountpt,
- FAR struct statfs *buf);
-
-static int binfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
- FAR struct stat *buf);
-
-/****************************************************************************
- * Private Variables
- ****************************************************************************/
-
-/****************************************************************************
- * Public Variables
- ****************************************************************************/
-
-/* 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 mountpt_operations binfs_operations =
-{
- binfs_open, /* open */
- binfs_close, /* close */
- binfs_read, /* read */
- NULL, /* write */
- NULL, /* seek */
- binfs_ioctl, /* ioctl */
-
- NULL, /* sync */
- binfs_dup, /* dup */
-
- binfs_opendir, /* opendir */
- NULL, /* closedir */
- binfs_readdir, /* readdir */
- binfs_rewinddir, /* rewinddir */
-
- binfs_bind, /* bind */
- binfs_unbind, /* unbind */
- binfs_statfs, /* statfs */
-
- NULL, /* unlink */
- NULL, /* mkdir */
- NULL, /* rmdir */
- NULL, /* rename */
- binfs_stat /* stat */
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: binfs_open
- ****************************************************************************/
-
-static int binfs_open(FAR struct file *filep, FAR const char *relpath,
- int oflags, mode_t mode)
-{
- int index;
-
- fvdbg("Open '%s'\n", relpath);
-
- /* BINFS is read-only. Any attempt to open with any kind of write
- * access is not permitted.
- */
-
- if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
- {
- fdbg("ERROR: Only O_RDONLY supported\n");
- return -EACCES;
- }
-
- /* Check if the an entry exists with this name in the root directory.
- * so the 'relpath' must be the name of the builtin function.
- */
-
- index = builtin_isavail(relpath);
- if (index < 0)
- {
- fdbg("ERROR: Builting %s does not exist\n", relpath);
- return -ENOENT;
- }
-
- /* Save the index as the open-specific state in filep->f_priv */
-
- filep->f_priv = (FAR void *)index;
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_close
- ****************************************************************************/
-
-static int binfs_close(FAR struct file *filep)
-{
- fvdbg("Closing\n");
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_read
- ****************************************************************************/
-
-static ssize_t binfs_read(FAR struct file *filep, char *buffer, size_t buflen)
-{
- /* Reading is not supported. Just return end-of-file */
-
- fvdbg("Read %d bytes from offset %d\n", buflen, filep->f_pos);
- return 0;
-}
-
-/****************************************************************************
- * Name: binfs_ioctl
- ****************************************************************************/
-
-static int binfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
-{
- int ret;
-
- fvdbg("cmd: %d arg: %08lx\n", cmd, arg);
-
- /* Only one IOCTL command is supported */
-
- if (cmd == FIOC_FILENAME)
- {
- /* IN: FAR char const ** pointer
- * OUT: Pointer to a persistent file name (Guaranteed to persist while
- * the file is open).
- */
-
- FAR const char **ptr = (FAR const char **)((uintptr_t)arg);
- if (ptr == NULL)
- {
- ret = -EINVAL;
- }
- else
- {
- *ptr = g_builtins[(int)filep->f_priv].name;
- ret = OK;
- }
- }
- else
- {
- ret = -ENOTTY;
- }
-
- return ret;
-}
-
-/****************************************************************************
- * Name: binfs_dup
- *
- * Description:
- * Duplicate open file data in the new file structure.
- *
- ****************************************************************************/
-
-static int binfs_dup(FAR const struct file *oldp, FAR struct file *newp)
-{
- fvdbg("Dup %p->%p\n", oldp, newp);
-
- /* Copy the index from the old to the new file structure */
-
- newp->f_priv = oldp->f_priv;
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_opendir
- *
- * Description:
- * Open a directory for read access
- *
- ****************************************************************************/
-
-static int binfs_opendir(struct inode *mountpt, const char *relpath,
- struct fs_dirent_s *dir)
-{
- fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL");
-
- /* The requested directory must be the volume-relative "root" directory */
-
- if (relpath && relpath[0] != '\0')
- {
- return -ENOENT;
- }
-
- /* Set the index to the first entry */
-
- dir->u.binfs.fb_index = 0;
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_readdir
- *
- * Description: Read the next directory entry
- *
- ****************************************************************************/
-
-static int binfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
-{
- unsigned int index;
- int ret;
-
- /* Have we reached the end of the directory */
-
- index = dir->u.binfs.fb_index;
- if (g_builtins[index].name == NULL)
- {
- /* We signal the end of the directory by returning the
- * special error -ENOENT
- */
-
- fvdbg("Entry %d: End of directory\n", index);
- ret = -ENOENT;
- }
- else
- {
- /* Save the filename and file type */
-
- fvdbg("Entry %d: \"%s\"\n", index, g_builtins[index].name);
- dir->fd_dir.d_type = DTYPE_FILE;
- strncpy(dir->fd_dir.d_name, g_builtins[index].name, NAME_MAX+1);
-
- /* The application list is terminated by an entry with a NULL name.
- * Therefore, there is at least one more entry in the list.
- */
-
- index++;
-
- /* Set up the next directory entry offset. NOTE that we could use the
- * standard f_pos instead of our own private fb_index.
- */
-
- dir->u.binfs.fb_index = index;
- ret = OK;
- }
-
- return ret;
-}
-
-/****************************************************************************
- * Name: binfs_rewindir
- *
- * Description: Reset directory read to the first entry
- *
- ****************************************************************************/
-
-static int binfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
-{
- fvdbg("Entry\n");
-
- dir->u.binfs.fb_index = 0;
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_bind
- *
- * Description: This implements a portion of the mount operation. This
- * function allocates and initializes the mountpoint private data and
- * binds the blockdriver inode to the filesystem private data. The final
- * binding of the private data (containing the blockdriver) to the
- * mountpoint is performed by mount().
- *
- ****************************************************************************/
-
-static int binfs_bind(FAR struct inode *blkdriver, const void *data,
- void **handle)
-{
- fvdbg("Entry\n");
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_unbind
- *
- * Description: This implements the filesystem portion of the umount
- * operation.
- *
- ****************************************************************************/
-
-static int binfs_unbind(void *handle, FAR struct inode **blkdriver)
-{
- fvdbg("Entry\n");
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_statfs
- *
- * Description: Return filesystem statistics
- *
- ****************************************************************************/
-
-static int binfs_statfs(struct inode *mountpt, struct statfs *buf)
-{
- fvdbg("Entry\n");
-
- /* Fill in the statfs info */
-
- memset(buf, 0, sizeof(struct statfs));
- buf->f_type = BINFS_MAGIC;
- buf->f_bsize = 0;
- buf->f_blocks = 0;
- buf->f_bfree = 0;
- buf->f_bavail = 0;
- buf->f_namelen = NAME_MAX;
- return OK;
-}
-
-/****************************************************************************
- * Name: binfs_stat
- *
- * Description: Return information about a file or directory
- *
- ****************************************************************************/
-
-static int binfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf)
-{
- fvdbg("Entry\n");
-
- /* The requested directory must be the volume-relative "root" directory */
-
- if (relpath && relpath[0] != '\0')
- {
- /* Check if there is a file with this name. */
-
- if (builtin_isavail(relpath) < 0)
- {
- return -ENOENT;
- }
-
- /* It's a execute-only file name */
-
- buf->st_mode = S_IFREG|S_IXOTH|S_IXGRP|S_IXUSR;
- }
- else
- {
- /* It's a read/execute-only directory name */
-
- buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR|S_IXOTH|S_IXGRP|S_IXUSR;
- }
-
- /* File/directory size, access block size */
-
- buf->st_size = 0;
- buf->st_blksize = 0;
- buf->st_blocks = 0;
- return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_APPS_BINDIR */
-
diff --git a/apps/builtin/builtin.c b/apps/builtin/builtin.c
index e0ae9888a..90c0b1353 100644
--- a/apps/builtin/builtin.c
+++ b/apps/builtin/builtin.c
@@ -40,6 +40,8 @@
****************************************************************************/
#include <nuttx/config.h>
+
+#include <nuttx/binfmt/builtin.h>
#include <apps/apps.h>
/****************************************************************************
diff --git a/apps/builtin/builtin.h b/apps/builtin/builtin.h
deleted file mode 100644
index 4593809ee..000000000
--- a/apps/builtin/builtin.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
- * apps/builtin/builtin.h
- *
- * Copyright (C) 2011 Uros Platise. All rights reserved.
- * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
- * Authors: Uros Platise <uros.platise@isotel.eu>
- * 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 __APPS_BUILTIN_BUILTIN_H
-#define __APPS_BUILTIN_BUILTIN_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <apps/apps.h>
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
-#endif
-
-EXTERN const struct builtin_s g_builtins[];
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-EXTERN int number_builtins(void);
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __APPS_BUILTIN_BUILTIN_H */
-
diff --git a/apps/builtin/exec_builtin.c b/apps/builtin/exec_builtin.c
index a3e79a945..6868d7ee7 100644
--- a/apps/builtin/exec_builtin.c
+++ b/apps/builtin/exec_builtin.c
@@ -53,10 +53,9 @@
#include <errno.h>
#include <debug.h>
+#include <nuttx/binfmt/builtin.h>
#include <apps/apps.h>
-#include "builtin.h"
-
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
diff --git a/apps/include/apps.h b/apps/include/apps.h
index 9f1918e57..0fb807c14 100644
--- a/apps/include/apps.h
+++ b/apps/include/apps.h
@@ -62,14 +62,6 @@
* Public Types
****************************************************************************/
-struct builtin_s
-{
- const char *name; /* Invocation name and as seen under /sbin/ */
- int priority; /* Use: SCHED_PRIORITY_DEFAULT */
- int stacksize; /* Desired stack size */
- main_t main; /* Entry point: main(int argc, char *argv[]) */
-};
-
/****************************************************************************
* Public Data
****************************************************************************/
@@ -82,15 +74,6 @@ extern "C" {
#define EXTERN extern
#endif
-/* The "bindir" is file system that supports access to the builtin applications.
- * It is typically mounted under /bin.
- */
-
-#ifdef CONFIG_APPS_BINDIR
-EXTERN mountpt_operations;
-EXTERN const struct mountpt_operations binfs_operations;
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c
index f6eb26c31..b16ba8465 100644
--- a/apps/nshlib/nsh_mntcmds.c
+++ b/apps/nshlib/nsh_mntcmds.c
@@ -131,7 +131,7 @@ static int mount_handler(FAR const char *mountpoint,
break;
#endif
-#ifdef CONFIG_APPS_BINDIR
+#ifdef CONFIG_FS_BINFS
case BINFS_MAGIC:
fstype = "bindir";
break;