aboutsummaryrefslogtreecommitdiffstats
path: root/resize/resize2fs.h
blob: d425491dcea5aa6345758bccfb2dc5339ad36df9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * resize2fs.h --- ext2 resizer header file
 *
 * Copyright (C) 1997, 1998 by Theodore Ts'o and
 * 	PowerQuest, Inc.
 *
 * Copyright (C) 1999, 2000 by Theosore Ts'o
 *
 * %Begin-Header%
 * This file may be redistributed under the terms of the GNU Public
 * License.
 * %End-Header%
 */

#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <stdlib.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif

#if EXT2_FLAT_INCLUDES
#include "ext2_fs.h"
#include "ext2fs.h"
#include "e2p.h"
#else
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
#include "e2p/e2p.h"
#endif

#ifdef ENABLE_NLS
#include <libintl.h>
#include <locale.h>
#define _(a) (gettext (a))
#ifdef gettext_noop
#define N_(a) gettext_noop (a)
#else
#define N_(a) (a)
#endif
#ifndef NLS_CAT_NAME
#define NLS_CAT_NAME "e2fsprogs"
#endif
#ifndef LOCALEDIR
#define LOCALEDIR "/usr/share/locale"
#endif
#else
#define _(a) (a)
#define N_(a) a
#endif


/*
 * For the extent map
 */
typedef struct _ext2_extent *ext2_extent;

/*
 * For the simple progress meter
 */
typedef struct ext2_sim_progress *ext2_sim_progmeter;

/*
 * Flags for the resizer; most are debugging flags only
 */
#define RESIZE_DEBUG_IO			0x0001
#define RESIZE_DEBUG_BMOVE		0x0002
#define RESIZE_DEBUG_INODEMAP		0x0004
#define RESIZE_DEBUG_ITABLEMOVE		0x0008
#define RESIZE_DEBUG_RTRACK		0x0010

#define RESIZE_PERCENT_COMPLETE		0x0100
#define RESIZE_VERBOSE			0x0200

/*
 * This structure is used for keeping track of how much resources have
 * been used for a particular resize2fs pass.
 */
struct resource_track {
	const char *desc;
	struct timeval time_start;
	struct timeval user_start;
	struct timeval system_start;
	void	*brk_start;
	unsigned long long bytes_read;
	unsigned long long bytes_written;
};

/*
 * The core state structure for the ext2 resizer
 */
typedef struct ext2_resize_struct *ext2_resize_t;

struct ext2_resize_struct {
	ext2_filsys	old_fs;
	ext2_filsys	new_fs;
	ext2fs_block_bitmap reserve_blocks;
	ext2fs_block_bitmap move_blocks;
	ext2_extent	bmap;
	ext2_extent	imap;
	blk64_t		needed_blocks;
	int		flags;
	char		*itable_buf;

	/*
	 * For the block allocator
	 */
	blk64_t		new_blk;
	int		alloc_state;

	/*
	 * For the progress meter
	 */
	errcode_t	(*progress)(ext2_resize_t rfs, int pass,
				    unsigned long cur,
				    unsigned long max);
	void		*prog_data;
};

/*
 * Progress pass numbers...
 */
#define E2_RSZ_EXTEND_ITABLE_PASS	1
#define E2_RSZ_BLOCK_RELOC_PASS		2
#define E2_RSZ_INODE_SCAN_PASS		3
#define E2_RSZ_INODE_REF_UPD_PASS	4
#define E2_RSZ_MOVE_ITABLE_PASS		5


/* prototypes */
extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,
			   errcode_t	(*progress)(ext2_resize_t rfs,
					    int pass, unsigned long cur,
					    unsigned long max));

extern errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
				ext2fs_block_bitmap reserve_blocks,
				blk64_t new_size);
extern blk64_t calculate_minimum_resize_size(ext2_filsys fs);


/* extent.c */
extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent,
					    __u64 size);
extern void ext2fs_free_extent_table(ext2_extent extent);
extern errcode_t ext2fs_add_extent_entry(ext2_extent extent,
					 __u64 old_loc, __u64 new_loc);
extern __u64 ext2fs_extent_translate(ext2_extent extent, __u64 old_loc);
extern void ext2fs_extent_dump(ext2_extent extent, FILE *out);
extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u64 *old_loc,
				       __u64 *new_loc, __u64 *size);

/* online.c */
extern errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
				  blk64_t *new_size, int flags);

/* resource_track.c */
extern void init_resource_track(struct resource_track *track, const char *desc,
				io_channel channel);
extern void print_resource_track(ext2_resize_t rfs,
				 struct resource_track *track,
				 io_channel channel);

/* sim_progress.c */
extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog,
				      const char *label,
				      int labelwidth, int barwidth,
				      __u32 maxdone, int flags);
extern void ext2fs_progress_update(ext2_sim_progmeter prog,
					__u32 current);
extern void ext2fs_progress_close(ext2_sim_progmeter prog);