89 |
|
|
90 |
struct problem_context { |
struct problem_context { |
91 |
errcode_t errcode; |
errcode_t errcode; |
92 |
ext2_ino_t ino, ino2, dir; |
ext2_ino_t ino, ino2, dir; |
93 |
struct ext2_inode *inode; |
struct ext2_inode *inode; |
94 |
struct ext2_dir_entry *dirent; |
struct ext2_dir_entry *dirent; |
95 |
blk_t blk, blk2; |
blk_t blk, blk2; |
96 |
e2_blkcnt_t blkcount; |
e2_blkcnt_t blkcount; |
97 |
int group; |
int group; |
98 |
__u64 num; |
__u64 num; |
99 |
const char *str; |
const char *str; |
100 |
}; |
}; |
101 |
|
|
102 |
|
|
133 |
typedef enum { dnode_red, dnode_black } dnode_color_t; |
typedef enum { dnode_red, dnode_black } dnode_color_t; |
134 |
|
|
135 |
typedef struct dnode_t { |
typedef struct dnode_t { |
136 |
struct dnode_t *dict_left; |
struct dnode_t *dict_left; |
137 |
struct dnode_t *dict_right; |
struct dnode_t *dict_right; |
138 |
struct dnode_t *dict_parent; |
struct dnode_t *dict_parent; |
139 |
dnode_color_t dict_color; |
dnode_color_t dict_color; |
140 |
const void *dict_key; |
const void *dict_key; |
141 |
void *dict_data; |
void *dict_data; |
142 |
} dnode_t; |
} dnode_t; |
143 |
|
|
144 |
typedef int (*dict_comp_t)(const void *, const void *); |
typedef int (*dict_comp_t)(const void *, const void *); |
145 |
typedef void (*dnode_free_t)(dnode_t *); |
typedef void (*dnode_free_t)(dnode_t *); |
146 |
|
|
147 |
typedef struct dict_t { |
typedef struct dict_t { |
148 |
dnode_t dict_nilnode; |
dnode_t dict_nilnode; |
149 |
dictcount_t dict_nodecount; |
dictcount_t dict_nodecount; |
150 |
dictcount_t dict_maxcount; |
dictcount_t dict_maxcount; |
151 |
dict_comp_t dict_compare; |
dict_comp_t dict_compare; |
152 |
dnode_free_t dict_freenode; |
dnode_free_t dict_freenode; |
153 |
int dict_dupes; |
int dict_dupes; |
154 |
} dict_t; |
} dict_t; |
155 |
|
|
156 |
typedef void (*dnode_process_t)(dict_t *, dnode_t *, void *); |
typedef void (*dnode_process_t)(dict_t *, dnode_t *, void *); |
157 |
|
|
158 |
typedef struct dict_load_t { |
typedef struct dict_load_t { |
159 |
dict_t *dict_dictptr; |
dict_t *dict_dictptr; |
160 |
dnode_t dict_nilnode; |
dnode_t dict_nilnode; |
161 |
} dict_load_t; |
} dict_load_t; |
162 |
|
|
163 |
#define dict_count(D) ((D)->dict_nodecount) |
#define dict_count(D) ((D)->dict_nodecount) |
214 |
{ |
{ |
215 |
kmem_cache_t *new_cache; |
kmem_cache_t *new_cache; |
216 |
|
|
217 |
new_cache = malloc(sizeof(*new_cache)); |
new_cache = xmalloc(sizeof(*new_cache)); |
218 |
if (new_cache) |
new_cache->object_length = len; |
|
new_cache->object_length = len; |
|
219 |
return new_cache; |
return new_cache; |
220 |
} |
} |
221 |
|
|
268 |
|
|
269 |
static void rotate_left(dnode_t *upper) |
static void rotate_left(dnode_t *upper) |
270 |
{ |
{ |
271 |
dnode_t *lower, *lowleft, *upparent; |
dnode_t *lower, *lowleft, *upparent; |
272 |
|
|
273 |
|
lower = upper->right; |
274 |
|
upper->right = lowleft = lower->left; |
275 |
|
lowleft->parent = upper; |
276 |
|
|
277 |
lower = upper->right; |
lower->parent = upparent = upper->parent; |
|
upper->right = lowleft = lower->left; |
|
|
lowleft->parent = upper; |
|
|
|
|
|
lower->parent = upparent = upper->parent; |
|
|
|
|
|
/* don't need to check for root node here because root->parent is |
|
|
the sentinel nil node, and root->parent->left points back to root */ |
|
|
|
|
|
if (upper == upparent->left) { |
|
|
upparent->left = lower; |
|
|
} else { |
|
|
assert (upper == upparent->right); |
|
|
upparent->right = lower; |
|
|
} |
|
278 |
|
|
279 |
lower->left = upper; |
/* don't need to check for root node here because root->parent is |
280 |
upper->parent = lower; |
the sentinel nil node, and root->parent->left points back to root */ |
281 |
|
|
282 |
|
if (upper == upparent->left) { |
283 |
|
upparent->left = lower; |
284 |
|
} else { |
285 |
|
assert (upper == upparent->right); |
286 |
|
upparent->right = lower; |
287 |
|
} |
288 |
|
|
289 |
|
lower->left = upper; |
290 |
|
upper->parent = lower; |
291 |
} |
} |
292 |
|
|
293 |
/* |
/* |
297 |
|
|
298 |
static void rotate_right(dnode_t *upper) |
static void rotate_right(dnode_t *upper) |
299 |
{ |
{ |
300 |
dnode_t *lower, *lowright, *upparent; |
dnode_t *lower, *lowright, *upparent; |
301 |
|
|
302 |
|
lower = upper->left; |
303 |
|
upper->left = lowright = lower->right; |
304 |
|
lowright->parent = upper; |
305 |
|
|
306 |
lower = upper->left; |
lower->parent = upparent = upper->parent; |
|
upper->left = lowright = lower->right; |
|
|
lowright->parent = upper; |
|
|
|
|
|
lower->parent = upparent = upper->parent; |
|
|
|
|
|
if (upper == upparent->right) { |
|
|
upparent->right = lower; |
|
|
} else { |
|
|
assert (upper == upparent->left); |
|
|
upparent->left = lower; |
|
|
} |
|
307 |
|
|
308 |
lower->right = upper; |
if (upper == upparent->right) { |
309 |
upper->parent = lower; |
upparent->right = lower; |
310 |
|
} else { |
311 |
|
assert (upper == upparent->left); |
312 |
|
upparent->left = lower; |
313 |
|
} |
314 |
|
|
315 |
|
lower->right = upper; |
316 |
|
upper->parent = lower; |
317 |
} |
} |
318 |
|
|
319 |
/* |
/* |
323 |
|
|
324 |
static void free_nodes(dict_t *dict, dnode_t *node, dnode_t *nil) |
static void free_nodes(dict_t *dict, dnode_t *node, dnode_t *nil) |
325 |
{ |
{ |
326 |
if (node == nil) |
if (node == nil) |
327 |
return; |
return; |
328 |
free_nodes(dict, node->left, nil); |
free_nodes(dict, node->left, nil); |
329 |
free_nodes(dict, node->right, nil); |
free_nodes(dict, node->right, nil); |
330 |
dict->dict_freenode(node); |
dict->dict_freenode(node); |
331 |
} |
} |
332 |
|
|
333 |
/* |
/* |
339 |
|
|
340 |
static int verify_dict_has_node(dnode_t *nil, dnode_t *root, dnode_t *node) |
static int verify_dict_has_node(dnode_t *nil, dnode_t *root, dnode_t *node) |
341 |
{ |
{ |
342 |
if (root != nil) { |
if (root != nil) { |
343 |
return root == node |
return root == node |
344 |
|| verify_dict_has_node(nil, root->left, node) |
|| verify_dict_has_node(nil, root->left, node) |
345 |
|| verify_dict_has_node(nil, root->right, node); |
|| verify_dict_has_node(nil, root->right, node); |
346 |
} |
} |
347 |
return 0; |
return 0; |
348 |
} |
} |
349 |
|
|
350 |
|
|
354 |
|
|
355 |
static void dict_set_allocator(dict_t *dict, dnode_free_t fr) |
static void dict_set_allocator(dict_t *dict, dnode_free_t fr) |
356 |
{ |
{ |
357 |
assert (dict_count(dict) == 0); |
assert(dict_count(dict) == 0); |
358 |
dict->dict_freenode = fr; |
dict->dict_freenode = fr; |
359 |
} |
} |
360 |
|
|
361 |
/* |
/* |
365 |
|
|
366 |
static void dict_free_nodes(dict_t *dict) |
static void dict_free_nodes(dict_t *dict) |
367 |
{ |
{ |
368 |
dnode_t *nil = dict_nil(dict), *root = dict_root(dict); |
dnode_t *nil = dict_nil(dict), *root = dict_root(dict); |
369 |
free_nodes(dict, root, nil); |
free_nodes(dict, root, nil); |
370 |
dict->dict_nodecount = 0; |
dict->dict_nodecount = 0; |
371 |
dict->nilnode.left = &dict->nilnode; |
dict->nilnode.left = &dict->nilnode; |
372 |
dict->nilnode.right = &dict->nilnode; |
dict->nilnode.right = &dict->nilnode; |
373 |
} |
} |
374 |
|
|
375 |
/* |
/* |
378 |
|
|
379 |
static dict_t *dict_init(dict_t *dict, dictcount_t maxcount, dict_comp_t comp) |
static dict_t *dict_init(dict_t *dict, dictcount_t maxcount, dict_comp_t comp) |
380 |
{ |
{ |
381 |
dict->compare = comp; |
dict->compare = comp; |
382 |
dict->dict_freenode = dnode_free; |
dict->dict_freenode = dnode_free; |
383 |
dict->dict_nodecount = 0; |
dict->dict_nodecount = 0; |
384 |
dict->maxcount = maxcount; |
dict->maxcount = maxcount; |
385 |
dict->nilnode.left = &dict->nilnode; |
dict->nilnode.left = &dict->nilnode; |
386 |
dict->nilnode.right = &dict->nilnode; |
dict->nilnode.right = &dict->nilnode; |
387 |
dict->nilnode.parent = &dict->nilnode; |
dict->nilnode.parent = &dict->nilnode; |
388 |
dict->nilnode.color = dnode_black; |
dict->nilnode.color = dnode_black; |
389 |
dict->dupes = 0; |
dict->dupes = 0; |
390 |
return dict; |
return dict; |
391 |
} |
} |
392 |
|
|
393 |
/* |
/* |
399 |
|
|
400 |
static dnode_t *dict_lookup(dict_t *dict, const void *key) |
static dnode_t *dict_lookup(dict_t *dict, const void *key) |
401 |
{ |
{ |
402 |
dnode_t *root = dict_root(dict); |
dnode_t *root = dict_root(dict); |
403 |
dnode_t *nil = dict_nil(dict); |
dnode_t *nil = dict_nil(dict); |
404 |
dnode_t *saved; |
dnode_t *saved; |
405 |
int result; |
int result; |
406 |
|
|
407 |
/* simple binary search adapted for trees that contain duplicate keys */ |
/* simple binary search adapted for trees that contain duplicate keys */ |
408 |
|
|
409 |
while (root != nil) { |
while (root != nil) { |
410 |
result = dict->compare(key, root->key); |
result = dict->compare(key, root->key); |
411 |
if (result < 0) |
if (result < 0) |
412 |
root = root->left; |
root = root->left; |
413 |
else if (result > 0) |
else if (result > 0) |
|
root = root->right; |
|
|
else { |
|
|
if (!dict->dupes) { /* no duplicates, return match */ |
|
|
return root; |
|
|
} else { /* could be dupes, find leftmost one */ |
|
|
do { |
|
|
saved = root; |
|
|
root = root->left; |
|
|
while (root != nil && dict->compare(key, root->key)) |
|
414 |
root = root->right; |
root = root->right; |
415 |
} while (root != nil); |
else { |
416 |
return saved; |
if (!dict->dupes) { /* no duplicates, return match */ |
417 |
} |
return root; |
418 |
|
} else { /* could be dupes, find leftmost one */ |
419 |
|
do { |
420 |
|
saved = root; |
421 |
|
root = root->left; |
422 |
|
while (root != nil && dict->compare(key, root->key)) |
423 |
|
root = root->right; |
424 |
|
} while (root != nil); |
425 |
|
return saved; |
426 |
|
} |
427 |
|
} |
428 |
} |
} |
|
} |
|
429 |
|
|
430 |
return NULL; |
return NULL; |
431 |
} |
} |
432 |
|
|
433 |
/* |
/* |
440 |
|
|
441 |
static void dict_insert(dict_t *dict, dnode_t *node, const void *key) |
static void dict_insert(dict_t *dict, dnode_t *node, const void *key) |
442 |
{ |
{ |
443 |
dnode_t *where = dict_root(dict), *nil = dict_nil(dict); |
dnode_t *where = dict_root(dict), *nil = dict_nil(dict); |
444 |
dnode_t *parent = nil, *uncle, *grandpa; |
dnode_t *parent = nil, *uncle, *grandpa; |
445 |
int result = -1; |
int result = -1; |
446 |
|
|
447 |
node->key = key; |
node->key = key; |
448 |
|
|
449 |
/* basic binary tree insert */ |
/* basic binary tree insert */ |
450 |
|
|
451 |
while (where != nil) { |
while (where != nil) { |
452 |
parent = where; |
parent = where; |
453 |
result = dict->compare(key, where->key); |
result = dict->compare(key, where->key); |
454 |
/* trap attempts at duplicate key insertion unless it's explicitly allowed */ |
/* trap attempts at duplicate key insertion unless it's explicitly allowed */ |
455 |
assert (dict->dupes || result != 0); |
assert(dict->dupes || result != 0); |
456 |
|
if (result < 0) |
457 |
|
where = where->left; |
458 |
|
else |
459 |
|
where = where->right; |
460 |
|
} |
461 |
|
|
462 |
|
assert(where == nil); |
463 |
|
|
464 |
if (result < 0) |
if (result < 0) |
465 |
where = where->left; |
parent->left = node; |
466 |
else |
else |
467 |
where = where->right; |
parent->right = node; |
|
} |
|
468 |
|
|
469 |
assert (where == nil); |
node->parent = parent; |
470 |
|
node->left = nil; |
471 |
if (result < 0) |
node->right = nil; |
472 |
parent->left = node; |
|
473 |
else |
dict->dict_nodecount++; |
474 |
parent->right = node; |
|
475 |
|
/* red black adjustments */ |
476 |
node->parent = parent; |
|
477 |
node->left = nil; |
node->color = dnode_red; |
478 |
node->right = nil; |
|
479 |
|
while (parent->color == dnode_red) { |
480 |
dict->dict_nodecount++; |
grandpa = parent->parent; |
481 |
|
if (parent == grandpa->left) { |
482 |
/* red black adjustments */ |
uncle = grandpa->right; |
483 |
|
if (uncle->color == dnode_red) { /* red parent, red uncle */ |
484 |
node->color = dnode_red; |
parent->color = dnode_black; |
485 |
|
uncle->color = dnode_black; |
486 |
while (parent->color == dnode_red) { |
grandpa->color = dnode_red; |
487 |
grandpa = parent->parent; |
node = grandpa; |
488 |
if (parent == grandpa->left) { |
parent = grandpa->parent; |
489 |
uncle = grandpa->right; |
} else { /* red parent, black uncle */ |
490 |
if (uncle->color == dnode_red) { /* red parent, red uncle */ |
if (node == parent->right) { |
491 |
parent->color = dnode_black; |
rotate_left(parent); |
492 |
uncle->color = dnode_black; |
parent = node; |
493 |
grandpa->color = dnode_red; |
assert (grandpa == parent->parent); |
494 |
node = grandpa; |
/* rotation between parent and child preserves grandpa */ |
495 |
parent = grandpa->parent; |
} |
496 |
} else { /* red parent, black uncle */ |
parent->color = dnode_black; |
497 |
if (node == parent->right) { |
grandpa->color = dnode_red; |
498 |
rotate_left(parent); |
rotate_right(grandpa); |
499 |
parent = node; |
break; |
500 |
assert (grandpa == parent->parent); |
} |
501 |
/* rotation between parent and child preserves grandpa */ |
} else { /* symmetric cases: parent == parent->parent->right */ |
502 |
} |
uncle = grandpa->left; |
503 |
parent->color = dnode_black; |
if (uncle->color == dnode_red) { |
504 |
grandpa->color = dnode_red; |
parent->color = dnode_black; |
505 |
rotate_right(grandpa); |
uncle->color = dnode_black; |
506 |
break; |
grandpa->color = dnode_red; |
507 |
} |
node = grandpa; |
508 |
} else { /* symmetric cases: parent == parent->parent->right */ |
parent = grandpa->parent; |
509 |
uncle = grandpa->left; |
} else { |
510 |
if (uncle->color == dnode_red) { |
if (node == parent->left) { |
511 |
parent->color = dnode_black; |
rotate_right(parent); |
512 |
uncle->color = dnode_black; |
parent = node; |
513 |
grandpa->color = dnode_red; |
assert (grandpa == parent->parent); |
514 |
node = grandpa; |
} |
515 |
parent = grandpa->parent; |
parent->color = dnode_black; |
516 |
} else { |
grandpa->color = dnode_red; |
517 |
if (node == parent->left) { |
rotate_left(grandpa); |
518 |
rotate_right(parent); |
break; |
519 |
parent = node; |
} |
520 |
assert (grandpa == parent->parent); |
} |
|
} |
|
|
parent->color = dnode_black; |
|
|
grandpa->color = dnode_red; |
|
|
rotate_left(grandpa); |
|
|
break; |
|
|
} |
|
521 |
} |
} |
|
} |
|
522 |
|
|
523 |
dict_root(dict)->color = dnode_black; |
dict_root(dict)->color = dnode_black; |
524 |
|
|
525 |
} |
} |
526 |
|
|
531 |
|
|
532 |
static dnode_t *dnode_init(dnode_t *dnode, void *data) |
static dnode_t *dnode_init(dnode_t *dnode, void *data) |
533 |
{ |
{ |
534 |
dnode->data = data; |
dnode->data = data; |
535 |
dnode->parent = NULL; |
dnode->parent = NULL; |
536 |
dnode->left = NULL; |
dnode->left = NULL; |
537 |
dnode->right = NULL; |
dnode->right = NULL; |
538 |
return dnode; |
return dnode; |
539 |
} |
} |
540 |
|
|
541 |
static int dict_alloc_insert(dict_t *dict, const void *key, void *data) |
static int dict_alloc_insert(dict_t *dict, const void *key, void *data) |
542 |
{ |
{ |
543 |
dnode_t *node = malloc(sizeof(dnode_t)); |
dnode_t *node = xmalloc(sizeof(dnode_t)); |
544 |
|
|
|
if (node) { |
|
545 |
dnode_init(node, data); |
dnode_init(node, data); |
546 |
dict_insert(dict, node, key); |
dict_insert(dict, node, key); |
547 |
return 1; |
return 1; |
|
} |
|
|
return 0; |
|
548 |
} |
} |
549 |
|
|
550 |
/* |
/* |
554 |
|
|
555 |
static dnode_t *dict_first(dict_t *dict) |
static dnode_t *dict_first(dict_t *dict) |
556 |
{ |
{ |
557 |
dnode_t *nil = dict_nil(dict), *root = dict_root(dict), *left; |
dnode_t *nil = dict_nil(dict), *root = dict_root(dict), *left; |
558 |
|
|
559 |
if (root != nil) |
if (root != nil) |
560 |
while ((left = root->left) != nil) |
while ((left = root->left) != nil) |
561 |
root = left; |
root = left; |
562 |
|
|
563 |
return (root == nil) ? NULL : root; |
return (root == nil) ? NULL : root; |
564 |
} |
} |
565 |
|
|
566 |
/* |
/* |
572 |
|
|
573 |
static dnode_t *dict_next(dict_t *dict, dnode_t *curr) |
static dnode_t *dict_next(dict_t *dict, dnode_t *curr) |
574 |
{ |
{ |
575 |
dnode_t *nil = dict_nil(dict), *parent, *left; |
dnode_t *nil = dict_nil(dict), *parent, *left; |
576 |
|
|
577 |
if (curr->right != nil) { |
if (curr->right != nil) { |
578 |
curr = curr->right; |
curr = curr->right; |
579 |
while ((left = curr->left) != nil) |
while ((left = curr->left) != nil) |
580 |
curr = left; |
curr = left; |
581 |
return curr; |
return curr; |
582 |
} |
} |
|
|
|
|
parent = curr->parent; |
|
583 |
|
|
|
while (parent != nil && curr == parent->right) { |
|
|
curr = parent; |
|
584 |
parent = curr->parent; |
parent = curr->parent; |
|
} |
|
585 |
|
|
586 |
return (parent == nil) ? NULL : parent; |
while (parent != nil && curr == parent->right) { |
587 |
|
curr = parent; |
588 |
|
parent = curr->parent; |
589 |
|
} |
590 |
|
|
591 |
|
return (parent == nil) ? NULL : parent; |
592 |
} |
} |
593 |
|
|
594 |
|
|
595 |
static void dnode_free(dnode_t *node) |
static void dnode_free(dnode_t *node) |
596 |
{ |
{ |
597 |
free(node); |
free(node); |
598 |
} |
} |
599 |
|
|
600 |
|
|
1882 |
int i; |
int i; |
1883 |
|
|
1884 |
/* Leave a valid existing V1 superblock signature alone. |
/* Leave a valid existing V1 superblock signature alone. |
1885 |
* Anything unrecognisable we overwrite with a new V2 |
* Anything unrecognizable we overwrite with a new V2 |
1886 |
* signature. */ |
* signature. */ |
1887 |
|
|
1888 |
if (jsb->s_header.h_magic != htonl(JFS_MAGIC_NUMBER) || |
if (jsb->s_header.h_magic != htonl(JFS_MAGIC_NUMBER) || |
2266 |
ext2fs_mark_super_dirty(fs); |
ext2fs_mark_super_dirty(fs); |
2267 |
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; |
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; |
2268 |
inode.i_links_count = 0; |
inode.i_links_count = 0; |
2269 |
inode.i_dtime = time(0); |
inode.i_dtime = time(NULL); |
2270 |
if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0) |
if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0) |
2271 |
goto err_out; |
goto err_out; |
2272 |
|
|
2388 |
N_("hHTREE @d @i"), |
N_("hHTREE @d @i"), |
2389 |
N_("llost+found"), |
N_("llost+found"), |
2390 |
N_("Lis a link"), |
N_("Lis a link"), |
2391 |
N_("mmultiply-claimed"), |
N_("mmultiply-claimed"), |
2392 |
N_("ninvalid"), |
N_("ninvalid"), |
2393 |
N_("oorphaned"), |
N_("oorphaned"), |
2394 |
N_("pproblem in"), |
N_("pproblem in"), |
2395 |
N_("rroot @i"), |
N_("rroot @i"), |
2738 |
{ |
{ |
2739 |
region_t region; |
region_t region; |
2740 |
|
|
2741 |
region = malloc(sizeof(struct region_struct)); |
region = xzalloc(sizeof(struct region_struct)); |
|
if (!region) |
|
|
return NULL; |
|
|
memset(region, 0, sizeof(struct region_struct)); |
|
2742 |
region->min = min; |
region->min = min; |
2743 |
region->max = max; |
region->max = max; |
2744 |
return region; |
return region; |
2803 |
/* |
/* |
2804 |
* Insert a new region element structure into the linked list |
* Insert a new region element structure into the linked list |
2805 |
*/ |
*/ |
2806 |
new_region = malloc(sizeof(struct region_el)); |
new_region = xmalloc(sizeof(struct region_el)); |
|
if (!new_region) |
|
|
return -1; |
|
2807 |
new_region->start = start; |
new_region->start = start; |
2808 |
new_region->end = start + n; |
new_region->end = start + n; |
2809 |
new_region->next = r; |
new_region->next = r; |
3372 |
*/ |
*/ |
3373 |
if (!LINUX_S_ISDIR(inode->i_mode)) { |
if (!LINUX_S_ISDIR(inode->i_mode)) { |
3374 |
if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) { |
if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) { |
3375 |
inode->i_dtime = time(0); |
inode->i_dtime = time(NULL); |
3376 |
inode->i_links_count = 0; |
inode->i_links_count = 0; |
3377 |
ext2fs_icount_store(ctx->inode_link_info, |
ext2fs_icount_store(ctx->inode_link_info, |
3378 |
ino, 0); |
ino, 0); |
3466 |
inode->i_dtime < ctx->fs->super->s_inodes_count) { |
inode->i_dtime < ctx->fs->super->s_inodes_count) { |
3467 |
if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) { |
if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) { |
3468 |
inode->i_dtime = inode->i_links_count ? |
inode->i_dtime = inode->i_links_count ? |
3469 |
0 : time(0); |
0 : time(NULL); |
3470 |
e2fsck_write_inode(ctx, ino, inode, |
e2fsck_write_inode(ctx, ino, inode, |
3471 |
"pass1"); |
"pass1"); |
3472 |
} |
} |
3480 |
if (!inode->i_dtime && inode->i_mode) { |
if (!inode->i_dtime && inode->i_mode) { |
3481 |
if (fix_problem(ctx, |
if (fix_problem(ctx, |
3482 |
PR_1_ZERO_DTIME, &pctx)) { |
PR_1_ZERO_DTIME, &pctx)) { |
3483 |
inode->i_dtime = time(0); |
inode->i_dtime = time(NULL); |
3484 |
e2fsck_write_inode(ctx, ino, inode, |
e2fsck_write_inode(ctx, ino, inode, |
3485 |
"pass1"); |
"pass1"); |
3486 |
} |
} |
3650 |
} |
} |
3651 |
e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode, |
e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode, |
3652 |
"recreate inode"); |
"recreate inode"); |
3653 |
inode->i_mtime = time(0); |
inode->i_mtime = time(NULL); |
3654 |
e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode, |
e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode, |
3655 |
"recreate inode"); |
"recreate inode"); |
3656 |
fs->block_map = save_bmap; |
fs->block_map = save_bmap; |
4160 |
if (pb.clear) { |
if (pb.clear) { |
4161 |
inode->i_links_count = 0; |
inode->i_links_count = 0; |
4162 |
ext2fs_icount_store(ctx->inode_link_info, ino, 0); |
ext2fs_icount_store(ctx->inode_link_info, ino, 0); |
4163 |
inode->i_dtime = time(0); |
inode->i_dtime = time(NULL); |
4164 |
dirty_inode++; |
dirty_inode++; |
4165 |
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); |
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); |
4166 |
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino); |
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino); |
4193 |
if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) { |
if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) { |
4194 |
inode->i_links_count = 0; |
inode->i_links_count = 0; |
4195 |
ext2fs_icount_store(ctx->inode_link_info, ino, 0); |
ext2fs_icount_store(ctx->inode_link_info, ino, 0); |
4196 |
inode->i_dtime = time(0); |
inode->i_dtime = time(NULL); |
4197 |
dirty_inode++; |
dirty_inode++; |
4198 |
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); |
ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); |
4199 |
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino); |
ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino); |
5138 |
/* Inode may have changed by block_iterate, so reread it */ |
/* Inode may have changed by block_iterate, so reread it */ |
5139 |
e2fsck_read_inode(ctx, ino, &inode, "delete_file"); |
e2fsck_read_inode(ctx, ino, &inode, "delete_file"); |
5140 |
inode.i_links_count = 0; |
inode.i_links_count = 0; |
5141 |
inode.i_dtime = time(0); |
inode.i_dtime = time(NULL); |
5142 |
if (inode.i_file_acl && |
if (inode.i_file_acl && |
5143 |
(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { |
(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { |
5144 |
count = 1; |
count = 1; |
6384 |
ext2fs_icount_store(ctx->inode_link_info, ino, 0); |
ext2fs_icount_store(ctx->inode_link_info, ino, 0); |
6385 |
e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode"); |
e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode"); |
6386 |
inode.i_links_count = 0; |
inode.i_links_count = 0; |
6387 |
inode.i_dtime = time(0); |
inode.i_dtime = time(NULL); |
6388 |
e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode"); |
e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode"); |
6389 |
clear_problem_context(&pctx); |
clear_problem_context(&pctx); |
6390 |
pctx.ino = ino; |
pctx.ino = ino; |
6881 |
memset(&inode, 0, sizeof(inode)); |
memset(&inode, 0, sizeof(inode)); |
6882 |
inode.i_mode = 040755; |
inode.i_mode = 040755; |
6883 |
inode.i_size = fs->blocksize; |
inode.i_size = fs->blocksize; |
6884 |
inode.i_atime = inode.i_ctime = inode.i_mtime = time(0); |
inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); |
6885 |
inode.i_links_count = 2; |
inode.i_links_count = 2; |
6886 |
inode.i_blocks = fs->blocksize / 512; |
inode.i_blocks = fs->blocksize / 512; |
6887 |
inode.i_block[0] = blk; |
inode.i_block[0] = blk; |
7129 |
memset(&inode, 0, sizeof(inode)); |
memset(&inode, 0, sizeof(inode)); |
7130 |
inode.i_mode = 040700; |
inode.i_mode = 040700; |
7131 |
inode.i_size = fs->blocksize; |
inode.i_size = fs->blocksize; |
7132 |
inode.i_atime = inode.i_ctime = inode.i_mtime = time(0); |
inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); |
7133 |
inode.i_links_count = 2; |
inode.i_links_count = 2; |
7134 |
inode.i_blocks = fs->blocksize / 512; |
inode.i_blocks = fs->blocksize / 512; |
7135 |
inode.i_block[0] = blk; |
inode.i_block[0] = blk; |
7483 |
if (fix_problem(ctx, PR_4_ZERO_LEN_INODE, &pctx)) { |
if (fix_problem(ctx, PR_4_ZERO_LEN_INODE, &pctx)) { |
7484 |
ext2fs_icount_store(ctx->inode_link_info, i, 0); |
ext2fs_icount_store(ctx->inode_link_info, i, 0); |
7485 |
inode.i_links_count = 0; |
inode.i_links_count = 0; |
7486 |
inode.i_dtime = time(0); |
inode.i_dtime = time(NULL); |
7487 |
e2fsck_write_inode(ctx, i, &inode, |
e2fsck_write_inode(ctx, i, &inode, |
7488 |
"disconnect_inode"); |
"disconnect_inode"); |
7489 |
/* |
/* |
9391 |
|
|
9392 |
/* Cannot proceed without a root inode. */ |
/* Cannot proceed without a root inode. */ |
9393 |
{ PR_3_NO_ROOT_INODE_ABORT, |
{ PR_3_NO_ROOT_INODE_ABORT, |
9394 |
N_("Cannot proceed without a @r.\n"), |
N_("can't proceed without a @r.\n"), |
9395 |
PROMPT_NONE, PR_FATAL }, |
PROMPT_NONE, PR_FATAL }, |
9396 |
|
|
9397 |
/* Internal error: couldn't find dir_info */ |
/* Internal error: couldn't find dir_info */ |
10302 |
continue; |
continue; |
10303 |
} |
} |
10304 |
if (fd->num_array >= fd->max_array) { |
if (fd->num_array >= fd->max_array) { |
10305 |
new_array = realloc(fd->harray, |
new_array = xrealloc(fd->harray, |
10306 |
sizeof(struct hash_entry) * (fd->max_array+500)); |
sizeof(struct hash_entry) * (fd->max_array+500)); |
|
if (!new_array) { |
|
|
fd->err = ENOMEM; |
|
|
return BLOCK_ABORT; |
|
|
} |
|
10307 |
fd->harray = new_array; |
fd->harray = new_array; |
10308 |
fd->max_array += 500; |
fd->max_array += 500; |
10309 |
} |
} |
10378 |
void *new_mem; |
void *new_mem; |
10379 |
|
|
10380 |
if (outdir->max) { |
if (outdir->max) { |
10381 |
new_mem = realloc(outdir->buf, blocks * fs->blocksize); |
new_mem = xrealloc(outdir->buf, blocks * fs->blocksize); |
|
if (!new_mem) |
|
|
return ENOMEM; |
|
10382 |
outdir->buf = new_mem; |
outdir->buf = new_mem; |
10383 |
new_mem = realloc(outdir->hashes, |
new_mem = xrealloc(outdir->hashes, |
10384 |
blocks * sizeof(ext2_dirhash_t)); |
blocks * sizeof(ext2_dirhash_t)); |
|
if (!new_mem) |
|
|
return ENOMEM; |
|
10385 |
outdir->hashes = new_mem; |
outdir->hashes = new_mem; |
10386 |
} else { |
} else { |
10387 |
outdir->buf = malloc(blocks * fs->blocksize); |
outdir->buf = xmalloc(blocks * fs->blocksize); |
10388 |
outdir->hashes = malloc(blocks * sizeof(ext2_dirhash_t)); |
outdir->hashes = xmalloc(blocks * sizeof(ext2_dirhash_t)); |
10389 |
outdir->num = 0; |
outdir->num = 0; |
10390 |
} |
} |
10391 |
outdir->max = blocks; |
outdir->max = blocks; |
10832 |
|
|
10833 |
retval = ENOMEM; |
retval = ENOMEM; |
10834 |
fd.harray = 0; |
fd.harray = 0; |
10835 |
dir_buf = malloc(inode.i_size); |
dir_buf = xmalloc(inode.i_size); |
|
if (!dir_buf) |
|
|
goto errout; |
|
10836 |
|
|
10837 |
fd.max_array = inode.i_size / 32; |
fd.max_array = inode.i_size / 32; |
10838 |
fd.num_array = 0; |
fd.num_array = 0; |
10839 |
fd.harray = malloc(fd.max_array * sizeof(struct hash_entry)); |
fd.harray = xmalloc(fd.max_array * sizeof(struct hash_entry)); |
|
if (!fd.harray) |
|
|
goto errout; |
|
10840 |
|
|
10841 |
fd.ctx = ctx; |
fd.ctx = ctx; |
10842 |
fd.buf = dir_buf; |
fd.buf = dir_buf; |
11141 |
shift++; |
shift++; |
11142 |
journal->j_revoke->hash_shift = shift; |
journal->j_revoke->hash_shift = shift; |
11143 |
|
|
11144 |
journal->j_revoke->hash_table = malloc(hash_size * sizeof(struct list_head)); |
journal->j_revoke->hash_table = xmalloc(hash_size * sizeof(struct list_head)); |
|
if (!journal->j_revoke->hash_table) { |
|
|
free(journal->j_revoke); |
|
|
journal->j_revoke = NULL; |
|
|
return -ENOMEM; |
|
|
} |
|
11145 |
|
|
11146 |
for (tmp = 0; tmp < hash_size; tmp++) |
for (tmp = 0; tmp < hash_size; tmp++) |
11147 |
INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); |
INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); |
11532 |
if (!inode.i_links_count) { |
if (!inode.i_links_count) { |
11533 |
ext2fs_inode_alloc_stats2(fs, ino, -1, |
ext2fs_inode_alloc_stats2(fs, ino, -1, |
11534 |
LINUX_S_ISDIR(inode.i_mode)); |
LINUX_S_ISDIR(inode.i_mode)); |
11535 |
inode.i_dtime = time(0); |
inode.i_dtime = time(NULL); |
11536 |
} else { |
} else { |
11537 |
inode.i_dtime = 0; |
inode.i_dtime = 0; |
11538 |
} |
} |
12193 |
void *ret; |
void *ret; |
12194 |
char buf[256]; |
char buf[256]; |
12195 |
|
|
12196 |
ret = malloc(size); |
ret = xzalloc(size); |
|
if (!ret) { |
|
|
sprintf(buf, "Can't allocate %s\n", description); |
|
|
bb_error_msg_and_die(buf); |
|
|
} |
|
|
memset(ret, 0, size); |
|
12197 |
return ret; |
return ret; |
12198 |
} |
} |
12199 |
|
|
12205 |
return NULL; |
return NULL; |
12206 |
if (!len) |
if (!len) |
12207 |
len = strlen(str); |
len = strlen(str); |
12208 |
ret = malloc(len+1); |
ret = xmalloc(len+1); |
12209 |
if (ret) { |
strncpy(ret, str, len); |
12210 |
strncpy(ret, str, len); |
ret[len] = 0; |
|
ret[len] = 0; |
|
|
} |
|
12211 |
return ret; |
return ret; |
12212 |
} |
} |
12213 |
|
|
12599 |
retval = ext2fs_check_if_mounted(ctx->filesystem_name, |
retval = ext2fs_check_if_mounted(ctx->filesystem_name, |
12600 |
&ctx->mount_flags); |
&ctx->mount_flags); |
12601 |
if (retval) { |
if (retval) { |
12602 |
bb_error_msg(_("while determining whether %s is mounted."), |
bb_error_msg(_("while determining whether %s is mounted"), |
12603 |
ctx->filesystem_name); |
ctx->filesystem_name); |
12604 |
return; |
return; |
12605 |
} |
} |
12620 |
|
|
12621 |
printf(_("%s is mounted. "), ctx->filesystem_name); |
printf(_("%s is mounted. "), ctx->filesystem_name); |
12622 |
if (!ctx->interactive) |
if (!ctx->interactive) |
12623 |
bb_error_msg_and_die(_("Cannot continue, aborting.")); |
bb_error_msg_and_die(_("can't continue, aborting")); |
12624 |
printf(_("\n\n\007\007\007\007WARNING!!! " |
printf(_("\n\n\007\007\007\007WARNING!!! " |
12625 |
"Running e2fsck on a mounted filesystem may cause\n" |
"Running e2fsck on a mounted filesystem may cause\n" |
12626 |
"SEVERE filesystem damage.\007\007\007\n\n")); |
"SEVERE filesystem damage.\007\007\007\n\n")); |
12681 |
unsigned int reason_arg = 0; |
unsigned int reason_arg = 0; |
12682 |
long next_check; |
long next_check; |
12683 |
int batt = is_on_batt(); |
int batt = is_on_batt(); |
12684 |
time_t now = time(0); |
time_t now = time(NULL); |
12685 |
|
|
12686 |
if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs) |
if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs) |
12687 |
return; |
return; |
12859 |
|
|
12860 |
if (ctx->progress_fd) { |
if (ctx->progress_fd) { |
12861 |
sprintf(buf, "%d %lu %lu\n", pass, cur, max); |
sprintf(buf, "%d %lu %lu\n", pass, cur, max); |
12862 |
write(ctx->progress_fd, buf, strlen(buf)); |
xwrite_str(ctx->progress_fd, buf); |
12863 |
} else { |
} else { |
12864 |
percent = calc_percent(&e2fsck_tbl, pass, cur, max); |
percent = calc_percent(&e2fsck_tbl, pass, cur, max); |
12865 |
e2fsck_simple_progress(ctx, ctx->device_name, |
e2fsck_simple_progress(ctx, ctx->device_name, |
13027 |
case 'a': |
case 'a': |
13028 |
if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) { |
if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) { |
13029 |
conflict_opt: |
conflict_opt: |
13030 |
bb_error_msg_and_die(_("Only one the options -p/-a, -n or -y may be specified.")); |
bb_error_msg_and_die(_("only one the options -p/-a, -n or -y may be specified")); |
13031 |
} |
} |
13032 |
ctx->options |= E2F_OPT_PREEN; |
ctx->options |= E2F_OPT_PREEN; |
13033 |
break; |
break; |
13340 |
* happen, unless the hardware or |
* happen, unless the hardware or |
13341 |
* device driver is being bogus. |
* device driver is being bogus. |
13342 |
*/ |
*/ |
13343 |
bb_error_msg(_("cannot set superblock flags on %s"), ctx->device_name); |
bb_error_msg(_("can't set superblock flags on %s"), ctx->device_name); |
13344 |
bb_error_msg_and_die(0); |
bb_error_msg_and_die(0); |
13345 |
} |
} |
13346 |
retval = e2fsck_run_ext3_journal(ctx); |
retval = e2fsck_run_ext3_journal(ctx); |
13372 |
#ifdef ENABLE_COMPRESSION |
#ifdef ENABLE_COMPRESSION |
13373 |
/* FIXME - do we support this at all? */ |
/* FIXME - do we support this at all? */ |
13374 |
if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION) |
if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION) |
13375 |
bb_error_msg(_("Warning: compression support is experimental.")); |
bb_error_msg(_("warning: compression support is experimental")); |
13376 |
#endif |
#endif |
13377 |
#ifndef ENABLE_HTREE |
#ifndef ENABLE_HTREE |
13378 |
if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) { |
if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) { |