--- ../fsys_xfs.c 2010-11-16 11:23:01.560322529 +0100 +++ tools/libfsimage/xfs/fsys_xfs.c 2010-11-26 10:39:42.000000000 +0100 @@ -18,10 +18,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef FSYS_XFS - -#include "shared.h" -#include "filesys.h" +#include +#include #include "xfs.h" #define MAX_LINK_COUNT 8 @@ -97,7 +95,7 @@ return ino & XFS_INO_MASK(XFS_INO_OFFSET_BITS); } -static inline __const__ xfs_uint16_t +static inline xfs_uint16_t le16 (xfs_uint16_t x) { __asm__("xchgb %b0,%h0" \ @@ -106,7 +104,7 @@ return x; } -static inline __const__ xfs_uint32_t +static inline xfs_uint32_t le32 (xfs_uint32_t x) { #if 0 @@ -122,7 +120,7 @@ return x; } -static inline __const__ xfs_uint64_t +static inline xfs_uint64_t le64 (xfs_uint64_t x) { xfs_uint32_t h = x >> 32; @@ -187,10 +185,10 @@ } #undef offsetof -#define offsetof(t,m) ((int)&(((t *)0)->m)) +#define offsetof(t,m) ((size_t)&(((t *)0)->m)) static inline int -btroot_maxrecs (void) +btroot_maxrecs (fsi_file_t *ffi) { int tmp = icore.di_forkoff ? (icore.di_forkoff << 3) : xfs.isize; @@ -199,7 +197,7 @@ } static int -di_read (xfs_ino_t ino) +di_read (fsi_file_t *ffi, xfs_ino_t ino) { xfs_agino_t agino; xfs_agnumber_t agno; @@ -213,17 +211,17 @@ offset = ino2offset (ino); daddr = agb2daddr (agno, agbno); - devread (daddr, offset*xfs.isize, xfs.isize, (char *)inode); + devread (ffi, daddr, offset*xfs.isize, xfs.isize, (char *)inode); xfs.ptr0 = *(xfs_bmbt_ptr_t *) (inode->di_u.di_c + sizeof(xfs_bmdr_block_t) - + btroot_maxrecs ()*sizeof(xfs_bmbt_key_t)); + + btroot_maxrecs (ffi)*sizeof(xfs_bmbt_key_t)); return 1; } static void -init_extents (void) +init_extents (fsi_file_t *ffi) { xfs_bmbt_ptr_t ptr0; xfs_btree_lblock_t h; @@ -237,7 +235,7 @@ ptr0 = xfs.ptr0; for (;;) { xfs.daddr = fsb2daddr (le64(ptr0)); - devread (xfs.daddr, 0, + devread (ffi, xfs.daddr, 0, sizeof(xfs_btree_lblock_t), (char *)&h); if (!h.bb_level) { xfs.nextents = le16(h.bb_numrecs); @@ -245,14 +243,14 @@ xfs.fpos = sizeof(xfs_btree_block_t); return; } - devread (xfs.daddr, xfs.btnode_ptr0_off, + devread (ffi, xfs.daddr, xfs.btnode_ptr0_off, sizeof(xfs_bmbt_ptr_t), (char *)&ptr0); } } } static xad_t * -next_extent (void) +next_extent (fsi_file_t *ffi) { static xad_t xad; @@ -267,13 +265,13 @@ if (xfs.next == 0) return NULL; xfs.daddr = xfs.next; - devread (xfs.daddr, 0, sizeof(xfs_btree_lblock_t), (char *)&h); + devread (ffi, xfs.daddr, 0, sizeof(xfs_btree_lblock_t), (char *)&h); xfs.nextents = le16(h.bb_numrecs); xfs.next = fsb2daddr (le64(h.bb_rightsib)); xfs.fpos = sizeof(xfs_btree_block_t); } /* Yeah, I know that's slow, but I really don't care */ - devread (xfs.daddr, xfs.fpos, sizeof(xfs_bmbt_rec_t), filebuf); + devread (ffi, xfs.daddr, xfs.fpos, sizeof(xfs_bmbt_rec_t), filebuf); xfs.xt = (xfs_bmbt_rec_32_t *)filebuf; xfs.fpos += sizeof(xfs_bmbt_rec_32_t); } @@ -290,16 +288,16 @@ * Name lies - the function reads only first 100 bytes */ static void -xfs_dabread (void) +xfs_dabread (fsi_file_t *ffi) { xad_t *xad; xfs_fileoff_t offset;; - init_extents (); - while ((xad = next_extent ())) { + init_extents (ffi); + while ((xad = next_extent (ffi))) { offset = xad->offset; if (isinxt (xfs.dablk, offset, xad->len)) { - devread (fsb2daddr (xad->start + xfs.dablk - offset), + devread (ffi, fsb2daddr (xad->start + xfs.dablk - offset), 0, 100, dirbuf); break; } @@ -316,7 +314,7 @@ } static inline xfs_ino_t -sf_parent_ino (void) +sf_parent_ino (fsi_file_t *ffi) { return (xfs.i8param == 0) ? le64(*(xfs_ino_t *)(&inode->di_u.di_dir2sf.hdr.parent)) @@ -329,8 +327,11 @@ return ((n+7)&~7); } +static int +xfs_read (fsi_file_t *ffi, char *buf, int len); + static char * -next_dentry (xfs_ino_t *ino) +next_dentry (fsi_file_t *ffi, xfs_ino_t *ino) { int namelen = 1; int toread; @@ -342,7 +343,7 @@ if (xfs.forw == 0) return NULL; xfs.dablk = xfs.forw; - xfs_dabread (); + xfs_dabread (ffi); #define h ((xfs_dir2_leaf_hdr_t *)dirbuf) xfs.dirmax = le16 (h->count) - le16 (h->stale); xfs.forw = le32 (h->info.forw); @@ -357,7 +358,7 @@ *ino = 0; break; case -1: - *ino = sf_parent_ino (); + *ino = sf_parent_ino (ffi); ++name; ++namelen; sfe = (xfs_dir2_sf_entry_t *) @@ -368,7 +369,7 @@ default: namelen = sfe->namelen; *ino = sf_ino ((char *)sfe, namelen); - name = sfe->name; + name = (char *)sfe->name; sfe = (xfs_dir2_sf_entry_t *) ((char *)sfe + namelen + 11 - xfs.i8param); } @@ -382,7 +383,7 @@ filepos &= ~(xfs.dirbsize - 1); filepos |= xfs.blkoff; } - xfs_read (dirbuf, 4); + xfs_read (ffi, dirbuf, 4); xfs.blkoff += 4; if (dau->unused.freetag == XFS_DIR2_DATA_FREE_TAG) { toread = roundup8 (le16(dau->unused.length)) - 4; @@ -392,12 +393,12 @@ } break; } - xfs_read ((char *)dirbuf + 4, 5); + xfs_read (ffi, (char *)dirbuf + 4, 5); *ino = le64 (dau->entry.inumber); namelen = dau->entry.namelen; #undef dau toread = roundup8 (namelen + 11) - 9; - xfs_read (dirbuf, toread); + xfs_read (ffi, dirbuf, toread); name = (char *)dirbuf; xfs.blkoff += toread + 5; } @@ -408,7 +409,7 @@ } static char * -first_dentry (xfs_ino_t *ino) +first_dentry (fsi_file_t *ffi, xfs_ino_t *ino) { xfs.forw = 0; switch (icore.di_format) { @@ -420,11 +421,11 @@ case XFS_DINODE_FMT_EXTENTS: case XFS_DINODE_FMT_BTREE: filepos = 0; - xfs_read (dirbuf, sizeof(xfs_dir2_data_hdr_t)); + xfs_read (ffi, dirbuf, sizeof(xfs_dir2_data_hdr_t)); if (((xfs_dir2_data_hdr_t *)dirbuf)->magic == le32(XFS_DIR2_BLOCK_MAGIC)) { #define tail ((xfs_dir2_block_tail_t *)dirbuf) filepos = xfs.dirbsize - sizeof(*tail); - xfs_read (dirbuf, sizeof(*tail)); + xfs_read (ffi, dirbuf, sizeof(*tail)); xfs.dirmax = le32 (tail->count) - le32 (tail->stale); #undef tail } else { @@ -432,7 +433,7 @@ #define h ((xfs_dir2_leaf_hdr_t *)dirbuf) #define n ((xfs_da_intnode_t *)dirbuf) for (;;) { - xfs_dabread (); + xfs_dabread (ffi); if ((n->hdr.info.magic == le16(XFS_DIR2_LEAFN_MAGIC)) || (n->hdr.info.magic == le16(XFS_DIR2_LEAF1_MAGIC))) { xfs.dirmax = le16 (h->count) - le16 (h->stale); @@ -448,15 +449,15 @@ filepos = xfs.blkoff; xfs.dirpos = 0; } - return next_dentry (ino); + return next_dentry (ffi, ino); } -int -xfs_mount (void) +static int +xfs_mount (fsi_file_t *ffi, const char *options) { xfs_sb_t super; - if (!devread (0, 0, sizeof(super), (char *)&super) + if (!devread (ffi, 0, 0, sizeof(super), (char *)&super) || (le32(super.sb_magicnum) != XFS_SB_MAGIC) || ((le16(super.sb_versionnum) & XFS_SB_VERSION_NUMBITS) != XFS_SB_VERSION_4) ) { @@ -483,8 +484,8 @@ return 1; } -int -xfs_read (char *buf, int len) +static int +xfs_read (fsi_file_t *ffi, char *buf, int len) { xad_t *xad; xfs_fileoff_t endofprev, endofcur, offset; @@ -500,8 +501,8 @@ startpos = filepos; endpos = filepos + len; endofprev = (xfs_fileoff_t)-1; - init_extents (); - while (len > 0 && (xad = next_extent ())) { + init_extents (ffi); + while (len > 0 && (xad = next_extent (ffi))) { offset = xad->offset; xadlen = xad->len; if (isinxt (filepos >> xfs.blklog, offset, xadlen)) { @@ -510,7 +511,7 @@ ? len : (endofcur - filepos); disk_read_func = disk_read_hook; - devread (fsb2daddr (xad->start), + devread (ffi, fsb2daddr (xad->start), filepos - (offset << xfs.blklog), toread, buf); disk_read_func = NULL; @@ -533,8 +534,8 @@ return filepos - startpos; } -int -xfs_dir (char *dirname) +static int +xfs_dir (fsi_file_t *ffi, char *dirname) { xfs_ino_t ino, parent_ino, new_ino; xfs_fsize_t di_size; @@ -546,7 +547,7 @@ parent_ino = ino = xfs.rootino; link_count = 0; for (;;) { - di_read (ino); + di_read (ffi, ino); di_size = le64 (icore.di_size); di_mode = le16 (icore.di_mode); @@ -558,7 +559,7 @@ if (di_size < xfs.bsize - 1) { filepos = 0; filemax = di_size; - n = xfs_read (linkbuf, filemax); + n = xfs_read (ffi, linkbuf, filemax); } else { errnum = ERR_FILELENGTH; return 0; @@ -591,7 +592,7 @@ for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++); *rest = 0; - name = first_dentry (&new_ino); + name = first_dentry (ffi, &new_ino); for (;;) { cmp = (!*dirname) ? -1 : substring (dirname, name); #ifndef STAGE1_5 @@ -608,7 +609,7 @@ *(dirname = rest) = ch; break; } - name = next_dentry (&new_ino); + name = next_dentry (ffi, &new_ino); if (name == NULL) { if (print_possibilities < 0) return 1; @@ -621,4 +622,16 @@ } } -#endif /* FSYS_XFS */ +fsi_plugin_ops_t * +fsi_init_plugin(int version, fsi_plugin_t *fp, const char **name) +{ + static fsig_plugin_ops_t ops = { + FSIMAGE_PLUGIN_VERSION, + .fpo_mount = xfs_mount, + .fpo_dir = xfs_dir, + .fpo_read = xfs_read + }; + + *name = "xfs"; + return (fsig_init(fp, &ops)); +}