chiark / gitweb /
switch tools and volume_id from LGPL to GPLv2
[elogind.git] / extras / volume_id / volume_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 #include "minix.h"
30
31 struct minix_super_block
32 {
33         uint16_t        s_ninodes;
34         uint16_t        s_nzones;
35         uint16_t        s_imap_blocks;
36         uint16_t        s_zmap_blocks;
37         uint16_t        s_firstdatazone;
38         uint16_t        s_log_zone_size;
39         uint32_t        s_max_size;
40         uint16_t        s_magic;
41         uint16_t        s_state;
42         uint32_t        s_zones;
43 } __attribute__((__packed__));
44
45 #define MINIX_SUPERBLOCK_OFFSET                 0x400
46
47 int volume_id_probe_minix(struct volume_id *id, uint64_t off)
48 {
49         struct minix_super_block *ms;
50
51         dbg("probing at offset 0x%llx", (unsigned long long) off);
52
53         ms = (struct minix_super_block *) volume_id_get_buffer(id, off + MINIX_SUPERBLOCK_OFFSET, 0x200);
54         if (ms == NULL)
55                 return -1;
56
57         if (le16_to_cpu(ms->s_magic) == 0x137f) {
58                 strcpy(id->type_version, "1");
59                 goto found;
60         }
61
62         if (le16_to_cpu(ms->s_magic) == 0x1387) {
63                 strcpy(id->type_version, "1");
64                 goto found;
65         }
66
67         if (le16_to_cpu(ms->s_magic) == 0x2468) {
68                 strcpy(id->type_version, "2");
69                 goto found;
70         }
71
72         if (le16_to_cpu(ms->s_magic) == 0x2478) {
73                 strcpy(id->type_version, "2");
74                 goto found;
75         }
76
77         goto exit;
78
79 found:
80         volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
81         id->type = "minix";
82         return 0;
83
84 exit:
85         return -1;
86 }