[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xfs_bmap & XML patch
Hi,
With this little change one can use
$ ./xfs_bmap -x ~/tmp/holes
<?xml version="1.0"?>
<extentlist>
<extent id="0" type="hole" blocks="192" file-offset-start="0" file-offset-end="191" >
</extent>
<extent id="1" blocks="8" file-offset-start="192" file-offset-end="199" allocation-group="2" allocation-offset-start="236328" allocation-offset-end="236335" >
</extent>
</extentlist>
So they can use XSLT to provide a Gtk+/HTML extent viewer
quite simply.
I'll probably play with some stuff for a nice extent viewer interface too
soon.
I was trying to abstract out the code doing
i = ioctl(fd, XFS_IOC_GETBMAPX, map);
but ran into the old problem of no exceptions in C. I have worked around
such problems in the past though it makes the code more complex than a
dump msg and exit() solution. I'll think more about a getExtents()
function in the next days and see if I can find an elegant solution to
it.
? config.status
? .census
? configure
? autom4te.cache
? config.log
? bmap/.libs
? bmap/xfs_bmap
? db/.libs
? db/xfs_db
? doc/CHANGES.gz
? freeze/.libs
? freeze/xfs_freeze
? fsck/.libs
? fsck/fsck.xfs
? growfs/.libs
? growfs/xfs_growfs
? imap/.libs
? imap/xfs_imap
? include/builddefs
? include/platform_defs.h
? libdisk/.libs
? libdisk/md.lo
? libdisk/fstype.lo
? libdisk/lvm.lo
? libdisk/mountinfo.lo
? libdisk/xvm.lo
? libdisk/drivers.lo
? libdisk/libdisk.la
? libdisk/pttype.lo
? libhandle/libhandle.la
? libhandle/.libs
? libhandle/jdm.lo
? libhandle/handle.lo
? libxfs/trans.lo
? libxfs/logitem.lo
? libxfs/.libs
? libxfs/rdwr.lo
? libxfs/xfs_dir2_node.lo
? libxfs/xfs_dir_leaf.lo
? libxfs/xfs_rtalloc.lo
? libxfs/libxfs.la
? libxfs/xfs_bmap_btree.lo
? libxfs/xfs_alloc_btree.lo
? libxfs/xfs_mount.lo
? libxfs/xfs_ialloc.lo
? libxfs/xfs_ialloc_btree.lo
? libxfs/xfs_btree.lo
? libxfs/xfs_da_btree.lo
? libxfs/xfs_bmap.lo
? libxfs/xfs_dir2_data.lo
? libxfs/xfs_attr_leaf.lo
? libxfs/xfs_alloc.lo
? libxfs/xfs_bit.lo
? libxfs/xfs_dir.lo
? libxfs/xfs_inode.lo
? libxfs/xfs_dir2_leaf.lo
? libxfs/xfs_dir2.lo
? libxfs/util.lo
? libxfs/xfs_dir2_block.lo
? libxfs/xfs_trans.lo
? libxfs/xfs_rtbit.lo
? libxfs/init.lo
? libxfs/xfs_dir2_sf.lo
? libxlog/.libs
? libxlog/xfs_log_recover.lo
? libxlog/util.lo
? libxlog/libxlog.la
? logprint/.libs
? logprint/xfs_logprint
? mkfile/.libs
? mkfile/xfs_mkfile
? mkfs/.libs
? mkfs/fstyp
? mkfs/maxtrres.h
? mkfs/maxtrres
? mkfs/mkfs.xfs
? repair/.libs
? repair/xfs_repair
? rtcp/.libs
? rtcp/xfs_rtcp
Index: configure.in
===================================================================
RCS file: /cvs/linux-2.4-xfs/cmd/xfsprogs/configure.in,v
retrieving revision 1.12
diff -u -3 -p -r1.12 configure.in
--- configure.in 2001/09/19 05:03:59 1.12
+++ configure.in 2002/02/11 14:13:04
@@ -232,6 +232,15 @@ dnl doc directory
pkg_doc_dir=${prefix}/share/doc/${pkg_name}
AC_SUBST(pkg_doc_dir)
+dnl see if some XML options are desired.
+AC_ARG_WITH(xmloutput,
+ [ --with-xmloutput Enable XML output options],
+ [
+ xmloutput_build=" -DENABLE_XML "
+ AC_SUBST(xmloutput_build)
+ echo enabled xml output
+ ])
+
dnl
dnl output files
Index: bmap/xfs_bmap.c
===================================================================
RCS file: /cvs/linux-2.4-xfs/cmd/xfsprogs/bmap/xfs_bmap.c,v
retrieving revision 1.5
diff -u -3 -p -r1.5 xfs_bmap.c
--- bmap/xfs_bmap.c 2002/01/11 04:01:45 1.5
+++ bmap/xfs_bmap.c 2002/02/11 14:13:04
@@ -43,6 +43,7 @@ int aflag = 0; /* Attribute fork. */
int lflag = 0; /* list number of blocks with each extent */
int nflag = 0; /* number of extents specified */
int vflag = 0; /* Verbose output */
+int xmlflag = 0; /* output in XML */
int bmv_iflags = 0; /* Input flags for XFS_IOC_GETBMAPX */
char *progname;
@@ -50,15 +51,69 @@ int dofile(char *);
__off64_t file_size(int fd, char * fname);
int numlen(__off64_t);
+static void
+perform_xml_output( struct getbmapx* map, __off64_t bbperag )
+{
+#ifdef ENABLE_XML
+ int i=0;
+
+ printf("<?xml version=\"1.0\"?>\n");
+ printf("<extentlist>\n");
+
+ for (i = 0; i < map->bmv_entries; i++)
+ {
+ if (map[i + 1].bmv_block == -1)
+ {
+ printf(" <extent id=\"%d\" type=\"%s\" blocks=\"%lld\"",
+ i, "hole", (long long)map[i+1].bmv_length);
+ printf(" file-offset-start=\"%lld\" file-offset-end=\"%lld\" ",
+ (long long) map[i + 1].bmv_offset,
+ (long long)(map[i + 1].bmv_offset +
+ map[i + 1].bmv_length - 1LL));
+ printf(" >\n");
+ printf("</extent>\n");
+ }
+ else
+ {
+
+ int agno = map[i + 1].bmv_block / bbperag;
+ int agoff = map[i + 1].bmv_block - (agno * bbperag);
+
+ printf(" <extent id=\"%d\" blocks=\"%lld\"",
+ i, (long long)map[i+1].bmv_length);
+ printf(" file-offset-start=\"%lld\" file-offset-end=\"%lld\" ",
+ (long long) map[i + 1].bmv_offset,
+ (long long)(map[i + 1].bmv_offset +
+ map[i + 1].bmv_length - 1LL));
+ printf(" allocation-group=\"%d\"", agno );
+ printf(" allocation-offset-start=\"%lld\"",
+ (long long)agoff );
+ printf(" allocation-offset-end=\"%lld\"",
+ (long long)(agoff + map[i + 1].bmv_length - 1LL));
+ printf(" >\n");
+ printf("</extent>\n");
+ }
+ }
+
+ printf("</extentlist>\n");
+#endif
+}
+
int
main(int argc, char **argv)
{
char *fname;
int i = 0;
int option;
-
+#ifdef ENABLE_XML
+ const char* getopt_options = "adln:pxvV";
+#else
+ const char* getopt_options = "adln:pvV";
+#endif
+
progname = basename(argv[0]);
- while ((option = getopt(argc, argv, "adln:pvV")) != EOF) {
+ while ((option = getopt(argc, argv, getopt_options)) != EOF)
+ {
switch (option) {
case 'a':
bmv_iflags |= BMV_IF_ATTRFORK;
@@ -84,10 +139,19 @@ main(int argc, char **argv)
case 'V':
printf("%s version %s\n", progname, VERSION);
break;
+#ifdef ENABLE_XML
+ case 'x':
+ xmlflag++;
+ break;
+#endif
+
default:
- fprintf(stderr, "Usage: %s [-adlpV] [-n nx] file...\n",
- progname);
- exit(1);
+#ifdef ENABLE_XML
+ fprintf(stderr, "Usage: %s [-adlpxV] [-n nx] file...\n", progname);
+#else
+ fprintf(stderr, "Usage: %s [-adlpV] [-n nx] file...\n", progname);
+#endif
+ exit(1);
}
}
if (aflag)
@@ -130,7 +194,12 @@ dofile(char *fname)
int map_size;
int loop = 0;
xfs_fsop_geom_t fsgeo;
-
+ /* extra info for xml or verbose output */
+ int agno=0;
+ __off64_t agoff=0, bbperag=0;
+ int foff_w=0, boff_w=0, aoff_w=0, tot_w=0, agno_w=0;
+ char rbuf[32], bbuf[32], abuf[32];
+
fd = open(fname, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "%s: cannot open \"%s\": %s\n",
@@ -146,7 +215,7 @@ dofile(char *fname)
return 1;
}
- if (vflag) {
+ if (vflag || xmlflag) {
if (ioctl(fd, XFS_IOC_FSGEOMETRY, &fsgeo) < 0) {
fprintf(stderr, "%s: can't get geometry [\"%s\"]: %s\n",
progname, fname, strerror(errno));
@@ -287,7 +356,29 @@ dofile(char *fname)
}
}
close(fd);
- printf("%s:\n", fname);
+
+ /* Get some more info for verbose output */
+ if( vflag || xmlflag )
+ {
+#define MINRANGE_WIDTH 16
+#define MINAG_WIDTH 2
+#define MINTOT_WIDTH 5
+#define max(a,b) (a > b ? a : b)
+
+ foff_w = boff_w = aoff_w = MINRANGE_WIDTH;
+ tot_w = MINTOT_WIDTH;
+ bbperag = (__off64_t)fsgeo.agblocks *
+ (__off64_t)fsgeo.blocksize / BBSIZE;
+ }
+
+
+ if( xmlflag )
+ {
+ perform_xml_output( map, bbperag );
+ exit(0);
+ }
+
+ printf("%s:\n", fname);
if (!vflag) {
for (i = 0; i < map->bmv_entries; i++) {
printf("\t%d: [%lld..%lld]: ", i,
@@ -314,19 +405,6 @@ dofile(char *fname)
* extent: [startoffset..endoffset]: startblock..endblock \
* ag# (agoffset..agendoffset) totalbbs
*/
-#define MINRANGE_WIDTH 16
-#define MINAG_WIDTH 2
-#define MINTOT_WIDTH 5
-#define max(a,b) (a > b ? a : b)
- int agno;
- __off64_t agoff, bbperag;
- int foff_w, boff_w, aoff_w, tot_w, agno_w;
- char rbuf[32], bbuf[32], abuf[32];
-
- foff_w = boff_w = aoff_w = MINRANGE_WIDTH;
- tot_w = MINTOT_WIDTH;
- bbperag = (__off64_t)fsgeo.agblocks *
- (__off64_t)fsgeo.blocksize / BBSIZE;
/*
* Go through the extents and figure out the width
Index: include/builddefs.in
===================================================================
RCS file: /cvs/linux-2.4-xfs/cmd/xfsprogs/include/builddefs.in,v
retrieving revision 1.18
diff -u -3 -p -r1.18 builddefs.in
--- include/builddefs.in 2001/10/17 11:00:32 1.18
+++ include/builddefs.in 2002/02/11 14:13:04
@@ -91,7 +91,8 @@ BUILDRULES = $(TOPDIR)/include/buildrule
CFLAGS += -O1 $(OPTIMIZER) $(DEBUG) -funsigned-char -Wall $(LCFLAGS) \
-I$(TOPDIR)/include '-DVERSION="$(PKG_VERSION)"' -D_GNU_SOURCE \
- -D_FILE_OFFSET_BITS=64 -DXFS_BIG_FILES=1 -DXFS_BIG_FILESYSTEMS=1
+ -D_FILE_OFFSET_BITS=64 -DXFS_BIG_FILES=1 -DXFS_BIG_FILESYSTEMS=1 \
+ @xmloutput_build@
LDFLAGS = $(LLDFLAGS)
LDLIBS = $(LLDLIBS) $(MALLOCLIB)
--
-----------------------------------------------------
http://witme.sourceforge.net/libferris.web/