blob: 21847593673170f6a1cfe813435d9920559e8bbf [file] [log] [blame]
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +00001/*
2 * resize2fs.h --- ext2 resizer header file
3 *
Theodore Ts'o0cee8a52000-04-06 21:38:34 +00004 * Copyright (C) 1997, 1998 by Theodore Ts'o and
5 * PowerQuest, Inc.
6 *
7 * Copyright (C) 1999, 2000 by Theosore Ts'o
Theodore Ts'oefc6f622008-08-27 23:07:54 -04008 *
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +00009 * %Begin-Header%
Theodore Ts'o0cee8a52000-04-06 21:38:34 +000010 * This file may be redistributed under the terms of the GNU Public
11 * License.
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000012 * %End-Header%
13 */
14
15#include <stdio.h>
16#include <string.h>
Theodore Ts'o169cb541998-08-01 04:33:31 +000017#ifdef HAVE_UNISTD_H
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000018#include <unistd.h>
Theodore Ts'o169cb541998-08-01 04:33:31 +000019#endif
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000020#include <stdlib.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000021#ifdef HAVE_SYS_TYPES_H
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000022#include <sys/types.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000023#endif
24#ifdef HAVE_SYS_TIME_H
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000025#include <sys/time.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000026#endif
Theodore Ts'obc75f2a1997-09-04 00:43:10 +000027#if HAVE_ERRNO_H
28#include <errno.h>
29#endif
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000030
Theodore Ts'oca8abba1998-01-19 14:55:24 +000031#if EXT2_FLAT_INCLUDES
32#include "ext2_fs.h"
33#include "ext2fs.h"
Andreas Dilgerde8f3a72007-05-25 11:18:11 -040034#include "e2p.h"
Theodore Ts'oca8abba1998-01-19 14:55:24 +000035#else
Theodore Ts'o54c637d2001-05-14 11:45:38 +000036#include "ext2fs/ext2_fs.h"
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000037#include "ext2fs/ext2fs.h"
Andreas Dilgerde8f3a72007-05-25 11:18:11 -040038#include "e2p/e2p.h"
Theodore Ts'oca8abba1998-01-19 14:55:24 +000039#endif
40
Theodore Ts'oa13575f2000-06-12 22:06:16 +000041#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
Theodore Ts'oa04eba32003-05-03 16:35:17 -040050#ifndef NLS_CAT_NAME
Theodore Ts'oa13575f2000-06-12 22:06:16 +000051#define NLS_CAT_NAME "e2fsprogs"
Theodore Ts'oa04eba32003-05-03 16:35:17 -040052#endif
53#ifndef LOCALEDIR
Theodore Ts'oa13575f2000-06-12 22:06:16 +000054#define LOCALEDIR "/usr/share/locale"
Theodore Ts'oa04eba32003-05-03 16:35:17 -040055#endif
Theodore Ts'oa13575f2000-06-12 22:06:16 +000056#else
57#define _(a) (a)
58#define N_(a) a
59#endif
60
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000061
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000062/*
Theodore Ts'oc762c8e1997-06-17 03:52:12 +000063 * For the extent map
64 */
65typedef struct _ext2_extent *ext2_extent;
66
67/*
68 * For the simple progress meter
69 */
70typedef struct ext2_sim_progress *ext2_sim_progmeter;
71
72/*
Theodore Ts'o05e112a1997-06-14 07:28:44 +000073 * 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
Theodore Ts'oc762c8e1997-06-17 03:52:12 +000081#define RESIZE_VERBOSE 0x0200
Theodore Ts'o05e112a1997-06-14 07:28:44 +000082
83/*
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000084 * The core state structure for the ext2 resizer
85 */
Theodore Ts'o63b44fb1998-02-13 22:58:18 +000086typedef struct ext2_resize_struct *ext2_resize_t;
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000087
88struct ext2_resize_struct {
89 ext2_filsys old_fs;
90 ext2_filsys new_fs;
Theodore Ts'o1e1da291997-06-09 14:51:29 +000091 ext2fs_block_bitmap reserve_blocks;
Theodore Ts'oc762c8e1997-06-17 03:52:12 +000092 ext2fs_block_bitmap move_blocks;
Theodore Ts'oa8519a21998-02-16 22:16:20 +000093 ext2_extent bmap;
94 ext2_extent imap;
Valerie Aurora Henson8728d502010-06-13 18:00:00 -040095 blk64_t needed_blocks;
Theodore Ts'o05e112a1997-06-14 07:28:44 +000096 int flags;
97 char *itable_buf;
Theodore Ts'oa8519a21998-02-16 22:16:20 +000098
99 /*
100 * For the block allocator
101 */
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400102 blk64_t new_blk;
Theodore Ts'oa8519a21998-02-16 22:16:20 +0000103 int alloc_state;
104
105 /*
106 * For the progress meter
107 */
Theodore Ts'o3b627e81998-02-24 20:24:49 +0000108 errcode_t (*progress)(ext2_resize_t rfs, int pass,
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000109 unsigned long cur,
110 unsigned long max);
111 void *prog_data;
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +0000112};
113
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000114/*
115 * Progress pass numbers...
116 */
Theodore Ts'oa8519a21998-02-16 22:16:20 +0000117#define E2_RSZ_EXTEND_ITABLE_PASS 1
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000118#define E2_RSZ_BLOCK_RELOC_PASS 2
Theodore Ts'oa8519a21998-02-16 22:16:20 +0000119#define E2_RSZ_INODE_SCAN_PASS 3
120#define E2_RSZ_INODE_REF_UPD_PASS 4
121#define E2_RSZ_MOVE_ITABLE_PASS 5
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000122
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +0000123
124/* prototypes */
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400125extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,
Theodore Ts'o3b627e81998-02-24 20:24:49 +0000126 errcode_t (*progress)(ext2_resize_t rfs,
127 int pass, unsigned long cur,
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000128 unsigned long max));
129
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400130extern errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
Theodore Ts'oc09043f2009-04-18 22:32:03 -0400131 ext2fs_block_bitmap reserve_blocks,
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400132 blk64_t new_size);
133extern blk64_t calculate_minimum_resize_size(ext2_filsys fs);
Theodore Ts'obf692352006-03-17 19:45:45 -0500134
135
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000136/* extent.c */
137extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent,
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400138 __u64 size);
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000139extern void ext2fs_free_extent_table(ext2_extent extent);
140extern errcode_t ext2fs_add_extent_entry(ext2_extent extent,
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400141 __u64 old_loc, __u64 new_loc);
142extern __u64 ext2fs_extent_translate(ext2_extent extent, __u64 old_loc);
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000143extern void ext2fs_extent_dump(ext2_extent extent, FILE *out);
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400144extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u64 *old_loc,
145 __u64 *new_loc, __u64 *size);
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000146
Theodore Ts'obf692352006-03-17 19:45:45 -0500147/* online.c */
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400148extern errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
Valerie Aurora Henson8728d502010-06-13 18:00:00 -0400149 blk64_t *new_size, int flags);
Theodore Ts'obf692352006-03-17 19:45:45 -0500150
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000151/* sim_progress.c */
152extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog,
153 const char *label,
154 int labelwidth, int barwidth,
155 __u32 maxdone, int flags);
156extern void ext2fs_progress_update(ext2_sim_progmeter prog,
157 __u32 current);
158extern void ext2fs_progress_close(ext2_sim_progmeter prog);
159
160