[Ocfs-tools-commits]
smushran commits r143 - in trunk/ocfs2/debugfs.ocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Jul 6 20:36:13 CDT 2004
Author: smushran
Date: 2004-07-06 19:36:10 -0500 (Tue, 06 Jul 2004)
New Revision: 143
Modified:
trunk/ocfs2/debugfs.ocfs2/commands.c
trunk/ocfs2/debugfs.ocfs2/dump.c
trunk/ocfs2/debugfs.ocfs2/include/dump.h
trunk/ocfs2/debugfs.ocfs2/include/journal.h
trunk/ocfs2/debugfs.ocfs2/include/main.h
trunk/ocfs2/debugfs.ocfs2/include/readfs.h
trunk/ocfs2/debugfs.ocfs2/include/utils.h
trunk/ocfs2/debugfs.ocfs2/journal.c
trunk/ocfs2/debugfs.ocfs2/readfs.c
trunk/ocfs2/debugfs.ocfs2/utils.c
Log:
output pageable using PAGER
Modified: trunk/ocfs2/debugfs.ocfs2/commands.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/commands.c 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/commands.c 2004-07-07 00:36:10 UTC (rev 143)
@@ -275,6 +275,7 @@
char *buf = NULL;
GArray *dirarr = NULL;
__u32 len;
+ FILE *out;
if (gbls.dev_fd == -1) {
printf ("device not open\n");
@@ -305,8 +306,10 @@
read_dir (gbls.dev_fd, &(inode->id2.i_list), inode->i_size, dirarr);
- dump_dir_entry (dirarr);
-
+ out = open_pager ();
+ dump_dir_entry (out, dirarr);
+ close_pager (out);
+
bail:
safefree (buf);
@@ -438,19 +441,24 @@
char *opts = args[1];
ocfs2_dinode *in;
ocfs2_super_block *sb;
+ FILE *out;
if (gbls.dev_fd == -1) {
printf ("device not open\n");
goto bail;
}
+ out = open_pager ();
+
in = gbls.superblk;
sb = &(in->id2.i_super);
- dump_super_block(sb);
+ dump_super_block(out, sb);
if (!opts || strncmp(opts, "-h", 2))
- dump_inode(in);
+ dump_inode(out, in);
+ close_pager (out);
+
bail:
return ;
} /* do_super */
@@ -466,6 +474,7 @@
__u32 blknum;
char *buf = NULL;
__u32 buflen;
+ FILE *out;
if (gbls.dev_fd == -1) {
printf ("device not open\n");
@@ -487,13 +496,16 @@
inode = gbls.rootin;
}
- dump_inode(inode);
+ out = open_pager();
+ dump_inode(out, inode);
if ((inode->i_flags & OCFS2_LOCAL_ALLOC_FL))
- dump_local_alloc(&(inode->id2.i_lab));
+ dump_local_alloc(out, &(inode->id2.i_lab));
else
- traverse_extents(gbls.dev_fd, &(inode->id2.i_list), NULL, 1);
+ traverse_extents(gbls.dev_fd, &(inode->id2.i_list), NULL, 1, out);
+ close_pager (out);
+
bail:
safefree (buf);
return ;
@@ -506,13 +518,16 @@
static void do_config (char **args)
{
char *dlmbuf = NULL;
+ FILE *out;
if (gbls.dev_fd == -1)
printf ("device not open\n");
else {
if (read_file (gbls.dev_fd, gbls.dlm_blkno, -1, &dlmbuf) == -1)
goto bail;
- dump_config (dlmbuf);
+ out = open_pager ();
+ dump_config (out, dlmbuf);
+ close_pager (out);
}
bail:
@@ -527,13 +542,16 @@
static void do_publish (char **args)
{
char *dlmbuf = NULL;
+ FILE *out;
if (gbls.dev_fd == -1)
printf ("device not open\n");
else {
if (read_file (gbls.dev_fd, gbls.dlm_blkno, -1, &dlmbuf) == -1)
goto bail;
- dump_publish (dlmbuf);
+ out = open_pager ();
+ dump_publish (out, dlmbuf);
+ close_pager (out);
}
bail:
@@ -548,13 +566,16 @@
static void do_vote (char **args)
{
char *dlmbuf = NULL;
+ FILE *out;
if (gbls.dev_fd == -1)
printf ("device not open\n");
else {
if (read_file (gbls.dev_fd, gbls.dlm_blkno, -1, &dlmbuf) == -1)
goto bail;
- dump_vote (dlmbuf);
+ out = open_pager ();
+ dump_vote (out, dlmbuf);
+ close_pager (out);
}
bail:
@@ -618,6 +639,7 @@
char *logbuf = NULL;
__u64 blknum = 0;
__s32 len = 0;
+ FILE *out;
if (args[1])
blknum = strtoull (args[1], NULL, 0);
@@ -629,7 +651,9 @@
else {
if ((len = read_file (gbls.dev_fd, blknum, -1, &logbuf)) == -1)
goto bail;
- read_journal (logbuf, (__u64)len);
+ out = open_pager ();
+ read_journal (logbuf, (__u64)len, out);
+ close_pager (out);
}
bail:
Modified: trunk/ocfs2/debugfs.ocfs2/dump.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/dump.c 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/dump.c 2004-07-07 00:36:10 UTC (rev 143)
@@ -36,37 +36,37 @@
* dump_super_block()
*
*/
-void dump_super_block(ocfs2_super_block *sb)
+void dump_super_block(FILE *out, ocfs2_super_block *sb)
{
int i;
char *str;
- printf("Revision: %u.%u\n", sb->s_major_rev_level, sb->s_minor_rev_level);
- printf("Mount Count: %u Max Mount Count: %u\n", sb->s_mnt_count,
+ fprintf(out, "Revision: %u.%u\n", sb->s_major_rev_level, sb->s_minor_rev_level);
+ fprintf(out, "Mount Count: %u Max Mount Count: %u\n", sb->s_mnt_count,
sb->s_max_mnt_count);
- printf("State: %u Errors: %u\n", sb->s_state, sb->s_errors);
+ fprintf(out, "State: %u Errors: %u\n", sb->s_state, sb->s_errors);
str = ctime((time_t*)&sb->s_lastcheck);
- printf("Check Interval: %u Last Check: %s", sb->s_checkinterval, str);
+ fprintf(out, "Check Interval: %u Last Check: %s", sb->s_checkinterval, str);
- printf("Creator OS: %u\n", sb->s_creator_os);
- printf("Feature Compat: %u Incompat: %u RO Compat: %u\n",
+ fprintf(out, "Creator OS: %u\n", sb->s_creator_os);
+ fprintf(out, "Feature Compat: %u Incompat: %u RO Compat: %u\n",
sb->s_feature_compat, sb->s_feature_incompat,
sb->s_feature_ro_compat);
- printf("Root Blknum: %llu System Dir Blknum: %llu\n",
+ fprintf(out, "Root Blknum: %llu System Dir Blknum: %llu\n",
sb->s_root_blkno, sb->s_system_dir_blkno);
- printf("Block Size Bits: %u Cluster Size Bits: %u\n",
+ fprintf(out, "Block Size Bits: %u Cluster Size Bits: %u\n",
sb->s_blocksize_bits, sb->s_clustersize_bits);
- printf("Max Nodes: %u\n", sb->s_max_nodes);
- printf("Label: %s\n", sb->s_label);
- printf("UUID: ");
+ fprintf(out, "Max Nodes: %u\n", sb->s_max_nodes);
+ fprintf(out, "Label: %s\n", sb->s_label);
+ fprintf(out, "UUID: ");
for (i = 0; i < 16; i++)
- printf("%02X", sb->s_uuid[i]);
- printf("\n");
+ fprintf(out, "%02X", sb->s_uuid[i]);
+ fprintf(out, "\n");
return ;
} /* dump_super_block */
@@ -75,12 +75,12 @@
* dump_local_alloc()
*
*/
-void dump_local_alloc (ocfs2_local_alloc *loc)
+void dump_local_alloc (FILE *out, ocfs2_local_alloc *loc)
{
- printf("Local Bitmap Offset: %u Size: %u\n",
+ fprintf(out, "Local Bitmap Offset: %u Size: %u\n",
loc->la_bm_off, loc->la_size);
- printf("\tTotal: %u Used: %u Clear: %u\n",
+ fprintf(out, "\tTotal: %u Used: %u Clear: %u\n",
loc->la_bm_bits, loc->la_bits_set,
(loc->la_bm_bits - loc->la_bits_set));
@@ -91,7 +91,7 @@
* dump_inode()
*
*/
-void dump_inode(ocfs2_dinode *in)
+void dump_inode(FILE *out, ocfs2_dinode *in)
{
struct passwd *pw;
struct group *gr;
@@ -140,37 +140,37 @@
if (in->i_flags & OCFS2_DLM_FL)
g_string_append (flags, "dlm ");
- printf("Inode: %llu Mode: 0%0o Generation: %u\n",
+ fprintf(out, "Inode: %llu Mode: 0%0o Generation: %u\n",
in->i_blkno, mode, in->i_generation);
- printf("Type: %s Flags: %s\n", str, flags->str);
+ fprintf(out, "Type: %s Flags: %s\n", str, flags->str);
pw = getpwuid(in->i_uid);
gr = getgrgid(in->i_gid);
- printf("User: %d (%s) Group: %d (%s) Size: %llu\n",
+ fprintf(out, "User: %d (%s) Group: %d (%s) Size: %llu\n",
in->i_uid, (pw ? pw->pw_name : "unknown"),
in->i_gid, (gr ? gr->gr_name : "unknown"),
in->i_size);
- printf("Links: %u Clusters: %u\n", in->i_links_count, in->i_clusters);
+ fprintf(out, "Links: %u Clusters: %u\n", in->i_links_count, in->i_clusters);
- dump_disk_lock (&(in->i_disk_lock));
+ dump_disk_lock (out, &(in->i_disk_lock));
str = ctime((time_t*)&in->i_ctime);
- printf("ctime: 0x%llx -- %s", in->i_ctime, str);
+ fprintf(out, "ctime: 0x%llx -- %s", in->i_ctime, str);
str = ctime((time_t*)&in->i_atime);
- printf("atime: 0x%llx -- %s", in->i_atime, str);
+ fprintf(out, "atime: 0x%llx -- %s", in->i_atime, str);
str = ctime((time_t*)&in->i_mtime);
- printf("mtime: 0x%llx -- %s", in->i_mtime, str);
+ fprintf(out, "mtime: 0x%llx -- %s", in->i_mtime, str);
str = ctime((time_t*)&in->i_dtime);
- printf("dtime: 0x%llx -- %s", in->i_dtime, str);
+ fprintf(out, "dtime: 0x%llx -- %s", in->i_dtime, str);
- printf("Last Extblk: %llu\n", in->i_last_eb_blk);
- printf("Sub Alloc Node: %u Sub Alloc Blknum: %llu\n",
+ fprintf(out, "Last Extblk: %llu\n", in->i_last_eb_blk);
+ fprintf(out, "Sub Alloc Node: %u Sub Alloc Blknum: %llu\n",
in->i_suballoc_node, in->i_suballoc_blkno);
if (in->i_flags & OCFS2_BITMAP_FL)
- printf("Bitmap Total: %u Used: %u Clear: %u\n",
+ fprintf(out, "Bitmap Total: %u Used: %u Clear: %u\n",
in->id1.bitmap1.i_total, in->id1.bitmap1.i_used,
(in->id1.bitmap1.i_total - in->id1.bitmap1.i_used));
@@ -183,24 +183,26 @@
* dump_disk_lock()
*
*/
-void dump_disk_lock (ocfs2_disk_lock *dl)
+void dump_disk_lock (FILE *out, ocfs2_disk_lock *dl)
{
ocfs2_super_block *sb = &((gbls.superblk)->id2.i_super);
int i, j, k;
__u32 node_map;
- printf("Lock Master: %u Level: 0x%0x Seqnum: %llu\n",
+ fprintf(out, "Lock Master: %u Level: 0x%0x Seqnum: %llu\n",
dl->dl_master, dl->dl_level, dl->dl_seq_num);
- printf("Lock Node Map: ");
+ fprintf(out, "Lock Node Map: ");
for (i = 0, j = 0; i < 8 && j < sb->s_max_nodes; ++i) {
if (i)
- printf(" ");
+ fprintf(out, " ");
node_map = dl->dl_node_map[i];
- for (k = 0; k < 32 && j < sb->s_max_nodes; k++, j++)
- printf ("%d%c", ((node_map & (1 << k)) ? 1 : 0),
- (((k + 1) % 8) ? '\0' : ' '));
- printf ("\n");
+ for (k = 0; k < 32 && j < sb->s_max_nodes; k++, j++) {
+ fprintf (out, "%d", ((node_map & (1 << k)) ? 1 : 0));
+ if (!((k + 1) % 8))
+ fprintf (out, " ");
+ }
+ fprintf (out, "\n");
}
return ;
@@ -210,23 +212,23 @@
* dump_extent_list()
*
*/
-void dump_extent_list (ocfs2_extent_list *ext)
+void dump_extent_list (FILE *out, ocfs2_extent_list *ext)
{
ocfs2_extent_rec *rec;
int i;
- printf("Tree Depth: %u Count: %u Next Free Rec: %u\n",
- ext->l_tree_depth, ext->l_count, ext->l_next_free_rec);
+ fprintf(out, "Tree Depth: %u Count: %u Next Free Rec: %u\n",
+ ext->l_tree_depth, ext->l_count, ext->l_next_free_rec);
if (!ext->l_next_free_rec)
goto bail;
- printf("## File Offset Num Clusters Disk Offset\n");
+ fprintf(out, "## File Offset Num Clusters Disk Offset\n");
for (i = 0; i < ext->l_next_free_rec; ++i) {
rec = &(ext->l_recs[i]);
- printf("%-2d %-11u %-12u %llu\n", i, rec->e_cpos,
- rec->e_clusters, rec->e_blkno);
+ fprintf(out, "%-2d %-11u %-12u %llu\n", i, rec->e_cpos,
+ rec->e_clusters, rec->e_blkno);
}
bail:
@@ -237,13 +239,13 @@
* dump_extent_block()
*
*/
-void dump_extent_block (ocfs2_extent_block *blk)
+void dump_extent_block (FILE *out, ocfs2_extent_block *blk)
{
- printf ("SubAlloc Blknum: %llu SubAlloc Node: %u\n",
- blk->h_suballoc_blkno, blk->h_suballoc_node);
+ fprintf (out, "SubAlloc Blknum: %llu SubAlloc Node: %u\n",
+ blk->h_suballoc_blkno, blk->h_suballoc_node);
- printf ("Blknum: %llu Parent: %llu Next Leaf: %llu\n",
- blk->h_blkno, blk->h_parent_blk, blk->h_next_leaf_blk);
+ fprintf (out, "Blknum: %llu Parent: %llu Next Leaf: %llu\n",
+ blk->h_blkno, blk->h_parent_blk, blk->h_next_leaf_blk);
return ;
} /* dump_extent_block */
@@ -252,18 +254,18 @@
* dump_dir_entry()
*
*/
-void dump_dir_entry (GArray *arr)
+void dump_dir_entry (FILE *out, GArray *arr)
{
struct ocfs2_dir_entry *rec;
int i;
- printf("%-20s %-4s %-4s %-2s %-4s\n",
- "Inode", "Rlen", "Nlen", "Ty", "Name");
+ fprintf(out, "%-20s %-4s %-4s %-2s %-4s\n",
+ "Inode", "Rlen", "Nlen", "Ty", "Name");
for (i = 0; i < arr->len; ++i) {
rec = &(g_array_index(arr, struct ocfs2_dir_entry, i));
- printf("%-20llu %-4u %-4u %-2u %s\n", rec->inode,
- rec->rec_len, rec->name_len, rec->file_type, rec->name);
+ fprintf(out, "%-20llu %-4u %-4u %-2u %s\n", rec->inode,
+ rec->rec_len, rec->name_len, rec->file_type, rec->name);
}
return ;
@@ -273,7 +275,7 @@
* dump_config()
*
*/
-void dump_config (char *buf)
+void dump_config (FILE *out, char *buf)
{
char *p;
ocfs_node_config_hdr *hdr;
@@ -286,13 +288,13 @@
hdr = (ocfs_node_config_hdr *)buf;
- printf("Version: %u Num Nodes: %u Last Node: %u SeqNum: %llu\n",
- hdr->version, hdr->num_nodes, hdr->last_node, hdr->cfg_seq_num);
+ fprintf(out, "Version: %u Num Nodes: %u Last Node: %u SeqNum: %llu\n",
+ hdr->version, hdr->num_nodes, hdr->last_node, hdr->cfg_seq_num);
- dump_disk_lock (&(hdr->disk_lock));
+ dump_disk_lock (out, &(hdr->disk_lock));
- printf("%-4s %-32s %-15s %-6s %s\n",
- "Node", "Name", "IP Addr", "Port", "UUID");
+ fprintf(out, "%-4s %-32s %-15s %-6s %s\n",
+ "Node", "Name", "IP Addr", "Port", "UUID");
p = buf + (2 << gbls.blksz_bits);
for (i = 0; i < sb->s_max_nodes; ++i) {
@@ -305,10 +307,11 @@
ina.s_addr = node->ipc_config.addr_u.ip_addr4;
strcpy (addr, inet_ntoa(ina));
- printf("%-4u %-32s %-15s %-6u ", i, node->node_name, addr, port);
+ fprintf(out, "%-4u %-32s %-15s %-6u ", i, node->node_name,
+ addr, port);
for (j = 0; j < OCFS2_GUID_LEN; j++)
- printf("%c", node->guid.guid[j]);
- printf("\n");
+ fprintf(out, "%c", node->guid.guid[j]);
+ fprintf(out, "\n");
p += (1 << gbls.blksz_bits);
}
@@ -319,7 +322,7 @@
* dump_publish()
*
*/
-void dump_publish (char *buf)
+void dump_publish (FILE *out, char *buf)
{
ocfs_publish *pub;
char *p;
@@ -327,9 +330,9 @@
ocfs2_super_block *sb = &((gbls.superblk)->id2.i_super);
__u32 i, j;
- printf("%-2s %-3s %-3s %-3s %-15s %-15s %-15s %-*s %-s\n",
- "No", "Mnt", "Vot", "Dty", "LockId", "Seq", "Time", sb->s_max_nodes,
- "Map", "Type");
+ fprintf(out, "%-2s %-3s %-3s %-3s %-15s %-15s %-15s %-*s %-s\n",
+ "No", "Mnt", "Vot", "Dty", "LockId", "Seq", "Time",
+ sb->s_max_nodes, "Map", "Type");
p = buf + ((2 + 4 + sb->s_max_nodes) << gbls.blksz_bits);
for (i = 0; i < sb->s_max_nodes; ++i) {
@@ -338,14 +341,16 @@
pub_flag = g_string_new (NULL);
get_publish_flag (pub->vote_type, pub_flag);
- printf("%-2d %1u %1u %1u %-15llu %-15llu %-15llu ",
- i, pub->mounted, pub->vote, pub->dirty, pub->lock_id,
- pub->publ_seq_num, pub->time);
+ fprintf(out, "%-2d %1u %1u %1u %-15llu %-15llu %-15llu ",
+ i, pub->mounted, pub->vote, pub->dirty, pub->lock_id,
+ pub->publ_seq_num, pub->time);
for (j = 0; j < sb->s_max_nodes; j++)
- printf ("%d", ((pub->vote_map[j / sizeof(pub->vote_map[0])] & (1 << (j % sizeof(pub->vote_map[0])))) ? 1 : 0));
+ fprintf (out, "%d",
+ ((pub->vote_map[j / sizeof(pub->vote_map[0])] &
+ (1 << (j % sizeof(pub->vote_map[0])))) ? 1 : 0));
- printf(" %-s\n", pub_flag->str);
+ fprintf(out, " %-s\n", pub_flag->str);
g_string_free (pub_flag, 1);
@@ -359,7 +364,7 @@
* dump_vote()
*
*/
-void dump_vote (char *buf)
+void dump_vote (FILE *out, char *buf)
{
ocfs_vote *vote;
char *p;
@@ -367,8 +372,8 @@
ocfs2_super_block *sb = &((gbls.superblk)->id2.i_super);
__u32 i;
- printf("%-2s %-2s %-1s %-15s %-15s %-s\n",
- "No", "NV", "O", "LockId", "Seq", "Type");
+ fprintf(out, "%-2s %-2s %-1s %-15s %-15s %-s\n",
+ "No", "NV", "O", "LockId", "Seq", "Type");
p = buf + ((2 + 4 + sb->s_max_nodes + sb->s_max_nodes) << gbls.blksz_bits);
for (i = 0; i < sb->s_max_nodes; ++i) {
@@ -377,9 +382,9 @@
vote_flag = g_string_new (NULL);
get_vote_flag (vote->type, vote_flag);
- printf("%-2u %-2u %-1u %-15llu %-15llu %-s\n", i,
- vote->node, vote->open_handle, vote->lock_id,
- vote->vote_seq_num, vote_flag->str);
+ fprintf(out, "%-2u %-2u %-1u %-15llu %-15llu %-s\n", i,
+ vote->node, vote->open_handle, vote->lock_id,
+ vote->vote_seq_num, vote_flag->str);
g_string_free (vote_flag, 1);
p += (1 << gbls.blksz_bits);
Modified: trunk/ocfs2/debugfs.ocfs2/include/dump.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/dump.h 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/include/dump.h 2004-07-07 00:36:10 UTC (rev 143)
@@ -26,15 +26,15 @@
#ifndef __DUMP_H__
#define __DUMP_H__
-void dump_super_block (ocfs2_super_block *sb);
-void dump_local_alloc (ocfs2_local_alloc *loc);
-void dump_inode (ocfs2_dinode *in);
-void dump_disk_lock (ocfs2_disk_lock *dl);
-void dump_extent_list (ocfs2_extent_list *ext);
-void dump_extent_block (ocfs2_extent_block *blk);
-void dump_dir_entry (GArray *arr);
-void dump_config (char *buf);
-void dump_publish (char *buf);
-void dump_vote (char *buf);
+void dump_super_block (FILE *out, ocfs2_super_block *sb);
+void dump_local_alloc (FILE *out, ocfs2_local_alloc *loc);
+void dump_inode (FILE *out, ocfs2_dinode *in);
+void dump_disk_lock (FILE *out, ocfs2_disk_lock *dl);
+void dump_extent_list (FILE *out, ocfs2_extent_list *ext);
+void dump_extent_block (FILE *out, ocfs2_extent_block *blk);
+void dump_dir_entry (FILE *out, GArray *arr);
+void dump_config (FILE *out, char *buf);
+void dump_publish (FILE *out, char *buf);
+void dump_vote (FILE *out, char *buf);
#endif /* __DUMP_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/include/journal.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/journal.h 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/include/journal.h 2004-07-07 00:36:10 UTC (rev 143)
@@ -28,11 +28,11 @@
#include <jbd.h>
-void read_journal (char *buf, __u64 buflen);
-void print_header (journal_header_t *header, char *hdr);
-void print_super_block (journal_superblock_t *sb);
-void print_metadata_blocks (int start, int end);
-void print_tag_flag (__u32 flags);
-void print_jbd_block (journal_header_t *header);
+void read_journal (char *buf, __u64 buflen, FILE *out);
+void print_header (journal_header_t *header, char *hdr, FILE *out);
+void print_super_block (journal_superblock_t *sb, FILE *out);
+void print_metadata_blocks (int start, int end, FILE *out);
+void print_tag_flag (__u32 flags, FILE *out);
+void print_jbd_block (journal_header_t *header, FILE *out);
#endif /* _JOURNAL_H_ */
Modified: trunk/ocfs2/debugfs.ocfs2/include/main.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/main.h 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/include/main.h 2004-07-07 00:36:10 UTC (rev 143)
@@ -43,6 +43,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <signal.h>
#include <glib.h>
Modified: trunk/ocfs2/debugfs.ocfs2/include/readfs.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/readfs.h 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/include/readfs.h 2004-07-07 00:36:10 UTC (rev 143)
@@ -28,7 +28,7 @@
int read_super_block (int fd, char **buf);
int read_inode (int fd, __u64 blknum, char *buf, int buflen);
-int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump);
+int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump, FILE *out);
void read_dir_block (struct ocfs2_dir_entry *dir, int len, GArray *arr);
void read_dir (int fd, ocfs2_extent_list *ext, __u64 size, GArray *dirarr);
void read_sysdir (int fd, char *sysdir);
Modified: trunk/ocfs2/debugfs.ocfs2/include/utils.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/utils.h 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/include/utils.h 2004-07-07 00:36:10 UTC (rev 143)
@@ -30,5 +30,7 @@
void add_dir_rec (GArray *arr, struct ocfs2_dir_entry *rec);
void get_vote_flag (__u32 flag, GString *str);
void get_publish_flag (__u32 flag, GString *str);
+FILE *open_pager(void);
+void close_pager(FILE *stream);
#endif /* __UTILS_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/journal.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/journal.c 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/journal.c 2004-07-07 00:36:10 UTC (rev 143)
@@ -36,7 +36,7 @@
* read_journal()
*
*/
-void read_journal (char *buf, __u64 buflen)
+void read_journal (char *buf, __u64 buflen, FILE *out)
{
char *block;
int blocknum;
@@ -55,16 +55,16 @@
block = p;
header = (journal_header_t *) block;
if (blocknum == 0) {
- printf("block %d: ", blocknum);
- print_super_block((journal_superblock_t *) block);
+ fprintf(out, "block %d: ", blocknum);
+ print_super_block((journal_superblock_t *) block, out);
} else if (header->h_magic == ntohl(JFS_MAGIC_NUMBER)) {
if (last_metadata > 0) {
print_metadata_blocks(last_metadata,
- blocknum - 1);
+ blocknum - 1, out);
last_metadata = 0;
}
- printf("block %d: ", blocknum);
- print_jbd_block(header);
+ fprintf(out, "block %d: ", blocknum);
+ print_jbd_block(header, out);
} else {
if (last_metadata == 0)
last_metadata = blocknum;
@@ -76,42 +76,42 @@
}
if (last_metadata > 0)
- print_metadata_blocks(last_metadata, blocknum);
+ print_metadata_blocks(last_metadata, blocknum, out);
return ;
} /* read_journal */
-#define PRINT_FIELD(name, size, field) printf("\t" #field ":\t\t" size \
- "\n", ntohl(name->field))
+#define PRINT_FIELD(name, size, field, out) fprintf(out, "\t" #field ":\t\t" size \
+ "\n", ntohl(name->field))
/*
* print_header()
*
*/
-void print_header (journal_header_t *header, char *hdr)
+void print_header (journal_header_t *header, char *hdr, FILE *out)
{
- printf("\t%s->h_magic:\t\t0x%x\n", hdr, ntohl(header->h_magic));
- printf("\t%s->h_blocktype:\t\t%u ", hdr, ntohl(header->h_blocktype));
+ fprintf(out, "\t%s->h_magic:\t\t0x%x\n", hdr, ntohl(header->h_magic));
+ fprintf(out, "\t%s->h_blocktype:\t\t%u ", hdr, ntohl(header->h_blocktype));
switch (ntohl(header->h_blocktype)) {
case JFS_DESCRIPTOR_BLOCK:
- printf("(JFS_DESCRIPTOR_BLOCK)");
+ fprintf(out, "(JFS_DESCRIPTOR_BLOCK)");
break;
case JFS_COMMIT_BLOCK:
- printf("(JFS_COMMIT_BLOCK)");
+ fprintf(out, "(JFS_COMMIT_BLOCK)");
break;
case JFS_SUPERBLOCK_V1:
- printf("(JFS_SUPERBLOCK_V1)");
+ fprintf(out, "(JFS_SUPERBLOCK_V1)");
break;
case JFS_SUPERBLOCK_V2:
- printf("(JFS_SUPERBLOCK_V2)");
+ fprintf(out, "(JFS_SUPERBLOCK_V2)");
break;
case JFS_REVOKE_BLOCK:
- printf("(JFS_REVOKE_BLOCK)");
+ fprintf(out, "(JFS_REVOKE_BLOCK)");
break;
}
- printf("\n");
- printf("\t%s->h_sequence:\t\t%u\n", hdr, ntohl(header->h_sequence));
+ fprintf(out, "\n");
+ fprintf(out, "\t%s->h_sequence:\t\t%u\n", hdr, ntohl(header->h_sequence));
return;
} /* print_header */
@@ -119,35 +119,34 @@
* print_super_block()
*
*/
-void print_super_block (journal_superblock_t *sb)
+void print_super_block (journal_superblock_t *sb, FILE *out)
{
int i;
- printf("Journal Superblock\n");
+ fprintf(out, "Journal Superblock\n");
- print_header(&(sb->s_header), "s_header");
+ print_header(&(sb->s_header), "s_header", out);
- PRINT_FIELD(sb, "%u", s_blocksize);
- PRINT_FIELD(sb, "%u", s_maxlen);
- PRINT_FIELD(sb, "%u", s_first);
- PRINT_FIELD(sb, "%u", s_sequence);
- PRINT_FIELD(sb, "%u", s_start);
- PRINT_FIELD(sb, "%d", s_errno);
- PRINT_FIELD(sb, "%u", s_feature_compat);
- PRINT_FIELD(sb, "%u", s_feature_incompat);
- PRINT_FIELD(sb, "%u", s_feature_ro_compat);
+ PRINT_FIELD(sb, "%u", s_blocksize, out);
+ PRINT_FIELD(sb, "%u", s_maxlen, out);
+ PRINT_FIELD(sb, "%u", s_first, out);
+ PRINT_FIELD(sb, "%u", s_sequence, out);
+ PRINT_FIELD(sb, "%u", s_start, out);
+ PRINT_FIELD(sb, "%d", s_errno, out);
+ PRINT_FIELD(sb, "%u", s_feature_compat, out);
+ PRINT_FIELD(sb, "%u", s_feature_incompat, out);
+ PRINT_FIELD(sb, "%u", s_feature_ro_compat, out);
- printf("\ts_uuid[16]:\t\t");
+ fprintf(out, "\ts_uuid[16]:\t\t");
for(i = 0; i < 16; i++)
- printf("%x ", sb->s_uuid[i]);
- printf("\n");
+ fprintf(out, "%x ", sb->s_uuid[i]);
+ fprintf(out, "\n");
+ PRINT_FIELD(sb, "%u", s_nr_users, out);
+ PRINT_FIELD(sb, "%u", s_dynsuper, out);
+ PRINT_FIELD(sb, "%u", s_max_transaction, out);
+ PRINT_FIELD(sb, "%u", s_max_trans_data, out);
- PRINT_FIELD(sb, "%u", s_nr_users);
- PRINT_FIELD(sb, "%u", s_dynsuper);
- PRINT_FIELD(sb, "%u", s_max_transaction);
- PRINT_FIELD(sb, "%u", s_max_trans_data);
-
return;
} /* print_super_block */
@@ -156,13 +155,13 @@
* print_metadata_blocks()
*
*/
-void print_metadata_blocks (int start, int end)
+void print_metadata_blocks (int start, int end, FILE *out)
{
if (start == end)
- printf("block %d: ", start);
+ fprintf(out, "block %d: ", start);
else
- printf("block %d --> block %d: ", start, end);
- printf("Filesystem Metadata\n\n");
+ fprintf(out, "block %d --> block %d: ", start, end);
+ fprintf(out, "Filesystem Metadata\n\n");
return;
} /* print_metadata_blocks */
@@ -170,21 +169,21 @@
* print_tag_flag()
*
*/
-void print_tag_flag (__u32 flags)
+void print_tag_flag (__u32 flags, FILE *out)
{
if (flags == 0) {
- printf("(none)");
+ fprintf(out, "(none)");
goto done;
}
if (flags & JFS_FLAG_ESCAPE)
- printf("JFS_FLAG_ESCAPE ");
+ fprintf(out, "JFS_FLAG_ESCAPE ");
if (flags & JFS_FLAG_SAME_UUID)
- printf("JFS_FLAG_SAME_UUID ");
+ fprintf(out, "JFS_FLAG_SAME_UUID ");
if (flags & JFS_FLAG_DELETED)
- printf("JFS_FLAG_DELETED ");
+ fprintf(out, "JFS_FLAG_DELETED ");
if (flags & JFS_FLAG_LAST_TAG)
- printf("JFS_FLAG_LAST_TAG");
+ fprintf(out, "JFS_FLAG_LAST_TAG");
done:
return;
} /* print_tag_flag */
@@ -193,7 +192,7 @@
* print_jbd_block()
*
*/
-void print_jbd_block (journal_header_t *header)
+void print_jbd_block (journal_header_t *header, FILE *out)
{
int i;
int j;
@@ -207,26 +206,26 @@
switch(ntohl(header->h_blocktype)) {
case JFS_DESCRIPTOR_BLOCK:
- printf("Journal Descriptor\n");
- print_header(header, "hdr");
+ fprintf(out, "Journal Descriptor\n");
+ print_header(header, "hdr", out);
for(i = sizeof(journal_header_t); i < (1 << gbls.blksz_bits);
i+=sizeof(journal_block_tag_t)) {
tag = (journal_block_tag_t *) &blk[i];
- printf("\ttag[%d]->t_blocknr:\t\t%u\n", count,
+ fprintf(out, "\ttag[%d]->t_blocknr:\t\t%u\n", count,
ntohl(tag->t_blocknr));
- printf("\ttag[%d]->t_flags:\t\t", count);
- print_tag_flag(ntohl(tag->t_flags));
- printf("\n");
+ fprintf(out, "\ttag[%d]->t_flags:\t\t", count);
+ print_tag_flag(ntohl(tag->t_flags), out);
+ fprintf(out, "\n");
if (tag->t_flags & htonl(JFS_FLAG_LAST_TAG))
break;
/* skip the uuid. */
if (!(tag->t_flags & htonl(JFS_FLAG_SAME_UUID))) {
uuid = &blk[i + sizeof(journal_block_tag_t)];
- printf("\ttag[%d] uuid:\t\t", count);
+ fprintf(out, "\ttag[%d] uuid:\t\t", count);
for(j = 0; j < 16; j++)
- printf("%x ", uuid[j]);
- printf("\n");
+ fprintf(out, "%x ", uuid[j]);
+ fprintf(out, "\n");
i += 16;
}
count++;
@@ -234,24 +233,24 @@
break;
case JFS_COMMIT_BLOCK:
- printf("Journal Commit Block\n");
- print_header(header, "hdr");
+ fprintf(out, "Journal Commit Block\n");
+ print_header(header, "hdr", out);
break;
case JFS_REVOKE_BLOCK:
- printf("Journal Revoke Block\n");
- print_header(header, "r_header");
+ fprintf(out, "Journal Revoke Block\n");
+ print_header(header, "r_header", out);
revoke = (journal_revoke_header_t *) blk;
- printf("\tr_count:\t\t%d\n", ntohl(revoke->r_count));
+ fprintf(out, "\tr_count:\t\t%d\n", ntohl(revoke->r_count));
count = (ntohl(revoke->r_count) -
sizeof(journal_revoke_header_t)) / sizeof(__u32);
blocknr = (__u32 *) &blk[sizeof(journal_revoke_header_t)];
for(i = 0; i < count; i++)
- printf("\trevoke[%d]:\t\t%u\n", i, ntohl(blocknr[i]));
+ fprintf(out, "\trevoke[%d]:\t\t%u\n", i, ntohl(blocknr[i]));
break;
default:
- printf("Unknown block type\n");
+ fprintf(out, "Unknown block type\n");
break;
}
Modified: trunk/ocfs2/debugfs.ocfs2/readfs.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-07-07 00:36:10 UTC (rev 143)
@@ -120,7 +120,7 @@
* traverse_extents()
*
*/
-int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump)
+int traverse_extents (int fd, ocfs2_extent_list *ext, GArray *arr, int dump, FILE *out)
{
ocfs2_extent_block *blk;
ocfs2_extent_rec *rec;
@@ -131,7 +131,7 @@
int i;
if (dump)
- dump_extent_list (ext);
+ dump_extent_list (out, ext);
for (i = 0; i < ext->l_next_free_rec; ++i) {
rec = &(ext->l_recs[i]);
@@ -149,9 +149,9 @@
blk = (ocfs2_extent_block *)buf;
if (dump)
- dump_extent_block (blk);
+ dump_extent_block (out, blk);
- traverse_extents (fd, &(blk->h_list), arr, dump);
+ traverse_extents (fd, &(blk->h_list), arr, dump, out);
}
}
@@ -196,7 +196,7 @@
arr = g_array_new(0, 1, sizeof(ocfs2_extent_rec));
- traverse_extents (fd, ext, arr, 0);
+ traverse_extents (fd, ext, arr, 0, stdout);
for (i = 0; i < arr->len; ++i) {
rec = &(g_array_index(arr, ocfs2_extent_rec, i));
@@ -291,7 +291,7 @@
}
inode = (ocfs2_dinode *)inode_buf;
- traverse_extents (fd, &(inode->id2.i_list), arr, 0);
+ traverse_extents (fd, &(inode->id2.i_list), arr, 0, stdout);
if (fdo == -1) {
newlen = inode->i_size;
Modified: trunk/ocfs2/debugfs.ocfs2/utils.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/utils.c 2004-07-04 20:39:45 UTC (rev 142)
+++ trunk/ocfs2/debugfs.ocfs2/utils.c 2004-07-07 00:36:10 UTC (rev 143)
@@ -195,3 +195,39 @@
return ;
} /* get_publish_flag */
+
+/*
+ * open_pager() -- copied from e2fsprogs-1.32/debugfs/util.c
+ *
+ * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
+ * redistributed under the terms of the GNU Public License.
+ *
+ */
+FILE *open_pager(void)
+{
+ FILE *outfile;
+ const char *pager = getenv("PAGER");
+
+ signal(SIGPIPE, SIG_IGN);
+ if (pager) {
+ if (strcmp(pager, "__none__") == 0) {
+ return stdout;
+ }
+ } else
+ pager = "more";
+
+ outfile = popen(pager, "w");
+
+ return (outfile ? outfile : stdout);
+} /* open_pager */
+
+/*
+ * close_pager() -- copied from e2fsprogs-1.32/debugfs/util.c
+ *
+ * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
+ * redistributed under the terms of the GNU Public License.
+ */
+void close_pager(FILE *stream)
+{
+ if (stream && stream != stdout) pclose(stream);
+} /* close_pager */
More information about the Ocfs-tools-commits
mailing list