3 * Copyright (c) International Business Machines Corp., 2000
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* If EVMS_ABI_CODE is not defined, default to EVMS ABI 1.2 */
25 #define EVMS_ABI_CODE 120
29 * EVMS 1.0 backwards compatibility functions
31 #if (EVMS_ABI_CODE == 100)
32 #define EVMS_IS_MOUNTED(vol) ((vol)->mount_point != 0)
33 #define EVMS_GET_DEVNAME(vol) ((vol)->name)
35 #define EVMS_IS_MOUNTED(vol) (EngFncs->is_mounted((vol)->dev_node, NULL))
36 #define EVMS_GET_DEVNAME(vol) ((vol)->dev_node)
47 extern plugin_record_t ext2_plugrec;
48 engine_functions_t *EngFncs;
50 /* file system type ... used by the SetPluginID macro */
51 #define FS_TYPE_EXT2 7
54 #define MESSAGE(msg, args...) EngFncs->user_message(pMyPluginRecord, NULL, NULL, msg, ##args)
55 #define LOGENTRY() EngFncs->write_log_entry(ENTRY_EXIT, pMyPluginRecord, "%s: Enter.\n", __FUNCTION__ )
56 #define LOGEXIT() EngFncs->write_log_entry(ENTRY_EXIT, pMyPluginRecord, "%s: Exit.\n", __FUNCTION__ )
57 #define LOGEXITRC() EngFncs->write_log_entry(ENTRY_EXIT, pMyPluginRecord, "%s: Exit. rc = %d.\n", __FUNCTION__ , rc)
58 #define LOG_CRITICAL(msg, args...) EngFncs->write_log_entry(CRITICAL, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
59 #define LOG_SERIOUS(msg, args...) EngFncs->write_log_entry(SERIOUS, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
60 #define LOG_ERROR(msg, args...) EngFncs->write_log_entry(ERROR, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
61 #define LOG_WARNING(msg, args...) EngFncs->write_log_entry(WARNING, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
62 #define LOG(msg, args...) EngFncs->write_log_entry(DEFAULT, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
63 #define LOG_DETAILS(msg, args...) EngFncs->write_log_entry(DETAILS, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
64 #define LOG_DEBUG(msg, args...) EngFncs->write_log_entry(DEBUG, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
65 #define LOG_EXTRA(msg, args...) EngFncs->write_log_entry(EXTRA, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
67 /* useful macro for option code */
68 #define SET_STRING_FIELD(a,b)\
69 a = EngFncs->engine_alloc( strlen(b)+1 );\
77 #define SET_STRING(a,b) a = EngFncs->engine_alloc( strlen(b)+1 );if (a ) { strcpy(a, b); } else { rc = ENOMEM; LOG_EXIT(rc);}
78 #define LOG_EXIT(x) LOG_PROC("Exiting: rc = %d\n", x)
79 #define LOG_PROC(msg, args...) EngFncs->write_log_entry(ENTRY_EXIT, pMyPluginRecord, "%s: " msg, __FUNCTION__ , ## args)
82 /**********************************
83 **********************************
85 ** fsck.jfs, mkfs.jfs defines **
87 **********************************
88 **********************************/
90 /* fsck.jfs, mkfs.jfs option counts */
92 /* fsck.jfs option array indices */
93 #define FSCK_FORCE_INDEX 0
94 #define FSCK_READONLY_INDEX 1
95 #define FSCK_CHECKBB_INDEX 2
96 #define FSCK_CHECKRW_INDEX 3
97 #define FSCK_TIMING_INDEX 4
98 #define FSCK_EXT2_OPTIONS_COUNT 5
100 /* mkfs.jfs option array indices */
101 #define MKFS_CHECKBB_INDEX 0
102 #define MKFS_CHECKRW_INDEX 1
103 #define MKFS_SETVOL_INDEX 2
104 #define MKFS_JOURNAL_INDEX 3
105 #define MKFS_EXT2_OPTIONS_COUNT 4
107 /* fsck exit codes */
109 #define FSCK_CORRECTED 1
110 #define FSCK_REBOOT 2
111 #define FSCK_ERRORS_UNCORRECTED 4
112 #define FSCK_OP_ERROR 8
113 #define FSCK_USAGE_ERROR 16
117 * EXT2/3 defines and structs
120 /* generic defines */
121 #define FSIM_SUCCESS 0
122 #define FSIM_ERROR -1
126 #define EXT2_SUPER_LOC 1024
128 #define EXT2_SUPER_MAGIC 0xEF53
130 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
132 #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
133 #define EXT2_ERROR_FS 0x0002 /* Errors detected */
136 * Structure of the ext2 super block
138 struct ext2_super_block {
139 u_int32_t s_inodes_count; /* Inodes count */
140 u_int32_t s_blocks_count; /* Blocks count */
141 u_int32_t s_r_blocks_count; /* Reserved blocks count */
142 u_int32_t s_free_blocks_count; /* Free blocks count */
143 u_int32_t s_free_inodes_count; /* Free inodes count */
144 u_int32_t s_first_data_block; /* First Data Block */
145 u_int32_t s_log_block_size; /* Block size */
146 int32_t s_log_frag_size; /* Fragment size */
147 u_int32_t s_blocks_per_group; /* # Blocks per group */
148 u_int32_t s_frags_per_group; /* # Fragments per group */
149 u_int32_t s_inodes_per_group; /* # Inodes per group */
150 u_int32_t s_mtime; /* Mount time */
151 u_int32_t s_wtime; /* Write time */
152 u_int16_t s_mnt_count; /* Mount count */
153 int16_t s_max_mnt_count; /* Maximal mount count */
154 u_int16_t s_magic; /* Magic signature */
155 u_int16_t s_state; /* File system state */
156 u_int16_t s_errors; /* Behaviour when detecting errors */
157 u_int16_t s_minor_rev_level; /* minor revision level */
158 u_int32_t s_lastcheck; /* time of last check */
159 u_int32_t s_checkinterval; /* max. time between checks */
160 u_int32_t s_creator_os; /* OS */
161 u_int32_t s_rev_level; /* Revision level */
162 u_int16_t s_def_resuid; /* Default uid for reserved blocks */
163 u_int16_t s_def_resgid; /* Default gid for reserved blocks */
165 * These fields are for EXT2_DYNAMIC_REV superblocks only.
167 * Note: the difference between the compatible feature set and
168 * the incompatible feature set is that if there is a bit set
169 * in the incompatible feature set that the kernel doesn't
170 * know about, it should refuse to mount the filesystem.
172 * e2fsck's requirements are more strict; if it doesn't know
173 * about a feature in either the compatible or incompatible
174 * feature set, it must abort and not try to meddle with
175 * things it doesn't understand...
177 u_int32_t s_first_ino; /* First non-reserved inode */
178 u_int16_t s_inode_size; /* size of inode structure */
179 u_int16_t s_block_group_nr; /* block group # of this superblock */
180 u_int32_t s_feature_compat; /* compatible feature set */
181 u_int32_t s_feature_incompat; /* incompatible feature set */
182 u_int32_t s_feature_ro_compat; /* readonly-compatible feature set */
183 u_int8_t s_uuid[16]; /* 128-bit uuid for volume */
184 int8_t s_volume_name[16]; /* volume name */
185 int8_t s_last_mounted[64]; /* directory where last mounted */
186 u_int32_t s_algorithm_usage_bitmap; /* For compression */
188 * Performance hints. Directory preallocation should only
189 * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
191 u_int8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
192 u_int8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
193 u_int16_t s_padding1;
195 * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
197 u_int8_t s_journal_uuid[16]; /* uuid of journal superblock */
198 u_int32_t s_journal_inum; /* inode number of journal file */
199 u_int32_t s_journal_dev; /* device number of journal file */
200 u_int32_t s_last_orphan; /* start of list of inodes to delete */
202 u_int32_t s_reserved[197]; /* Padding to the end of the block */
205 #define L2MEGABYTE 20
206 #define MEGABYTE (1 << L2MEGABYTE)
207 #define MEGABYTE32 (MEGABYTE << 5)
208 #define MAX_LOG_PERCENTAGE 10 /* Log can be at most 10% of disk */
211 * buffer cache configuration
217 #define PSIZE 4096 /* page size (in byte) */
219 #define PBSIZE 512 /* physical block size (in byte) */
222 * Minimum number of bytes supported for an ext2 partition
223 * (64k, quite small!)
225 #define MINEXT2 (64*1024)
228 * SIZE_OF_SUPER defines the total amount of space reserved on disk for the
229 * superblock. This is not the same as the superblock structure, since all of
230 * this space is not currently being used.
232 #define SIZE_OF_SUPER sizeof(struct ext2_super_block)
235 * SIZE_OF_MAP_PAGE defines the amount of disk space reserved for each page of
236 * the inode allocation map (to hold iag)
238 #define SIZE_OF_MAP_PAGE PSIZE
241 * directory configuration
243 #define JFS_NAME_MAX 255
244 #define JFS_PATH_MAX BPSIZE
247 * file system state (superblock state)
249 #define FM_CLEAN 0x00000000 /* file system is unmounted and clean */
250 #define FM_MOUNT 0x00000001 /* file system is mounted cleanly */
251 #define FM_DIRTY 0x00000002 /* file system was not unmounted and clean
253 * commit failure occurred while being mounted:
254 * fsck() must be run to repair
256 #define FM_LOGREDO 0x00000004 /* log based recovery (logredo()) failed:
257 * fsck() must be run to repair
259 #define FM_EXTENDFS 0x00000008 /* file system extendfs() in progress */
270 int fsim_get_ext2_superblock( logical_volume_t *, struct ext2_super_block * );
271 int fsim_unmkfs( logical_volume_t * );
272 int fsim_mkfs( logical_volume_t *, option_array_t * );
273 int fsim_fsck( logical_volume_t *, option_array_t *, int * );
274 int fsim_get_volume_limits( struct ext2_super_block *, sector_count_t *,
275 sector_count_t *, sector_count_t * );
276 int fsim_test_version( void );