1 |
199 |
simons |
/*
|
2 |
|
|
* linux/fs/ext2/super.c
|
3 |
|
|
*
|
4 |
|
|
* Copyright (C) 1992, 1993, 1994, 1995
|
5 |
|
|
* Remy Card (card@masi.ibp.fr)
|
6 |
|
|
* Laboratoire MASI - Institut Blaise Pascal
|
7 |
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
8 |
|
|
*
|
9 |
|
|
* from
|
10 |
|
|
*
|
11 |
|
|
* linux/fs/minix/inode.c
|
12 |
|
|
*
|
13 |
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
14 |
|
|
*
|
15 |
|
|
* Big-endian to little-endian byte-swapping/bitmaps by
|
16 |
|
|
* David S. Miller (davem@caip.rutgers.edu), 1995
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
#include <linux/module.h>
|
20 |
|
|
|
21 |
|
|
#include <stdarg.h>
|
22 |
|
|
|
23 |
|
|
#include <asm/bitops.h>
|
24 |
|
|
#include <asm/segment.h>
|
25 |
|
|
#include <asm/system.h>
|
26 |
|
|
|
27 |
|
|
#include <linux/errno.h>
|
28 |
|
|
#include <linux/fs.h>
|
29 |
|
|
#include <linux/ext2_fs.h>
|
30 |
|
|
#include <linux/malloc.h>
|
31 |
|
|
#include <linux/sched.h>
|
32 |
|
|
#include <linux/stat.h>
|
33 |
|
|
#include <linux/string.h>
|
34 |
|
|
#include <linux/locks.h>
|
35 |
|
|
|
36 |
|
|
static char error_buf[1024];
|
37 |
|
|
|
38 |
|
|
void ext2_error (struct super_block * sb, const char * function,
|
39 |
|
|
const char * fmt, ...)
|
40 |
|
|
{
|
41 |
|
|
va_list args;
|
42 |
|
|
|
43 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
44 |
|
|
sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
|
45 |
|
|
sb->u.ext2_sb.s_es->s_state =
|
46 |
|
|
swab16(swab16(sb->u.ext2_sb.s_es->s_state) | EXT2_ERROR_FS);
|
47 |
|
|
mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
|
48 |
|
|
sb->s_dirt = 1;
|
49 |
|
|
}
|
50 |
|
|
va_start (args, fmt);
|
51 |
|
|
vsprintf (error_buf, fmt, args);
|
52 |
|
|
va_end (args);
|
53 |
|
|
if (test_opt (sb, ERRORS_PANIC) ||
|
54 |
|
|
(swab16(sb->u.ext2_sb.s_es->s_errors) == EXT2_ERRORS_PANIC &&
|
55 |
|
|
!test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_RO)))
|
56 |
|
|
panic ("EXT2-fs panic (device %s): %s: %s\n",
|
57 |
|
|
kdevname(sb->s_dev), function, error_buf);
|
58 |
|
|
printk (KERN_CRIT "EXT2-fs error (device %s): %s: %s\n",
|
59 |
|
|
kdevname(sb->s_dev), function, error_buf);
|
60 |
|
|
if (test_opt (sb, ERRORS_RO) ||
|
61 |
|
|
(swab16(sb->u.ext2_sb.s_es->s_errors) == EXT2_ERRORS_RO &&
|
62 |
|
|
!test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_PANIC))) {
|
63 |
|
|
printk ("Remounting filesystem read-only\n");
|
64 |
|
|
sb->s_flags |= MS_RDONLY;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
NORET_TYPE void ext2_panic (struct super_block * sb, const char * function,
|
69 |
|
|
const char * fmt, ...)
|
70 |
|
|
{
|
71 |
|
|
va_list args;
|
72 |
|
|
|
73 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
74 |
|
|
sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
|
75 |
|
|
sb->u.ext2_sb.s_es->s_state =
|
76 |
|
|
swab16(swab16(sb->u.ext2_sb.s_es->s_state) | EXT2_ERROR_FS);
|
77 |
|
|
mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
|
78 |
|
|
sb->s_dirt = 1;
|
79 |
|
|
}
|
80 |
|
|
va_start (args, fmt);
|
81 |
|
|
vsprintf (error_buf, fmt, args);
|
82 |
|
|
va_end (args);
|
83 |
|
|
/* this is to prevent panic from syncing this filesystem */
|
84 |
|
|
if (sb->s_lock)
|
85 |
|
|
sb->s_lock=0;
|
86 |
|
|
sb->s_flags |= MS_RDONLY;
|
87 |
|
|
panic ("EXT2-fs panic (device %s): %s: %s\n",
|
88 |
|
|
kdevname(sb->s_dev), function, error_buf);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void ext2_warning (struct super_block * sb, const char * function,
|
92 |
|
|
const char * fmt, ...)
|
93 |
|
|
{
|
94 |
|
|
va_list args;
|
95 |
|
|
|
96 |
|
|
va_start (args, fmt);
|
97 |
|
|
vsprintf (error_buf, fmt, args);
|
98 |
|
|
va_end (args);
|
99 |
|
|
printk (KERN_WARNING "EXT2-fs warning (device %s): %s: %s\n",
|
100 |
|
|
kdevname(sb->s_dev), function, error_buf);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
void ext2_put_super (struct super_block * sb)
|
104 |
|
|
{
|
105 |
|
|
int db_count;
|
106 |
|
|
int i;
|
107 |
|
|
|
108 |
|
|
lock_super (sb);
|
109 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
110 |
|
|
sb->u.ext2_sb.s_es->s_state = swab16(sb->u.ext2_sb.s_mount_state);
|
111 |
|
|
mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
|
112 |
|
|
}
|
113 |
|
|
sb->s_dev = 0;
|
114 |
|
|
db_count = sb->u.ext2_sb.s_db_per_group;
|
115 |
|
|
for (i = 0; i < db_count; i++)
|
116 |
|
|
if (sb->u.ext2_sb.s_group_desc[i])
|
117 |
|
|
brelse (sb->u.ext2_sb.s_group_desc[i]);
|
118 |
|
|
kfree_s (sb->u.ext2_sb.s_group_desc,
|
119 |
|
|
db_count * sizeof (struct buffer_head *));
|
120 |
|
|
for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
|
121 |
|
|
if (sb->u.ext2_sb.s_inode_bitmap[i])
|
122 |
|
|
brelse (sb->u.ext2_sb.s_inode_bitmap[i]);
|
123 |
|
|
for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++)
|
124 |
|
|
if (sb->u.ext2_sb.s_block_bitmap[i])
|
125 |
|
|
brelse (sb->u.ext2_sb.s_block_bitmap[i]);
|
126 |
|
|
brelse (sb->u.ext2_sb.s_sbh);
|
127 |
|
|
unlock_super (sb);
|
128 |
|
|
MOD_DEC_USE_COUNT;
|
129 |
|
|
return;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
static struct super_operations ext2_sops = {
|
133 |
|
|
ext2_read_inode,
|
134 |
|
|
NULL,
|
135 |
|
|
ext2_write_inode,
|
136 |
|
|
ext2_put_inode,
|
137 |
|
|
ext2_put_super,
|
138 |
|
|
ext2_write_super,
|
139 |
|
|
ext2_statfs,
|
140 |
|
|
ext2_remount
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
/*
|
144 |
|
|
* This function has been shamelessly adapted from the msdos fs
|
145 |
|
|
*/
|
146 |
|
|
static int parse_options (char * options, unsigned long * sb_block,
|
147 |
|
|
unsigned short *resuid, unsigned short * resgid,
|
148 |
|
|
unsigned long * mount_options)
|
149 |
|
|
{
|
150 |
|
|
char * this_char;
|
151 |
|
|
char * value;
|
152 |
|
|
|
153 |
|
|
if (!options)
|
154 |
|
|
return 1;
|
155 |
|
|
for (this_char = strtok (options, ",");
|
156 |
|
|
this_char != NULL;
|
157 |
|
|
this_char = strtok (NULL, ",")) {
|
158 |
|
|
if ((value = strchr (this_char, '=')) != NULL)
|
159 |
|
|
*value++ = 0;
|
160 |
|
|
if (!strcmp (this_char, "bsddf"))
|
161 |
|
|
clear_opt (*mount_options, MINIX_DF);
|
162 |
|
|
else if (!strcmp (this_char, "check")) {
|
163 |
|
|
if (!value || !*value)
|
164 |
|
|
set_opt (*mount_options, CHECK_NORMAL);
|
165 |
|
|
else if (!strcmp (value, "none")) {
|
166 |
|
|
clear_opt (*mount_options, CHECK_NORMAL);
|
167 |
|
|
clear_opt (*mount_options, CHECK_STRICT);
|
168 |
|
|
}
|
169 |
|
|
else if (!strcmp (value, "normal"))
|
170 |
|
|
set_opt (*mount_options, CHECK_NORMAL);
|
171 |
|
|
else if (!strcmp (value, "strict")) {
|
172 |
|
|
set_opt (*mount_options, CHECK_NORMAL);
|
173 |
|
|
set_opt (*mount_options, CHECK_STRICT);
|
174 |
|
|
}
|
175 |
|
|
else {
|
176 |
|
|
printk ("EXT2-fs: Invalid check option: %s\n",
|
177 |
|
|
value);
|
178 |
|
|
return 0;
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
else if (!strcmp (this_char, "debug"))
|
182 |
|
|
set_opt (*mount_options, DEBUG);
|
183 |
|
|
else if (!strcmp (this_char, "errors")) {
|
184 |
|
|
if (!value || !*value) {
|
185 |
|
|
printk ("EXT2-fs: the errors option requires "
|
186 |
|
|
"an argument");
|
187 |
|
|
return 0;
|
188 |
|
|
}
|
189 |
|
|
if (!strcmp (value, "continue")) {
|
190 |
|
|
clear_opt (*mount_options, ERRORS_RO);
|
191 |
|
|
clear_opt (*mount_options, ERRORS_PANIC);
|
192 |
|
|
set_opt (*mount_options, ERRORS_CONT);
|
193 |
|
|
}
|
194 |
|
|
else if (!strcmp (value, "remount-ro")) {
|
195 |
|
|
clear_opt (*mount_options, ERRORS_CONT);
|
196 |
|
|
clear_opt (*mount_options, ERRORS_PANIC);
|
197 |
|
|
set_opt (*mount_options, ERRORS_RO);
|
198 |
|
|
}
|
199 |
|
|
else if (!strcmp (value, "panic")) {
|
200 |
|
|
clear_opt (*mount_options, ERRORS_CONT);
|
201 |
|
|
clear_opt (*mount_options, ERRORS_RO);
|
202 |
|
|
set_opt (*mount_options, ERRORS_PANIC);
|
203 |
|
|
}
|
204 |
|
|
else {
|
205 |
|
|
printk ("EXT2-fs: Invalid errors option: %s\n",
|
206 |
|
|
value);
|
207 |
|
|
return 0;
|
208 |
|
|
}
|
209 |
|
|
}
|
210 |
|
|
else if (!strcmp (this_char, "grpid") ||
|
211 |
|
|
!strcmp (this_char, "bsdgroups"))
|
212 |
|
|
set_opt (*mount_options, GRPID);
|
213 |
|
|
else if (!strcmp (this_char, "minixdf"))
|
214 |
|
|
set_opt (*mount_options, MINIX_DF);
|
215 |
|
|
else if (!strcmp (this_char, "nocheck")) {
|
216 |
|
|
clear_opt (*mount_options, CHECK_NORMAL);
|
217 |
|
|
clear_opt (*mount_options, CHECK_STRICT);
|
218 |
|
|
}
|
219 |
|
|
else if (!strcmp (this_char, "nogrpid") ||
|
220 |
|
|
!strcmp (this_char, "sysvgroups"))
|
221 |
|
|
clear_opt (*mount_options, GRPID);
|
222 |
|
|
else if (!strcmp (this_char, "resgid")) {
|
223 |
|
|
if (!value || !*value) {
|
224 |
|
|
printk ("EXT2-fs: the resgid option requires "
|
225 |
|
|
"an argument");
|
226 |
|
|
return 0;
|
227 |
|
|
}
|
228 |
|
|
*resgid = simple_strtoul (value, &value, 0);
|
229 |
|
|
if (*value) {
|
230 |
|
|
printk ("EXT2-fs: Invalid resgid option: %s\n",
|
231 |
|
|
value);
|
232 |
|
|
return 0;
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
else if (!strcmp (this_char, "resuid")) {
|
236 |
|
|
if (!value || !*value) {
|
237 |
|
|
printk ("EXT2-fs: the resuid option requires "
|
238 |
|
|
"an argument");
|
239 |
|
|
return 0;
|
240 |
|
|
}
|
241 |
|
|
*resuid = simple_strtoul (value, &value, 0);
|
242 |
|
|
if (*value) {
|
243 |
|
|
printk ("EXT2-fs: Invalid resuid option: %s\n",
|
244 |
|
|
value);
|
245 |
|
|
return 0;
|
246 |
|
|
}
|
247 |
|
|
}
|
248 |
|
|
else if (!strcmp (this_char, "sb")) {
|
249 |
|
|
if (!value || !*value) {
|
250 |
|
|
printk ("EXT2-fs: the sb option requires "
|
251 |
|
|
"an argument");
|
252 |
|
|
return 0;
|
253 |
|
|
}
|
254 |
|
|
*sb_block = simple_strtoul (value, &value, 0);
|
255 |
|
|
if (*value) {
|
256 |
|
|
printk ("EXT2-fs: Invalid sb option: %s\n",
|
257 |
|
|
value);
|
258 |
|
|
return 0;
|
259 |
|
|
}
|
260 |
|
|
}
|
261 |
|
|
/* Silently ignore the quota options */
|
262 |
|
|
else if (!strcmp (this_char, "grpquota")
|
263 |
|
|
|| !strcmp (this_char, "noquota")
|
264 |
|
|
|| !strcmp (this_char, "quota")
|
265 |
|
|
|| !strcmp (this_char, "usrquota"))
|
266 |
|
|
/* Don't do anything ;-) */ ;
|
267 |
|
|
else {
|
268 |
|
|
printk ("EXT2-fs: Unrecognized mount option %s\n", this_char);
|
269 |
|
|
return 0;
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
return 1;
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
static void ext2_setup_super (struct super_block * sb,
|
276 |
|
|
struct ext2_super_block * es)
|
277 |
|
|
{
|
278 |
|
|
printk("%s - %s:%s\n",__FILE__,__FUNCTION__,__LINE__);
|
279 |
|
|
if (swab32(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
|
280 |
|
|
printk ("EXT2-fs warning: revision level too high, "
|
281 |
|
|
"forcing read/only mode\n");
|
282 |
|
|
sb->s_flags |= MS_RDONLY;
|
283 |
|
|
}
|
284 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
285 |
|
|
if (!(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
|
286 |
|
|
printk ("EXT2-fs warning: mounting unchecked fs, "
|
287 |
|
|
"running e2fsck is recommended\n");
|
288 |
|
|
else if ((sb->u.ext2_sb.s_mount_state & EXT2_ERROR_FS))
|
289 |
|
|
printk ("EXT2-fs warning: mounting fs with errors, "
|
290 |
|
|
"running e2fsck is recommended\n");
|
291 |
|
|
else if ((__s16) swab16(es->s_max_mnt_count) >= 0 &&
|
292 |
|
|
swab16(es->s_mnt_count) >=
|
293 |
|
|
(unsigned short) (__s16) swab16(es->s_max_mnt_count))
|
294 |
|
|
printk ("EXT2-fs warning: maximal mount count reached, "
|
295 |
|
|
"running e2fsck is recommended\n");
|
296 |
|
|
else if (swab32(es->s_checkinterval) &&
|
297 |
|
|
(swab32(es->s_lastcheck) + swab32(es->s_checkinterval) <= CURRENT_TIME))
|
298 |
|
|
printk ("EXT2-fs warning: checktime reached, "
|
299 |
|
|
"running e2fsck is recommended\n");
|
300 |
|
|
es->s_state = swab16(swab16(es->s_state) & ~EXT2_VALID_FS);
|
301 |
|
|
if (!(__s16) swab16(es->s_max_mnt_count))
|
302 |
|
|
es->s_max_mnt_count = (__s16) swab16(EXT2_DFL_MAX_MNT_COUNT);
|
303 |
|
|
es->s_mnt_count=swab16(swab16(es->s_mnt_count) + 1);
|
304 |
|
|
es->s_mtime = swab32(CURRENT_TIME);
|
305 |
|
|
mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
|
306 |
|
|
sb->s_dirt = 1;
|
307 |
|
|
if (test_opt (sb, DEBUG))
|
308 |
|
|
printk ("[EXT II FS %s, %s, bs=%lu, fs=%lu, gc=%lu, "
|
309 |
|
|
"bpg=%lu, ipg=%lu, mo=%04lx]\n",
|
310 |
|
|
EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
|
311 |
|
|
sb->u.ext2_sb.s_frag_size,
|
312 |
|
|
sb->u.ext2_sb.s_groups_count,
|
313 |
|
|
EXT2_BLOCKS_PER_GROUP(sb),
|
314 |
|
|
EXT2_INODES_PER_GROUP(sb),
|
315 |
|
|
sb->u.ext2_sb.s_mount_opt);
|
316 |
|
|
if (test_opt (sb, CHECK)) {
|
317 |
|
|
ext2_check_blocks_bitmap (sb);
|
318 |
|
|
ext2_check_inodes_bitmap (sb);
|
319 |
|
|
}
|
320 |
|
|
}
|
321 |
|
|
printk("%s - %s:%s\n",__FILE__,__FUNCTION__,__LINE__);
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
static int ext2_check_descriptors (struct super_block * sb)
|
325 |
|
|
{
|
326 |
|
|
int i;
|
327 |
|
|
int desc_block = 0;
|
328 |
|
|
unsigned long block = swab32(sb->u.ext2_sb.s_es->s_first_data_block);
|
329 |
|
|
struct ext2_group_desc * gdp = NULL;
|
330 |
|
|
|
331 |
|
|
ext2_debug ("Checking group descriptors");
|
332 |
|
|
|
333 |
|
|
for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++)
|
334 |
|
|
{
|
335 |
|
|
if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
|
336 |
|
|
gdp = (struct ext2_group_desc *) sb->u.ext2_sb.s_group_desc[desc_block++]->b_data;
|
337 |
|
|
if (swab32(gdp->bg_block_bitmap) < block ||
|
338 |
|
|
swab32(gdp->bg_block_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
|
339 |
|
|
{
|
340 |
|
|
ext2_error (sb, "ext2_check_descriptors",
|
341 |
|
|
"Block bitmap for group %d"
|
342 |
|
|
" not in group (block %lu)!",
|
343 |
|
|
i, (unsigned long) swab32(gdp->bg_block_bitmap));
|
344 |
|
|
return 0;
|
345 |
|
|
}
|
346 |
|
|
if (swab32(gdp->bg_inode_bitmap) < block ||
|
347 |
|
|
swab32(gdp->bg_inode_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
|
348 |
|
|
{
|
349 |
|
|
ext2_error (sb, "ext2_check_descriptors",
|
350 |
|
|
"Inode bitmap for group %d"
|
351 |
|
|
" not in group (block %lu)!",
|
352 |
|
|
i, (unsigned long) swab32(gdp->bg_inode_bitmap));
|
353 |
|
|
return 0;
|
354 |
|
|
}
|
355 |
|
|
if (swab32(gdp->bg_inode_table) < block ||
|
356 |
|
|
swab32(gdp->bg_inode_table) + sb->u.ext2_sb.s_itb_per_group >=
|
357 |
|
|
block + EXT2_BLOCKS_PER_GROUP(sb))
|
358 |
|
|
{
|
359 |
|
|
ext2_error (sb, "ext2_check_descriptors",
|
360 |
|
|
"Inode table for group %d"
|
361 |
|
|
" not in group (block %lu)!",
|
362 |
|
|
i, (unsigned long) swab32(gdp->bg_inode_table));
|
363 |
|
|
return 0;
|
364 |
|
|
}
|
365 |
|
|
block += EXT2_BLOCKS_PER_GROUP(sb);
|
366 |
|
|
gdp++;
|
367 |
|
|
}
|
368 |
|
|
return 1;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
#define log2(n) ffz(~(n))
|
372 |
|
|
|
373 |
|
|
struct super_block * ext2_read_super (struct super_block * sb, void * data,
|
374 |
|
|
int silent)
|
375 |
|
|
{
|
376 |
|
|
struct buffer_head * bh;
|
377 |
|
|
struct ext2_super_block * es;
|
378 |
|
|
unsigned long sb_block = 1;
|
379 |
|
|
unsigned short resuid = EXT2_DEF_RESUID;
|
380 |
|
|
unsigned short resgid = EXT2_DEF_RESGID;
|
381 |
|
|
unsigned long logic_sb_block = 1;
|
382 |
|
|
kdev_t dev = sb->s_dev;
|
383 |
|
|
int db_count;
|
384 |
|
|
int i, j;
|
385 |
|
|
|
386 |
|
|
printk("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
|
387 |
|
|
sb->u.ext2_sb.s_mount_opt = 0;
|
388 |
|
|
set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL);
|
389 |
|
|
if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
|
390 |
|
|
&sb->u.ext2_sb.s_mount_opt)) {
|
391 |
|
|
sb->s_dev = 0;
|
392 |
|
|
return NULL;
|
393 |
|
|
}
|
394 |
|
|
|
395 |
|
|
printk("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
|
396 |
|
|
MOD_INC_USE_COUNT;
|
397 |
|
|
lock_super (sb);
|
398 |
|
|
set_blocksize (dev, BLOCK_SIZE);
|
399 |
|
|
if (!(bh = bread (dev, sb_block, BLOCK_SIZE))) {
|
400 |
|
|
sb->s_dev = 0;
|
401 |
|
|
unlock_super (sb);
|
402 |
|
|
printk ("EXT2-fs: unable to read superblock\n");
|
403 |
|
|
MOD_DEC_USE_COUNT;
|
404 |
|
|
return NULL;
|
405 |
|
|
}
|
406 |
|
|
printk("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
|
407 |
|
|
/*
|
408 |
|
|
* Note: s_es must be initialized s_es as soon as possible because
|
409 |
|
|
* some ext2 macro-instructions depend on its value
|
410 |
|
|
*/
|
411 |
|
|
es = (struct ext2_super_block *) bh->b_data;
|
412 |
|
|
printk("magic1 = %x\n",es->s_magic);
|
413 |
|
|
printk("magic2 = %x\n",sb->s_magic);
|
414 |
|
|
sb->u.ext2_sb.s_es = es;
|
415 |
|
|
sb->s_magic = swab16(es->s_magic);
|
416 |
|
|
printk("magic3 = %x\n",sb->s_magic);
|
417 |
|
|
if (sb->s_magic != EXT2_SUPER_MAGIC) {
|
418 |
|
|
if (!silent)
|
419 |
|
|
printk ("VFS: Can't find an ext2 filesystem on dev "
|
420 |
|
|
"%s.\n", kdevname(dev));
|
421 |
|
|
failed_mount:
|
422 |
|
|
sb->s_dev = 0;
|
423 |
|
|
unlock_super (sb);
|
424 |
|
|
if (bh)
|
425 |
|
|
brelse(bh);
|
426 |
|
|
MOD_DEC_USE_COUNT;
|
427 |
|
|
printk("%s - %s:%d\n",__FILE__,__FUNCTION__,__LINE__);
|
428 |
|
|
return NULL;
|
429 |
|
|
}
|
430 |
|
|
if (swab32(es->s_rev_level) > EXT2_GOOD_OLD_REV) {
|
431 |
|
|
if (swab32(es->s_feature_incompat) & ~EXT2_FEATURE_INCOMPAT_SUPP) {
|
432 |
|
|
printk("EXT2-fs: %s: couldn't mount because of "
|
433 |
|
|
"unsupported optional features.\n",
|
434 |
|
|
kdevname(dev));
|
435 |
|
|
goto failed_mount;
|
436 |
|
|
}
|
437 |
|
|
if (!(sb->s_flags & MS_RDONLY) &&
|
438 |
|
|
(swab32(es->s_feature_ro_compat) & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
|
439 |
|
|
printk("EXT2-fs: %s: couldn't mount RDWR because of "
|
440 |
|
|
"unsupported optional features.\n",
|
441 |
|
|
kdevname(dev));
|
442 |
|
|
goto failed_mount;
|
443 |
|
|
}
|
444 |
|
|
}
|
445 |
|
|
sb->s_blocksize_bits = swab32(sb->u.ext2_sb.s_es->s_log_block_size) + 10;
|
446 |
|
|
sb->s_blocksize = 1 << sb->s_blocksize_bits;
|
447 |
|
|
if (sb->s_blocksize != BLOCK_SIZE &&
|
448 |
|
|
(sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||
|
449 |
|
|
sb->s_blocksize == 4096)) {
|
450 |
|
|
unsigned long offset;
|
451 |
|
|
|
452 |
|
|
brelse (bh);
|
453 |
|
|
set_blocksize (dev, sb->s_blocksize);
|
454 |
|
|
logic_sb_block = (sb_block*BLOCK_SIZE) / sb->s_blocksize;
|
455 |
|
|
offset = (sb_block*BLOCK_SIZE) % sb->s_blocksize;
|
456 |
|
|
bh = bread (dev, logic_sb_block, sb->s_blocksize);
|
457 |
|
|
if(!bh) {
|
458 |
|
|
printk("EXT2-fs: Couldn't read superblock on "
|
459 |
|
|
"2nd try.\n");
|
460 |
|
|
goto failed_mount;
|
461 |
|
|
}
|
462 |
|
|
es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
|
463 |
|
|
sb->u.ext2_sb.s_es = es;
|
464 |
|
|
if (es->s_magic != swab16(EXT2_SUPER_MAGIC)) {
|
465 |
|
|
printk ("EXT2-fs: Magic mismatch, very weird !\n");
|
466 |
|
|
goto failed_mount;
|
467 |
|
|
}
|
468 |
|
|
}
|
469 |
|
|
if (swab32(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
|
470 |
|
|
sb->u.ext2_sb.s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
|
471 |
|
|
sb->u.ext2_sb.s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
|
472 |
|
|
} else {
|
473 |
|
|
sb->u.ext2_sb.s_inode_size = swab16(es->s_inode_size);
|
474 |
|
|
sb->u.ext2_sb.s_first_ino = swab32(es->s_first_ino);
|
475 |
|
|
if (sb->u.ext2_sb.s_inode_size != EXT2_GOOD_OLD_INODE_SIZE) {
|
476 |
|
|
printk ("EXT2-fs: unsupported inode size: %d\n",
|
477 |
|
|
sb->u.ext2_sb.s_inode_size);
|
478 |
|
|
goto failed_mount;
|
479 |
|
|
}
|
480 |
|
|
}
|
481 |
|
|
sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
|
482 |
|
|
(__s32) swab32(es->s_log_frag_size);
|
483 |
|
|
if (sb->u.ext2_sb.s_frag_size)
|
484 |
|
|
sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
|
485 |
|
|
sb->u.ext2_sb.s_frag_size;
|
486 |
|
|
else
|
487 |
|
|
sb->s_magic = 0;
|
488 |
|
|
sb->u.ext2_sb.s_blocks_per_group = swab32(es->s_blocks_per_group);
|
489 |
|
|
sb->u.ext2_sb.s_frags_per_group = swab32(es->s_frags_per_group);
|
490 |
|
|
sb->u.ext2_sb.s_inodes_per_group = swab32(es->s_inodes_per_group);
|
491 |
|
|
sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
|
492 |
|
|
EXT2_INODE_SIZE(sb);
|
493 |
|
|
sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
|
494 |
|
|
sb->u.ext2_sb.s_inodes_per_block;
|
495 |
|
|
sb->u.ext2_sb.s_desc_per_block = sb->s_blocksize /
|
496 |
|
|
sizeof (struct ext2_group_desc);
|
497 |
|
|
sb->u.ext2_sb.s_sbh = bh;
|
498 |
|
|
if (resuid != EXT2_DEF_RESUID)
|
499 |
|
|
sb->u.ext2_sb.s_resuid = resuid;
|
500 |
|
|
else
|
501 |
|
|
sb->u.ext2_sb.s_resuid = swab16(es->s_def_resuid);
|
502 |
|
|
if (resgid != EXT2_DEF_RESGID)
|
503 |
|
|
sb->u.ext2_sb.s_resgid = resgid;
|
504 |
|
|
else
|
505 |
|
|
sb->u.ext2_sb.s_resgid = swab16(es->s_def_resgid);
|
506 |
|
|
sb->u.ext2_sb.s_mount_state = swab16(es->s_state);
|
507 |
|
|
sb->u.ext2_sb.s_rename_lock = 0;
|
508 |
|
|
sb->u.ext2_sb.s_rename_wait = NULL;
|
509 |
|
|
sb->u.ext2_sb.s_addr_per_block_bits =
|
510 |
|
|
log2 (EXT2_ADDR_PER_BLOCK(sb));
|
511 |
|
|
sb->u.ext2_sb.s_desc_per_block_bits =
|
512 |
|
|
log2 (EXT2_DESC_PER_BLOCK(sb));
|
513 |
|
|
if (sb->s_magic != EXT2_SUPER_MAGIC) {
|
514 |
|
|
if (!silent)
|
515 |
|
|
printk ("VFS: Can't find an ext2 filesystem on dev "
|
516 |
|
|
"%s.\n",
|
517 |
|
|
kdevname(dev));
|
518 |
|
|
goto failed_mount;
|
519 |
|
|
}
|
520 |
|
|
if (sb->s_blocksize != bh->b_size) {
|
521 |
|
|
if (!silent)
|
522 |
|
|
printk ("VFS: Unsupported blocksize on dev "
|
523 |
|
|
"%s.\n", kdevname(dev));
|
524 |
|
|
goto failed_mount;
|
525 |
|
|
}
|
526 |
|
|
|
527 |
|
|
if (sb->s_blocksize != sb->u.ext2_sb.s_frag_size) {
|
528 |
|
|
printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n",
|
529 |
|
|
sb->u.ext2_sb.s_frag_size, sb->s_blocksize);
|
530 |
|
|
goto failed_mount;
|
531 |
|
|
}
|
532 |
|
|
|
533 |
|
|
if (sb->u.ext2_sb.s_blocks_per_group > sb->s_blocksize * 8) {
|
534 |
|
|
printk ("EXT2-fs: #blocks per group too big: %lu\n",
|
535 |
|
|
sb->u.ext2_sb.s_blocks_per_group);
|
536 |
|
|
goto failed_mount;
|
537 |
|
|
}
|
538 |
|
|
if (sb->u.ext2_sb.s_frags_per_group > sb->s_blocksize * 8) {
|
539 |
|
|
printk ("EXT2-fs: #fragments per group too big: %lu\n",
|
540 |
|
|
sb->u.ext2_sb.s_frags_per_group);
|
541 |
|
|
goto failed_mount;
|
542 |
|
|
}
|
543 |
|
|
if (sb->u.ext2_sb.s_inodes_per_group > sb->s_blocksize * 8) {
|
544 |
|
|
printk ("EXT2-fs: #inodes per group too big: %lu\n",
|
545 |
|
|
sb->u.ext2_sb.s_inodes_per_group);
|
546 |
|
|
goto failed_mount;
|
547 |
|
|
}
|
548 |
|
|
|
549 |
|
|
sb->u.ext2_sb.s_groups_count = (swab32(es->s_blocks_count) -
|
550 |
|
|
swab32(es->s_first_data_block) +
|
551 |
|
|
EXT2_BLOCKS_PER_GROUP(sb) - 1) /
|
552 |
|
|
EXT2_BLOCKS_PER_GROUP(sb);
|
553 |
|
|
db_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
|
554 |
|
|
EXT2_DESC_PER_BLOCK(sb);
|
555 |
|
|
sb->u.ext2_sb.s_group_desc = kmalloc (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
|
556 |
|
|
if (sb->u.ext2_sb.s_group_desc == NULL) {
|
557 |
|
|
printk ("EXT2-fs: not enough memory\n");
|
558 |
|
|
goto failed_mount;
|
559 |
|
|
}
|
560 |
|
|
for (i = 0; i < db_count; i++) {
|
561 |
|
|
sb->u.ext2_sb.s_group_desc[i] = bread (dev, logic_sb_block + i + 1,
|
562 |
|
|
sb->s_blocksize);
|
563 |
|
|
if (!sb->u.ext2_sb.s_group_desc[i]) {
|
564 |
|
|
for (j = 0; j < i; j++)
|
565 |
|
|
brelse (sb->u.ext2_sb.s_group_desc[j]);
|
566 |
|
|
kfree_s (sb->u.ext2_sb.s_group_desc,
|
567 |
|
|
db_count * sizeof (struct buffer_head *));
|
568 |
|
|
printk ("EXT2-fs: unable to read group descriptors\n");
|
569 |
|
|
goto failed_mount;
|
570 |
|
|
}
|
571 |
|
|
}
|
572 |
|
|
if (!ext2_check_descriptors (sb)) {
|
573 |
|
|
for (j = 0; j < db_count; j++)
|
574 |
|
|
brelse (sb->u.ext2_sb.s_group_desc[j]);
|
575 |
|
|
kfree_s (sb->u.ext2_sb.s_group_desc,
|
576 |
|
|
db_count * sizeof (struct buffer_head *));
|
577 |
|
|
printk ("EXT2-fs: group descriptors corrupted !\n");
|
578 |
|
|
goto failed_mount;
|
579 |
|
|
}
|
580 |
|
|
for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) {
|
581 |
|
|
sb->u.ext2_sb.s_inode_bitmap_number[i] = 0;
|
582 |
|
|
sb->u.ext2_sb.s_inode_bitmap[i] = NULL;
|
583 |
|
|
sb->u.ext2_sb.s_block_bitmap_number[i] = 0;
|
584 |
|
|
sb->u.ext2_sb.s_block_bitmap[i] = NULL;
|
585 |
|
|
}
|
586 |
|
|
sb->u.ext2_sb.s_loaded_inode_bitmaps = 0;
|
587 |
|
|
sb->u.ext2_sb.s_loaded_block_bitmaps = 0;
|
588 |
|
|
sb->u.ext2_sb.s_db_per_group = db_count;
|
589 |
|
|
unlock_super (sb);
|
590 |
|
|
/*
|
591 |
|
|
* set up enough so that it can read an inode
|
592 |
|
|
*/
|
593 |
|
|
sb->s_dev = dev;
|
594 |
|
|
sb->s_op = &ext2_sops;
|
595 |
|
|
if (!(sb->s_mounted = iget (sb, EXT2_ROOT_INO))) {
|
596 |
|
|
sb->s_dev = 0;
|
597 |
|
|
for (i = 0; i < db_count; i++)
|
598 |
|
|
if (sb->u.ext2_sb.s_group_desc[i])
|
599 |
|
|
brelse (sb->u.ext2_sb.s_group_desc[i]);
|
600 |
|
|
kfree_s (sb->u.ext2_sb.s_group_desc,
|
601 |
|
|
db_count * sizeof (struct buffer_head *));
|
602 |
|
|
brelse (bh);
|
603 |
|
|
printk ("EXT2-fs: get root inode failed\n");
|
604 |
|
|
MOD_DEC_USE_COUNT;
|
605 |
|
|
return NULL;
|
606 |
|
|
}
|
607 |
|
|
printk("%s - %s:%s\n",__FILE__,__FUNCTION__,__LINE__);
|
608 |
|
|
ext2_setup_super (sb, es);
|
609 |
|
|
printk("%s - %s:%s\n",__FILE__,__FUNCTION__,__LINE__);
|
610 |
|
|
return sb;
|
611 |
|
|
}
|
612 |
|
|
|
613 |
|
|
static void ext2_commit_super (struct super_block * sb,
|
614 |
|
|
struct ext2_super_block * es)
|
615 |
|
|
{
|
616 |
|
|
es->s_wtime = swab32(CURRENT_TIME);
|
617 |
|
|
mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
|
618 |
|
|
sb->s_dirt = 0;
|
619 |
|
|
}
|
620 |
|
|
|
621 |
|
|
/*
|
622 |
|
|
* In the second extended file system, it is not necessary to
|
623 |
|
|
* write the super block since we use a mapping of the
|
624 |
|
|
* disk super block in a buffer.
|
625 |
|
|
*
|
626 |
|
|
* However, this function is still used to set the fs valid
|
627 |
|
|
* flags to 0. We need to set this flag to 0 since the fs
|
628 |
|
|
* may have been checked while mounted and e2fsck may have
|
629 |
|
|
* set s_state to EXT2_VALID_FS after some corrections.
|
630 |
|
|
*/
|
631 |
|
|
|
632 |
|
|
void ext2_write_super (struct super_block * sb)
|
633 |
|
|
{
|
634 |
|
|
struct ext2_super_block * es;
|
635 |
|
|
|
636 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
637 |
|
|
es = sb->u.ext2_sb.s_es;
|
638 |
|
|
|
639 |
|
|
ext2_debug ("setting valid to 0\n");
|
640 |
|
|
|
641 |
|
|
if (swab16(es->s_state) & EXT2_VALID_FS) {
|
642 |
|
|
es->s_state = swab16(swab16(es->s_state) & ~EXT2_VALID_FS);
|
643 |
|
|
es->s_mtime = swab32(CURRENT_TIME);
|
644 |
|
|
}
|
645 |
|
|
ext2_commit_super (sb, es);
|
646 |
|
|
}
|
647 |
|
|
sb->s_dirt = 0;
|
648 |
|
|
}
|
649 |
|
|
|
650 |
|
|
int ext2_remount (struct super_block * sb, int * flags, char * data)
|
651 |
|
|
{
|
652 |
|
|
struct ext2_super_block * es;
|
653 |
|
|
unsigned short resuid = sb->u.ext2_sb.s_resuid;
|
654 |
|
|
unsigned short resgid = sb->u.ext2_sb.s_resgid;
|
655 |
|
|
unsigned long new_mount_opt;
|
656 |
|
|
unsigned long tmp;
|
657 |
|
|
|
658 |
|
|
/*
|
659 |
|
|
* Allow the "check" option to be passed as a remount option.
|
660 |
|
|
*/
|
661 |
|
|
new_mount_opt = EXT2_MOUNT_CHECK_NORMAL;
|
662 |
|
|
if (!parse_options (data, &tmp, &resuid, &resgid,
|
663 |
|
|
&new_mount_opt))
|
664 |
|
|
return -EINVAL;
|
665 |
|
|
|
666 |
|
|
sb->u.ext2_sb.s_mount_opt = new_mount_opt;
|
667 |
|
|
sb->u.ext2_sb.s_resuid = resuid;
|
668 |
|
|
sb->u.ext2_sb.s_resgid = resgid;
|
669 |
|
|
es = sb->u.ext2_sb.s_es;
|
670 |
|
|
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
|
671 |
|
|
return 0;
|
672 |
|
|
if (*flags & MS_RDONLY) {
|
673 |
|
|
if (swab16(es->s_state) & EXT2_VALID_FS ||
|
674 |
|
|
!(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
|
675 |
|
|
return 0;
|
676 |
|
|
/*
|
677 |
|
|
* OK, we are remounting a valid rw partition rdonly, so set
|
678 |
|
|
* the rdonly flag and then mark the partition as valid again.
|
679 |
|
|
*/
|
680 |
|
|
es->s_state = swab16(sb->u.ext2_sb.s_mount_state);
|
681 |
|
|
es->s_mtime = swab32(CURRENT_TIME);
|
682 |
|
|
mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
|
683 |
|
|
sb->s_dirt = 1;
|
684 |
|
|
ext2_commit_super (sb, es);
|
685 |
|
|
}
|
686 |
|
|
else {
|
687 |
|
|
/*
|
688 |
|
|
* Mounting a RDONLY partition read-write, so reread and
|
689 |
|
|
* store the current valid flag. (It may have been changed
|
690 |
|
|
* by e2fsck since we originally mounted the partition.)
|
691 |
|
|
*/
|
692 |
|
|
sb->u.ext2_sb.s_mount_state = swab16(es->s_state);
|
693 |
|
|
sb->s_flags &= ~MS_RDONLY;
|
694 |
|
|
ext2_setup_super (sb, es);
|
695 |
|
|
}
|
696 |
|
|
return 0;
|
697 |
|
|
}
|
698 |
|
|
|
699 |
|
|
static struct file_system_type ext2_fs_type = {
|
700 |
|
|
ext2_read_super, "ext2", 1, NULL
|
701 |
|
|
};
|
702 |
|
|
|
703 |
|
|
int init_ext2_fs(void)
|
704 |
|
|
{
|
705 |
|
|
return register_filesystem(&ext2_fs_type);
|
706 |
|
|
}
|
707 |
|
|
|
708 |
|
|
#ifdef MODULE
|
709 |
|
|
int init_module(void)
|
710 |
|
|
{
|
711 |
|
|
int status;
|
712 |
|
|
|
713 |
|
|
if ((status = init_ext2_fs()) == 0)
|
714 |
|
|
register_symtab(0);
|
715 |
|
|
return status;
|
716 |
|
|
}
|
717 |
|
|
|
718 |
|
|
void cleanup_module(void)
|
719 |
|
|
{
|
720 |
|
|
unregister_filesystem(&ext2_fs_type);
|
721 |
|
|
}
|
722 |
|
|
|
723 |
|
|
#endif
|
724 |
|
|
|
725 |
|
|
void ext2_statfs (struct super_block * sb, struct statfs * buf, int bufsiz)
|
726 |
|
|
{
|
727 |
|
|
unsigned long overhead;
|
728 |
|
|
unsigned long overhead_per_group;
|
729 |
|
|
struct statfs tmp;
|
730 |
|
|
|
731 |
|
|
if (test_opt (sb, MINIX_DF))
|
732 |
|
|
overhead = 0;
|
733 |
|
|
else {
|
734 |
|
|
/*
|
735 |
|
|
* Compute the overhead (FS structures)
|
736 |
|
|
*/
|
737 |
|
|
overhead_per_group = 1 /* super block */ +
|
738 |
|
|
sb->u.ext2_sb.s_db_per_group /* descriptors */ +
|
739 |
|
|
1 /* block bitmap */ +
|
740 |
|
|
1 /* inode bitmap */ +
|
741 |
|
|
sb->u.ext2_sb.s_itb_per_group /* inode table */;
|
742 |
|
|
overhead = swab32(sb->u.ext2_sb.s_es->s_first_data_block) +
|
743 |
|
|
sb->u.ext2_sb.s_groups_count * overhead_per_group;
|
744 |
|
|
}
|
745 |
|
|
|
746 |
|
|
tmp.f_type = EXT2_SUPER_MAGIC;
|
747 |
|
|
tmp.f_bsize = sb->s_blocksize;
|
748 |
|
|
tmp.f_blocks = swab32(sb->u.ext2_sb.s_es->s_blocks_count) - overhead;
|
749 |
|
|
tmp.f_bfree = ext2_count_free_blocks (sb);
|
750 |
|
|
tmp.f_bavail = tmp.f_bfree - swab32(sb->u.ext2_sb.s_es->s_r_blocks_count);
|
751 |
|
|
if (tmp.f_bfree < swab32(sb->u.ext2_sb.s_es->s_r_blocks_count))
|
752 |
|
|
tmp.f_bavail = 0;
|
753 |
|
|
tmp.f_files = swab32(sb->u.ext2_sb.s_es->s_inodes_count);
|
754 |
|
|
tmp.f_ffree = ext2_count_free_inodes (sb);
|
755 |
|
|
tmp.f_namelen = EXT2_NAME_LEN;
|
756 |
|
|
memcpy_tofs(buf, &tmp, bufsiz);
|
757 |
|
|
}
|