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