blob: cc89f4f642bbe480db79a91c64591615a4d3a538 [file] [log] [blame]
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +00001/*
2 * resize2fs.h --- ext2 resizer header file
3 *
4 * Copyright (C) 1997 Theodore Ts'o
5 *
6 * %Begin-Header%
7 * All rights reserved.
8 * %End-Header%
9 */
10
11#include <stdio.h>
12#include <string.h>
13#include <unistd.h>
14#include <stdlib.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000015#ifdef HAVE_SYS_TYPES_H
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000016#include <sys/types.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000017#endif
18#ifdef HAVE_SYS_TIME_H
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000019#include <sys/time.h>
Theodore Ts'od40259f1997-10-20 00:44:26 +000020#endif
Theodore Ts'obc75f2a1997-09-04 00:43:10 +000021#if HAVE_ERRNO_H
22#include <errno.h>
23#endif
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000024
25#ifdef HAVE_LINUX_FS_H
26#include <linux/fs.h>
27#endif
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000028
Theodore Ts'oca8abba1998-01-19 14:55:24 +000029#if EXT2_FLAT_INCLUDES
30#include "ext2_fs.h"
31#include "ext2fs.h"
32#else
33#include <linux/ext2_fs.h>
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000034#include "ext2fs/ext2fs.h"
Theodore Ts'oca8abba1998-01-19 14:55:24 +000035#endif
36
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000037
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000038/*
Theodore Ts'oc762c8e1997-06-17 03:52:12 +000039 * For the extent map
40 */
41typedef struct _ext2_extent *ext2_extent;
42
43/*
44 * For the simple progress meter
45 */
46typedef struct ext2_sim_progress *ext2_sim_progmeter;
47
48/*
Theodore Ts'o05e112a1997-06-14 07:28:44 +000049 * Flags for the resizer; most are debugging flags only
50 */
51#define RESIZE_DEBUG_IO 0x0001
52#define RESIZE_DEBUG_BMOVE 0x0002
53#define RESIZE_DEBUG_INODEMAP 0x0004
54#define RESIZE_DEBUG_ITABLEMOVE 0x0008
55
56#define RESIZE_PERCENT_COMPLETE 0x0100
Theodore Ts'oc762c8e1997-06-17 03:52:12 +000057#define RESIZE_VERBOSE 0x0200
Theodore Ts'o05e112a1997-06-14 07:28:44 +000058
59/*
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000060 * The core state structure for the ext2 resizer
61 */
Theodore Ts'o63b44fb1998-02-13 22:58:18 +000062typedef struct ext2_resize_struct *ext2_resize_t;
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000063
64struct ext2_resize_struct {
65 ext2_filsys old_fs;
66 ext2_filsys new_fs;
Theodore Ts'o1e1da291997-06-09 14:51:29 +000067 ext2fs_block_bitmap reserve_blocks;
Theodore Ts'oc762c8e1997-06-17 03:52:12 +000068 ext2fs_block_bitmap move_blocks;
Theodore Ts'oa8519a21998-02-16 22:16:20 +000069 ext2_extent bmap;
70 ext2_extent imap;
Theodore Ts'o1e1da291997-06-09 14:51:29 +000071 int needed_blocks;
Theodore Ts'o05e112a1997-06-14 07:28:44 +000072 int flags;
73 char *itable_buf;
Theodore Ts'oa8519a21998-02-16 22:16:20 +000074
75 /*
76 * For the block allocator
77 */
78 blk_t new_blk;
79 int alloc_state;
80
81 /*
82 * For the progress meter
83 */
Theodore Ts'o3b627e81998-02-24 20:24:49 +000084 errcode_t (*progress)(ext2_resize_t rfs, int pass,
Theodore Ts'o63b44fb1998-02-13 22:58:18 +000085 unsigned long cur,
86 unsigned long max);
87 void *prog_data;
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000088};
89
Theodore Ts'o63b44fb1998-02-13 22:58:18 +000090/*
91 * Progress pass numbers...
92 */
Theodore Ts'oa8519a21998-02-16 22:16:20 +000093#define E2_RSZ_EXTEND_ITABLE_PASS 1
Theodore Ts'o63b44fb1998-02-13 22:58:18 +000094#define E2_RSZ_BLOCK_RELOC_PASS 2
Theodore Ts'oa8519a21998-02-16 22:16:20 +000095#define E2_RSZ_INODE_SCAN_PASS 3
96#define E2_RSZ_INODE_REF_UPD_PASS 4
97#define E2_RSZ_MOVE_ITABLE_PASS 5
Theodore Ts'o63b44fb1998-02-13 22:58:18 +000098
Theodore Ts'o24b2c7a1997-06-07 20:42:58 +000099
100/* prototypes */
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000101extern errcode_t resize_fs(ext2_filsys fs, blk_t new_size, int flags,
Theodore Ts'o3b627e81998-02-24 20:24:49 +0000102 errcode_t (*progress)(ext2_resize_t rfs,
103 int pass, unsigned long cur,
Theodore Ts'o63b44fb1998-02-13 22:58:18 +0000104 unsigned long max));
105
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000106/* extent.c */
107extern errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent,
108 int size);
109extern void ext2fs_free_extent_table(ext2_extent extent);
110extern errcode_t ext2fs_add_extent_entry(ext2_extent extent,
Theodore Ts'oca8abba1998-01-19 14:55:24 +0000111 __u32 old_loc, __u32 new_loc);
112extern __u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc);
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000113extern void ext2fs_extent_dump(ext2_extent extent, FILE *out);
Theodore Ts'oca8abba1998-01-19 14:55:24 +0000114extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc,
115 __u32 *new_loc, int *size);
Theodore Ts'oc762c8e1997-06-17 03:52:12 +0000116
117/* sim_progress.c */
118extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog,
119 const char *label,
120 int labelwidth, int barwidth,
121 __u32 maxdone, int flags);
122extern void ext2fs_progress_update(ext2_sim_progmeter prog,
123 __u32 current);
124extern void ext2fs_progress_close(ext2_sim_progmeter prog);
125
126