[Ocfs-tools-commits]
smushran commits r113 - in trunk/ocfs2/debugfs.ocfs2: . include
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon Jun 28 21:20:16 CDT 2004
Author: smushran
Date: 2004-06-28 20:20:14 -0500 (Mon, 28 Jun 2004)
New Revision: 113
Modified:
trunk/ocfs2/debugfs.ocfs2/commands.c
trunk/ocfs2/debugfs.ocfs2/include/readfs.h
trunk/ocfs2/debugfs.ocfs2/readfs.c
Log:
cat implemented
Modified: trunk/ocfs2/debugfs.ocfs2/commands.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/commands.c 2004-06-29 00:54:39 UTC (rev 112)
+++ trunk/ocfs2/debugfs.ocfs2/commands.c 2004-06-29 01:20:14 UTC (rev 113)
@@ -106,7 +106,7 @@
{ "q", do_quit },
{ "dump", do_dump },
- { "cat", do_dump },
+ { "cat", do_cat },
{ "curdev", do_curdev },
@@ -118,10 +118,8 @@
{ "nodes", do_config },
{ "publish", do_publish },
- { "vote", do_vote },
+ { "vote", do_vote }
- { "cat", do_cat }
-
};
@@ -269,6 +267,11 @@
GArray *dirarr = NULL;
__u32 len;
+ if (dev_fd == -1) {
+ printf ("device not open\n");
+ goto bail;
+ }
+
len = 1 << blksz_bits;
if (!(buf = malloc(len)))
DBGFS_FATAL("%s", strerror(errno));
@@ -372,6 +375,7 @@
// printf ("cd\t\t\tChange working directory\n");
printf ("pwd\t\t\t\tPrint working directory\n");
printf ("ls [blknum]\t\t\tList directory\n");
+ printf ("cat [blknum]\t\t\tPrints file on stdout\n");
// printf ("rm\t\t\t\tRemove a file\n");
// printf ("mkdir\t\t\t\tMake a directory\n");
// printf ("rmdir\t\t\t\tRemove a directory\n");
@@ -441,6 +445,11 @@
ocfs2_dinode *in;
ocfs2_super_block *sb;
+ if (dev_fd == -1) {
+ printf ("device not open\n");
+ goto bail;
+ }
+
in = (ocfs2_dinode *)superblk;
sb = &(in->id2.i_super);
dump_super_block(sb);
@@ -448,6 +457,7 @@
if (!opts || strncmp(opts, "-h", 2))
dump_inode(in);
+bail:
return ;
} /* do_super */
@@ -463,6 +473,11 @@
char *buf = NULL;
__u32 buflen;
+ if (dev_fd == -1) {
+ printf ("device not open\n");
+ goto bail;
+ }
+
buflen = 1 << blksz_bits;
if (!(buf = malloc(buflen)))
DBGFS_FATAL("%s", strerror(errno));
@@ -496,7 +511,10 @@
*/
static void do_config (char **args)
{
- process_dlm (dev_fd, CONFIG);
+ if (dev_fd == -1)
+ printf ("device not open\n");
+ else
+ process_dlm (dev_fd, CONFIG);
return ;
} /* do_config */
@@ -507,7 +525,10 @@
*/
static void do_publish (char **args)
{
- process_dlm (dev_fd, PUBLISH);
+ if (dev_fd == -1)
+ printf ("device not open\n");
+ else
+ process_dlm (dev_fd, PUBLISH);
return ;
} /* do_publish */
@@ -518,7 +539,10 @@
*/
static void do_vote (char **args)
{
- process_dlm (dev_fd, VOTE);
+ if (dev_fd == -1)
+ printf ("device not open\n");
+ else
+ process_dlm (dev_fd, VOTE);
return ;
} /* do_vote */
@@ -529,13 +553,17 @@
*/
static void do_cat (char **args)
{
-#if 0
char *opts = args[1];
ocfs2_dinode *inode;
__u32 blknum = 0;
char *buf = NULL;
__u32 buflen;
+ if (dev_fd == -1) {
+ printf ("device not open\n");
+ goto bail;
+ }
+
if (opts)
blknum = atoi(opts);
@@ -552,7 +580,8 @@
}
inode = (ocfs2_dinode *)buf;
+ read_file (dev_fd, &(inode->id2.i_list), inode->i_size, NULL, 1);
+
bail:
-#endif
return ;
} /* do_cat */
Modified: trunk/ocfs2/debugfs.ocfs2/include/readfs.h
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/include/readfs.h 2004-06-29 00:54:39 UTC (rev 112)
+++ trunk/ocfs2/debugfs.ocfs2/include/readfs.h 2004-06-29 01:20:14 UTC (rev 113)
@@ -32,7 +32,7 @@
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);
-void read_file (int fd, ocfs2_extent_list *ext, __u64 size, char *buf);
+void read_file (int fd, ocfs2_extent_list *ext, __u64 size, char *buf, int fdo);
void process_dlm (int fd, int type);
#endif /* __READFS_H__ */
Modified: trunk/ocfs2/debugfs.ocfs2/readfs.c
===================================================================
--- trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-06-29 00:54:39 UTC (rev 112)
+++ trunk/ocfs2/debugfs.ocfs2/readfs.c 2004-06-29 01:20:14 UTC (rev 113)
@@ -268,13 +268,15 @@
* read_file()
*
*/
-void read_file (int fd, ocfs2_extent_list *ext, __u64 size, char *buf)
+void read_file (int fd, ocfs2_extent_list *ext, __u64 size, char *buf, int fdo)
{
GArray *arr = NULL;
ocfs2_extent_rec *rec;
char *p;
__u64 off, foff, len;
int i;
+ char *newbuf = NULL;
+ __u32 newlen = 0;
arr = g_array_new(0, 1, sizeof(ocfs2_extent_rec));
@@ -290,12 +292,29 @@
if ((foff + len) > size)
len = size - foff;
+ if (fd != -1) {
+ if (newlen <= len) {
+ safefree (newbuf);
+ if (!(newbuf = malloc (len)))
+ DBGFS_FATAL("%s", strerror(errno));
+ newlen = len;
+ p = newbuf;
+ }
+ }
+
if ((pread64(fd, p, len, off)) == -1)
DBGFS_FATAL("%s", strerror(errno));
- p += len;
+ if (fd != -1) {
+ if (len)
+ if (!(write (fdo, p, len)))
+ DBGFS_FATAL("%s", strerror(errno));
+ } else
+ p += len;
}
+ safefree (newbuf);
+
if (arr)
g_array_free (arr, 1);
@@ -333,7 +352,7 @@
if (!(dlmbuf = malloc (buflen)))
DBGFS_FATAL("%s", strerror(errno));
- read_file (fd, &(inode->id2.i_list), buflen, dlmbuf);
+ read_file (fd, &(inode->id2.i_list), buflen, dlmbuf, -1);
switch (type) {
case CONFIG:
More information about the Ocfs-tools-commits
mailing list