summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/imfs/imfs_debug.c
blob: 9f56466697c83e4cc110fa531f7ad39354af6eb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
 * @file
 *
 * @brief IMFS Debug Support
 * @ingroup IMFS
 */

/*
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#if HAVE_CONFIG_H
  #include "config.h"
#endif

#include "imfs.h"

#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>

/*
 *  IMFS_print_jnode
 *
 *  This routine prints the contents of the specified jnode.
 */
static void IMFS_print_jnode(
  IMFS_jnode_t *the_jnode
)
{
  IMFS_assert( the_jnode );

  fprintf(stdout, "%s", the_jnode->name );
  switch( IMFS_type( the_jnode ) ) {
    case IMFS_DIRECTORY:
      fprintf(stdout, "/" );
      break;

    case IMFS_DEVICE:
      fprintf(stdout, " (device %" PRId32 ", %" PRId32 ")",
        the_jnode->info.device.major, the_jnode->info.device.minor );
      break;

    case IMFS_LINEAR_FILE:
      fprintf(stdout, " (file %" PRId32 " %p)",
        (uint32_t)the_jnode->info.linearfile.size,
        the_jnode->info.linearfile.direct
      );
      break;

    case IMFS_MEMORY_FILE:
      /* Useful when debugging .. varies between targets  */
#if 0
      fprintf(stdout, " (file %" PRId32 " %p %p %p)",
        (uint32_t)the_jnode->info.file.size,
        the_jnode->info.file.indirect,
        the_jnode->info.file.doubly_indirect,
        the_jnode->info.file.triply_indirect
      );
#else
      fprintf(stdout, " (file %" PRId32 ")",
        (uint32_t)the_jnode->info.file.size );
#endif
      break;

    case IMFS_HARD_LINK:
      fprintf(stdout, " links not printed\n" );
      return;

    case IMFS_SYM_LINK:
      fprintf(stdout, " links not printed\n" );
      return;

    case IMFS_FIFO:
      fprintf(stdout, " FIFO not printed\n" );
      return;

    default:
      fprintf(stdout, " bad type %d\n", IMFS_type( the_jnode ) );
      return;
  }
  puts("");
}

/*
 *  IMFS_dump_directory
 *
 *  This routine prints the contents of a directory in the IMFS.  If a
 *  directory is encountered, then this routine will recurse to process
 *  the subdirectory.
 */
static void IMFS_dump_directory(
  IMFS_jnode_t  *the_directory,
  int            level
)
{
  rtems_chain_node     *the_node;
  rtems_chain_control  *the_chain;
  IMFS_jnode_t         *the_jnode;
  int                   i;

  IMFS_assert( the_directory );
  IMFS_assert( level >= 0 );
  IMFS_assert( IMFS_is_directory( the_directory ) );

  the_chain = &the_directory->info.directory.Entries;

  for ( the_node = rtems_chain_first( the_chain );
        !rtems_chain_is_tail( the_chain, the_node );
        the_node = the_node->next ) {

    the_jnode = (IMFS_jnode_t *) the_node;

    for ( i=0 ; i<=level ; i++ )
      fprintf(stdout, "...." );
    IMFS_print_jnode( the_jnode );
    if ( IMFS_is_directory( the_jnode ) )
      IMFS_dump_directory( the_jnode, level + 1 );
  }
}

void IMFS_dump( void )
{
  fprintf(stdout, "*************** Dump of Entire IMFS ***************\n" );
  fprintf(stdout, "/\n" );
  IMFS_dump_directory( rtems_filesystem_root->location.node_access, 0 );
  fprintf(stdout, "***************      End of Dump       ***************\n" );
}

int IMFS_memfile_maximum_size( void )
{
  return IMFS_MEMFILE_MAXIMUM_SIZE;
}