reiserfs.c revision 2603474ff9be2418900581da1af5cccc9f13cae1
456N/A/*
456N/A * volume_id - reads filesystem label and uuid
456N/A *
905N/A * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
851N/A * Copyright (C) 2005 Tobias Klauser <tklauser@access.unizh.ch>
456N/A *
456N/A * This program is free software; you can redistribute it and/or modify it
919N/A * under the terms of the GNU General Public License as published by the
919N/A * Free Software Foundation version 2 of the License.
919N/A */
919N/A
919N/A#ifndef _GNU_SOURCE
919N/A#define _GNU_SOURCE 1
919N/A#endif
919N/A
919N/A#ifdef HAVE_CONFIG_H
919N/A# include <config.h>
919N/A#endif
919N/A
919N/A#include <stdio.h>
919N/A#include <stdlib.h>
919N/A#include <unistd.h>
919N/A#include <string.h>
919N/A#include <errno.h>
456N/A#include <ctype.h>
456N/A
456N/A#include "libvolume_id.h"
456N/A#include "libvolume_id-private.h"
493N/A#include "util.h"
456N/A
456N/Astruct reiserfs_super_block {
851N/A uint32_t blocks_count;
456N/A uint32_t free_blocks;
911N/A uint32_t root_block;
911N/A uint32_t journal_block;
911N/A uint32_t journal_dev;
911N/A uint32_t orig_journal_size;
456N/A uint32_t dummy2[5];
851N/A uint16_t blocksize;
456N/A uint16_t dummy3[3];
456N/A uint8_t magic[12];
456N/A uint32_t dummy4[5];
456N/A uint8_t uuid[16];
456N/A uint8_t label[16];
456N/A} PACKED;
456N/A
456N/Astruct reiser4_super_block {
456N/A uint8_t magic[16];
905N/A uint16_t dummy[2];
851N/A uint8_t uuid[16];
851N/A uint8_t label[16];
851N/A uint64_t dummy2;
456N/A} PACKED;
456N/A
456N/A#define REISERFS1_SUPERBLOCK_OFFSET 0x2000
851N/A#define REISERFS_SUPERBLOCK_OFFSET 0x10000
851N/A
851N/Aint volume_id_probe_reiserfs(struct volume_id *id, uint64_t off, uint64_t size)
851N/A{
851N/A struct reiserfs_super_block *rs;
503N/A struct reiser4_super_block *rs4;
456N/A uint8_t *buf;
851N/A
851N/A info("probing at offset 0x%llx\n", (unsigned long long) off);
910N/A
922N/A buf = volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200);
922N/A if (buf == NULL)
922N/A return -1;
rs = (struct reiserfs_super_block *) buf;
if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
strcpy(id->type_version, "3.5");
id->type = "reiserfs";
goto found;
}
if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) {
strcpy(id->type_version, "3.6");
id->type = "reiserfs";
goto found_label;
}
if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) {
strcpy(id->type_version, "JR");
id->type = "reiserfs";
goto found_label;
}
rs4 = (struct reiser4_super_block *) buf;
if (memcmp(rs4->magic, "ReIsEr4", 7) == 0) {
strcpy(id->type_version, "4");
volume_id_set_label_raw(id, rs4->label, 16);
volume_id_set_label_string(id, rs4->label, 16);
volume_id_set_uuid(id, rs4->uuid, 0, UUID_DCE);
id->type = "reiser4";
goto found;
}
buf = volume_id_get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200);
if (buf == NULL)
return -1;
rs = (struct reiserfs_super_block *) buf;
if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
strcpy(id->type_version, "3.5");
id->type = "reiserfs";
goto found;
}
return -1;
found_label:
volume_id_set_label_raw(id, rs->label, 16);
volume_id_set_label_string(id, rs->label, 16);
volume_id_set_uuid(id, rs->uuid, 0, UUID_DCE);
found:
volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
return 0;
}