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