[Ocfs-tools-commits] smushran commits r43 - trunk/debugocfs
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri May 28 20:43:18 CDT 2004
Author: smushran
Date: 2004-05-28 19:43:15 -0500 (Fri, 28 May 2004)
New Revision: 43
Modified:
trunk/debugocfs/Cscope.make
trunk/debugocfs/debugocfs.c
trunk/debugocfs/debugocfs.h
trunk/debugocfs/io.c
trunk/debugocfs/libdebugocfs.c
Log:
suck_file option now works from debugocfs and ocfstool
Modified: trunk/debugocfs/Cscope.make
===================================================================
--- trunk/debugocfs/Cscope.make 2004-05-24 22:11:27 UTC (rev 42)
+++ trunk/debugocfs/Cscope.make 2004-05-29 00:43:15 UTC (rev 43)
@@ -1,8 +1,10 @@
cscope:
rm -f cscope.*
echo "-k" >> cscope.files
- echo "-I ../../ocfs2/Common/inc" >> cscope.files
- echo "-I ../../ocfs2/Linux/inc" >> cscope.files
+ echo "-I ../libocfs/Common/inc" >> cscope.files
+ echo "-I ../libocfs/Linux/inc" >> cscope.files
find . -name '*.c' -print >>cscope.files
find . -name '*.h' -print >>cscope.files
+ find ../libocfs -name '*.h' -print >>cscope.files
+ find ../libocfs -name '*.c' -print >>cscope.files
cscope -b
Modified: trunk/debugocfs/debugocfs.c
===================================================================
--- trunk/debugocfs/debugocfs.c 2004-05-24 22:11:27 UTC (rev 42)
+++ trunk/debugocfs/debugocfs.c 2004-05-29 00:43:15 UTC (rev 43)
@@ -302,17 +302,20 @@
* ocfs_file_entry structure, depending upon mode
*/
void find_file_entry(ocfs_super * vcb, __u64 offset, const char *parent,
- const char *searchFor, int mode, void *buf)
+ const char *searchFor, int mode, filedata *buf)
{
ocfs_dir_node *dir, *foundDir;
int i, fd;
char *newname;
- __u64 ret = 0, dirPartOffset;
+ filedata ret;
+ __u64 dirPartOffset;
fd = (int) vcb->sb->s_dev;
dir = (ocfs_dir_node *) malloc_aligned(DIR_NODE_SIZE);
dirPartOffset = offset;
+ memset(&ret, 0, sizeof(filedata));
+
while (1)
{
if (dirPartOffset == 0)
@@ -341,11 +344,11 @@
if (strcmp(searchFor, newname) == 0)
{
if (mode == FIND_MODE_FILE || mode == FIND_MODE_FILE_EXTENT)
- ret = offset; // return the first part of the dir chain
+ ret.off = offset; // return the first part of the dir chain
else if (mode == FIND_MODE_DIR)
- ret = fe->extents[0].disk_off;
+ ret.off = fe->extents[0].disk_off;
else if (mode == FIND_MODE_FILE_DATA)
- get_file_data_mapping(vcb, fe, buf);
+ get_file_data_mapping(vcb, fe, &ret);
#ifndef LIBDEBUGOCFS
printf("\tName = %s\n", newname);
@@ -379,7 +382,7 @@
else if (strstr(searchFor, newname) == searchFor)
{
find_file_entry(vcb, fe->extents[0].disk_off, newname,
- searchFor, mode, (void *) (&ret));
+ searchFor, mode, &ret);
free(newname);
break;
}
@@ -390,11 +393,11 @@
if (strcmp(searchFor, newname) == 0)
{
if (mode == FIND_MODE_FILE || mode == FIND_MODE_FILE_EXTENT)
- ret = offset; // return the first part of the dir chain
+ ret.off = offset; // return the first part of the dir chain
else if (mode == FIND_MODE_DIR)
- ret = 0; // file found, not dir
+ ret.off = 0; // file found, not dir
else if (mode == FIND_MODE_FILE_DATA)
- get_file_data_mapping(vcb, fe, buf);
+ get_file_data_mapping(vcb, fe, &ret);
#ifndef LIBDEBUGOCFS
if (mode == FIND_MODE_DIR)
@@ -422,9 +425,8 @@
}
free(dir);
- if ((mode == FIND_MODE_FILE || mode == FIND_MODE_DIR ||
- mode == FIND_MODE_FILE_EXTENT) && buf)
- *(__u64 *) buf = ret;
+ if (buf)
+ memcpy(buf, &ret, sizeof(filedata));
}
@@ -438,18 +440,27 @@
fd = (int) vcb->sb->s_dev;
oldmask = umask(0000);
- if (unlink(file) == -1)
- {
-#ifndef LIBDEBUGOCFS
- printf("failed to unlink file: %s\n", file);
-#endif
- }
+ memset (&data, 0, sizeof(filedata));
+ /* del outfile if it already exists */
+ unlink(file);
+
if (access(file, F_OK) == -1)
{
find_file_entry(vcb, vcb->vol_layout.root_start_off, "/",
path, FIND_MODE_FILE_DATA, &data);
+#if 0
+ if (1) {
+ filedata *p = &data;
+ int i;
+ printf("\n");
+ for(i=0; i < p->num; ++i)
+ printf("do=%u.%u, fo=%u, len=%u\n", HILO(p->array[i].disk_off),
+ p->array[i].offset, p->array[i].byte_cnt);
+ }
+#endif
+
if (S_ISLNK(data.mode) && data.linkname)
{
newfd = symlink(data.linkname, file);
@@ -471,11 +482,20 @@
else if (S_ISREG(data.mode))
{
void *filebuf = malloc_aligned(FILE_BUFFER_SIZE);
- __u32 remaining, readlen;
+ __u32 remaining, readlen, rndup;
+ if (!filebuf) {
+ ret = -1;
+ printf("Error: Out of memory\n");
+ goto do_close;
+ }
+
newfd = creat(file, data.mode);
if (newfd != -1)
{
+#ifndef LIBDEBUGOCFS
+ printf("From %s to %s ", path, file);
+#endif
for (i = 0; i < data.num; i++)
{
run = (ocfs_io_runs *) & (data.array[i]);
@@ -483,22 +503,34 @@
// in new file: seek to run->Offset
// in ocfs: read from run->disk_off, run->byte_cnt bytes
remaining = run->byte_cnt;
- myseek64(newfd, run->offset, SEEK_SET);
myseek64(fd, run->disk_off, SEEK_SET);
while (remaining > 0)
{
readlen =
remaining <
FILE_BUFFER_SIZE ? remaining : FILE_BUFFER_SIZE;
- if (read(fd, filebuf, readlen) != readlen ||
- write(newfd, filebuf, readlen) != readlen)
- {
- ret = 2;
- goto do_close;
- }
+ /* rndup is reqd because source is read o_direct */
+ rndup = readlen % 512;
+ rndup = (rndup ? 512 - rndup : 0);
+ readlen += rndup;
+
+ if ((ret = myread(fd, filebuf, readlen)) == -1)
+ goto do_close;
+
+ readlen -= rndup;
+ if ((ret = mywrite(newfd, filebuf, readlen)) == -1)
+ goto do_close;
+
remaining -= readlen;
+ ret = 0;
}
+#ifndef LIBDEBUGOCFS
+ printf("."); fflush(stdout);
+#endif
}
+#ifndef LIBDEBUGOCFS
+ printf("\n"); fflush(stdout);
+#endif
}
}
Modified: trunk/debugocfs/debugocfs.h
===================================================================
--- trunk/debugocfs/debugocfs.h 2004-05-24 22:11:27 UTC (rev 42)
+++ trunk/debugocfs/debugocfs.h 2004-05-29 00:43:15 UTC (rev 43)
@@ -75,6 +75,7 @@
{
ocfs_io_runs *array;
__u32 num;
+ __u64 off;
mode_t mode;
uid_t user;
gid_t group;
@@ -113,7 +114,7 @@
ocfs_super *get_fake_vcb(int fd, ocfs_vol_disk_hdr * hdr, int nodenum);
void walk_dir_nodes(int fd, __u64 offset, const char *parent, void *buf);
void find_file_entry(ocfs_super * vcb, __u64 offset, const char *parent,
- const char *searchFor, int mode, void *buf);
+ const char *searchFor, int mode, filedata *buf);
void traverse_fe_extents(ocfs_super * vcb, ocfs_file_entry *fe);
void traverse_extent(ocfs_super * vcb, ocfs_extent_group * exthdr, int flag);
Modified: trunk/debugocfs/io.c
===================================================================
--- trunk/debugocfs/io.c 2004-05-24 22:11:27 UTC (rev 42)
+++ trunk/debugocfs/io.c 2004-05-29 00:43:15 UTC (rev 43)
@@ -33,7 +33,46 @@
extern __u32 OcfsDebugCtxt;
extern __u32 OcfsDebugLevel;
+int myread(int file, char *buf, __u32 len)
+{
+ int ret = 0;
+ char *p = buf;
+ __u32 remlen = len;
+ while(remlen) {
+ ret = read(file, p, remlen);
+ if (ret == -1) {
+ printf("Failed to read: %s\n", strerror(errno));
+ goto bail;
+ }
+ remlen -= ret;
+ p += ret;
+ }
+
+bail:
+ return ret;
+}
+
+int mywrite(int file, char *buf, __u32 len)
+{
+ int ret = 0;
+ char *p = buf;
+ __u32 remlen = len;
+
+ while(remlen) {
+ ret = write(file, p, remlen);
+ if (ret == -1) {
+ printf("Failed to write: %s\n", strerror(errno));
+ goto bail;
+ }
+ remlen -= ret;
+ p += ret;
+ }
+
+bail:
+ return ret;
+}
+
loff_t myseek64(int fd, loff_t off, int whence)
{
loff_t res;
Modified: trunk/debugocfs/libdebugocfs.c
===================================================================
--- trunk/debugocfs/libdebugocfs.c 2004-05-24 22:11:27 UTC (rev 42)
+++ trunk/debugocfs/libdebugocfs.c 2004-05-29 00:43:15 UTC (rev 43)
@@ -104,7 +104,7 @@
{
int fd;
ocfs_vol_disk_hdr *diskHeader;
- __u64 off;
+ filedata fil;
ocfs_super *vcb;
if ((fd = libocfs_init(dev, &diskHeader, TRUE)) == -1)
@@ -118,17 +118,17 @@
return 2;
}
+ memset(&fil, 0, sizeof(filedata));
if (strcmp(dir, "/") == 0)
- off = diskHeader->root_off;
+ fil.off = diskHeader->root_off;
else
{
vcb = get_fake_vcb(fd, diskHeader, DEFAULT_NODE_NUMBER);
- find_file_entry(vcb, diskHeader->root_off, "/", dir, FIND_MODE_DIR,
- (void *) (&off));
+ find_file_entry(vcb, diskHeader->root_off, "/", dir, FIND_MODE_DIR, &fil);
free_aligned(vcb);
}
- if (off <= 0)
+ if (fil.off <= 0)
{
g_array_free(*arr, FALSE);
free_aligned(diskHeader);
@@ -136,7 +136,7 @@
return 3;
}
- walk_dir_nodes(fd, off, dir, (void *) (*arr));
+ walk_dir_nodes(fd, fil.off, dir, (void *) (*arr));
close(fd);
free_aligned(diskHeader);
More information about the Ocfs-tools-commits
mailing list