]> git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/minix_programs.h
hexdump: check blocksize when display data
[thirdparty/util-linux.git] / disk-utils / minix_programs.h
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * Copyright (C) 2011 Sami Kerola <kerolasa@iki.fi>
10 */
11 #ifndef UTIL_LINUX_MINIX_PROGRAMS_H
12 #define UTIL_LINUX_MINIX_PROGRAMS_H
13
14 #include "minix.h"
15
16 /*
17 * Global variables.
18 */
19 extern int fs_version;
20 extern char *super_block_buffer;
21
22 #define Super (*(struct minix_super_block *) super_block_buffer)
23 #define Super3 (*(struct minix3_super_block *) super_block_buffer)
24
25 #define INODE_SIZE (sizeof(struct minix_inode))
26 #define INODE2_SIZE (sizeof(struct minix2_inode))
27
28 #define BITS_PER_BLOCK (MINIX_BLOCK_SIZE << 3)
29
30 #define UPPER(size,n) ((size+((n)-1))/(n))
31
32 /*
33 * Inline functions.
34 */
35 static inline unsigned long get_ninodes(void)
36 {
37 switch (fs_version) {
38 case 3:
39 return Super3.s_ninodes;
40 default:
41 return Super.s_ninodes;
42 }
43 }
44
45 static inline unsigned long get_nzones(void)
46 {
47 switch (fs_version) {
48 case 3:
49 return Super3.s_zones;
50 case 2:
51 return Super.s_zones;
52 default:
53 return Super.s_nzones;
54 }
55 }
56
57 static inline unsigned long get_nimaps(void)
58 {
59 switch (fs_version) {
60 case 3:
61 return Super3.s_imap_blocks;
62 default:
63 return Super.s_imap_blocks;
64 }
65 }
66
67 static inline unsigned long get_nzmaps(void)
68 {
69 switch (fs_version) {
70 case 3:
71 return Super3.s_zmap_blocks;
72 default:
73 return Super.s_zmap_blocks;
74 }
75 }
76
77 static inline off_t get_first_zone(void)
78 {
79 switch (fs_version) {
80 case 3:
81 return Super3.s_firstdatazone;
82 default:
83 return Super.s_firstdatazone;
84 }
85 }
86
87 static inline size_t get_zone_size(void)
88 {
89 switch (fs_version) {
90 case 3:
91 return Super3.s_log_zone_size;
92 default:
93 return Super.s_log_zone_size;
94 }
95 }
96
97 static inline size_t get_max_size(void)
98 {
99 switch (fs_version) {
100 case 3:
101 return Super3.s_max_size;
102 default:
103 return Super.s_max_size;
104 }
105 }
106
107 static inline unsigned long inode_blocks(void)
108 {
109 switch (fs_version) {
110 case 3:
111 case 2:
112 return UPPER(get_ninodes(), MINIX2_INODES_PER_BLOCK);
113 default:
114 return UPPER(get_ninodes(), MINIX_INODES_PER_BLOCK);
115 }
116 }
117
118 static inline off_t first_zone_data(void)
119 {
120 return 2 + get_nimaps() + get_nzmaps() + inode_blocks();
121 }
122
123 static inline size_t get_inode_buffer_size(void)
124 {
125 return inode_blocks() * MINIX_BLOCK_SIZE;
126 }
127
128 #endif /* UTIL_LINUX_MINIX_PROGRAMS_H */