Upload Tizen:Base source
[framework/base/util-linux-ng.git] / shlibs / blkid / src / probers / jfs.c
1 /*
2  * Copyright (C) 1999 by Andries Brouwer
3  * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
4  * Copyright (C) 2001 by Andreas Dilger
5  * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6  * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
7  *
8  * This file may be redistributed under the terms of the
9  * GNU Lesser General Public License.
10  */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <errno.h>
16 #include <ctype.h>
17 #include <stdint.h>
18
19 #include "blkidP.h"
20
21 struct jfs_super_block {
22         unsigned char   js_magic[4];
23         uint32_t        js_version;
24         uint64_t        js_size;
25         uint32_t        js_bsize;       /* 4: aggregate block size in bytes */
26         uint16_t        js_l2bsize;     /* 2: log2 of s_bsize */
27         uint16_t        js_l2bfactor;   /* 2: log2(s_bsize/hardware block size) */
28         uint32_t        js_pbsize;      /* 4: hardware/LVM block size in bytes */
29         uint16_t        js_l2pbsize;    /* 2: log2 of s_pbsize */
30         uint16_t        js_pad;         /* 2: padding necessary for alignment */
31         uint32_t        js_dummy2[26];
32         unsigned char   js_uuid[16];
33         unsigned char   js_label[16];
34         unsigned char   js_loguuid[16];
35 };
36
37 static int probe_jfs(blkid_probe pr, const struct blkid_idmag *mag)
38 {
39         struct jfs_super_block *js;
40
41         js = blkid_probe_get_sb(pr, mag, struct jfs_super_block);
42         if (!js)
43                 return -1;
44         if (le32_to_cpu(js->js_bsize) != (1 << le16_to_cpu(js->js_l2bsize)))
45                 return 1;
46         if (le32_to_cpu(js->js_pbsize) != (1 << le16_to_cpu(js->js_l2pbsize)))
47                 return 1;
48         if ((le16_to_cpu(js->js_l2bsize) - le16_to_cpu(js->js_l2pbsize)) !=
49             le16_to_cpu(js->js_l2bfactor))
50                 return 1;
51
52         if (strlen((char *) js->js_label))
53                 blkid_probe_set_label(pr, js->js_label, sizeof(js->js_label));
54         blkid_probe_set_uuid(pr, js->js_uuid);
55         return 0;
56 }
57
58
59 const struct blkid_idinfo jfs_idinfo =
60 {
61         .name           = "jfs",
62         .usage          = BLKID_USAGE_FILESYSTEM,
63         .probefunc      = probe_jfs,
64         .magics         =
65         {
66                 { .magic = "JFS1", .len = 4, .kboff = 32 },
67                 { NULL }
68         }
69 };
70