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 | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 8 | * |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 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" |
Andreas Dilger | de8f3a7 | 2007-05-25 11:18:11 -0400 | [diff] [blame] | 34 | #include "e2p.h" |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 35 | #else |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 36 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 37 | #include "ext2fs/ext2fs.h" |
Andreas Dilger | de8f3a7 | 2007-05-25 11:18:11 -0400 | [diff] [blame] | 38 | #include "e2p/e2p.h" |
Theodore Ts'o | ca8abba | 1998-01-19 14:55:24 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 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 |
Theodore Ts'o | a04eba3 | 2003-05-03 16:35:17 -0400 | [diff] [blame] | 50 | #ifndef NLS_CAT_NAME |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 51 | #define NLS_CAT_NAME "e2fsprogs" |
Theodore Ts'o | a04eba3 | 2003-05-03 16:35:17 -0400 | [diff] [blame] | 52 | #endif |
| 53 | #ifndef LOCALEDIR |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 54 | #define LOCALEDIR "/usr/share/locale" |
Theodore Ts'o | a04eba3 | 2003-05-03 16:35:17 -0400 | [diff] [blame] | 55 | #endif |
Theodore Ts'o | a13575f | 2000-06-12 22:06:16 +0000 | [diff] [blame] | 56 | #else |
| 57 | #define _(a) (a) |
| 58 | #define N_(a) a |
| 59 | #endif |
| 60 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 61 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 62 | /* |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 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 | |
| 72 | /* |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 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 |
| 79 | |
| 80 | #define RESIZE_PERCENT_COMPLETE 0x0100 |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 81 | #define RESIZE_VERBOSE 0x0200 |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 82 | |
| 83 | /* |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 84 | * The core state structure for the ext2 resizer |
| 85 | */ |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 86 | typedef struct ext2_resize_struct *ext2_resize_t; |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 87 | |
| 88 | struct ext2_resize_struct { |
| 89 | ext2_filsys old_fs; |
| 90 | ext2_filsys new_fs; |
Theodore Ts'o | 1e1da29 | 1997-06-09 14:51:29 +0000 | [diff] [blame] | 91 | ext2fs_block_bitmap reserve_blocks; |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 92 | ext2fs_block_bitmap move_blocks; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 93 | ext2_extent bmap; |
| 94 | ext2_extent imap; |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 95 | blk64_t needed_blocks; |
Theodore Ts'o | 05e112a | 1997-06-14 07:28:44 +0000 | [diff] [blame] | 96 | int flags; |
| 97 | char *itable_buf; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * For the block allocator |
| 101 | */ |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 102 | blk64_t new_blk; |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 103 | int alloc_state; |
| 104 | |
| 105 | /* |
| 106 | * For the progress meter |
| 107 | */ |
Theodore Ts'o | 3b627e8 | 1998-02-24 20:24:49 +0000 | [diff] [blame] | 108 | errcode_t (*progress)(ext2_resize_t rfs, int pass, |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 109 | unsigned long cur, |
| 110 | unsigned long max); |
| 111 | void *prog_data; |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Progress pass numbers... |
| 116 | */ |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 117 | #define E2_RSZ_EXTEND_ITABLE_PASS 1 |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 118 | #define E2_RSZ_BLOCK_RELOC_PASS 2 |
Theodore Ts'o | a8519a2 | 1998-02-16 22:16:20 +0000 | [diff] [blame] | 119 | #define E2_RSZ_INODE_SCAN_PASS 3 |
| 120 | #define E2_RSZ_INODE_REF_UPD_PASS 4 |
| 121 | #define E2_RSZ_MOVE_ITABLE_PASS 5 |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 122 | |
Theodore Ts'o | 24b2c7a | 1997-06-07 20:42:58 +0000 | [diff] [blame] | 123 | |
| 124 | /* prototypes */ |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 125 | extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, |
Theodore Ts'o | 3b627e8 | 1998-02-24 20:24:49 +0000 | [diff] [blame] | 126 | errcode_t (*progress)(ext2_resize_t rfs, |
| 127 | int pass, unsigned long cur, |
Theodore Ts'o | 63b44fb | 1998-02-13 22:58:18 +0000 | [diff] [blame] | 128 | unsigned long max)); |
| 129 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 130 | extern errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, |
Theodore Ts'o | c09043f | 2009-04-18 22:32:03 -0400 | [diff] [blame] | 131 | ext2fs_block_bitmap reserve_blocks, |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 132 | blk64_t new_size); |
| 133 | extern blk64_t calculate_minimum_resize_size(ext2_filsys fs); |
Theodore Ts'o | bf69235 | 2006-03-17 19:45:45 -0500 | [diff] [blame] | 134 | |
| 135 | |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 136 | /* extent.c */ |
| 137 | extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 138 | __u64 size); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 139 | extern void ext2fs_free_extent_table(ext2_extent extent); |
| 140 | extern errcode_t ext2fs_add_extent_entry(ext2_extent extent, |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 141 | __u64 old_loc, __u64 new_loc); |
| 142 | extern __u64 ext2fs_extent_translate(ext2_extent extent, __u64 old_loc); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 143 | extern void ext2fs_extent_dump(ext2_extent extent, FILE *out); |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 144 | extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u64 *old_loc, |
| 145 | __u64 *new_loc, __u64 *size); |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 146 | |
Theodore Ts'o | bf69235 | 2006-03-17 19:45:45 -0500 | [diff] [blame] | 147 | /* online.c */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 148 | extern errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, |
Valerie Aurora Henson | 8728d50 | 2010-06-13 18:00:00 -0400 | [diff] [blame] | 149 | blk64_t *new_size, int flags); |
Theodore Ts'o | bf69235 | 2006-03-17 19:45:45 -0500 | [diff] [blame] | 150 | |
Theodore Ts'o | c762c8e | 1997-06-17 03:52:12 +0000 | [diff] [blame] | 151 | /* sim_progress.c */ |
| 152 | extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog, |
| 153 | const char *label, |
| 154 | int labelwidth, int barwidth, |
| 155 | __u32 maxdone, int flags); |
| 156 | extern void ext2fs_progress_update(ext2_sim_progmeter prog, |
| 157 | __u32 current); |
| 158 | extern void ext2fs_progress_close(ext2_sim_progmeter prog); |
| 159 | |
| 160 | |