chiark / gitweb /
volume_id: replace __packed__ by PACKED macro
[elogind.git] / extras / volume_id / libvolume_id / minix.c
1 /*
2  * volume_id - reads filesystem label and uuid
3  *
4  * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
5  *
6  *      This program is free software; you can redistribute it and/or modify it
7  *      under the terms of the GNU General Public License as published by the
8  *      Free Software Foundation version 2 of the License.
9  */
10
11 #ifndef _GNU_SOURCE
12 #define _GNU_SOURCE 1
13 #endif
14
15 #ifdef HAVE_CONFIG_H
16 #  include <config.h>
17 #endif
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <ctype.h>
25
26 #include "volume_id.h"
27 #include "logging.h"
28 #include "util.h"
29
30 struct minix_super_block
31 {
32         uint16_t        s_ninodes;
33         uint16_t        s_nzones;
34         uint16_t        s_imap_blocks;
35         uint16_t        s_zmap_blocks;
36         uint16_t        s_firstdatazone;
37         uint16_t        s_log_zone_size;
38         uint32_t        s_max_size;
39         uint16_t        s_magic;
40         uint16_t        s_state;
41         uint32_t        s_zones;
42 } PACKED;
43
44 #define MINIX_SUPERBLOCK_OFFSET                 0x400
45
46 int volume_id_probe_minix(struct volume_id *id, uint64_t off)
47 {
48         struct minix_super_block *ms;
49
50         dbg("probing at offset 0x%llx", (unsigned long long) off);
51
52         ms = (struct minix_super_block *) volume_id_get_buffer(id, off + MINIX_SUPERBLOCK_OFFSET, 0x200);
53         if (ms == NULL)
54                 return -1;
55
56         if (le16_to_cpu(ms->s_magic) == 0x137f) {
57                 strcpy(id->type_version, "1");
58                 goto found;
59         }
60
61         if (le16_to_cpu(ms->s_magic) == 0x1387) {
62                 strcpy(id->type_version, "1");
63                 goto found;
64         }
65
66         if (le16_to_cpu(ms->s_magic) == 0x2468) {
67                 strcpy(id->type_version, "2");
68                 goto found;
69         }
70
71         if (le16_to_cpu(ms->s_magic) == 0x2478) {
72                 strcpy(id->type_version, "2");
73                 goto found;
74         }
75
76         goto exit;
77
78 found:
79         volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
80         id->type = "minix";
81         return 0;
82
83 exit:
84         return -1;
85 }