]>
Commit | Line | Data |
---|---|---|
24b2c7a7 TT |
1 | /* |
2 | * resize2fs.h --- ext2 resizer header file | |
3 | * | |
0cee8a5c TT |
4 | * Copyright (C) 1997, 1998 by Theodore Ts'o and |
5 | * PowerQuest, Inc. | |
6 | * | |
055866d8 | 7 | * Copyright (C) 1999, 2000 by Theodore Ts'o |
efc6f628 | 8 | * |
24b2c7a7 | 9 | * %Begin-Header% |
0cee8a5c TT |
10 | * This file may be redistributed under the terms of the GNU Public |
11 | * License. | |
24b2c7a7 TT |
12 | * %End-Header% |
13 | */ | |
14 | ||
15 | #include <stdio.h> | |
16 | #include <string.h> | |
169cb546 | 17 | #ifdef HAVE_UNISTD_H |
24b2c7a7 | 18 | #include <unistd.h> |
169cb546 | 19 | #endif |
24b2c7a7 | 20 | #include <stdlib.h> |
d40259fd | 21 | #ifdef HAVE_SYS_TYPES_H |
24b2c7a7 | 22 | #include <sys/types.h> |
d40259fd TT |
23 | #endif |
24 | #ifdef HAVE_SYS_TIME_H | |
24b2c7a7 | 25 | #include <sys/time.h> |
d40259fd | 26 | #endif |
bc75f2a1 TT |
27 | #if HAVE_ERRNO_H |
28 | #include <errno.h> | |
29 | #endif | |
24b2c7a7 | 30 | |
ca8abba7 TT |
31 | #if EXT2_FLAT_INCLUDES |
32 | #include "ext2_fs.h" | |
33 | #include "ext2fs.h" | |
de8f3a76 | 34 | #include "e2p.h" |
ca8abba7 | 35 | #else |
54c637d4 | 36 | #include "ext2fs/ext2_fs.h" |
24b2c7a7 | 37 | #include "ext2fs/ext2fs.h" |
de8f3a76 | 38 | #include "e2p/e2p.h" |
ca8abba7 TT |
39 | #endif |
40 | ||
a13575f4 TT |
41 | #ifdef ENABLE_NLS |
42 | #include <libintl.h> | |
43 | #include <locale.h> | |
44 | #define _(a) (gettext (a)) | |
45 | #ifdef gettext_noop | |
46 | #define N_(a) gettext_noop (a) | |
47 | #else | |
48 | #define N_(a) (a) | |
49 | #endif | |
a04eba3f | 50 | #ifndef NLS_CAT_NAME |
a13575f4 | 51 | #define NLS_CAT_NAME "e2fsprogs" |
a04eba3f TT |
52 | #endif |
53 | #ifndef LOCALEDIR | |
a13575f4 | 54 | #define LOCALEDIR "/usr/share/locale" |
a04eba3f | 55 | #endif |
a13575f4 TT |
56 | #else |
57 | #define _(a) (a) | |
58 | #define N_(a) a | |
59 | #endif | |
60 | ||
24b2c7a7 | 61 | |
c762c8e6 TT |
62 | /* |
63 | * For the extent map | |
64 | */ | |
65 | typedef struct _ext2_extent *ext2_extent; | |
66 | ||
67 | /* | |
68 | * For the simple progress meter | |
69 | */ | |
70 | typedef struct ext2_sim_progress *ext2_sim_progmeter; | |
71 | ||
05e112a1 TT |
72 | /* |
73 | * Flags for the resizer; most are debugging flags only | |
74 | */ | |
75 | #define RESIZE_DEBUG_IO 0x0001 | |
76 | #define RESIZE_DEBUG_BMOVE 0x0002 | |
77 | #define RESIZE_DEBUG_INODEMAP 0x0004 | |
78 | #define RESIZE_DEBUG_ITABLEMOVE 0x0008 | |
1eb31c48 | 79 | #define RESIZE_DEBUG_RTRACK 0x0010 |
e231f175 | 80 | #define RESIZE_DEBUG_MIN_CALC 0x0020 |
05e112a1 TT |
81 | |
82 | #define RESIZE_PERCENT_COMPLETE 0x0100 | |
c762c8e6 | 83 | #define RESIZE_VERBOSE 0x0200 |
05e112a1 | 84 | |
fe12931f DW |
85 | #define RESIZE_ENABLE_64BIT 0x0400 |
86 | #define RESIZE_DISABLE_64BIT 0x0800 | |
87 | ||
1eb31c48 TT |
88 | /* |
89 | * This structure is used for keeping track of how much resources have | |
90 | * been used for a particular resize2fs pass. | |
91 | */ | |
92 | struct resource_track { | |
93 | const char *desc; | |
94 | struct timeval time_start; | |
95 | struct timeval user_start; | |
96 | struct timeval system_start; | |
97 | void *brk_start; | |
98 | unsigned long long bytes_read; | |
99 | unsigned long long bytes_written; | |
100 | }; | |
101 | ||
24b2c7a7 TT |
102 | /* |
103 | * The core state structure for the ext2 resizer | |
104 | */ | |
63b44fbe | 105 | typedef struct ext2_resize_struct *ext2_resize_t; |
24b2c7a7 TT |
106 | |
107 | struct ext2_resize_struct { | |
108 | ext2_filsys old_fs; | |
109 | ext2_filsys new_fs; | |
1e1da29f | 110 | ext2fs_block_bitmap reserve_blocks; |
c762c8e6 | 111 | ext2fs_block_bitmap move_blocks; |
a8519a2d TT |
112 | ext2_extent bmap; |
113 | ext2_extent imap; | |
8728d506 | 114 | blk64_t needed_blocks; |
05e112a1 TT |
115 | int flags; |
116 | char *itable_buf; | |
a8519a2d TT |
117 | |
118 | /* | |
119 | * For the block allocator | |
120 | */ | |
8728d506 | 121 | blk64_t new_blk; |
a8519a2d TT |
122 | int alloc_state; |
123 | ||
124 | /* | |
125 | * For the progress meter | |
126 | */ | |
3b627e8d | 127 | errcode_t (*progress)(ext2_resize_t rfs, int pass, |
63b44fbe TT |
128 | unsigned long cur, |
129 | unsigned long max); | |
130 | void *prog_data; | |
24b2c7a7 TT |
131 | }; |
132 | ||
63b44fbe TT |
133 | /* |
134 | * Progress pass numbers... | |
135 | */ | |
a8519a2d | 136 | #define E2_RSZ_EXTEND_ITABLE_PASS 1 |
63b44fbe | 137 | #define E2_RSZ_BLOCK_RELOC_PASS 2 |
a8519a2d TT |
138 | #define E2_RSZ_INODE_SCAN_PASS 3 |
139 | #define E2_RSZ_INODE_REF_UPD_PASS 4 | |
140 | #define E2_RSZ_MOVE_ITABLE_PASS 5 | |
63b44fbe | 141 | |
24b2c7a7 TT |
142 | |
143 | /* prototypes */ | |
8728d506 | 144 | extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, |
3b627e8d TT |
145 | errcode_t (*progress)(ext2_resize_t rfs, |
146 | int pass, unsigned long cur, | |
63b44fbe TT |
147 | unsigned long max)); |
148 | ||
efc6f628 | 149 | extern errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, |
c09043f1 | 150 | ext2fs_block_bitmap reserve_blocks, |
8728d506 | 151 | blk64_t new_size); |
e231f175 | 152 | extern blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags); |
bf69235a TT |
153 | |
154 | ||
c762c8e6 TT |
155 | /* extent.c */ |
156 | extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, | |
8728d506 | 157 | __u64 size); |
c762c8e6 TT |
158 | extern void ext2fs_free_extent_table(ext2_extent extent); |
159 | extern errcode_t ext2fs_add_extent_entry(ext2_extent extent, | |
8728d506 VAH |
160 | __u64 old_loc, __u64 new_loc); |
161 | extern __u64 ext2fs_extent_translate(ext2_extent extent, __u64 old_loc); | |
c762c8e6 | 162 | extern void ext2fs_extent_dump(ext2_extent extent, FILE *out); |
8728d506 VAH |
163 | extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u64 *old_loc, |
164 | __u64 *new_loc, __u64 *size); | |
c762c8e6 | 165 | |
f404167d TT |
166 | /* main.c */ |
167 | extern char *program_name; | |
168 | ||
bf69235a | 169 | /* online.c */ |
efc6f628 | 170 | extern errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, |
8728d506 | 171 | blk64_t *new_size, int flags); |
bf69235a | 172 | |
1eb31c48 TT |
173 | /* resource_track.c */ |
174 | extern void init_resource_track(struct resource_track *track, const char *desc, | |
175 | io_channel channel); | |
176 | extern void print_resource_track(ext2_resize_t rfs, | |
177 | struct resource_track *track, | |
178 | io_channel channel); | |
179 | ||
c762c8e6 TT |
180 | /* sim_progress.c */ |
181 | extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog, | |
182 | const char *label, | |
183 | int labelwidth, int barwidth, | |
184 | __u32 maxdone, int flags); | |
185 | extern void ext2fs_progress_update(ext2_sim_progmeter prog, | |
186 | __u32 current); | |
187 | extern void ext2fs_progress_close(ext2_sim_progmeter prog); | |
188 | ||
189 |