/src/util-linux/libblkid/src/superblocks/romfs.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 1999, 2001 by Andries Brouwer |
3 | | * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o |
4 | | * Copyright (C) 2008 Karel Zak <kzak@redhat.com> |
5 | | * |
6 | | * This file may be redistributed under the terms of the |
7 | | * GNU Lesser General Public License. |
8 | | */ |
9 | | |
10 | | #include <stdio.h> |
11 | | #include <stdlib.h> |
12 | | #include <unistd.h> |
13 | | #include <string.h> |
14 | | #include <errno.h> |
15 | | #include <ctype.h> |
16 | | #include <stdint.h> |
17 | | |
18 | | #include "superblocks.h" |
19 | | |
20 | | struct romfs_super_block { |
21 | | unsigned char ros_magic[8]; |
22 | | uint32_t ros_full_size; |
23 | | uint32_t ros_checksum; |
24 | | unsigned char ros_volume[16]; |
25 | | } __attribute__((packed)); |
26 | | |
27 | | static int romfs_verify_csum(blkid_probe pr, const struct blkid_idmag *mag, |
28 | | const struct romfs_super_block *ros) |
29 | 126 | { |
30 | 126 | uint32_t csummed_size = min((uint32_t) 512, |
31 | 126 | be32_to_cpu(ros->ros_full_size)); |
32 | 126 | const unsigned char *csummed; |
33 | 126 | uint32_t csum; |
34 | | |
35 | 126 | if (csummed_size % sizeof(uint32_t) != 0) |
36 | 8 | return 0; |
37 | | |
38 | 118 | csummed = blkid_probe_get_sb_buffer(pr, mag, csummed_size); |
39 | 118 | if (!csummed) |
40 | 10 | return 0; |
41 | | |
42 | 108 | csum = 0; |
43 | 12.8k | while (csummed_size) { |
44 | 12.7k | csum += be32_to_cpu(*(uint32_t *) csummed); |
45 | 12.7k | csummed_size -= sizeof(uint32_t); |
46 | 12.7k | csummed += sizeof(uint32_t); |
47 | 12.7k | } |
48 | 108 | return blkid_probe_verify_csum(pr, csum, 0); |
49 | 118 | } |
50 | | |
51 | | static int probe_romfs(blkid_probe pr, const struct blkid_idmag *mag) |
52 | 126 | { |
53 | 126 | const struct romfs_super_block *ros; |
54 | | |
55 | 126 | ros = blkid_probe_get_sb(pr, mag, struct romfs_super_block); |
56 | 126 | if (!ros) |
57 | 0 | return errno ? -errno : 1; |
58 | | |
59 | 126 | if (!romfs_verify_csum(pr, mag, ros)) |
60 | 126 | return 1; |
61 | | |
62 | 0 | if (*((char *) ros->ros_volume) != '\0') |
63 | 0 | blkid_probe_set_label(pr, ros->ros_volume, |
64 | 0 | sizeof(ros->ros_volume)); |
65 | |
|
66 | 0 | blkid_probe_set_fsblocksize(pr, 1024); |
67 | 0 | blkid_probe_set_fssize(pr, be32_to_cpu(ros->ros_full_size)); |
68 | 0 | blkid_probe_set_block_size(pr, 1024); |
69 | |
|
70 | 0 | return 0; |
71 | 126 | } |
72 | | |
73 | | const struct blkid_idinfo romfs_idinfo = |
74 | | { |
75 | | .name = "romfs", |
76 | | .usage = BLKID_USAGE_FILESYSTEM, |
77 | | .probefunc = probe_romfs, |
78 | | .magics = |
79 | | { |
80 | | { .magic = "-rom1fs-", .len = 8 }, |
81 | | { NULL } |
82 | | } |
83 | | }; |
84 | | |