(root)/
util-linux-2.39/
libblkid/
src/
superblocks/
reiserfs.c
       1  /*
       2   * Copyright (C) 1999, 2001 by Andries Brouwer
       3   * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
       4   * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
       5   *
       6   * This file may be redistributed under the terms of the
       7   * GNU Lesser General Public License.
       8   */
       9  #include <stdio.h>
      10  #include <stdlib.h>
      11  #include <unistd.h>
      12  #include <string.h>
      13  #include <stdint.h>
      14  
      15  #include "superblocks.h"
      16  
      17  struct reiserfs_super_block {
      18  	uint32_t	rs_blocks_count;
      19  	uint32_t	rs_free_blocks;
      20  	uint32_t	rs_root_block;
      21  	uint32_t	rs_journal_block;
      22  	uint32_t	rs_journal_dev;
      23  	uint32_t	rs_orig_journal_size;
      24  	uint32_t	rs_dummy2[5];
      25  	uint16_t	rs_blocksize;
      26  	uint16_t	rs_dummy3[3];
      27  	unsigned char	rs_magic[12];
      28  	uint32_t	rs_dummy4[5];
      29  	unsigned char	rs_uuid[16];
      30  	char		rs_label[16];
      31  } __attribute__((packed));
      32  
      33  struct reiser4_super_block {
      34  	unsigned char	rs4_magic[16];
      35  	uint8_t		rs4_dummy[3];
      36  	uint8_t		rs4_blocksize;
      37  	unsigned char	rs4_uuid[16];
      38  	unsigned char	rs4_label[16];
      39  	uint64_t	rs4_dummy2;
      40  } __attribute__((packed));
      41  
      42  static int probe_reiser(blkid_probe pr, const struct blkid_idmag *mag)
      43  {
      44  	struct reiserfs_super_block *rs;
      45  	unsigned int blocksize;
      46  
      47  	rs = blkid_probe_get_sb(pr, mag, struct reiserfs_super_block);
      48  	if (!rs)
      49  		return errno ? -errno : 1;
      50  
      51  	blocksize = le16_to_cpu(rs->rs_blocksize);
      52  
      53  	/* The blocksize must be at least 512B */
      54  	if ((blocksize >> 9) == 0)
      55  		return 1;
      56  
      57  	/* If the superblock is inside the journal, we have the wrong one */
      58  	if (mag->kboff / (blocksize >> 9) > le32_to_cpu(rs->rs_journal_block) / 2)
      59  		return 1;
      60  
      61  	/* LABEL/UUID are only valid for later versions of Reiserfs v3.6. */
      62  	if (mag->magic[6] == '2' || mag->magic[6] == '3') {
      63  		if (*rs->rs_label)
      64  			blkid_probe_set_label(pr,
      65  					(unsigned char *) rs->rs_label,
      66  					sizeof(rs->rs_label));
      67  		blkid_probe_set_uuid(pr, rs->rs_uuid);
      68  	}
      69  
      70  	if (mag->magic[6] == '3')
      71  		blkid_probe_set_version(pr, "JR");
      72  	else if (mag->magic[6] == '2')
      73  		blkid_probe_set_version(pr, "3.6");
      74  	else
      75  		blkid_probe_set_version(pr, "3.5");
      76  
      77  	blkid_probe_set_fsblocksize(pr, blocksize);
      78  	blkid_probe_set_block_size(pr, blocksize);
      79  
      80  	return 0;
      81  }
      82  
      83  static int probe_reiser4(blkid_probe pr, const struct blkid_idmag *mag)
      84  {
      85  	struct reiser4_super_block *rs4;
      86  	unsigned int blocksize;
      87  
      88  	rs4 = blkid_probe_get_sb(pr, mag, struct reiser4_super_block);
      89  	if (!rs4)
      90  		return errno ? -errno : 1;
      91  
      92  	blocksize = rs4->rs4_blocksize * 256;
      93  
      94  	if (*rs4->rs4_label)
      95  		blkid_probe_set_label(pr, rs4->rs4_label, sizeof(rs4->rs4_label));
      96  	blkid_probe_set_uuid(pr, rs4->rs4_uuid);
      97  	blkid_probe_set_version(pr, "4");
      98  
      99  	blkid_probe_set_fsblocksize(pr, blocksize);
     100  	blkid_probe_set_block_size(pr, blocksize);
     101  
     102  	return 0;
     103  }
     104  
     105  
     106  const struct blkid_idinfo reiser_idinfo =
     107  {
     108  	.name		= "reiserfs",
     109  	.usage		= BLKID_USAGE_FILESYSTEM,
     110  	.probefunc	= probe_reiser,
     111  	.minsz		= 128 * 1024,
     112  	.magics		=
     113  	{
     114  		{ .magic = "ReIsErFs",  .len = 8, .kboff = 8,  .sboff = 0x34 },
     115  		{ .magic = "ReIsEr2Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
     116  		{ .magic = "ReIsEr3Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
     117  		{ .magic = "ReIsErFs",  .len = 8, .kboff = 64, .sboff = 0x34 },
     118  		{ .magic = "ReIsErFs",  .len = 8, .kboff =  8, .sboff = 20   },
     119  		{ NULL }
     120  	}
     121  };
     122  
     123  const struct blkid_idinfo reiser4_idinfo =
     124  {
     125  	.name		= "reiser4",
     126  	.usage		= BLKID_USAGE_FILESYSTEM,
     127  	.probefunc	= probe_reiser4,
     128  	.minsz		= 128 * 1024,
     129  	.magics		=
     130  	{
     131  		{ .magic = "ReIsEr4", .len = 7, .kboff = 64 },
     132  		{ NULL }
     133  	}
     134  };
     135  
     136  
     137  
     138