• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Theodore 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 #define RESIZE_ENABLE_64BIT		0x0400
86 #define RESIZE_DISABLE_64BIT		0x0800
87 
88 /*
89  * This structure is used for keeping track of how much resources have
90  * been used for a particular resize2fs pass.
91  */
92 struct resource_track {
93 	const char *desc;
94 	struct timeval time_start;
95 	struct timeval user_start;
96 	struct timeval system_start;
97 	void	*brk_start;
98 	unsigned long long bytes_read;
99 	unsigned long long bytes_written;
100 };
101 
102 /*
103  * The core state structure for the ext2 resizer
104  */
105 typedef struct ext2_resize_struct *ext2_resize_t;
106 
107 struct ext2_resize_struct {
108 	ext2_filsys	old_fs;
109 	ext2_filsys	new_fs;
110 	ext2fs_block_bitmap reserve_blocks;
111 	ext2fs_block_bitmap move_blocks;
112 	ext2_extent	bmap;
113 	ext2_extent	imap;
114 	blk64_t		needed_blocks;
115 	int		flags;
116 	char		*itable_buf;
117 
118 	/*
119 	 * For the block allocator
120 	 */
121 	blk64_t		new_blk;
122 	int		alloc_state;
123 
124 	/*
125 	 * For the progress meter
126 	 */
127 	errcode_t	(*progress)(ext2_resize_t rfs, int pass,
128 				    unsigned long cur,
129 				    unsigned long max);
130 	void		*prog_data;
131 };
132 
133 /*
134  * Progress pass numbers...
135  */
136 #define E2_RSZ_EXTEND_ITABLE_PASS	1
137 #define E2_RSZ_BLOCK_RELOC_PASS		2
138 #define E2_RSZ_INODE_SCAN_PASS		3
139 #define E2_RSZ_INODE_REF_UPD_PASS	4
140 #define E2_RSZ_MOVE_ITABLE_PASS		5
141 
142 
143 /* prototypes */
144 extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,
145 			   errcode_t	(*progress)(ext2_resize_t rfs,
146 					    int pass, unsigned long cur,
147 					    unsigned long max));
148 
149 extern errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
150 				ext2fs_block_bitmap reserve_blocks,
151 				blk64_t new_size);
152 extern blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags);
153 
154 
155 /* extent.c */
156 extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent,
157 					    __u64 size);
158 extern void ext2fs_free_extent_table(ext2_extent extent);
159 extern errcode_t ext2fs_add_extent_entry(ext2_extent extent,
160 					 __u64 old_loc, __u64 new_loc);
161 extern __u64 ext2fs_extent_translate(ext2_extent extent, __u64 old_loc);
162 extern void ext2fs_extent_dump(ext2_extent extent, FILE *out);
163 extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u64 *old_loc,
164 				       __u64 *new_loc, __u64 *size);
165 
166 /* main.c */
167 extern char *program_name;
168 
169 /* online.c */
170 extern errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
171 				  blk64_t *new_size, int flags);
172 
173 /* resource_track.c */
174 extern void init_resource_track(struct resource_track *track, const char *desc,
175 				io_channel channel);
176 extern void print_resource_track(ext2_resize_t rfs,
177 				 struct resource_track *track,
178 				 io_channel channel);
179 
180 /* sim_progress.c */
181 extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog,
182 				      const char *label,
183 				      int labelwidth, int barwidth,
184 				      __u32 maxdone, int flags);
185 extern void ext2fs_progress_update(ext2_sim_progmeter prog,
186 					__u32 current);
187 extern void ext2fs_progress_close(ext2_sim_progmeter prog);
188 
189 
190