Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * resize2fs.h --- ext2 resizer header file |
| 3 | * |
Theodore Ts'o | 0cee8a5 | 2000-04-06 21:38:34 +0000 | [diff] [blame] | 4 | * Copyright (C) 1997, 1998 by Theodore Ts'o and |
| 5 | * PowerQuest, Inc. |
| 6 | * |
| 7 | * Copyright (C) 1999, 2000 by Theosore Ts'o |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 8 | * |
| 9 | * %Begin-Header% |
Theodore Ts'o | 0cee8a5 | 2000-04-06 21:38:34 +0000 | [diff] [blame] | 10 | * This file may be redistributed under the terms of the GNU Public |
| 11 | * License. |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 12 | * %End-Header% |
| 13 | */ |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <string.h> |
Theodore Ts'o | 169cb54 | 1998-08-01 04:33:31 +0000 | [diff] [blame] | 17 | #ifdef HAVE_UNISTD_H |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 18 | #include <unistd.h> |
Theodore Ts'o | 169cb54 | 1998-08-01 04:33:31 +0000 | [diff] [blame] | 19 | #endif |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 21 | #ifdef HAVE_SYS_TYPES_H |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 22 | #include <sys/types.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 23 | #endif |
| 24 | #ifdef HAVE_SYS_TIME_H |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 25 | #include <sys/time.h> |
Theodore Ts'o | d40259f | 1997-10-20 00:44:26 +0000 | [diff] [blame] | 26 | #endif |
Theodore Ts'o | bc75f2a | 1997-09-04 00:43:10 +0000 | [diff] [blame] | 27 | #if HAVE_ERRNO_H |
| 28 | #include <errno.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 |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 35 | #include "ext2fs/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 | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 39 | #ifdef ENABLE_NLS |
| 40 | #include <libintl.h> |
| 41 | #include <locale.h> |
| 42 | #define _(a) (gettext (a)) |
| 43 | #ifdef gettext_noop |
| 44 | #define N_(a) gettext_noop (a) |
| 45 | #else |
| 46 | #define N_(a) (a) |
| 47 | #endif |
Theodore Ts'o | a04eba3 | 2003-05-03 16:35:17 -0400 | [diff] [blame^] | 48 | #ifndef NLS_CAT_NAME |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 49 | #define NLS_CAT_NAME "e2fsprogs" |
Theodore Ts'o | a04eba3 | 2003-05-03 16:35:17 -0400 | [diff] [blame^] | 50 | #endif |
| 51 | #ifndef LOCALEDIR |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 52 | #define LOCALEDIR "/usr/share/locale" |
Theodore Ts'o | a04eba3 | 2003-05-03 16:35:17 -0400 | [diff] [blame^] | 53 | #endif |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 54 | #else |
| 55 | #define _(a) (a) |
| 56 | #define N_(a) a |
| 57 | #endif |
| 58 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 59 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 60 | /* |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 61 | * For the extent map |
| 62 | */ |
| 63 | typedef struct _ext2_extent *ext2_extent; |
| 64 | |
| 65 | /* |
| 66 | * For the simple progress meter |
| 67 | */ |
| 68 | typedef struct ext2_sim_progress *ext2_sim_progmeter; |
| 69 | |
| 70 | /* |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 71 | * Flags for the resizer; most are debugging flags only |
| 72 | */ |
| 73 | #define RESIZE_DEBUG_IO 0x0001 |
| 74 | #define RESIZE_DEBUG_BMOVE 0x0002 |
| 75 | #define RESIZE_DEBUG_INODEMAP 0x0004 |
| 76 | #define RESIZE_DEBUG_ITABLEMOVE 0x0008 |
| 77 | |
| 78 | #define RESIZE_PERCENT_COMPLETE 0x0100 |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 79 | #define RESIZE_VERBOSE 0x0200 |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 80 | |
| 81 | /* |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 82 | * The core state structure for the ext2 resizer |
| 83 | */ |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 84 | typedef struct ext2_resize_struct *ext2_resize_t; |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 85 | |
| 86 | struct ext2_resize_struct { |
| 87 | ext2_filsys old_fs; |
| 88 | ext2_filsys new_fs; |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 89 | ext2fs_block_bitmap reserve_blocks; |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 90 | ext2fs_block_bitmap move_blocks; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 91 | ext2_extent bmap; |
| 92 | ext2_extent imap; |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 93 | int needed_blocks; |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 94 | int flags; |
| 95 | char *itable_buf; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | * For the block allocator |
| 99 | */ |
| 100 | blk_t new_blk; |
| 101 | int alloc_state; |
| 102 | |
| 103 | /* |
| 104 | * For the progress meter |
| 105 | */ |
Theodore Ts'o | 3b627e8 | 1998-02-24 20:24:49 +0000 | [diff] [blame] | 106 | errcode_t (*progress)(ext2_resize_t rfs, int pass, |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 107 | unsigned long cur, |
| 108 | unsigned long max); |
| 109 | void *prog_data; |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 112 | /* |
| 113 | * Progress pass numbers... |
| 114 | */ |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 115 | #define E2_RSZ_EXTEND_ITABLE_PASS 1 |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 116 | #define E2_RSZ_BLOCK_RELOC_PASS 2 |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 117 | #define E2_RSZ_INODE_SCAN_PASS 3 |
| 118 | #define E2_RSZ_INODE_REF_UPD_PASS 4 |
| 119 | #define E2_RSZ_MOVE_ITABLE_PASS 5 |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 120 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 121 | |
| 122 | /* prototypes */ |
Theodore Ts'o | 116db1b | 2002-04-01 01:28:30 -0500 | [diff] [blame] | 123 | 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] | 124 | errcode_t (*progress)(ext2_resize_t rfs, |
| 125 | int pass, unsigned long cur, |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 126 | unsigned long max)); |
| 127 | |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 128 | /* extent.c */ |
| 129 | extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, |
| 130 | int size); |
| 131 | extern void ext2fs_free_extent_table(ext2_extent extent); |
| 132 | extern errcode_t ext2fs_add_extent_entry(ext2_extent extent, |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 133 | __u32 old_loc, __u32 new_loc); |
| 134 | extern __u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 135 | extern void ext2fs_extent_dump(ext2_extent extent, FILE *out); |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 136 | extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc, |
| 137 | __u32 *new_loc, int *size); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 138 | |
| 139 | /* sim_progress.c */ |
| 140 | extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog, |
| 141 | const char *label, |
| 142 | int labelwidth, int barwidth, |
| 143 | __u32 maxdone, int flags); |
| 144 | extern void ext2fs_progress_update(ext2_sim_progmeter prog, |
| 145 | __u32 current); |
| 146 | extern void ext2fs_progress_close(ext2_sim_progmeter prog); |
| 147 | |
| 148 | |