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