source: grub-pc/trunk/fuentes/debian/patches/xfs-v5.patch @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 18.9 KB
  • grub-core/fs/xfs.c

    From cd6abe82a63c633d94290eb22341d884627ef57a Mon Sep 17 00:00:00 2001
    From: Jan Kara <jack@suse.cz>
    Date: Mon, 1 Jun 2015 14:28:46 +0200
    Subject: xfs: V5 filesystem format support
    
    Add support for new XFS on disk format. We have to handle optional
    filetype fields in directory entries, additional CRC, LSN, UUID entries
    in some structures, etc.
    
    Signed-off-by: Jan Kara <jack@suse.cz>
    
    Origin: upstream, http://git.savannah.gnu.org/cgit/grub.git/commit/?id=b6e80c7778b708c1632d957d00507aad60d9e255
    Bug-Debian: https://bugs.debian.org/772565
    Last-Update: 2015-11-05
    
    Patch-Name: xfs-v5.patch
    ---
     grub-core/fs/xfs.c | 332 ++++++++++++++++++++++++++++++++++++++++-------------
     1 file changed, 252 insertions(+), 80 deletions(-)
    
    diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
    index 26d8147..f00e43e 100644
    a b GRUB_MOD_LICENSE ("GPLv3+"); 
    3434#define XFS_INODE_FORMAT_EXT    2
    3535#define XFS_INODE_FORMAT_BTREE  3
    3636
     37/* Superblock version field flags */
     38#define XFS_SB_VERSION_NUMBITS          0x000f
     39#define XFS_SB_VERSION_ATTRBIT          0x0010
     40#define XFS_SB_VERSION_NLINKBIT         0x0020
     41#define XFS_SB_VERSION_QUOTABIT         0x0040
     42#define XFS_SB_VERSION_ALIGNBIT         0x0080
     43#define XFS_SB_VERSION_DALIGNBIT        0x0100
     44#define XFS_SB_VERSION_LOGV2BIT         0x0400
     45#define XFS_SB_VERSION_SECTORBIT        0x0800
     46#define XFS_SB_VERSION_EXTFLGBIT        0x1000
     47#define XFS_SB_VERSION_DIRV2BIT         0x2000
     48#define XFS_SB_VERSION_MOREBITSBIT      0x8000
     49#define XFS_SB_VERSION_BITS_SUPPORTED \
     50        (XFS_SB_VERSION_NUMBITS | \
     51         XFS_SB_VERSION_ATTRBIT | \
     52         XFS_SB_VERSION_NLINKBIT | \
     53         XFS_SB_VERSION_QUOTABIT | \
     54         XFS_SB_VERSION_ALIGNBIT | \
     55         XFS_SB_VERSION_DALIGNBIT | \
     56         XFS_SB_VERSION_LOGV2BIT | \
     57         XFS_SB_VERSION_SECTORBIT | \
     58         XFS_SB_VERSION_EXTFLGBIT | \
     59         XFS_SB_VERSION_DIRV2BIT | \
     60         XFS_SB_VERSION_MOREBITSBIT)
     61
     62/* Recognized xfs format versions */
     63#define XFS_SB_VERSION_4                4       /* Good old XFS filesystem */
     64#define XFS_SB_VERSION_5                5       /* CRC enabled filesystem */
     65
     66/* features2 field flags */
     67#define XFS_SB_VERSION2_LAZYSBCOUNTBIT  0x00000002      /* Superblk counters */
     68#define XFS_SB_VERSION2_ATTR2BIT        0x00000008      /* Inline attr rework */
     69#define XFS_SB_VERSION2_PROJID32BIT     0x00000080      /* 32-bit project ids */
     70#define XFS_SB_VERSION2_FTYPE           0x00000200      /* inode type in dir */
     71#define XFS_SB_VERSION2_BITS_SUPPORTED \
     72        (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
     73         XFS_SB_VERSION2_ATTR2BIT | \
     74         XFS_SB_VERSION2_PROJID32BIT | \
     75         XFS_SB_VERSION2_FTYPE)
     76
     77/* incompat feature flags */
     78#define XFS_SB_FEAT_INCOMPAT_FTYPE      (1 << 0)        /* filetype in dirent */
     79#define XFS_SB_FEAT_INCOMPAT_SUPPORTED \
     80        (XFS_SB_FEAT_INCOMPAT_FTYPE)
    3781
    3882struct grub_xfs_sblock
    3983{
    struct grub_xfs_sblock 
    4589  grub_uint64_t rootino;
    4690  grub_uint8_t unused3[20];
    4791  grub_uint32_t agsize;
    48   grub_uint8_t unused4[20];
     92  grub_uint8_t unused4[12];
     93  grub_uint16_t version;
     94  grub_uint8_t unused5[6];
    4995  grub_uint8_t label[12];
    5096  grub_uint8_t log2_bsize;
    5197  grub_uint8_t log2_sect;
    struct grub_xfs_sblock 
    54100  grub_uint8_t log2_agblk;
    55101  grub_uint8_t unused6[67];
    56102  grub_uint8_t log2_dirblk;
     103  grub_uint8_t unused7[7];
     104  grub_uint32_t features2;
     105  grub_uint8_t unused8[4];
     106  grub_uint32_t sb_features_compat;
     107  grub_uint32_t sb_features_ro_compat;
     108  grub_uint32_t sb_features_incompat;
     109  grub_uint32_t sb_features_log_incompat;
    57110} GRUB_PACKED;
    58111
    59112struct grub_xfs_dir_header
    60113{
    61114  grub_uint8_t count;
    62   grub_uint8_t smallino;
     115  grub_uint8_t largeino;
    63116  union
    64117  {
    65118    grub_uint32_t i4;
    struct grub_xfs_dir_header 
    67120  } GRUB_PACKED parent;
    68121} GRUB_PACKED;
    69122
     123/* Structure for directory entry inlined in the inode */
    70124struct grub_xfs_dir_entry
    71125{
    72126  grub_uint8_t len;
    73127  grub_uint16_t offset;
    74128  char name[1];
    75   /* Inode number follows, 32 bits.  */
     129  /* Inode number follows, 32 / 64 bits.  */
    76130} GRUB_PACKED;
    77131
     132/* Structure for directory entry in a block */
    78133struct grub_xfs_dir2_entry
    79134{
    80135  grub_uint64_t inode;
    struct grub_xfs_btree_node 
    90145  grub_uint16_t numrecs;
    91146  grub_uint64_t left;
    92147  grub_uint64_t right;
    93   grub_uint64_t keys[1];
     148  /* In V5 here follow crc, uuid, etc. */
     149  /* Then follow keys and block pointers */
    94150}  GRUB_PACKED;
    95151
    96152struct grub_xfs_btree_root
    struct grub_xfs_inode 
    123179  grub_uint16_t unused3;
    124180  grub_uint8_t fork_offset;
    125181  grub_uint8_t unused4[17];
    126   union
    127   {
    128     char raw[156];
    129     struct dir
    130     {
    131       struct grub_xfs_dir_header dirhead;
    132       struct grub_xfs_dir_entry direntry[1];
    133     } dir;
    134     grub_xfs_extent extents[XFS_INODE_EXTENTS];
    135     struct grub_xfs_btree_root btree;
    136   } GRUB_PACKED data;
    137182} GRUB_PACKED;
    138183
     184#define XFS_V2_INODE_SIZE sizeof(struct grub_xfs_inode)
     185#define XFS_V3_INODE_SIZE (XFS_V2_INODE_SIZE + 76)
     186
    139187struct grub_xfs_dirblock_tail
    140188{
    141189  grub_uint32_t leaf_count;
    struct grub_xfs_data 
    157205  int pos;
    158206  int bsize;
    159207  grub_uint32_t agsize;
     208  unsigned int hasftype:1;
     209  unsigned int hascrc:1;
    160210  struct grub_fshelp_node diropen;
    161211};
    162212
    static grub_dl_t my_mod; 
    164214
    165215
    166216
    167217
     218static int grub_xfs_sb_hascrc(struct grub_xfs_data *data)
     219{
     220  return (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) ==
     221          grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5);
     222}
     223
     224static int grub_xfs_sb_hasftype(struct grub_xfs_data *data)
     225{
     226  if ((data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) ==
     227        grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5) &&
     228      data->sblock.sb_features_incompat & grub_cpu_to_be32_compile_time(XFS_SB_FEAT_INCOMPAT_FTYPE))
     229    return 1;
     230  if (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_MOREBITSBIT) &&
     231      data->sblock.features2 & grub_cpu_to_be32_compile_time(XFS_SB_VERSION2_FTYPE))
     232    return 1;
     233  return 0;
     234}
     235
     236static int grub_xfs_sb_valid(struct grub_xfs_data *data)
     237{
     238  grub_dprintf("xfs", "Validating superblock\n");
     239  if (grub_strncmp ((char *) (data->sblock.magic), "XFSB", 4)
     240      || data->sblock.log2_bsize < GRUB_DISK_SECTOR_BITS
     241      || ((int) data->sblock.log2_bsize
     242          + (int) data->sblock.log2_dirblk) >= 27)
     243    {
     244      grub_error (GRUB_ERR_BAD_FS, "not a XFS filesystem");
     245      return 0;
     246    }
     247  if ((data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) ==
     248       grub_cpu_to_be16_compile_time(XFS_SB_VERSION_5))
     249    {
     250      grub_dprintf("xfs", "XFS v5 superblock detected\n");
     251      if (data->sblock.sb_features_incompat &
     252          grub_cpu_to_be32_compile_time(~XFS_SB_FEAT_INCOMPAT_SUPPORTED))
     253        {
     254          grub_error (GRUB_ERR_BAD_FS, "XFS filesystem has unsupported "
     255                      "incompatible features");
     256          return 0;
     257        }
     258      return 1;
     259    }
     260  else if ((data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_NUMBITS)) ==
     261           grub_cpu_to_be16_compile_time(XFS_SB_VERSION_4))
     262    {
     263      grub_dprintf("xfs", "XFS v4 superblock detected\n");
     264      if (!(data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_DIRV2BIT)))
     265        {
     266          grub_error (GRUB_ERR_BAD_FS, "XFS filesystem without V2 directories "
     267                      "is unsupported");
     268          return 0;
     269        }
     270      if (data->sblock.version & grub_cpu_to_be16_compile_time(~XFS_SB_VERSION_BITS_SUPPORTED) ||
     271          (data->sblock.version & grub_cpu_to_be16_compile_time(XFS_SB_VERSION_MOREBITSBIT) &&
     272           data->sblock.features2 & grub_cpu_to_be16_compile_time(~XFS_SB_VERSION2_BITS_SUPPORTED)))
     273        {
     274          grub_error (GRUB_ERR_BAD_FS, "XFS filesystem has unsupported version "
     275                      "bits");
     276          return 0;
     277        }
     278      return 1;
     279    }
     280  return 0;
     281}
     282
    168283/* Filetype information as used in inodes.  */
    169284#define FILETYPE_INO_MASK       0170000
Note: See TracBrowser for help on using the repository browser.