>From d0c201cf35b76bbebebd96fb2de4e8f2f0dffa6f Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Wed, 5 Jan 2011 12:02:29 +0100 Subject: [PATCH 2/7] Initial porting to libfsimage's devread --- Makefile | 13 ++++++++ fsys_xfs.c | 99 ++++++++++++++++++++++++++++++++--------------------------- 2 files changed, 67 insertions(+), 45 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..99ed1ba --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +XEN_ROOT = ../../.. + +LIB_SRCS-y = fsys_xfs.c + +FS = xfs + +.PHONY: all +all: fs-all + +.PHONY: install +install: fs-install + +include $(XEN_ROOT)/tools/libfsimage/Rules.mk diff --git a/fsys_xfs.c b/fsys_xfs.c index 76c4c13..043af2f 100644 --- a/fsys_xfs.c +++ b/fsys_xfs.c @@ -18,10 +18,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef FSYS_XFS - -#include "shared.h" -#include "filesys.h" +#include #include "xfs.h" #define MAX_LINK_COUNT 8 @@ -190,7 +187,7 @@ fsb2daddr (xfs_fsblock_t fsbno) #define offsetof(t,m) ((int)&(((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 +196,7 @@ btroot_maxrecs (void) } 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 +210,17 @@ di_read (xfs_ino_t ino) 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 +234,7 @@ init_extents (void) 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 +242,14 @@ init_extents (void) 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 +264,13 @@ next_extent (void) 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 +287,16 @@ next_extent (void) * 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 +313,7 @@ sf_ino (char *sfe, int namelen) } 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)) @@ -330,7 +327,7 @@ roundup8 (int n) } 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 +339,7 @@ next_dentry (xfs_ino_t *ino) 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 +354,7 @@ next_dentry (xfs_ino_t *ino) *ino = 0; break; case -1: - *ino = sf_parent_ino (); + *ino = sf_parent_ino (ffi); ++name; ++namelen; sfe = (xfs_dir2_sf_entry_t *) @@ -382,7 +379,7 @@ next_dentry (xfs_ino_t *ino) 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 +389,12 @@ next_dentry (xfs_ino_t *ino) } 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 +405,7 @@ next_dentry (xfs_ino_t *ino) } 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 +417,11 @@ first_dentry (xfs_ino_t *ino) 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 +429,7 @@ first_dentry (xfs_ino_t *ino) #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 +445,15 @@ first_dentry (xfs_ino_t *ino) 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 +480,8 @@ xfs_mount (void) 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 +497,8 @@ xfs_read (char *buf, int len) 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 +507,7 @@ xfs_read (char *buf, int len) ? 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 +530,8 @@ xfs_read (char *buf, int len) 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 +543,7 @@ xfs_dir (char *dirname) 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 +555,7 @@ xfs_dir (char *dirname) 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 +588,7 @@ xfs_dir (char *dirname) 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 +605,7 @@ xfs_dir (char *dirname) *(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 +618,16 @@ xfs_dir (char *dirname) } } -#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)); +} -- 1.7.2.3