Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * resize2fs.h --- ext2 resizer header file |
| 3 | * |
| 4 | * Copyright (C) 1997 Theodore Ts'o |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * All rights reserved. |
| 8 | * %End-Header% |
| 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <string.h> |
Theodore Ts'o | 169cb54 | 1998-08-01 04:33:31 +0000 | [diff] [blame] | 13 | #ifdef HAVE_UNISTD_H |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 14 | #include <unistd.h> |
Theodore Ts'o | 169cb54 | 1998-08-01 04:33:31 +0000 | [diff] [blame] | 15 | #endif |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 16 | #include <stdlib.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 17 | #ifdef HAVE_SYS_TYPES_H |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 18 | #include <sys/types.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 19 | #endif |
| 20 | #ifdef HAVE_SYS_TIME_H |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 21 | #include <sys/time.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 22 | #endif |
Theodore Ts'o | bc75f2a | 1997-09-04 00:43:10 +0000 | [diff] [blame] | 23 | #if HAVE_ERRNO_H |
| 24 | #include <errno.h> |
| 25 | #endif |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 26 | |
| 27 | #ifdef HAVE_LINUX_FS_H |
| 28 | #include <linux/fs.h> |
| 29 | #endif |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 30 | |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 31 | #if EXT2_FLAT_INCLUDES |
| 32 | #include "ext2_fs.h" |
| 33 | #include "ext2fs.h" |
| 34 | #else |
| 35 | #include <linux/ext2_fs.h> |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 36 | #include "ext2fs/ext2fs.h" |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 39 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 40 | /* |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 41 | * For the extent map |
| 42 | */ |
| 43 | typedef struct _ext2_extent *ext2_extent; |
| 44 | |
| 45 | /* |
| 46 | * For the simple progress meter |
| 47 | */ |
| 48 | typedef struct ext2_sim_progress *ext2_sim_progmeter; |
| 49 | |
| 50 | /* |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 51 | * Flags for the resizer; most are debugging flags only |
| 52 | */ |
| 53 | #define RESIZE_DEBUG_IO 0x0001 |
| 54 | #define RESIZE_DEBUG_BMOVE 0x0002 |
| 55 | #define RESIZE_DEBUG_INODEMAP 0x0004 |
| 56 | #define RESIZE_DEBUG_ITABLEMOVE 0x0008 |
| 57 | |
| 58 | #define RESIZE_PERCENT_COMPLETE 0x0100 |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 59 | #define RESIZE_VERBOSE 0x0200 |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 60 | |
| 61 | /* |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 62 | * The core state structure for the ext2 resizer |
| 63 | */ |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 64 | typedef struct ext2_resize_struct *ext2_resize_t; |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 65 | |
| 66 | struct ext2_resize_struct { |
| 67 | ext2_filsys old_fs; |
| 68 | ext2_filsys new_fs; |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 69 | ext2fs_block_bitmap reserve_blocks; |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 70 | ext2fs_block_bitmap move_blocks; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 71 | ext2_extent bmap; |
| 72 | ext2_extent imap; |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 73 | int needed_blocks; |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 74 | int flags; |
| 75 | char *itable_buf; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * For the block allocator |
| 79 | */ |
| 80 | blk_t new_blk; |
| 81 | int alloc_state; |
| 82 | |
| 83 | /* |
| 84 | * For the progress meter |
| 85 | */ |
Theodore Ts'o | 3b627e8 | 1998-02-24 20:24:49 +0000 | [diff] [blame] | 86 | errcode_t (*progress)(ext2_resize_t rfs, int pass, |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 87 | unsigned long cur, |
| 88 | unsigned long max); |
| 89 | void *prog_data; |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 92 | /* |
| 93 | * Progress pass numbers... |
| 94 | */ |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 95 | #define E2_RSZ_EXTEND_ITABLE_PASS 1 |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 96 | #define E2_RSZ_BLOCK_RELOC_PASS 2 |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 97 | #define E2_RSZ_INODE_SCAN_PASS 3 |
| 98 | #define E2_RSZ_INODE_REF_UPD_PASS 4 |
| 99 | #define E2_RSZ_MOVE_ITABLE_PASS 5 |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 100 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 101 | |
| 102 | /* prototypes */ |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 103 | extern errcode_t resize_fs(ext2_filsys fs, blk_t new_size, int flags, |
Theodore Ts'o | 3b627e8 | 1998-02-24 20:24:49 +0000 | [diff] [blame] | 104 | errcode_t (*progress)(ext2_resize_t rfs, |
| 105 | int pass, unsigned long cur, |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 106 | unsigned long max)); |
| 107 | |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 108 | /* extent.c */ |
| 109 | extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, |
| 110 | int size); |
| 111 | extern void ext2fs_free_extent_table(ext2_extent extent); |
| 112 | extern errcode_t ext2fs_add_extent_entry(ext2_extent extent, |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 113 | __u32 old_loc, __u32 new_loc); |
| 114 | extern __u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 115 | extern void ext2fs_extent_dump(ext2_extent extent, FILE *out); |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 116 | extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc, |
| 117 | __u32 *new_loc, int *size); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 118 | |
| 119 | /* sim_progress.c */ |
| 120 | extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog, |
| 121 | const char *label, |
| 122 | int labelwidth, int barwidth, |
| 123 | __u32 maxdone, int flags); |
| 124 | extern void ext2fs_progress_update(ext2_sim_progmeter prog, |
| 125 | __u32 current); |
| 126 | extern void ext2fs_progress_close(ext2_sim_progmeter prog); |
| 127 | |
| 128 | |