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 
     80 #define RESIZE_PERCENT_COMPLETE		0x0100
     81 #define RESIZE_VERBOSE			0x0200
     82 
     83 /*
     84  * The core state structure for the ext2 resizer
     85  */
     86 typedef struct ext2_resize_struct *ext2_resize_t;
     87 
     88 struct ext2_resize_struct {
     89 	ext2_filsys	old_fs;
     90 	ext2_filsys	new_fs;
     91 	ext2fs_block_bitmap reserve_blocks;
     92 	ext2fs_block_bitmap move_blocks;
     93 	ext2_extent	bmap;
     94 	ext2_extent	imap;
     95 	int		needed_blocks;
     96 	int		flags;
     97 	char		*itable_buf;
     98 
     99 	/*
    100 	 * For the block allocator
    101 	 */
    102 	blk_t		new_blk;
    103 	int		alloc_state;
    104 
    105 	/*
    106 	 * For the progress meter
    107 	 */
    108 	errcode_t	(*progress)(ext2_resize_t rfs, int pass,
    109 				    unsigned long cur,
    110 				    unsigned long max);
    111 	void		*prog_data;
    112 };
    113 
    114 /*
    115  * Progress pass numbers...
    116  */
    117 #define E2_RSZ_EXTEND_ITABLE_PASS	1
    118 #define E2_RSZ_BLOCK_RELOC_PASS		2
    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
    122 
    123 
    124 /* prototypes */
    125 extern errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
    126 			   errcode_t	(*progress)(ext2_resize_t rfs,
    127 					    int pass, unsigned long cur,
    128 					    unsigned long max));
    129 
    130 extern errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
    131 				ext2fs_block_bitmap reserve_blocks,
    132 				blk_t new_size);
    133 extern blk_t calculate_minimum_resize_size(ext2_filsys fs);
    134 
    135 
    136 /* extent.c */
    137 extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent,
    138 					    int size);
    139 extern void ext2fs_free_extent_table(ext2_extent extent);
    140 extern errcode_t ext2fs_add_extent_entry(ext2_extent extent,
    141 					 __u32 old_loc, __u32 new_loc);
    142 extern __u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc);
    143 extern void ext2fs_extent_dump(ext2_extent extent, FILE *out);
    144 extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc,
    145 				       __u32 *new_loc, int *size);
    146 
    147 /* online.c */
    148 extern errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
    149 				  blk_t *new_size, int flags);
    150 
    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 
    161