~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libblkid/src/superblocks/btrfs.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
 
3
 *
 
4
 * This file may be redistributed under the terms of the
 
5
 * GNU Lesser General Public License.
 
6
 */
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <unistd.h>
 
10
#include <string.h>
 
11
#include <stdint.h>
 
12
 
 
13
#include "superblocks.h"
 
14
 
 
15
struct btrfs_super_block {
 
16
        uint8_t csum[32];
 
17
        uint8_t fsid[16];
 
18
        uint64_t bytenr;
 
19
        uint64_t flags;
 
20
        uint8_t magic[8];
 
21
        uint64_t generation;
 
22
        uint64_t root;
 
23
        uint64_t chunk_root;
 
24
        uint64_t log_root;
 
25
        uint64_t log_root_transid;
 
26
        uint64_t total_bytes;
 
27
        uint64_t bytes_used;
 
28
        uint64_t root_dir_objectid;
 
29
        uint64_t num_devices;
 
30
        uint32_t sectorsize;
 
31
        uint32_t nodesize;
 
32
        uint32_t leafsize;
 
33
        uint32_t stripesize;
 
34
        uint32_t sys_chunk_array_size;
 
35
        uint64_t chunk_root_generation;
 
36
        uint64_t compat_flags;
 
37
        uint64_t compat_ro_flags;
 
38
        uint64_t incompat_flags;
 
39
        uint16_t csum_type;
 
40
        uint8_t root_level;
 
41
        uint8_t chunk_root_level;
 
42
        uint8_t log_root_level;
 
43
        struct btrfs_dev_item {
 
44
                uint64_t devid;
 
45
                uint64_t total_bytes;
 
46
                uint64_t bytes_used;
 
47
                uint32_t io_align;
 
48
                uint32_t io_width;
 
49
                uint32_t sector_size;
 
50
                uint64_t type;
 
51
                uint64_t generation;
 
52
                uint64_t start_offset;
 
53
                uint32_t dev_group;
 
54
                uint8_t seek_speed;
 
55
                uint8_t bandwidth;
 
56
                uint8_t uuid[16];
 
57
                uint8_t fsid[16];
 
58
        } __attribute__ ((__packed__)) dev_item;
 
59
        uint8_t label[256];
 
60
} __attribute__ ((__packed__));
 
61
 
 
62
static int probe_btrfs(blkid_probe pr, const struct blkid_idmag *mag)
 
63
{
 
64
        struct btrfs_super_block *bfs;
 
65
 
 
66
        bfs = blkid_probe_get_sb(pr, mag, struct btrfs_super_block);
 
67
        if (!bfs)
 
68
                return -1;
 
69
 
 
70
        if (*bfs->label)
 
71
                blkid_probe_set_label(pr,
 
72
                                (unsigned char *) bfs->label,
 
73
                                sizeof(bfs->label));
 
74
 
 
75
        blkid_probe_set_uuid(pr, bfs->fsid);
 
76
        blkid_probe_set_uuid_as(pr, bfs->dev_item.uuid, "UUID_SUB");
 
77
 
 
78
        return 0;
 
79
}
 
80
 
 
81
const struct blkid_idinfo btrfs_idinfo =
 
82
{
 
83
        .name           = "btrfs",
 
84
        .usage          = BLKID_USAGE_FILESYSTEM,
 
85
        .probefunc      = probe_btrfs,
 
86
        .minsz          = 256 * 1024 * 1024,
 
87
        .magics         =
 
88
        {
 
89
                { .magic = "_BHRfS_M", .len = 8, .kboff = 64, .sboff = 0x40 },
 
90
                { NULL }
 
91
        }
 
92
};
 
93