home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / src / linux-headers-2.6.17-6 / include / linux / gfs_ondisk.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-11  |  53.5 KB  |  1,900 lines

  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
  5. **  Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
  6. **
  7. **  This copyrighted material is made available to anyone wishing to use,
  8. **  modify, copy, or redistribute it subject to the terms and conditions
  9. **  of the GNU General Public License v.2.
  10. **
  11. *******************************************************************************
  12. ******************************************************************************/
  13.  
  14. /*
  15.  * On-disk structures.
  16.  *
  17.  * THE BIG PICTURE of on-disk layout:
  18.  *
  19.  * GFS filesystem code views the entire filesystem, including journals, as
  20.  * one contiguous group of blocks on one (perhaps virtual) storage device.
  21.  * The filesystem space is shared, not distributed; each node in the cluster
  22.  * must see the entire filesystem space.
  23.  *
  24.  * If the filesystem is spread across multiple physical storage devices,
  25.  * volume management (device mapping) must be used to present the fileystem
  26.  * space to GFS as one (virtual) device, with contiguous blocks.
  27.  *
  28.  * The superblock contains basic information about the filesytem, and appears
  29.  * at a location 64 KBytes into the filesystem.  The first 64 KBytes of the
  30.  * filesystem are empty, providing a safety buffer against wayward volume
  31.  * management software (that sometimes write data into the first few bytes of
  32.  * a device) or administrators.
  33.  *
  34.  * After the superblock, the rest of the filesystem is divided into multiple
  35.  * Resource Groups and several journals.
  36.  *
  37.  * The Resource Groups (RGs or rgrps) contain the allocatable blocks that are
  38.  * used for storing files, directories, etc., and all of the associated
  39.  * metadata.  Each RG has its own set of block allocation statistics (within
  40.  * the RG header), a number of blocks containing the block allocation bitmap,
  41.  * and a large number of allocatable blocks for file data and metadata.
  42.  * Multiple RGs allow multiple nodes to simultaneously allocate blocks from the 
  43.  * filesystem (using different RGs), enhancing parallel access.  RG size and
  44.  * number of RGs are determined by gfs_mkfs when creating the filesystem.
  45.  * An administrator can specify RG size (see man gfs_mkfs).
  46.  *
  47.  * The journals contain temporary copies of metadata blocks, along with
  48.  * other data, that allow GFS to recover the filesystem to a consistent state
  49.  * (at least as far as metadata is concerned) if a node fails in the midst
  50.  * of performing a write transaction.  There must be one journal for each node
  51.  * in the cluster.  Since access to the entire filesystem space is shared,
  52.  * if a node crashes, another node will be able to read the crashed node's
  53.  * journal, and perform recovery.
  54.  *
  55.  * Currently, gfs_mkfs places the journals right in the middle of a freshly
  56.  * created filesystem space, between 2 large groups of RGs.  From a filesystem
  57.  * layout perspective, this placement is not a requirement; the journals
  58.  * could be placed anywhere within the filesystem space.
  59.  *
  60.  * New Resource Groups and Journals may be added to the filesystem after the
  61.  * filesystem has been created, if the filesystem's (virtual) device is made
  62.  * larger.  See man gfs_grow and gfs_jadd.
  63.  *
  64.  * A few special hidden inodes are contained in a GFS filesystem.  They do
  65.  * not appear in any directories; instead, the superblock points to them
  66.  * using block numbers for their location.  The special inodes are:
  67.  *
  68.  *   Root inode:  Root directory of the filesystem
  69.  *   Resource Group Index:  A file containing block numbers and sizes of all RGs
  70.  *   Journal Index:  A file containing block numbers and sizes of all journals
  71.  *   Quota:  A file containing all quota information for the filesystem
  72.  *   License:  A file containing license information
  73.  *
  74.  * Note that there is NOTHING RELATED TO INTER-NODE LOCK MANAGEMENT ON-DISK.
  75.  * Locking is handled completely off-disk, typically via LAN.
  76.  *
  77.  * NOTE:
  78.  * If you add 8 byte fields to these structures, they must be 8 byte
  79.  * aligned.  4 byte field must be 4 byte aligned, etc...
  80.  *
  81.  * All structures must be a multiple of 8 bytes long.
  82.  *
  83.  * GRIPES:
  84.  * We should have forgetten about supporting 512B FS block sizes 
  85.  * and made the di_reserved field in the struct gfs_dinode structure
  86.  * much bigger.
  87.  *
  88.  * de_rec_len in struct gfs_dirent should really have been a 32-bit value
  89.  * as it now limits us to a 64k FS block size (with the current code
  90.  * in dir.c).
  91.  */
  92.  
  93. #ifndef __GFS_ONDISK_DOT_H__
  94. #define __GFS_ONDISK_DOT_H__
  95.  
  96. #define GFS_MAGIC               (0x01161970) /* for all on-disk headers */
  97. #define GFS_BASIC_BLOCK         (512)  /* "basic block" = "sector" = 512B */
  98. #define GFS_BASIC_BLOCK_SHIFT   (9)
  99.  
  100. /*  Controls how much data can be logged in-core before dumping log to disk */
  101.  
  102. #define GFS_DUMPS_PER_LOG       (4)    /* 1/4 of on-disk journal size*/
  103.  
  104. /*  Lock numbers of the LM_TYPE_NONDISK type.  These protect certain
  105.  *  cluster-wide operations (rather than on-disk entities).
  106.  *  Currently, the LIVE lock is not used for any real purpose.  */
  107.  
  108. #define GFS_MOUNT_LOCK          (0)    /* only one node can Mount at a time */
  109. #define GFS_LIVE_LOCK           (1)    /* shared by all mounted nodes */
  110. #define GFS_TRANS_LOCK          (2)    /* Transaction, protects jrnl recovery */
  111. #define GFS_RENAME_LOCK         (3)    /* only one node can Rename at a time */
  112.  
  113. /*  On-disk format (version) numbers for various metadata types,
  114.  *  used in gfs_meta_header  */
  115.  
  116. #define GFS_FORMAT_SB           (100)  /* Super-Block */
  117. #define GFS_FORMAT_RG           (200)  /* Resource Group Header */
  118. #define GFS_FORMAT_RB           (300)  /* Resource Group Block Alloc BitBlock */
  119. #define GFS_FORMAT_DI           (400)  /* "Disk" inode (dinode) */
  120. #define GFS_FORMAT_IN           (500)  /* Indirect dinode block list */
  121. #define GFS_FORMAT_LF           (600)  /* Leaf dinode block list */
  122. #define GFS_FORMAT_JD           (700)  /* Journal Data */
  123. #define GFS_FORMAT_LH           (800)  /* Log Header */
  124. #define GFS_FORMAT_LD           (900)  /* Log Descriptor */
  125. /*  These don't have actual struct gfs_meta_header structures to go with them */
  126. #define GFS_FORMAT_JI           (1000) /* Journal Index */
  127. #define GFS_FORMAT_RI           (1100) /* Resource Group Index */
  128. #define GFS_FORMAT_DE           (1200) /* Directory Entry */
  129. #define GFS_FORMAT_QU           (1500) /* Quota */
  130. #define GFS_FORMAT_EA           (1600) /* Extended Attribute */
  131. #define GFS_FORMAT_ED           (1700) /* Extended Attribute data */
  132. /*  These version #s are embedded in the superblock  */
  133. #define GFS_FORMAT_FS           (1309) /* Filesystem (all-encompassing) */
  134. #define GFS_FORMAT_MULTI        (1401) /* Multi-Host */
  135.  
  136. /*
  137.  *  An on-disk inode number
  138.  *  Initially, the on-disk block address of the inode block is assigned as the
  139.  *  formal (permanent) ID as well.  Block address can change (to move inode
  140.  *  on-disk), but formal ID must stay unchanged once assigned.
  141.  */
  142.  
  143. #define gfs_inum_equal(ino1, ino2) \
  144. (((ino1)->no_formal_ino == (ino2)->no_formal_ino) && \
  145.  ((ino1)->no_addr == (ino2)->no_addr))
  146.  
  147. struct gfs_inum {
  148.     uint64_t no_formal_ino;        /* inode identifier */
  149.     uint64_t no_addr;              /* block # of dinode block */
  150. };
  151.  
  152. /*
  153.  *  Generic metadata head structure
  154.  *
  155.  *  Every inplace buffer logged in the journal must start
  156.  *  with a struct gfs_meta_header.
  157.  *
  158.  *  In addition to telling what kind of metadata is in the block,
  159.  *  the metaheader contains the important generation and incarnation
  160.  *  numbers.
  161.  *
  162.  *  The generation number is used during journal recovery to determine
  163.  *  whether an in-place block on-disk is older than an on-disk journaled copy
  164.  *  of the block.  If so, GFS overwrites the in-place block with the journaled
  165.  *  version of the block.
  166.  *
  167.  *  A meta block's generation number must increment monotonically across the
  168.  *  cluster, each time new contents are committed to the block.  This means
  169.  *  that whenever GFS allocates a pre-existing metadata block, GFS must read
  170.  *  that block from disk (in case another node has incremented it).  It also
  171.  *  means that GFS must sync the block (with incremented generation number)
  172.  *  to disk (both log and in-place blocks), not only after changing contents
  173.  *  of the block, but also after de-allocating the block (GFS can't just throw
  174.  *  away incore metadata for a file that it's just erased).
  175.  *
  176.  *  The incarnation number is used only for on-disk (d)inodes.  GFS increments
  177.  *  it each time it de-allocates a dinode block (i.e. each time the dinode
  178.  *  loses its identity with a particular file, directory, etc.).  When the
  179.  *  dinode is later allocated (i.e. to be identified with a new file, etc.),
  180.  *  GFS copies the incarnation number into the VFS inode's i_generation member.
  181.  *  If GFS is used as the backing store for an NFS server, GFS uses this
  182.  *  i_generation number as part of the NFS filehandle, which differentiates
  183.  *  it from the previous identity of the dinode, and helps protect against
  184.  *  filesystem corruption that could happen with the use of outdated,
  185.  *  invalid, or malicious filehandles.  See ops_export.c.
  186.  *
  187.  *  GFS caches de-allocated meta-headers, to minimize disk reads.
  188.  *  See struct gfs_meta_header_cache.
  189.  */
  190.  
  191. #define GFS_METATYPE_NONE       (0)
  192. #define GFS_METATYPE_SB         (1)    /* Super-Block */
  193. #define GFS_METATYPE_RG         (2)    /* Resource Group Header */
  194. #define GFS_METATYPE_RB         (3)    /* Resource Group Block Alloc BitBlock */
  195. #define GFS_METATYPE_DI         (4)    /* "Disk" inode (dinode) */
  196. #define GFS_METATYPE_IN         (5)    /* Indirect dinode block list */
  197. #define GFS_METATYPE_LF         (6)    /* Leaf dinode block list */
  198. #define GFS_METATYPE_JD         (7)    /* Journal Data */
  199. #define GFS_METATYPE_LH         (8)    /* Log Header (gfs_log_header) */
  200. #define GFS_METATYPE_LD         (9)    /* Log Descriptor (gfs_log_descriptor) */
  201. #define GFS_METATYPE_EA         (10)   /* Extended Attribute */
  202. #define GFS_METATYPE_ED         (11)   /* Extended Attribute data */
  203.  
  204. #define GFS_META_CLUMP          (64)   /* # blocks to convert fm data to meta */
  205.  
  206. struct gfs_meta_header {
  207.     uint32_t mh_magic;      /* GFS_MAGIC sanity check magic number */
  208.     uint32_t mh_type;       /* GFS_METATYPE_XX type of metadata block */
  209.     uint64_t mh_generation; /* increment before writing to journal */
  210.     uint32_t mh_format;     /* GFS_FORMAT_XX (version # for this type) */
  211.     uint32_t mh_incarn;     /* increment when marking dinode "unused" */
  212. };
  213.  
  214. /*
  215.  *  super-block structure
  216.  *
  217.  *  One of these is at beginning of filesystem.
  218.  *  It's probably good if SIZEOF_SB <= GFS_BASIC_BLOCK (512 bytes)
  219.  */
  220.  
  221. /*  Address of SuperBlock in GFS basic blocks.  1st 64K of filesystem is empty
  222.     for safety against getting clobbered by wayward volume managers, etc.
  223.     64k was chosen because it's the largest GFS-supported fs block size.  */
  224. #define GFS_SB_ADDR             (128)
  225.  
  226. /*  The lock number for the superblock (must be zero)  */
  227. #define GFS_SB_LOCK             (0)
  228. #define GFS_CRAP_LOCK           (1)
  229.  
  230. /*  Requirement:  GFS_LOCKNAME_LEN % 8 == 0
  231.     Includes: the fencing zero at the end  */
  232. #define GFS_LOCKNAME_LEN        (64)
  233.  
  234. struct gfs_sb {
  235.     /*  Order is important; need to be able to read old superblocks
  236.         in order to support on-disk version upgrades */
  237.     struct gfs_meta_header sb_header;
  238.  
  239.     uint32_t sb_fs_format;         /* GFS_FORMAT_FS (on-disk version) */
  240.     uint32_t sb_multihost_format;  /* GFS_FORMAT_MULTI */
  241.     uint32_t sb_flags;             /* ?? */
  242.  
  243.     uint32_t sb_bsize;             /* fundamental FS block size in bytes */
  244.     uint32_t sb_bsize_shift;       /* log2(sb_bsize) */
  245.     uint32_t sb_seg_size;          /* Journal segment size in FS blocks */
  246.  
  247.     /* These special inodes do not appear in any on-disk directory. */
  248.     struct gfs_inum sb_jindex_di;  /* journal index inode */
  249.     struct gfs_inum sb_rindex_di;  /* resource group index inode */
  250.     struct gfs_inum sb_root_di;    /* root directory inode */
  251.  
  252.     /* Default inter-node locking protocol (lock module) and namespace */
  253.     char sb_lockproto[GFS_LOCKNAME_LEN]; /* lock protocol name */
  254.     char sb_locktable[GFS_LOCKNAME_LEN]; /* unique name for this FS */
  255.  
  256.     /* More special inodes */
  257.     struct gfs_inum sb_quota_di;   /* quota inode */
  258.     struct gfs_inum sb_license_di; /* license inode */
  259.  
  260.     char sb_reserved[96];
  261. };
  262.  
  263. /*
  264.  *  journal index structure 
  265.  *
  266.  *  One for each journal used by the filesystem.
  267.  *  These descriptors are packed contiguously within the jindex inode (file).
  268.  */
  269.  
  270. struct gfs_jindex {
  271.     uint64_t ji_addr;       /* starting block of the journal */
  272.     uint32_t ji_nsegment;   /* number (quantity) of segments in journal */
  273.     uint32_t ji_pad;
  274.  
  275.     char ji_reserved[64];
  276. };
  277.  
  278. /*
  279.  *  resource index structure 
  280.  *
  281.  *  One of these for each resource group in the filesystem.
  282.  *  These descriptors are packed contiguously within the rindex inode (file).
  283.  *  Also see struct gfs_rgrp.
  284.  */
  285.  
  286. struct gfs_rindex {
  287.     uint64_t ri_addr;     /* block # of 1st block (header) in rgrp */
  288.     uint32_t ri_length;   /* # fs blocks containing rgrp header & bitmap */
  289.     uint32_t ri_pad;
  290.  
  291.     uint64_t ri_data1;    /* block # of first data/meta block in rgrp */
  292.     uint32_t ri_data;     /* number (qty) of data/meta blocks in rgrp */
  293.  
  294.     uint32_t ri_bitbytes; /* total # bytes used by block alloc bitmap */
  295.  
  296.     char ri_reserved[64];
  297. };
  298.  
  299. /*
  300.  *  resource group header structure
  301.  *
  302.  *  One of these at beginning of the first block of an rgrp,
  303.  *     followed by block alloc bitmap data in remainder of first block.
  304.  *  Each resource group contains:
  305.  *    Header block, including block allocation statistics (struct gfs_rgrp)
  306.  *       and first part of block alloc bitmap.
  307.  *    Bitmap block(s), continuing block alloc bitmap started in header block.
  308.  *    Data/meta blocks, allocatable blocks containing file data and metadata.
  309.  *  
  310.  *  In older versions, now-unused (but previously allocated) dinodes were
  311.  *  saved for re-use in an on-disk linked list (chain).  This is no longer
  312.  *  done, but support still exists for reclaiming dinodes from this list,
  313.  *  to support upgrades from older on-disk formats.
  314.  */
  315.  
  316. /* Each data block within rgrp is represented by 2 bits in the alloc bitmap */
  317. #define GFS_NBBY                (4)  /* # blocks represented by 1 bitmap byte */
  318. #define GFS_BIT_SIZE            (2)
  319. #define GFS_BIT_MASK            (0x00000003)
  320.  
  321. /*
  322.  * 4 possible block allocation states:
  323.  *   bit 0 = alloc(1)/free(0)
  324.  *   bit 1 = metadata(1)/data(0)
  325.  */
  326. #define GFS_BLKST_FREE          (0)
  327. #define GFS_BLKST_USED          (1)
  328. #define GFS_BLKST_FREEMETA      (2)
  329. #define GFS_BLKST_USEDMETA      (3)
  330.  
  331. struct gfs_rgrp {
  332.     struct gfs_meta_header rg_header;
  333.  
  334.     uint32_t rg_flags;      /* ?? */
  335.  
  336.     uint32_t rg_free;       /* Number (qty) of free data blocks */
  337.  
  338.     /* Dinodes are USEDMETA, but are handled separately from other METAs */
  339.     uint32_t rg_useddi;     /* Number (qty) of dinodes (used or free) */
  340.     uint32_t rg_freedi;     /* Number (qty) of unused (free) dinodes */
  341.     struct gfs_inum rg_freedi_list; /* 1st block in chain of free dinodes */
  342.  
  343.     /* These META statistics do not include dinodes (used or free) */
  344.     uint32_t rg_usedmeta;   /* Number (qty) of used metadata blocks */
  345.     uint32_t rg_freemeta;   /* Number (qty) of unused metadata blocks */
  346.  
  347.     char rg_reserved[64];
  348. };
  349.  
  350. /*
  351.  *  quota structure
  352.  */
  353.  
  354. struct gfs_quota {
  355.     uint64_t qu_limit;
  356.     uint64_t qu_warn;
  357.     int64_t qu_value;
  358.  
  359.     char qu_reserved[64];
  360. };
  361.  
  362. /*
  363.  *  dinode (disk inode) structure
  364.  *  The ondisk representation of inodes
  365.  *  One for each file, directory, etc.
  366.  *  GFS does not put more than one inode in a single block.
  367.  *  The inode may be "stuffed", carrying file data along with metadata,
  368.  *    if the file data is small enough.
  369.  *  Otherwise, the inode block contains pointers to other blocks that contain
  370.  *    either file data or other pointers to other blocks (indirect addressing
  371.  *    via a metadata tree).
  372.  */
  373.  
  374. #define GFS_MAX_META_HEIGHT     (10)
  375. #define GFS_DIR_MAX_DEPTH       (17)
  376.  
  377. /*  Dinode types  */
  378. #define GFS_FILE_NON            (0)
  379. #define GFS_FILE_REG            (1)    /* regular file */
  380. #define GFS_FILE_DIR            (2)    /* directory */
  381. #define GFS_FILE_LNK            (5)    /* link */
  382. #define GFS_FILE_BLK            (7)    /* block device node */
  383. #define GFS_FILE_CHR            (8)    /* character device node */
  384. #define GFS_FILE_FIFO           (101)  /* fifo/pipe */
  385. #define GFS_FILE_SOCK           (102)  /* socket */
  386.  
  387. /*  Dinode flags  */
  388. #define GFS_DIF_JDATA             (0x00000001) /* jrnl all data for this file */
  389. #define GFS_DIF_EXHASH            (0x00000002) /* hashed directory (leaves) */
  390. #define GFS_DIF_UNUSED            (0x00000004) /* unused dinode */
  391. #define GFS_DIF_EA_INDIRECT       (0x00000008) /* extended attribute, indirect*/
  392. #define GFS_DIF_DIRECTIO          (0x00000010)
  393. #define GFS_DIF_IMMUTABLE         (0x00000020) /* Can't change file */
  394. #define GFS_DIF_APPENDONLY        (0x00000040) /* Can only add to end of file */
  395. #define GFS_DIF_NOATIME           (0x00000080) /* Don't update access time
  396.                           (currently unused/ignored) */
  397. #define GFS_DIF_SYNC              (0x00000100) /* Flush to disk, don't cache
  398.                           (currently unused/ignored) */
  399. #define GFS_DIF_INHERIT_DIRECTIO  (0x40000000) /* new files get DIRECTIO flag */
  400. #define GFS_DIF_INHERIT_JDATA     (0x80000000) /* new files get JDATA flag */
  401.  
  402. struct gfs_dinode {
  403.     struct gfs_meta_header di_header;
  404.  
  405.     struct gfs_inum di_num; /* formal inode # and block address */
  406.  
  407.     uint32_t di_mode;    /* mode of file */
  408.     uint32_t di_uid;    /* owner's user id */
  409.     uint32_t di_gid;    /* owner's group id */
  410.     uint32_t di_nlink;    /* number (qty) of links to this file */
  411.     uint64_t di_size;    /* number (qty) of bytes in file */
  412.     uint64_t di_blocks;    /* number (qty) of blocks in file */
  413.     int64_t di_atime;    /* time last accessed */
  414.     int64_t di_mtime;    /* time last modified */
  415.     int64_t di_ctime;    /* time last changed */
  416.  
  417.     /*  Non-zero only for character or block device nodes  */
  418.     uint32_t di_major;    /* device major number */
  419.     uint32_t di_minor;    /* device minor number */
  420.  
  421.     /*  Block allocation strategy  */
  422.     uint64_t di_rgrp;    /* dinode rgrp block number */
  423.     uint64_t di_goal_rgrp;    /* rgrp to alloc from next */
  424.     uint32_t di_goal_dblk;    /* data block goal */
  425.     uint32_t di_goal_mblk;    /* metadata block goal */
  426.  
  427.     uint32_t di_flags;    /* GFS_DIF_... */
  428.  
  429.     /*  struct gfs_rindex, struct gfs_jindex, or struct gfs_dirent */
  430.     uint32_t di_payload_format;  /* GFS_FORMAT_... */
  431.     uint16_t di_type;    /* GFS_FILE_... type of file */
  432.     uint16_t di_height;    /* height of metadata (0 == stuffed) */
  433.     uint32_t di_incarn;    /* incarnation (unused, see gfs_meta_header) */
  434.     uint16_t di_pad;
  435.  
  436.     /*  These only apply to directories  */
  437.     uint16_t di_depth;    /* Number of bits in the table */
  438.     uint32_t di_entries;    /* The # (qty) of entries in the directory */
  439.  
  440.     /*  This formed an on-disk chain of unused dinodes  */
  441.     struct gfs_inum di_next_unused;  /* used in old versions only */
  442.  
  443.     uint64_t di_eattr;    /* extended attribute block number */
  444.  
  445.     char di_reserved[56];
  446. };
  447.  
  448. /*
  449.  *  indirect block header
  450.  *
  451.  *  A component of a dinode's indirect addressing metadata tree.
  452.  *  These are pointed to by pointers in dinodes or other indirect blocks.
  453.  */
  454.  
  455. struct gfs_indirect {
  456.     struct gfs_meta_header in_header;
  457.  
  458.     char in_reserved[64];
  459. };
  460.  
  461. /*
  462.  *  directory structure - many of these per directory file
  463.  *
  464.  * See comments at beginning of dir.c
  465.  */
  466.  
  467. #define GFS_FNAMESIZE               (255)
  468. #define GFS_DIRENT_SIZE(name_len) ((sizeof(struct gfs_dirent) + (name_len) + 7) & ~7)
  469. #define IS_LEAF     (1) /* Hashed (leaf) directory */
  470. #define IS_DINODE   (2) /* Linear (stuffed dinode block) directory */
  471.  
  472. struct gfs_dirent {
  473.     struct gfs_inum de_inum;    /* formal inode number and block address */
  474.     uint32_t de_hash;           /* hash of the filename */
  475.     uint16_t de_rec_len;        /* the length of the dirent */
  476.     uint16_t de_name_len;       /* the length of the name */
  477.     uint16_t de_type;           /* GFS_FILE_... type of dinode this points to */
  478.  
  479.     char de_reserved[14];
  480. };
  481.  
  482. /*
  483.  *  Header of leaf directory nodes
  484.  *
  485.  * See comments at beginning of dir.c
  486.  */
  487.  
  488. struct gfs_leaf {
  489.     struct gfs_meta_header lf_header;
  490.  
  491.     uint16_t lf_depth;          /* Depth of leaf */
  492.     uint16_t lf_entries;        /* Number of dirents in leaf */
  493.     uint32_t lf_dirent_format;  /* GFS_FORMAT_DE (version #) */
  494.     uint64_t lf_next;           /* Next leaf, if overflow */
  495.  
  496.     char lf_reserved[64];
  497. };
  498.  
  499. /*
  500.  *  Log header structure
  501.  *
  502.  *  Two of these are in the first block of a transaction log:
  503.  *    1)  at beginning of block
  504.  *    2)  at end of first 512-byte sector within block
  505.  */
  506.  
  507. #define GFS_LOG_HEAD_UNMOUNT    (0x00000001)  /* log is clean, can unmount fs */
  508.  
  509. struct gfs_log_header {
  510.     struct gfs_meta_header lh_header;
  511.  
  512.     uint32_t lh_flags;    /* GFS_LOG_HEAD_... */
  513.     uint32_t lh_pad;
  514.  
  515.     uint64_t lh_first;    /* Block number of first header in this trans */
  516.     uint64_t lh_sequence;    /* Sequence number of this transaction */
  517.  
  518.     uint64_t lh_tail;    /* Block number of log tail */
  519.     uint64_t lh_last_dump;    /* Block number of last dump */
  520.  
  521.     char lh_reserved[64];
  522. };
  523.  
  524. /*
  525.  *  Log type descriptor
  526.  *
  527.  *  One of these for each chunk in a transaction
  528.  */
  529.  
  530. #define GFS_LOG_DESC_METADATA   (300)    /* metadata */
  531. /*  ld_data1 is the number (quantity) of metadata blocks in the descriptor.
  532.     ld_data2 is unused.
  533.     */
  534.  
  535. #define GFS_LOG_DESC_IUL        (400)    /* unlinked inode */
  536. /*  ld_data1 is TRUE if this is a dump.
  537.     ld_data2 is unused.
  538.     FixMe!!!  ld_data1 should be the number (quantity) of entries.
  539.               ld_data2 should be "TRUE if this is a dump".
  540.     */
  541.  
  542. #define GFS_LOG_DESC_IDA        (401)    /* de-allocated inode */
  543. /*  ld_data1 is unused.
  544.     ld_data2 is unused.
  545.     FixMe!!!  ld_data1 should be the number (quantity) of entries.
  546.     */
  547.  
  548. #define GFS_LOG_DESC_Q          (402)    /* quota */
  549. /*  ld_data1 is the number of quota changes in the descriptor.
  550.     ld_data2 is TRUE if this is a dump.
  551.     */
  552.  
  553. #define GFS_LOG_DESC_LAST       (500)    /* final in a logged transaction */
  554. /*  ld_data1 is unused.
  555.     ld_data2 is unused.
  556.     */
  557.  
  558. struct gfs_log_descriptor {
  559.     struct gfs_meta_header ld_header;
  560.  
  561.     uint32_t ld_type;    /* GFS_LOG_DESC_... Type of this log chunk */
  562.     uint32_t ld_length;    /* Number of buffers in this chunk */
  563.     uint32_t ld_data1;    /* descriptor-specific field */
  564.     uint32_t ld_data2;    /* descriptor-specific field */
  565.  
  566.     char ld_reserved[64];
  567. };
  568.  
  569. /*
  570.  *  Metadata block tags
  571.  *
  572.  *  One for each logged block.  Tells where block really belongs on-disk.
  573.  *  These descriptor tags are packed contiguously after a gfs_log_descriptor.
  574.  */
  575.  
  576. struct gfs_block_tag {
  577.     uint64_t bt_blkno;    /* inplace block number */
  578.     uint32_t bt_flags;    /* ?? */
  579.     uint32_t bt_pad;
  580. };
  581.  
  582. /*
  583.  *  Quota Journal Tag
  584.  */
  585.  
  586. #define GFS_QTF_USER            (0x00000001)
  587.  
  588. struct gfs_quota_tag {
  589.     int64_t qt_change;
  590.     uint32_t qt_flags;      /* GFS_QTF_... */
  591.     uint32_t qt_id;
  592. };
  593.  
  594. /*
  595.  *  Extended attribute header format
  596.  */
  597.  
  598. #define GFS_EA_MAX_NAME_LEN     (255)
  599. #define GFS_EA_MAX_DATA_LEN     (65536)
  600.  
  601. #define GFS_EATYPE_UNUSED       (0)
  602. #define GFS_EATYPE_USR          (1)     /* user attribute */
  603. #define GFS_EATYPE_SYS          (2)     /* system attribute */
  604. #define GFS_EATYPE_SECURITY    (3)    /* security attribute */
  605.  
  606. #define GFS_EATYPE_LAST         (3)
  607. #define GFS_EATYPE_VALID(x)     ((x) <= GFS_EATYPE_LAST)
  608.  
  609. #define GFS_EAFLAG_LAST         (0x01)    /* last ea in block */
  610.  
  611. struct gfs_ea_header {
  612.     uint32_t ea_rec_len;    /* total record length: hdr + name + data */
  613.     uint32_t ea_data_len;   /* data length, in bytes */
  614.     uint8_t ea_name_len;    /* no NULL pointer after the string */
  615.     uint8_t ea_type;        /* GFS_EATYPE_... */
  616.     uint8_t ea_flags;       /* GFS_EAFLAG_... */
  617.     uint8_t ea_num_ptrs;    /* # fs blocks needed for EA */
  618.     uint32_t ea_pad;
  619. };
  620.  
  621. /*  Endian functions  */
  622.  
  623. #define GFS_ENDIAN_BIG
  624.  
  625. #ifdef GFS_ENDIAN_BIG
  626.  
  627. #define gfs16_to_cpu be16_to_cpu
  628. #define gfs32_to_cpu be32_to_cpu
  629. #define gfs64_to_cpu be64_to_cpu
  630.  
  631. #define cpu_to_gfs16 cpu_to_be16
  632. #define cpu_to_gfs32 cpu_to_be32
  633. #define cpu_to_gfs64 cpu_to_be64
  634.  
  635. #else                /*  GFS_ENDIAN_BIG  */
  636.  
  637. #define gfs16_to_cpu le16_to_cpu
  638. #define gfs32_to_cpu le32_to_cpu
  639. #define gfs64_to_cpu le64_to_cpu
  640.  
  641. #define cpu_to_gfs16 cpu_to_le16
  642. #define cpu_to_gfs32 cpu_to_le32
  643. #define cpu_to_gfs64 cpu_to_le64
  644.  
  645. #endif                /*  GFS_ENDIAN_BIG  */
  646.  
  647. /*  Translation functions  */
  648.  
  649. void gfs_inum_in(struct gfs_inum *no, char *buf);
  650. void gfs_inum_out(struct gfs_inum *no, char *buf);
  651. void gfs_meta_header_in(struct gfs_meta_header *mh, char *buf);
  652. void gfs_meta_header_out(struct gfs_meta_header *mh, char *buf);
  653. void gfs_sb_in(struct gfs_sb *sb, char *buf);
  654. void gfs_sb_out(struct gfs_sb *sb, char *buf);
  655. void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
  656. void gfs_jindex_out(struct gfs_jindex *jindex, char *buf);
  657. void gfs_rindex_in(struct gfs_rindex *rindex, char *buf);
  658. void gfs_rindex_out(struct gfs_rindex *rindex, char *buf);
  659. void gfs_rgrp_in(struct gfs_rgrp *rgrp, char *buf);
  660. void gfs_rgrp_out(struct gfs_rgrp *rgrp, char *buf);
  661. void gfs_quota_in(struct gfs_quota *quota, char *buf);
  662. void gfs_quota_out(struct gfs_quota *quota, char *buf);
  663. void gfs_dinode_in(struct gfs_dinode *dinode, char *buf);
  664. void gfs_dinode_out(struct gfs_dinode *dinode, char *buf);
  665. void gfs_indirect_in(struct gfs_indirect *indirect, char *buf);
  666. void gfs_indirect_out(struct gfs_indirect *indirect, char *buf);
  667. void gfs_dirent_in(struct gfs_dirent *dirent, char *buf);
  668. void gfs_dirent_out(struct gfs_dirent *dirent, char *buf);
  669. void gfs_leaf_in(struct gfs_leaf *leaf, char *buf);
  670. void gfs_leaf_out(struct gfs_leaf *leaf, char *buf);
  671. void gfs_log_header_in(struct gfs_log_header *head, char *buf);
  672. void gfs_log_header_out(struct gfs_log_header *head, char *buf);
  673. void gfs_desc_in(struct gfs_log_descriptor *desc, char *buf);
  674. void gfs_desc_out(struct gfs_log_descriptor *desc, char *buf);
  675. void gfs_block_tag_in(struct gfs_block_tag *btag, char *buf);
  676. void gfs_block_tag_out(struct gfs_block_tag *btag, char *buf);
  677. void gfs_quota_tag_in(struct gfs_quota_tag *qtag, char *buf);
  678. void gfs_quota_tag_out(struct gfs_quota_tag *qtag, char *buf);
  679. void gfs_ea_header_in(struct gfs_ea_header *qtag, char *buf);
  680. void gfs_ea_header_out(struct gfs_ea_header *qtag, char *buf);
  681.  
  682. /*  Printing functions  */
  683.  
  684. void gfs_inum_print(struct gfs_inum *no);
  685. void gfs_meta_header_print(struct gfs_meta_header *mh);
  686. void gfs_sb_print(struct gfs_sb *sb);
  687. void gfs_jindex_print(struct gfs_jindex *jindex);
  688. void gfs_rindex_print(struct gfs_rindex *rindex);
  689. void gfs_rgrp_print(struct gfs_rgrp *rgrp);
  690. void gfs_quota_print(struct gfs_quota *quota);
  691. void gfs_dinode_print(struct gfs_dinode *dinode);
  692. void gfs_indirect_print(struct gfs_indirect *indirect);
  693. void gfs_dirent_print(struct gfs_dirent *dirent, char *name);
  694. void gfs_leaf_print(struct gfs_leaf *leaf);
  695. void gfs_log_header_print(struct gfs_log_header *head);
  696. void gfs_desc_print(struct gfs_log_descriptor *desc);
  697. void gfs_block_tag_print(struct gfs_block_tag *tag);
  698. void gfs_quota_tag_print(struct gfs_quota_tag *tag);
  699. void gfs_ea_header_print(struct gfs_ea_header *ea, char *name);
  700.  
  701. /*  The hash function for ExHash directories  */
  702.  
  703. uint32_t gfs_dir_hash(const char *data, int len);
  704.  
  705. #endif /* __GFS_ONDISK_DOT_H__ */
  706.  
  707.  
  708.  
  709. #ifdef WANT_GFS_CONVERSION_FUNCTIONS
  710.  
  711. #define CPIN_08(s1, s2, member, count) {memcpy((s1->member), (s2->member), (count));}
  712. #define CPOUT_08(s1, s2, member, count) {memcpy((s2->member), (s1->member), (count));}
  713. #define CPIN_16(s1, s2, member) {(s1->member) = gfs16_to_cpu((s2->member));}
  714. #define CPOUT_16(s1, s2, member) {(s2->member) = cpu_to_gfs16((s1->member));}
  715. #define CPIN_32(s1, s2, member) {(s1->member) = gfs32_to_cpu((s2->member));}
  716. #define CPOUT_32(s1, s2, member) {(s2->member) = cpu_to_gfs32((s1->member));}
  717. #define CPIN_64(s1, s2, member) {(s1->member) = gfs64_to_cpu((s2->member));}
  718. #define CPOUT_64(s1, s2, member) {(s2->member) = cpu_to_gfs64((s1->member));}
  719.  
  720. #define pa(struct, member, count) print_array(#member, struct->member, count);
  721.  
  722. /**
  723.  * print_array - Print out an array of bytes
  724.  * @title: what to print before the array
  725.  * @buf: the array
  726.  * @count: the number of bytes
  727.  *
  728.  */
  729.  
  730. static void
  731. print_array(char *title, char *buf, int count)
  732. {
  733.     int x;
  734.  
  735.     printk("  %s =\n", title);
  736.     for (x = 0; x < count; x++) {
  737.         printk("%.2X ", (unsigned char)buf[x]);
  738.         if (x % 16 == 15)
  739.             printk("\n");
  740.     }
  741.     if (x % 16)
  742.         printk("\n");
  743. }
  744.  
  745. /**
  746.  * gfs_inum_in - Read in an inode number
  747.  * @no: the cpu-order structure
  748.  * @buf: the disk-order buffer
  749.  *
  750.  */
  751.  
  752. void
  753. gfs_inum_in(struct gfs_inum *no, char *buf)
  754. {
  755.     struct gfs_inum *str = (struct gfs_inum *)buf;
  756.  
  757.     CPIN_64(no, str, no_formal_ino);
  758.     CPIN_64(no, str, no_addr);
  759. }
  760.  
  761. /**
  762.  * gfs_inum_out - Write out an inode number
  763.  * @no: the cpu-order structure
  764.  * @buf: the disk-order buffer
  765.  *
  766.  */
  767.  
  768. void
  769. gfs_inum_out(struct gfs_inum *no, char *buf)
  770. {
  771.     struct gfs_inum *str = (struct gfs_inum *)buf;
  772.  
  773.     CPOUT_64(no, str, no_formal_ino);
  774.     CPOUT_64(no, str, no_addr);
  775. }
  776.  
  777. /**
  778.  * gfs_inum_print - Print out a inode number
  779.  * @no: the cpu-order buffer
  780.  *
  781.  */
  782.  
  783. void
  784. gfs_inum_print(struct gfs_inum *no)
  785. {
  786.     pv(no, no_formal_ino, "%"PRIu64);
  787.     pv(no, no_addr, "%"PRIu64);
  788. }
  789.  
  790. /**
  791.  * gfs_meta_header_in - Read in a metadata header
  792.  * @mh: the cpu-order structure
  793.  * @buf: the disk-order buffer
  794.  *
  795.  */
  796.  
  797. void
  798. gfs_meta_header_in(struct gfs_meta_header *mh, char *buf)
  799. {
  800.     struct gfs_meta_header *str = (struct gfs_meta_header *)buf;
  801.  
  802.     CPIN_32(mh, str, mh_magic);
  803.     CPIN_32(mh, str, mh_type);
  804.     CPIN_64(mh, str, mh_generation);
  805.     CPIN_32(mh, str, mh_format);
  806.     CPIN_32(mh, str, mh_incarn);
  807. }
  808.  
  809. /**
  810.  * gfs_meta_header_in - Write out a metadata header
  811.  * @mh: the cpu-order structure
  812.  * @buf: the disk-order buffer
  813.  *
  814.  * Don't ever change the generation number in this routine.
  815.  * It's done manually in increment_generation().
  816.  */
  817.  
  818. void
  819. gfs_meta_header_out(struct gfs_meta_header *mh, char *buf)
  820. {
  821.     struct gfs_meta_header *str = (struct gfs_meta_header *)buf;
  822.  
  823.     CPOUT_32(mh, str, mh_magic);
  824.     CPOUT_32(mh, str, mh_type);
  825. #if 0
  826.     /* Don't do this!
  827.        Mh_generation should only be change manually. */
  828.     CPOUT_64(mh, str, mh_generation);
  829. #endif
  830.     CPOUT_32(mh, str, mh_format);
  831.     CPOUT_32(mh, str, mh_incarn);
  832. }
  833.  
  834. /**
  835.  * gfs_meta_header_print - Print out a metadata header
  836.  * @mh: the cpu-order buffer
  837.  *
  838.  */
  839.  
  840. void
  841. gfs_meta_header_print(struct gfs_meta_header *mh)
  842. {
  843.     pv(mh, mh_magic, "0x%.8X");
  844.     pv(mh, mh_type, "%u");
  845.     pv(mh, mh_generation, "%"PRIu64);
  846.     pv(mh, mh_format, "%u");
  847.     pv(mh, mh_incarn, "%u");
  848. }
  849.  
  850. /**
  851.  * gfs_sb_in - Read in a superblock
  852.  * @sb: the cpu-order structure
  853.  * @buf: the disk-order buffer
  854.  *
  855.  */
  856.  
  857. void
  858. gfs_sb_in(struct gfs_sb *sb, char *buf)
  859. {
  860.     struct gfs_sb *str = (struct gfs_sb *)buf;
  861.  
  862.     gfs_meta_header_in(&sb->sb_header, buf);
  863.  
  864.     CPIN_32(sb, str, sb_fs_format);
  865.     CPIN_32(sb, str, sb_multihost_format);
  866.     CPIN_32(sb, str, sb_flags);
  867.  
  868.     CPIN_32(sb, str, sb_bsize);
  869.     CPIN_32(sb, str, sb_bsize_shift);
  870.     CPIN_32(sb, str, sb_seg_size);
  871.  
  872.     gfs_inum_in(&sb->sb_jindex_di, (char *)&str->sb_jindex_di);
  873.     gfs_inum_in(&sb->sb_rindex_di, (char *)&str->sb_rindex_di);
  874.     gfs_inum_in(&sb->sb_root_di, (char *)&str->sb_root_di);
  875.  
  876.     CPIN_08(sb, str, sb_lockproto, GFS_LOCKNAME_LEN);
  877.     CPIN_08(sb, str, sb_locktable, GFS_LOCKNAME_LEN);
  878.  
  879.     gfs_inum_in(&sb->sb_quota_di, (char *)&str->sb_quota_di);
  880.     gfs_inum_in(&sb->sb_license_di, (char *)&str->sb_license_di);
  881.  
  882.     CPIN_08(sb, str, sb_reserved, 96);
  883. }
  884.  
  885. /**
  886.  * gfs_sb_out - Write out a superblock
  887.  * @sb: the cpu-order structure
  888.  * @buf: the disk-order buffer
  889.  *
  890.  */
  891.  
  892. void
  893. gfs_sb_out(struct gfs_sb *sb, char *buf)
  894. {
  895.     struct gfs_sb *str = (struct gfs_sb *)buf;
  896.  
  897.     gfs_meta_header_out(&sb->sb_header, buf);
  898.  
  899.     CPOUT_32(sb, str, sb_fs_format);
  900.     CPOUT_32(sb, str, sb_multihost_format);
  901.     CPOUT_32(sb, str, sb_flags);
  902.  
  903.     CPOUT_32(sb, str, sb_bsize);
  904.     CPOUT_32(sb, str, sb_bsize_shift);
  905.     CPOUT_32(sb, str, sb_seg_size);
  906.  
  907.     gfs_inum_out(&sb->sb_jindex_di, (char *)&str->sb_jindex_di);
  908.     gfs_inum_out(&sb->sb_rindex_di, (char *)&str->sb_rindex_di);
  909.     gfs_inum_out(&sb->sb_root_di, (char *)&str->sb_root_di);
  910.  
  911.     CPOUT_08(sb, str, sb_lockproto, GFS_LOCKNAME_LEN);
  912.     CPOUT_08(sb, str, sb_locktable, GFS_LOCKNAME_LEN);
  913.  
  914.     gfs_inum_out(&sb->sb_quota_di, (char *)&str->sb_quota_di);
  915.     gfs_inum_out(&sb->sb_license_di, (char *)&str->sb_license_di);
  916.  
  917.     CPOUT_08(sb, str, sb_reserved, 96);
  918. }
  919.  
  920. /**
  921.  * gfs_sb_print - Print out a superblock
  922.  * @sb: the cpu-order buffer
  923.  *
  924.  */
  925.  
  926. void
  927. gfs_sb_print(struct gfs_sb *sb)
  928. {
  929.     gfs_meta_header_print(&sb->sb_header);
  930.  
  931.     pv(sb, sb_fs_format, "%u");
  932.     pv(sb, sb_multihost_format, "%u");
  933.     pv(sb, sb_flags, "%u");
  934.  
  935.     pv(sb, sb_bsize, "%u");
  936.     pv(sb, sb_bsize_shift, "%u");
  937.     pv(sb, sb_seg_size, "%u");
  938.  
  939.     gfs_inum_print(&sb->sb_jindex_di);
  940.     gfs_inum_print(&sb->sb_rindex_di);
  941.     gfs_inum_print(&sb->sb_root_di);
  942.  
  943.     pv(sb, sb_lockproto, "%s");
  944.     pv(sb, sb_locktable, "%s");
  945.  
  946.     gfs_inum_print(&sb->sb_quota_di);
  947.     gfs_inum_print(&sb->sb_license_di);
  948.  
  949.     pa(sb, sb_reserved, 96);
  950. }
  951.  
  952. /**
  953.  * gfs_jindex_in - Read in a journal index structure
  954.  * @jindex: the cpu-order structure
  955.  * @buf: the disk-order buffer
  956.  *
  957.  */
  958.  
  959. void
  960. gfs_jindex_in(struct gfs_jindex *jindex, char *buf)
  961. {
  962.     struct gfs_jindex *str = (struct gfs_jindex *)buf;
  963.  
  964.     CPIN_64(jindex, str, ji_addr);
  965.     CPIN_32(jindex, str, ji_nsegment);
  966.     CPIN_32(jindex, str, ji_pad);
  967.  
  968.     CPIN_08(jindex, str, ji_reserved, 64);
  969. }
  970.  
  971. /**
  972.  * gfs_jindex_out - Write out a journal index structure
  973.  * @jindex: the cpu-order structure
  974.  * @buf: the disk-order buffer
  975.  *
  976.  */
  977.  
  978. void
  979. gfs_jindex_out(struct gfs_jindex *jindex, char *buf)
  980. {
  981.     struct gfs_jindex *str = (struct gfs_jindex *)buf;
  982.  
  983.     CPOUT_64(jindex, str, ji_addr);
  984.     CPOUT_32(jindex, str, ji_nsegment);
  985.     CPOUT_32(jindex, str, ji_pad);
  986.  
  987.     CPOUT_08(jindex, str, ji_reserved, 64);
  988. }
  989.  
  990. /**
  991.  * gfs_jindex_print - Print out a journal index structure
  992.  * @ji: the cpu-order buffer
  993.  *
  994.  */
  995.  
  996. void
  997. gfs_jindex_print(struct gfs_jindex *ji)
  998. {
  999.     pv(ji, ji_addr, "%"PRIu64);
  1000.     pv(ji, ji_nsegment, "%u");
  1001.     pv(ji, ji_pad, "%u");
  1002.  
  1003.     pa(ji, ji_reserved, 64);
  1004. }
  1005.  
  1006. /**
  1007.  * gfs_rindex_in - Read in a resource index structure
  1008.  * @rindex: the cpu-order structure
  1009.  * @buf: the disk-order buffer
  1010.  *
  1011.  */
  1012.  
  1013. void
  1014. gfs_rindex_in(struct gfs_rindex *rindex, char *buf)
  1015. {
  1016.     struct gfs_rindex *str = (struct gfs_rindex *)buf;
  1017.  
  1018.     CPIN_64(rindex, str, ri_addr);
  1019.     CPIN_32(rindex, str, ri_length);
  1020.     CPIN_32(rindex, str, ri_pad);
  1021.  
  1022.     CPIN_64(rindex, str, ri_data1);
  1023.     CPIN_32(rindex, str, ri_data);
  1024.  
  1025.     CPIN_32(rindex, str, ri_bitbytes);
  1026.  
  1027.     CPIN_08(rindex, str, ri_reserved, 64);
  1028. }
  1029.  
  1030. /**
  1031.  * gfs_rindex_out - Write out a resource index structure
  1032.  * @rindex: the cpu-order structure
  1033.  * @buf: the disk-order buffer
  1034.  *
  1035.  */
  1036.  
  1037. void
  1038. gfs_rindex_out(struct gfs_rindex *rindex, char *buf)
  1039. {
  1040.     struct gfs_rindex *str = (struct gfs_rindex *)buf;
  1041.  
  1042.     CPOUT_64(rindex, str, ri_addr);
  1043.     CPOUT_32(rindex, str, ri_length);
  1044.     CPOUT_32(rindex, str, ri_pad);
  1045.  
  1046.     CPOUT_64(rindex, str, ri_data1);
  1047.     CPOUT_32(rindex, str, ri_data);
  1048.  
  1049.     CPOUT_32(rindex, str, ri_bitbytes);
  1050.  
  1051.     CPOUT_08(rindex, str, ri_reserved, 64);
  1052. }
  1053.  
  1054. /**
  1055.  * gfs_rindex_print - Print out a resource index structure
  1056.  * @ri: the cpu-order buffer
  1057.  *
  1058.  */
  1059.  
  1060. void
  1061. gfs_rindex_print(struct gfs_rindex *ri)
  1062. {
  1063.     pv(ri, ri_addr, "%"PRIu64);
  1064.     pv(ri, ri_length, "%u");
  1065.     pv(ri, ri_pad, "%u");
  1066.  
  1067.     pv(ri, ri_data1, "%"PRIu64);
  1068.     pv(ri, ri_data, "%u");
  1069.  
  1070.     pv(ri, ri_bitbytes, "%u");
  1071.  
  1072.     pa(ri, ri_reserved, 64);
  1073. }
  1074.  
  1075. /**
  1076.  * gfs_rgrp_in - Read in a resource group header
  1077.  * @rgrp: the cpu-order structure
  1078.  * @buf: the disk-order buffer
  1079.  *
  1080.  */
  1081.  
  1082. void
  1083. gfs_rgrp_in(struct gfs_rgrp *rgrp, char *buf)
  1084. {
  1085.     struct gfs_rgrp *str = (struct gfs_rgrp *)buf;
  1086.  
  1087.     gfs_meta_header_in(&rgrp->rg_header, buf);
  1088.  
  1089.     CPIN_32(rgrp, str, rg_flags);
  1090.  
  1091.     CPIN_32(rgrp, str, rg_free);
  1092.  
  1093.     CPIN_32(rgrp, str, rg_useddi);
  1094.     CPIN_32(rgrp, str, rg_freedi);
  1095.     gfs_inum_in(&rgrp->rg_freedi_list, (char *)&str->rg_freedi_list);
  1096.  
  1097.     CPIN_32(rgrp, str, rg_usedmeta);
  1098.     CPIN_32(rgrp, str, rg_freemeta);
  1099.  
  1100.     CPIN_08(rgrp, str, rg_reserved, 64);
  1101. }
  1102.  
  1103. /**
  1104.  * gfs_rgrp_out - Write out a resource group header
  1105.  * @rgrp: the cpu-order structure
  1106.  * @buf: the disk-order buffer
  1107.  *
  1108.  */
  1109.  
  1110. void
  1111. gfs_rgrp_out(struct gfs_rgrp *rgrp, char *buf)
  1112. {
  1113.     struct gfs_rgrp *str = (struct gfs_rgrp *)buf;
  1114.  
  1115.     gfs_meta_header_out(&rgrp->rg_header, buf);
  1116.  
  1117.     CPOUT_32(rgrp, str, rg_flags);
  1118.  
  1119.     CPOUT_32(rgrp, str, rg_free);
  1120.  
  1121.     CPOUT_32(rgrp, str, rg_useddi);
  1122.     CPOUT_32(rgrp, str, rg_freedi);
  1123.     gfs_inum_out(&rgrp->rg_freedi_list, (char *)&str->rg_freedi_list);
  1124.  
  1125.     CPOUT_32(rgrp, str, rg_usedmeta);
  1126.     CPOUT_32(rgrp, str, rg_freemeta);
  1127.  
  1128.     CPOUT_08(rgrp, str, rg_reserved, 64);
  1129. }
  1130.  
  1131. /**
  1132.  * gfs_rgrp_print - Print out a resource group header
  1133.  * @rg: the cpu-order buffer
  1134.  *
  1135.  */
  1136.  
  1137. void
  1138. gfs_rgrp_print(struct gfs_rgrp *rg)
  1139. {
  1140.     gfs_meta_header_print(&rg->rg_header);
  1141.  
  1142.     pv(rg, rg_flags, "%u");
  1143.  
  1144.     pv(rg, rg_free, "%u");
  1145.  
  1146.     pv(rg, rg_useddi, "%u");
  1147.     pv(rg, rg_freedi, "%u");
  1148.     gfs_inum_print(&rg->rg_freedi_list);
  1149.  
  1150.     pv(rg, rg_usedmeta, "%u");
  1151.     pv(rg, rg_freemeta, "%u");
  1152.  
  1153.     pa(rg, rg_reserved, 64);
  1154. }
  1155.  
  1156. /**
  1157.  * gfs_quota_in - Read in a quota structures
  1158.  * @quota: the cpu-order structure
  1159.  * @buf: the disk-order buffer
  1160.  *
  1161.  */
  1162.  
  1163. void
  1164. gfs_quota_in(struct gfs_quota *quota, char *buf)
  1165. {
  1166.     struct gfs_quota *str = (struct gfs_quota *)buf;
  1167.  
  1168.     CPIN_64(quota, str, qu_limit);
  1169.     CPIN_64(quota, str, qu_warn);
  1170.     CPIN_64(quota, str, qu_value);
  1171.  
  1172.     CPIN_08(quota, str, qu_reserved, 64);
  1173. }
  1174.  
  1175. /**
  1176.  * gfs_quota_out - Write out a quota structure
  1177.  * @quota: the cpu-order structure
  1178.  * @buf: the disk-order buffer
  1179.  *
  1180.  */
  1181.  
  1182. void
  1183. gfs_quota_out(struct gfs_quota *quota, char *buf)
  1184. {
  1185.     struct gfs_quota *str = (struct gfs_quota *)buf;
  1186.  
  1187.     CPOUT_64(quota, str, qu_limit);
  1188.     CPOUT_64(quota, str, qu_warn);
  1189.     CPOUT_64(quota, str, qu_value);
  1190.  
  1191.     CPOUT_08(quota, str, qu_reserved, 64);
  1192. }
  1193.  
  1194. /**
  1195.  * gfs_quota_print - Print out a quota structure
  1196.  * @quota: the cpu-order buffer
  1197.  *
  1198.  */
  1199.  
  1200. void
  1201. gfs_quota_print(struct gfs_quota *quota)
  1202. {
  1203.     pv(quota, qu_limit, "%"PRIu64);
  1204.     pv(quota, qu_warn, "%"PRIu64);
  1205.     pv(quota, qu_value, "%"PRId64);
  1206.  
  1207.     pa(quota, qu_reserved, 64);
  1208. }
  1209.  
  1210. /**
  1211.  * gfs_dinode_in - Read in a dinode
  1212.  * @dinode: the cpu-order structure
  1213.  * @buf: the disk-order buffer
  1214.  *
  1215.  */
  1216.  
  1217. void
  1218. gfs_dinode_in(struct gfs_dinode *dinode, char *buf)
  1219. {
  1220.     struct gfs_dinode *str = (struct gfs_dinode *)buf;
  1221.  
  1222.     gfs_meta_header_in(&dinode->di_header, buf);
  1223.  
  1224.     gfs_inum_in(&dinode->di_num, (char *)&str->di_num);
  1225.  
  1226.     CPIN_32(dinode, str, di_mode);
  1227.     CPIN_32(dinode, str, di_uid);
  1228.     CPIN_32(dinode, str, di_gid);
  1229.     CPIN_32(dinode, str, di_nlink);
  1230.     CPIN_64(dinode, str, di_size);
  1231.     CPIN_64(dinode, str, di_blocks);
  1232.     CPIN_64(dinode, str, di_atime);
  1233.     CPIN_64(dinode, str, di_mtime);
  1234.     CPIN_64(dinode, str, di_ctime);
  1235.     CPIN_32(dinode, str, di_major);
  1236.     CPIN_32(dinode, str, di_minor);
  1237.  
  1238.     CPIN_64(dinode, str, di_rgrp);
  1239.     CPIN_64(dinode, str, di_goal_rgrp);
  1240.     CPIN_32(dinode, str, di_goal_dblk);
  1241.     CPIN_32(dinode, str, di_goal_mblk);
  1242.     CPIN_32(dinode, str, di_flags);
  1243.     CPIN_32(dinode, str, di_payload_format);
  1244.     CPIN_16(dinode, str, di_type);
  1245.     CPIN_16(dinode, str, di_height);
  1246.     CPIN_32(dinode, str, di_incarn);
  1247.     CPIN_16(dinode, str, di_pad);
  1248.  
  1249.     CPIN_16(dinode, str, di_depth);
  1250.     CPIN_32(dinode, str, di_entries);
  1251.  
  1252.     gfs_inum_in(&dinode->di_next_unused, (char *)&str->di_next_unused);
  1253.  
  1254.     CPIN_64(dinode, str, di_eattr);
  1255.  
  1256.     CPIN_08(dinode, str, di_reserved, 56);
  1257. }
  1258.  
  1259. /**
  1260.  * gfs_dinode_out - Write out a dinode
  1261.  * @dinode: the cpu-order structure
  1262.  * @buf: the disk-order buffer
  1263.  *
  1264.  */
  1265.  
  1266. void
  1267. gfs_dinode_out(struct gfs_dinode *dinode, char *buf)
  1268. {
  1269.     struct gfs_dinode *str = (struct gfs_dinode *)buf;
  1270.  
  1271.     gfs_meta_header_out(&dinode->di_header, buf);
  1272.  
  1273.     gfs_inum_out(&dinode->di_num, (char *)&str->di_num);
  1274.  
  1275.     CPOUT_32(dinode, str, di_mode);
  1276.     CPOUT_32(dinode, str, di_uid);
  1277.     CPOUT_32(dinode, str, di_gid);
  1278.     CPOUT_32(dinode, str, di_nlink);
  1279.     CPOUT_64(dinode, str, di_size);
  1280.     CPOUT_64(dinode, str, di_blocks);
  1281.     CPOUT_64(dinode, str, di_atime);
  1282.     CPOUT_64(dinode, str, di_mtime);
  1283.     CPOUT_64(dinode, str, di_ctime);
  1284.     CPOUT_32(dinode, str, di_major);
  1285.     CPOUT_32(dinode, str, di_minor);
  1286.  
  1287.     CPOUT_64(dinode, str, di_rgrp);
  1288.     CPOUT_64(dinode, str, di_goal_rgrp);
  1289.     CPOUT_32(dinode, str, di_goal_dblk);
  1290.     CPOUT_32(dinode, str, di_goal_mblk);
  1291.     CPOUT_32(dinode, str, di_flags);
  1292.     CPOUT_32(dinode, str, di_payload_format);
  1293.     CPOUT_16(dinode, str, di_type);
  1294.     CPOUT_16(dinode, str, di_height);
  1295.     CPOUT_32(dinode, str, di_incarn);
  1296.     CPOUT_16(dinode, str, di_pad);
  1297.  
  1298.     CPOUT_16(dinode, str, di_depth);
  1299.     CPOUT_32(dinode, str, di_entries);
  1300.  
  1301.     gfs_inum_out(&dinode->di_next_unused, (char *)&str->di_next_unused);
  1302.  
  1303.     CPOUT_64(dinode, str, di_eattr);
  1304.  
  1305.     CPOUT_08(dinode, str, di_reserved, 56);
  1306. }
  1307.  
  1308. /**
  1309.  * gfs_dinode_print - Print out a dinode
  1310.  * @di: the cpu-order buffer
  1311.  *
  1312.  */
  1313.  
  1314. void
  1315. gfs_dinode_print(struct gfs_dinode *di)
  1316. {
  1317.     gfs_meta_header_print(&di->di_header);
  1318.  
  1319.     gfs_inum_print(&di->di_num);
  1320.  
  1321.     pv(di, di_mode, "0%o");
  1322.     pv(di, di_uid, "%u");
  1323.     pv(di, di_gid, "%u");
  1324.     pv(di, di_nlink, "%u");
  1325.     pv(di, di_size, "%"PRIu64);
  1326.     pv(di, di_blocks, "%"PRIu64);
  1327.     pv(di, di_atime, "%"PRId64);
  1328.     pv(di, di_mtime, "%"PRId64);
  1329.     pv(di, di_ctime, "%"PRId64);
  1330.     pv(di, di_major, "%u");
  1331.     pv(di, di_minor, "%u");
  1332.  
  1333.     pv(di, di_rgrp, "%"PRIu64);
  1334.     pv(di, di_goal_rgrp, "%"PRIu64);
  1335.     pv(di, di_goal_dblk, "%u");
  1336.     pv(di, di_goal_mblk, "%u");
  1337.     pv(di, di_flags, "0x%.8X");
  1338.     pv(di, di_payload_format, "%u");
  1339.     pv(di, di_type, "%u");
  1340.     pv(di, di_height, "%u");
  1341.     pv(di, di_incarn, "%u");
  1342.     pv(di, di_pad, "%u");
  1343.  
  1344.     pv(di, di_depth, "%u");
  1345.     pv(di, di_entries, "%u");
  1346.  
  1347.     gfs_inum_print(&di->di_next_unused);
  1348.  
  1349.     pv(di, di_eattr, "%"PRIu64);
  1350.  
  1351.     pa(di, di_reserved, 56);
  1352. }
  1353.  
  1354. /**
  1355.  * gfs_indirect_in - copy in the header of an indirect block
  1356.  * @indirect: the in memory copy
  1357.  * @buf: the buffer copy
  1358.  *
  1359.  */
  1360.  
  1361. void
  1362. gfs_indirect_in(struct gfs_indirect *indirect, char *buf)
  1363. {
  1364.     struct gfs_indirect *str = (struct gfs_indirect *)buf;
  1365.  
  1366.     gfs_meta_header_in(&indirect->in_header, buf);
  1367.  
  1368.     CPIN_08(indirect, str, in_reserved, 64);
  1369. }
  1370.  
  1371. /**
  1372.  * gfs_indirect_out - copy out the header of an indirect block
  1373.  * @indirect: the in memory copy
  1374.  * @buf: the buffer copy
  1375.  *
  1376.  */
  1377.  
  1378. void
  1379. gfs_indirect_out(struct gfs_indirect *indirect, char *buf)
  1380. {
  1381.     struct gfs_indirect *str = (struct gfs_indirect *)buf;
  1382.  
  1383.     gfs_meta_header_out(&indirect->in_header, buf);
  1384.  
  1385.     CPOUT_08(indirect, str, in_reserved, 64);
  1386. }
  1387.  
  1388. /**
  1389.  * gfs_indirect_print - Print out a indirect block header
  1390.  * @indirect: the cpu-order buffer
  1391.  *
  1392.  */
  1393.  
  1394. void
  1395. gfs_indirect_print(struct gfs_indirect *indirect)
  1396. {
  1397.     gfs_meta_header_print(&indirect->in_header);
  1398.  
  1399.     pa(indirect, in_reserved, 64);
  1400. }
  1401.  
  1402. /**
  1403.  * gfs_dirent_in - Read in a directory entry
  1404.  * @dirent: the cpu-order structure
  1405.  * @buf: the disk-order buffer
  1406.  *
  1407.  */
  1408.  
  1409. void
  1410. gfs_dirent_in(struct gfs_dirent *dirent, char *buf)
  1411. {
  1412.     struct gfs_dirent *str = (struct gfs_dirent *)buf;
  1413.  
  1414.     gfs_inum_in(&dirent->de_inum, (char *)&str->de_inum);
  1415.     CPIN_32(dirent, str, de_hash);
  1416.     CPIN_16(dirent, str, de_rec_len);
  1417.     CPIN_16(dirent, str, de_name_len);
  1418.     CPIN_16(dirent, str, de_type);
  1419.  
  1420.     CPIN_08(dirent, str, de_reserved, 14);
  1421. }
  1422.  
  1423. /**
  1424.  * gfs_dirent_out - Write out a directory entry
  1425.  * @dirent: the cpu-order structure
  1426.  * @buf: the disk-order buffer
  1427.  *
  1428.  */
  1429.  
  1430. void
  1431. gfs_dirent_out(struct gfs_dirent *dirent, char *buf)
  1432. {
  1433.     struct gfs_dirent *str = (struct gfs_dirent *)buf;
  1434.  
  1435.     gfs_inum_out(&dirent->de_inum, (char *)&str->de_inum);
  1436.     CPOUT_32(dirent, str, de_hash);
  1437.     CPOUT_16(dirent, str, de_rec_len);
  1438.     CPOUT_16(dirent, str, de_name_len);
  1439.     CPOUT_16(dirent, str, de_type);
  1440.  
  1441.     CPOUT_08(dirent, str, de_reserved, 14);
  1442. }
  1443.  
  1444. /**
  1445.  * gfs_dirent_print - Print out a directory entry
  1446.  * @de: the cpu-order buffer
  1447.  * @name: the filename
  1448.  *
  1449.  */
  1450.  
  1451. void
  1452. gfs_dirent_print(struct gfs_dirent *de, char *name)
  1453. {
  1454.     char buf[GFS_FNAMESIZE + 1];
  1455.  
  1456.     gfs_inum_print(&de->de_inum);
  1457.     pv(de, de_hash, "0x%.8X");
  1458.     pv(de, de_rec_len, "%u");
  1459.     pv(de, de_name_len, "%u");
  1460.     pv(de, de_type, "%u");
  1461.  
  1462.     pa(de, de_reserved, 14);
  1463.  
  1464.     memset(buf, 0, GFS_FNAMESIZE + 1);
  1465.     memcpy(buf, name, de->de_name_len);
  1466.     printk("  name = %s\n", buf);
  1467. }
  1468.  
  1469. /**
  1470.  * gfs_leaf_in - Read in a directory leaf header
  1471.  * @leaf: the cpu-order structure
  1472.  * @buf: the disk-order buffer
  1473.  *
  1474.  */
  1475.  
  1476. void
  1477. gfs_leaf_in(struct gfs_leaf *leaf, char *buf)
  1478. {
  1479.     struct gfs_leaf *str = (struct gfs_leaf *)buf;
  1480.  
  1481.     gfs_meta_header_in(&leaf->lf_header, buf);
  1482.  
  1483.     CPIN_16(leaf, str, lf_depth);
  1484.     CPIN_16(leaf, str, lf_entries);
  1485.     CPIN_32(leaf, str, lf_dirent_format);
  1486.     CPIN_64(leaf, str, lf_next);
  1487.  
  1488.     CPIN_08(leaf, str, lf_reserved, 64);
  1489. }
  1490.  
  1491. /**
  1492.  * gfs_leaf_out - Write out a directory leaf header
  1493.  * @leaf: the cpu-order structure
  1494.  * @buf: the disk-order buffer
  1495.  *
  1496.  */
  1497.  
  1498. void
  1499. gfs_leaf_out(struct gfs_leaf *leaf, char *buf)
  1500. {
  1501.     struct gfs_leaf *str = (struct gfs_leaf *)buf;
  1502.  
  1503.     gfs_meta_header_out(&leaf->lf_header, buf);
  1504.  
  1505.     CPOUT_16(leaf, str, lf_depth);
  1506.     CPOUT_16(leaf, str, lf_entries);
  1507.     CPOUT_32(leaf, str, lf_dirent_format);
  1508.     CPOUT_64(leaf, str, lf_next);
  1509.  
  1510.     CPOUT_08(leaf, str, lf_reserved, 64);
  1511. }
  1512.  
  1513. /**
  1514.  * gfs_leaf_print - Print out a directory leaf header
  1515.  * @lf: the cpu-order buffer
  1516.  *
  1517.  */
  1518.  
  1519. void
  1520. gfs_leaf_print(struct gfs_leaf *lf)
  1521. {
  1522.     gfs_meta_header_print(&lf->lf_header);
  1523.  
  1524.     pv(lf, lf_depth, "%u");
  1525.     pv(lf, lf_entries, "%u");
  1526.     pv(lf, lf_dirent_format, "%u");
  1527.     pv(lf, lf_next, "%"PRIu64);
  1528.  
  1529.     pa(lf, lf_reserved, 64);
  1530. }
  1531.  
  1532. /**
  1533.  * gfs_log_header_in - Read in a log header
  1534.  * @head: the cpu-order structure
  1535.  * @buf: the disk-order buffer
  1536.  *
  1537.  */
  1538.  
  1539. void
  1540. gfs_log_header_in(struct gfs_log_header *head, char *buf)
  1541. {
  1542.     struct gfs_log_header *str = (struct gfs_log_header *)buf;
  1543.  
  1544.     gfs_meta_header_in(&head->lh_header, buf);
  1545.  
  1546.     CPIN_32(head, str, lh_flags);
  1547.     CPIN_32(head, str, lh_pad);
  1548.  
  1549.     CPIN_64(head, str, lh_first);
  1550.     CPIN_64(head, str, lh_sequence);
  1551.  
  1552.     CPIN_64(head, str, lh_tail);
  1553.     CPIN_64(head, str, lh_last_dump);
  1554.  
  1555.     CPIN_08(head, str, lh_reserved, 64);
  1556. }
  1557.  
  1558. /**
  1559.  * gfs_log_header_out - Write out a log header
  1560.  * @head: the cpu-order structure
  1561.  * @buf: the disk-order buffer
  1562.  *
  1563.  */
  1564.  
  1565. void
  1566. gfs_log_header_out(struct gfs_log_header *head, char *buf)
  1567. {
  1568.     struct gfs_log_header *str = (struct gfs_log_header *)buf;
  1569.  
  1570.     gfs_meta_header_out(&head->lh_header, buf);
  1571.  
  1572.     CPOUT_32(head, str, lh_flags);
  1573.     CPOUT_32(head, str, lh_pad);
  1574.  
  1575.     CPOUT_64(head, str, lh_first);
  1576.     CPOUT_64(head, str, lh_sequence);
  1577.  
  1578.     CPOUT_64(head, str, lh_tail);
  1579.     CPOUT_64(head, str, lh_last_dump);
  1580.  
  1581.     CPOUT_08(head, str, lh_reserved, 64);
  1582. }
  1583.  
  1584. /**
  1585.  * gfs_log_header_print - Print out a log header
  1586.  * @head: the cpu-order buffer
  1587.  *
  1588.  */
  1589.  
  1590. void
  1591. gfs_log_header_print(struct gfs_log_header *lh)
  1592. {
  1593.     gfs_meta_header_print(&lh->lh_header);
  1594.  
  1595.     pv(lh, lh_flags, "0x%.8X");
  1596.     pv(lh, lh_pad, "%u");
  1597.  
  1598.     pv(lh, lh_first, "%"PRIu64);
  1599.     pv(lh, lh_sequence, "%"PRIu64);
  1600.  
  1601.     pv(lh, lh_tail, "%"PRIu64);
  1602.     pv(lh, lh_last_dump, "%"PRIu64);
  1603.  
  1604.     pa(lh, lh_reserved, 64);
  1605. }
  1606.  
  1607. /**
  1608.  * gfs_desc_in - Read in a log descriptor
  1609.  * @desc: the cpu-order structure
  1610.  * @buf: the disk-order buffer
  1611.  *
  1612.  */
  1613.  
  1614. void
  1615. gfs_desc_in(struct gfs_log_descriptor *desc, char *buf)
  1616. {
  1617.     struct gfs_log_descriptor *str = (struct gfs_log_descriptor *)buf;
  1618.  
  1619.     gfs_meta_header_in(&desc->ld_header, buf);
  1620.  
  1621.     CPIN_32(desc, str, ld_type);
  1622.     CPIN_32(desc, str, ld_length);
  1623.     CPIN_32(desc, str, ld_data1);
  1624.     CPIN_32(desc, str, ld_data2);
  1625.  
  1626.     CPIN_08(desc, str, ld_reserved, 64);
  1627. }
  1628.  
  1629. /**
  1630.  * gfs_desc_out - Write out a log descriptor
  1631.  * @desc: the cpu-order structure
  1632.  * @buf: the disk-order buffer
  1633.  *
  1634.  */
  1635.  
  1636. void
  1637. gfs_desc_out(struct gfs_log_descriptor *desc, char *buf)
  1638. {
  1639.     struct gfs_log_descriptor *str = (struct gfs_log_descriptor *)buf;
  1640.  
  1641.     gfs_meta_header_out(&desc->ld_header, buf);
  1642.  
  1643.     CPOUT_32(desc, str, ld_type);
  1644.     CPOUT_32(desc, str, ld_length);
  1645.     CPOUT_32(desc, str, ld_data1);
  1646.     CPOUT_32(desc, str, ld_data2);
  1647.  
  1648.     CPOUT_08(desc, str, ld_reserved, 64);
  1649. }
  1650.  
  1651. /**
  1652.  * gfs_desc_print - Print out a log descriptor
  1653.  * @ld: the cpu-order buffer
  1654.  *
  1655.  */
  1656.  
  1657. void
  1658. gfs_desc_print(struct gfs_log_descriptor *ld)
  1659. {
  1660.     gfs_meta_header_print(&ld->ld_header);
  1661.  
  1662.     pv(ld, ld_type, "%u");
  1663.     pv(ld, ld_length, "%u");
  1664.     pv(ld, ld_data1, "%u");
  1665.     pv(ld, ld_data2, "%u");
  1666.  
  1667.     pa(ld, ld_reserved, 64);
  1668. }
  1669.  
  1670. /**
  1671.  * gfs_block_tag_in - Read in a block tag
  1672.  * @tag: the cpu-order structure
  1673.  * @buf: the disk-order buffer
  1674.  *
  1675.  */
  1676.  
  1677. void
  1678. gfs_block_tag_in(struct gfs_block_tag *tag, char *buf)
  1679. {
  1680.     struct gfs_block_tag *str = (struct gfs_block_tag *)buf;
  1681.  
  1682.     CPIN_64(tag, str, bt_blkno);
  1683.     CPIN_32(tag, str, bt_flags);
  1684.     CPIN_32(tag, str, bt_pad);
  1685. }
  1686.  
  1687. /**
  1688.  * gfs_block_tag_out - Write out a block tag
  1689.  * @tag: the cpu-order structure
  1690.  * @buf: the disk-order buffer
  1691.  *
  1692.  */
  1693.  
  1694. void
  1695. gfs_block_tag_out(struct gfs_block_tag *tag, char *buf)
  1696. {
  1697.     struct gfs_block_tag *str = (struct gfs_block_tag *)buf;
  1698.  
  1699.     CPOUT_64(tag, str, bt_blkno);
  1700.     CPOUT_32(tag, str, bt_flags);
  1701.     CPOUT_32(tag, str, bt_pad);
  1702. }
  1703.  
  1704. /**
  1705.  * gfs_block_tag_print - Print out a block tag
  1706.  * @tag: the cpu-order buffer
  1707.  *
  1708.  */
  1709.  
  1710. void
  1711. gfs_block_tag_print(struct gfs_block_tag *tag)
  1712. {
  1713.     pv(tag, bt_blkno, "%"PRIu64);
  1714.     pv(tag, bt_flags, "%u");
  1715.     pv(tag, bt_pad, "%u");
  1716. }
  1717.  
  1718. /**
  1719.  * gfs_quota_tag_in - Read in a quota tag
  1720.  * @tag: the cpu-order structure
  1721.  * @buf: the disk-order buffer
  1722.  *
  1723.  */
  1724.  
  1725. void
  1726. gfs_quota_tag_in(struct gfs_quota_tag *tag, char *buf)
  1727. {
  1728.     struct gfs_quota_tag *str = (struct gfs_quota_tag *)buf;
  1729.  
  1730.     CPIN_64(tag, str, qt_change);
  1731.     CPIN_32(tag, str, qt_flags);
  1732.     CPIN_32(tag, str, qt_id);
  1733. }
  1734.  
  1735. /**
  1736.  * gfs_quota_tag_out - Write out a quota tag
  1737.  * @tag: the cpu-order structure
  1738.  * @buf: the disk-order buffer
  1739.  *
  1740.  */
  1741.  
  1742. void
  1743. gfs_quota_tag_out(struct gfs_quota_tag *tag, char *buf)
  1744. {
  1745.     struct gfs_quota_tag *str = (struct gfs_quota_tag *)buf;
  1746.  
  1747.     CPOUT_64(tag, str, qt_change);
  1748.     CPOUT_32(tag, str, qt_flags);
  1749.     CPOUT_32(tag, str, qt_id);
  1750. }
  1751.  
  1752. /**
  1753.  * gfs_quota_tag_print - Print out a quota tag
  1754.  * @tag: the cpu-order buffer
  1755.  *
  1756.  */
  1757.  
  1758. void
  1759. gfs_quota_tag_print(struct gfs_quota_tag *tag)
  1760. {
  1761.     pv(tag, qt_change, "%"PRId64);
  1762.     pv(tag, qt_flags, "0x%.8X");
  1763.     pv(tag, qt_id, "%u");
  1764. }
  1765.  
  1766. /**
  1767.  * gfs_ea_header_in - Read in a Extended Attribute header
  1768.  * @tag: the cpu-order structure
  1769.  * @buf: the disk-order buffer
  1770.  *
  1771.  */
  1772.  
  1773. void
  1774. gfs_ea_header_in(struct gfs_ea_header *ea, char *buf)
  1775. {
  1776.     struct gfs_ea_header *str = (struct gfs_ea_header *)buf;
  1777.  
  1778.     CPIN_32(ea, str, ea_rec_len);
  1779.     CPIN_32(ea, str, ea_data_len);
  1780.     ea->ea_name_len = str->ea_name_len;
  1781.     ea->ea_type = str->ea_type;
  1782.     ea->ea_flags = str->ea_flags;
  1783.     ea->ea_num_ptrs = str->ea_num_ptrs;
  1784.     CPIN_32(ea, str, ea_pad);
  1785. }
  1786.  
  1787. /**
  1788.  * gfs_ea_header_out - Write out a Extended Attribute header
  1789.  * @ea: the cpu-order structure
  1790.  * @buf: the disk-order buffer
  1791.  *
  1792.  */
  1793.  
  1794. void
  1795. gfs_ea_header_out(struct gfs_ea_header *ea, char *buf)
  1796. {
  1797.     struct gfs_ea_header *str = (struct gfs_ea_header *)buf;
  1798.  
  1799.     CPOUT_32(ea, str, ea_rec_len);
  1800.     CPOUT_32(ea, str, ea_data_len);
  1801.     str->ea_name_len = ea->ea_name_len;
  1802.     str->ea_type = ea->ea_type;
  1803.     str->ea_flags = ea->ea_flags;
  1804.     str->ea_num_ptrs = ea->ea_num_ptrs;
  1805.     CPOUT_32(ea, str, ea_pad);
  1806. }
  1807.  
  1808. /**
  1809.  * gfs_ea_header_printt - Print out a Extended Attribute header
  1810.  * @ea: the cpu-order buffer
  1811.  *
  1812.  */
  1813.  
  1814. void
  1815. gfs_ea_header_print(struct gfs_ea_header *ea, char *name)
  1816. {
  1817.     char buf[GFS_EA_MAX_NAME_LEN + 1];
  1818.  
  1819.     pv(ea, ea_rec_len, "%u");
  1820.     pv(ea, ea_data_len, "%u");
  1821.     pv(ea, ea_name_len, "%u");
  1822.     pv(ea, ea_type, "%u");
  1823.     pv(ea, ea_flags, "%u");
  1824.     pv(ea, ea_num_ptrs, "%u");
  1825.     pv(ea, ea_pad, "%u");
  1826.  
  1827.     memset(buf, 0, GFS_EA_MAX_NAME_LEN + 1);
  1828.     memcpy(buf, name, ea->ea_name_len);
  1829.     printk("  name = %s\n", buf);
  1830. }
  1831.  
  1832. static const uint32_t crc_32_tab[] =
  1833. {
  1834.   0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
  1835.   0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
  1836.   0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
  1837.   0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
  1838.   0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
  1839.   0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
  1840.   0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
  1841.   0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
  1842.   0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
  1843.   0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
  1844.   0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
  1845.   0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
  1846.   0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
  1847.   0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
  1848.   0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
  1849.   0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
  1850.   0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
  1851.   0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
  1852.   0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
  1853.   0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
  1854.   0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
  1855.   0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
  1856.   0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
  1857.   0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
  1858.   0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
  1859.   0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
  1860.   0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
  1861.   0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
  1862.   0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
  1863.   0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
  1864.   0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
  1865.   0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
  1866. };
  1867.  
  1868. /**
  1869.  * gfs_dir_hash - hash an array of data
  1870.  * @data: the data to be hashed
  1871.  * @len: the length of data to be hashed
  1872.  *
  1873.  * Take some data and convert it to a 32-bit hash.
  1874.  *
  1875.  * The hash function is a 32-bit CRC of the data.  The algorithm uses
  1876.  * the crc_32_tab table above.
  1877.  *
  1878.  * This may not be the fastest hash function, but it does a fair bit better
  1879.  * at providing uniform results than the others I've looked at.  That's
  1880.  * really important for efficient directories.
  1881.  *
  1882.  * Returns: the hash
  1883.  */
  1884.  
  1885. uint32_t
  1886. gfs_dir_hash(const char *data, int len)
  1887. {
  1888.     uint32_t hash = 0xFFFFFFFF;
  1889.  
  1890.     for (; len--; data++)
  1891.         hash = crc_32_tab[(hash ^ *data) & 0xFF] ^ (hash >> 8);
  1892.  
  1893.     hash = ~hash;
  1894.  
  1895.     return hash;
  1896. }
  1897.  
  1898. #endif  /* WANT_GFS_CONVERSION_FUNCTIONS */
  1899.  
  1900.