1 | /* |
---|
2 | * Copyright (c) 2012-2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <stdio.h> |
---|
20 | #include <inttypes.h> |
---|
21 | |
---|
22 | #include <rtems/libio_.h> |
---|
23 | #include <rtems/shell.h> |
---|
24 | #include <rtems/shellconfig.h> |
---|
25 | |
---|
26 | static void print_location( const rtems_filesystem_location_info_t *loc ) |
---|
27 | { |
---|
28 | fprintf( |
---|
29 | stdout, |
---|
30 | "\tloc = 0x%08" PRIxPTR "\n\t\tnode_access = 0x%08" PRIxPTR |
---|
31 | ", node_access_2 = 0x%08" PRIxPTR ", handler = 0x%08" PRIxPTR "\n", |
---|
32 | (uintptr_t) loc, |
---|
33 | (uintptr_t) loc->node_access, |
---|
34 | (uintptr_t) loc->node_access_2, |
---|
35 | (uintptr_t) loc->handlers |
---|
36 | ); |
---|
37 | } |
---|
38 | |
---|
39 | static void print_mt_entry_locations( |
---|
40 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
41 | ) |
---|
42 | { |
---|
43 | const rtems_chain_control *mt_entry_chain = &mt_entry->location_chain; |
---|
44 | const rtems_chain_node *mt_entry_node; |
---|
45 | |
---|
46 | for ( |
---|
47 | mt_entry_node = rtems_chain_immutable_first( mt_entry_chain ); |
---|
48 | !rtems_chain_is_tail( mt_entry_chain, mt_entry_node ); |
---|
49 | mt_entry_node = rtems_chain_immutable_next( mt_entry_node ) |
---|
50 | ) { |
---|
51 | const rtems_filesystem_location_info_t *loc = |
---|
52 | (const rtems_filesystem_location_info_t *) mt_entry_node; |
---|
53 | |
---|
54 | print_location( loc ); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | static void lsof(void) |
---|
59 | { |
---|
60 | const rtems_chain_control *mt_chain = &rtems_filesystem_mount_table; |
---|
61 | const rtems_chain_node *mt_node; |
---|
62 | |
---|
63 | fprintf( |
---|
64 | stdout, |
---|
65 | "type = null, root loc = 0x%08" PRIxPTR "\n", |
---|
66 | (uintptr_t) rtems_filesystem_null_mt_entry.mt_fs_root |
---|
67 | ); |
---|
68 | |
---|
69 | print_mt_entry_locations( &rtems_filesystem_null_mt_entry ); |
---|
70 | |
---|
71 | for ( |
---|
72 | mt_node = rtems_chain_immutable_first( mt_chain ); |
---|
73 | !rtems_chain_is_tail( mt_chain, mt_node ); |
---|
74 | mt_node = rtems_chain_immutable_next( mt_node ) |
---|
75 | ) { |
---|
76 | rtems_filesystem_mount_table_entry_t *mt_entry = |
---|
77 | (rtems_filesystem_mount_table_entry_t *) mt_node; |
---|
78 | |
---|
79 | fprintf( |
---|
80 | stdout, |
---|
81 | "type = %s, %s, %s, target = %s, dev = %s, root loc = 0x%08" PRIxPTR "\n", |
---|
82 | mt_entry->type, |
---|
83 | mt_entry->mounted ? "mounted" : "unmounted", |
---|
84 | mt_entry->writeable ? "read-write" : "read-only", |
---|
85 | mt_entry->target, |
---|
86 | mt_entry->dev == NULL ? "NULL" : mt_entry->dev, |
---|
87 | (uintptr_t) mt_entry->mt_fs_root |
---|
88 | ); |
---|
89 | |
---|
90 | print_mt_entry_locations( mt_entry ); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | static int rtems_shell_main_lsof(int argc, char **argv) |
---|
95 | { |
---|
96 | lsof(); |
---|
97 | |
---|
98 | return 0; |
---|
99 | } |
---|
100 | |
---|
101 | rtems_shell_cmd_t rtems_shell_LSOF_Command = { |
---|
102 | .name = "lsof", |
---|
103 | .usage = "lsof", |
---|
104 | .topic = "files", |
---|
105 | .command = rtems_shell_main_lsof |
---|
106 | }; |
---|