[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: |
---|
[53462762] | 76 | /* Useful when debugging .. varies between targets */ |
---|
| 77 | #if 0 |
---|
[07a3253d] | 78 | printf( " (file %d %p %p %p)", |
---|
| 79 | (int)the_jnode->info.file.size, |
---|
| 80 | the_jnode->info.file.indirect, |
---|
| 81 | the_jnode->info.file.doubly_indirect, |
---|
| 82 | the_jnode->info.file.triply_indirect |
---|
| 83 | ); |
---|
[53462762] | 84 | #else |
---|
| 85 | printf( " (file %d)", (int)the_jnode->info.file.size ); |
---|
| 86 | #endif |
---|
[07a3253d] | 87 | break; |
---|
| 88 | |
---|
| 89 | case IMFS_HARD_LINK: |
---|
| 90 | printf( " links not printed\n" ); |
---|
| 91 | assert(0); |
---|
| 92 | break; |
---|
| 93 | |
---|
| 94 | case IMFS_SYM_LINK: |
---|
| 95 | printf( " links not printed\n" ); |
---|
| 96 | assert(0); |
---|
| 97 | break; |
---|
| 98 | |
---|
| 99 | default: |
---|
| 100 | printf( " bad type %d\n", the_jnode->type ); |
---|
| 101 | assert(0); |
---|
| 102 | break; |
---|
| 103 | } |
---|
| 104 | puts(""); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * IMFS_dump_directory |
---|
| 109 | * |
---|
| 110 | * This routine prints the contents of a directory in the IMFS. If a |
---|
| 111 | * directory is encountered, then this routine will recurse to process |
---|
| 112 | * the subdirectory. |
---|
| 113 | */ |
---|
| 114 | |
---|
| 115 | void IMFS_dump_directory( |
---|
| 116 | IMFS_jnode_t *the_directory, |
---|
| 117 | int level |
---|
| 118 | ) |
---|
| 119 | { |
---|
| 120 | Chain_Node *the_node; |
---|
| 121 | Chain_Control *the_chain; |
---|
| 122 | IMFS_jnode_t *the_jnode; |
---|
| 123 | int i; |
---|
| 124 | |
---|
| 125 | assert( the_directory ); |
---|
| 126 | |
---|
| 127 | assert( level >= 0 ); |
---|
| 128 | |
---|
| 129 | assert( the_directory->type == IMFS_DIRECTORY ); |
---|
| 130 | |
---|
| 131 | the_chain = &the_directory->info.directory.Entries; |
---|
| 132 | |
---|
| 133 | for ( the_node = the_chain->first; |
---|
| 134 | !_Chain_Is_tail( the_chain, the_node ); |
---|
| 135 | the_node = the_node->next ) { |
---|
| 136 | |
---|
| 137 | the_jnode = (IMFS_jnode_t *) the_node; |
---|
| 138 | |
---|
| 139 | for ( i=0 ; i<=level ; i++ ) |
---|
[c774a07e] | 140 | printf( "...." ); |
---|
[07a3253d] | 141 | IMFS_print_jnode( the_jnode ); |
---|
| 142 | if ( the_jnode->type == IMFS_DIRECTORY ) |
---|
| 143 | IMFS_dump_directory( the_jnode, level + 1 ); |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | /* |
---|
| 148 | * IMFS_dump |
---|
| 149 | * |
---|
| 150 | * This routine dumps the entire IMFS that is mounted at the root |
---|
| 151 | * directory. |
---|
| 152 | * |
---|
| 153 | * NOTE: Assuming the "/" directory is bad. |
---|
| 154 | * Not checking that the starting directory is in an IMFS is bad. |
---|
| 155 | */ |
---|
| 156 | |
---|
| 157 | void IMFS_dump( void ) |
---|
| 158 | { |
---|
| 159 | printf( "*************** Dump of Entire IMFS ***************\n" ); |
---|
| 160 | printf( "/\n" ); |
---|
| 161 | IMFS_dump_directory( rtems_filesystem_root.node_access, 0 ); |
---|
| 162 | printf( "*************** End of Dump ***************\n" ); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /* |
---|
| 166 | * IMFS_memfile_maximum_size() |
---|
| 167 | * |
---|
| 168 | * This routine returns the size of the largest file which can be created |
---|
| 169 | * using the IMFS memory file type. |
---|
| 170 | * |
---|
| 171 | */ |
---|
| 172 | |
---|
| 173 | int IMFS_memfile_maximum_size( void ) |
---|
| 174 | { |
---|
| 175 | return IMFS_MEMFILE_MAXIMUM_SIZE; |
---|
| 176 | } |
---|