summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libmisc')
-rw-r--r--cpukit/libmisc/Makefile.am1
-rw-r--r--cpukit/libmisc/shell/main_lsof.c78
-rw-r--r--cpukit/libmisc/shell/shellconfig.h6
3 files changed, 85 insertions, 0 deletions
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index e468dd13a0..654c0505aa 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -103,6 +103,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \
shell/main_time.c shell/main_mknod.c \
shell/main_setenv.c shell/main_getenv.c shell/main_unsetenv.c \
shell/main_mkrfs.c shell/main_debugrfs.c \
+ shell/main_lsof.c \
shell/shell-wait-for-input.c
if LIBNETWORKING
diff --git a/cpukit/libmisc/shell/main_lsof.c b/cpukit/libmisc/shell/main_lsof.c
new file mode 100644
index 0000000000..993d107da8
--- /dev/null
+++ b/cpukit/libmisc/shell/main_lsof.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2012 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * 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.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/libio_.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+
+static void lsof(void)
+{
+ rtems_chain_control *mt_chain = &rtems_filesystem_mount_table;
+ rtems_chain_node *mt_node = NULL;
+
+ for (
+ mt_node = rtems_chain_first( mt_chain );
+ !rtems_chain_is_tail( mt_chain, mt_node );
+ mt_node = rtems_chain_next( mt_node )
+ ) {
+ rtems_filesystem_mount_table_entry_t *mt_entry =
+ (rtems_filesystem_mount_table_entry_t *) mt_node;
+ rtems_chain_control *mt_entry_chain = &mt_entry->location_chain;
+ rtems_chain_node *mt_entry_node = NULL;
+
+ printk(
+ "%c %c %s %s -> %s root 0x%08x -> 0x%08x\n",
+ mt_entry->mounted ? 'M' : 'U',
+ mt_entry->writeable ? 'W' : 'R',
+ mt_entry->type,
+ mt_entry->target,
+ mt_entry->dev,
+ mt_entry->mt_fs_root,
+ mt_entry->mt_fs_root->location.node_access
+ );
+
+ for (
+ mt_entry_node = rtems_chain_first( mt_entry_chain );
+ !rtems_chain_is_tail( mt_entry_chain, mt_entry_node );
+ mt_entry_node = rtems_chain_next( mt_entry_node )
+ ) {
+ const rtems_filesystem_location_info_t *loc =
+ (rtems_filesystem_location_info_t *) mt_entry_node;
+
+ printk(
+ "\t0x%08x -> 0x%08x\n",
+ loc,
+ loc->node_access
+ );
+ }
+ }
+}
+
+static int rtems_shell_main_lsof(int argc, char **argv)
+{
+ lsof();
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_LSOF_Command = {
+ .name = "lsof",
+ .usage = "lsof",
+ .topic = "files",
+ .command = rtems_shell_main_lsof
+};
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
index 971df25b22..85fb3d0a6d 100644
--- a/cpukit/libmisc/shell/shellconfig.h
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -61,6 +61,7 @@ extern rtems_shell_cmd_t rtems_shell_RM_Command;
extern rtems_shell_cmd_t rtems_shell_LN_Command;
extern rtems_shell_cmd_t rtems_shell_MKNOD_Command;
extern rtems_shell_cmd_t rtems_shell_UMASK_Command;
+extern rtems_shell_cmd_t rtems_shell_LSOF_Command;
extern rtems_shell_cmd_t rtems_shell_MOUNT_Command;
extern rtems_shell_cmd_t rtems_shell_UNMOUNT_Command;
extern rtems_shell_cmd_t rtems_shell_BLKSYNC_Command;
@@ -329,6 +330,11 @@ extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
&rtems_shell_UMASK_Command,
#endif
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_LSOF)) || \
+ defined(CONFIGURE_SHELL_COMMAND_LSOF)
+ &rtems_shell_LSOF_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
!defined(CONFIGURE_SHELL_NO_COMMAND_MOUNT)) || \
defined(CONFIGURE_SHELL_COMMAND_MOUNT)
&rtems_shell_MOUNT_Command,