[07a3253d] | 1 | /* |
---|
| 2 | * IMFS debug support routines |
---|
| 3 | * |
---|
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
| 9 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
[d6b1d73] | 14 | #if HAVE_CONFIG_H |
---|
| 15 | #include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
[07a3253d] | 18 | #include <assert.h> |
---|
| 19 | #include <string.h> |
---|
| 20 | #include <fcntl.h> |
---|
| 21 | #include <errno.h> |
---|
| 22 | #include <stdlib.h> |
---|
| 23 | #include <unistd.h> /* for close */ |
---|
| 24 | |
---|
| 25 | #include <stdio.h> |
---|
| 26 | #include <sys/stat.h> |
---|
| 27 | |
---|
| 28 | #include "imfs.h" |
---|
[c058578] | 29 | #include <rtems/libio_.h> |
---|
[07a3253d] | 30 | |
---|
| 31 | /* |
---|
| 32 | * IMFS_types |
---|
| 33 | * |
---|
| 34 | * Printable names for each of the IMFS file system types. |
---|
| 35 | */ |
---|
| 36 | |
---|
| 37 | char *IMFS_types[ IMFS_NUMBER_OF_TYPES ] = { |
---|
| 38 | "directory", |
---|
| 39 | "device", |
---|
| 40 | "link", |
---|
[0ef748fb] | 41 | "memory file", |
---|
| 42 | "linear file" |
---|
[07a3253d] | 43 | }; |
---|
| 44 | |
---|
| 45 | /* |
---|
| 46 | * IMFS_print_jnode |
---|
| 47 | * |
---|
| 48 | * This routine prints the contents of the specified jnode. |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | void IMFS_print_jnode( |
---|
| 52 | IMFS_jnode_t *the_jnode |
---|
| 53 | ) |
---|
| 54 | { |
---|
| 55 | assert( the_jnode ); |
---|
| 56 | |
---|
| 57 | printf( "%s", the_jnode->name ); |
---|
| 58 | switch( the_jnode->type ) { |
---|
| 59 | case IMFS_DIRECTORY: |
---|
| 60 | printf( "/" ); |
---|
| 61 | break; |
---|
| 62 | |
---|
| 63 | case IMFS_DEVICE: |
---|
| 64 | printf( " (device %d, %d)", |
---|
| 65 | the_jnode->info.device.major, the_jnode->info.device.minor ); |
---|
| 66 | break; |
---|
| 67 | |
---|
[0ef748fb] | 68 | case IMFS_LINEAR_FILE: |
---|
| 69 | printf( " (file %d %p)", |
---|
| 70 | (int)the_jnode->info.linearfile.size, |
---|
| 71 | the_jnode->info.linearfile.direct |
---|
| 72 | ); |
---|
| 73 | break; |
---|
| 74 | |
---|
[07a3253d] | 75 | case IMFS_MEMORY_FILE: |
---|
| 76 | printf( " (file %d %p %p %p)", |
---|
| 77 | (int)the_jnode->info.file.size, |
---|
| 78 | the_jnode->info.file.indirect, |
---|
| 79 | the_jnode->info.file.doubly_indirect, |
---|
| 80 | the_jnode->info.file.triply_indirect |
---|
| 81 | ); |
---|
| 82 | break; |
---|
| 83 | |
---|
| 84 | case IMFS_HARD_LINK: |
---|
| 85 | printf( " links not printed\n" ); |
---|
| 86 | assert(0); |
---|
| 87 | break; |
---|
| 88 | |
---|
| 89 | case IMFS_SYM_LINK: |
---|
| 90 | printf( " links not printed\n" ); |
---|
| 91 | assert(0); |
---|
| 92 | break; |
---|
| 93 | |
---|
| 94 | default: |
---|
| 95 | printf( " bad type %d\n", the_jnode->type ); |
---|
| 96 | assert(0); |
---|
| 97 | break; |
---|
| 98 | } |
---|
| 99 | puts(""); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /* |
---|
| 103 | * IMFS_dump_directory |
---|
| 104 | * |
---|
| 105 | * This routine prints the contents of a directory in the IMFS. If a |
---|
| 106 | * directory is encountered, then this routine will recurse to process |
---|
| 107 | * the subdirectory. |
---|
| 108 | */ |
---|
| 109 | |
---|
| 110 | void IMFS_dump_directory( |
---|
| 111 | IMFS_jnode_t *the_directory, |
---|
| 112 | int level |
---|
| 113 | ) |
---|
| 114 | { |
---|
| 115 | Chain_Node *the_node; |
---|
| 116 | Chain_Control *the_chain; |
---|
| 117 | IMFS_jnode_t *the_jnode; |
---|
| 118 | int i; |
---|
| 119 | |
---|
| 120 | assert( the_directory ); |
---|
| 121 | |
---|
| 122 | assert( level >= 0 ); |
---|
| 123 | |
---|
| 124 | assert( the_directory->type == IMFS_DIRECTORY ); |
---|
| 125 | |
---|
| 126 | the_chain = &the_directory->info.directory.Entries; |
---|
| 127 | |
---|
| 128 | for ( the_node = the_chain->first; |
---|
| 129 | !_Chain_Is_tail( the_chain, the_node ); |
---|
| 130 | the_node = the_node->next ) { |
---|
| 131 | |
---|
| 132 | the_jnode = (IMFS_jnode_t *) the_node; |
---|
| 133 | |
---|
| 134 | for ( i=0 ; i<=level ; i++ ) |
---|
[c774a07e] | 135 | printf( "...." ); |
---|
[07a3253d] | 136 | IMFS_print_jnode( the_jnode ); |
---|
| 137 | if ( the_jnode->type == IMFS_DIRECTORY ) |
---|
| 138 | IMFS_dump_directory( the_jnode, level + 1 ); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | * IMFS_dump |
---|
| 144 | * |
---|
| 145 | * This routine dumps the entire IMFS that is mounted at the root |
---|
| 146 | * directory. |
---|
| 147 | * |
---|
| 148 | * NOTE: Assuming the "/" directory is bad. |
---|
| 149 | * Not checking that the starting directory is in an IMFS is bad. |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | void IMFS_dump( void ) |
---|
| 153 | { |
---|
| 154 | printf( "*************** Dump of Entire IMFS ***************\n" ); |
---|
| 155 | printf( "/\n" ); |
---|
| 156 | IMFS_dump_directory( rtems_filesystem_root.node_access, 0 ); |
---|
| 157 | printf( "*************** End of Dump ***************\n" ); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /* |
---|
| 161 | * IMFS_memfile_maximum_size() |
---|
| 162 | * |
---|
| 163 | * This routine returns the size of the largest file which can be created |
---|
| 164 | * using the IMFS memory file type. |
---|
| 165 | * |
---|
| 166 | */ |
---|
| 167 | |
---|
| 168 | int IMFS_memfile_maximum_size( void ) |
---|
| 169 | { |
---|
| 170 | return IMFS_MEMFILE_MAXIMUM_SIZE; |
---|
| 171 | } |
---|