]>
Commit | Line | Data |
---|---|---|
9e95aa12 KZ |
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 | */ | |
7cc112d9 SK |
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 | */ | |
058cda4c KZ |
19 | extern int fs_version; |
20 | extern char *super_block_buffer; | |
7cc112d9 | 21 | |
058cda4c KZ |
22 | #define Super (*(struct minix_super_block *) super_block_buffer) |
23 | #define Super3 (*(struct minix3_super_block *) super_block_buffer) | |
7cc112d9 | 24 | |
058cda4c KZ |
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)) | |
7cc112d9 SK |
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: | |
1908a3c2 | 41 | return Super.s_ninodes; |
7cc112d9 SK |
42 | } |
43 | } | |
44 | ||
45 | static inline unsigned long get_nzones(void) | |
46 | { | |
47 | switch (fs_version) { | |
48 | case 3: | |
1908a3c2 | 49 | return Super3.s_zones; |
7cc112d9 | 50 | case 2: |
1908a3c2 | 51 | return Super.s_zones; |
7cc112d9 | 52 | default: |
1908a3c2 | 53 | return Super.s_nzones; |
7cc112d9 SK |
54 | } |
55 | } | |
56 | ||
57 | static inline unsigned long get_nimaps(void) | |
58 | { | |
59 | switch (fs_version) { | |
60 | case 3: | |
1908a3c2 | 61 | return Super3.s_imap_blocks; |
7cc112d9 | 62 | default: |
1908a3c2 | 63 | return Super.s_imap_blocks; |
7cc112d9 SK |
64 | } |
65 | } | |
66 | ||
67 | static inline unsigned long get_nzmaps(void) | |
68 | { | |
69 | switch (fs_version) { | |
70 | case 3: | |
1908a3c2 | 71 | return Super3.s_zmap_blocks; |
7cc112d9 | 72 | default: |
1908a3c2 | 73 | return Super.s_zmap_blocks; |
7cc112d9 SK |
74 | } |
75 | } | |
76 | ||
1908a3c2 | 77 | static inline off_t get_first_zone(void) |
7cc112d9 SK |
78 | { |
79 | switch (fs_version) { | |
80 | case 3: | |
1908a3c2 | 81 | return Super3.s_firstdatazone; |
7cc112d9 | 82 | default: |
1908a3c2 | 83 | return Super.s_firstdatazone; |
7cc112d9 SK |
84 | } |
85 | } | |
86 | ||
1908a3c2 | 87 | static inline size_t get_zone_size(void) |
7cc112d9 SK |
88 | { |
89 | switch (fs_version) { | |
90 | case 3: | |
1908a3c2 | 91 | return Super3.s_log_zone_size; |
7cc112d9 | 92 | default: |
1908a3c2 | 93 | return Super.s_log_zone_size; |
7cc112d9 SK |
94 | } |
95 | } | |
96 | ||
1908a3c2 | 97 | static inline size_t get_max_size(void) |
7cc112d9 SK |
98 | { |
99 | switch (fs_version) { | |
100 | case 3: | |
1908a3c2 | 101 | return Super3.s_max_size; |
7cc112d9 | 102 | default: |
1908a3c2 | 103 | return Super.s_max_size; |
7cc112d9 SK |
104 | } |
105 | } | |
106 | ||
1908a3c2 | 107 | static inline unsigned long inode_blocks(void) |
7cc112d9 SK |
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 | ||
1908a3c2 | 118 | static inline off_t first_zone_data(void) |
7cc112d9 SK |
119 | { |
120 | return 2 + get_nimaps() + get_nzmaps() + inode_blocks(); | |
121 | } | |
122 | ||
1908a3c2 | 123 | static inline size_t get_inode_buffer_size(void) |
7cc112d9 SK |
124 | { |
125 | return inode_blocks() * MINIX_BLOCK_SIZE; | |
126 | } | |
127 | ||
128 | #endif /* UTIL_LINUX_MINIX_PROGRAMS_H */ |