Whamcloud - gitweb
Remove the a.out DLL support, since it's been obsolete and unmaintained
[tools/e2fsprogs.git] / lib / evms / fsimext2.h
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2000
4  *
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.
9  * 
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.
14  *
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
18  *
19  *   Module: fsimext2.h
20  *
21  */
22
23 /* If EVMS_ABI_CODE is not defined, default to EVMS ABI 1.2 */
24 #ifndef EVMS_ABI_CODE
25 #define EVMS_ABI_CODE 120
26 #endif
27
28 /*
29  * EVMS 1.0 backwards compatibility functions
30  */
31 #if (EVMS_ABI_CODE == 100)
32 #define EVMS_IS_MOUNTED(vol)    ((vol)->mount_point != 0)
33 #define EVMS_GET_DEVNAME(vol)   ((vol)->name)
34 #else
35 #define EVMS_IS_MOUNTED(vol)    (EngFncs->is_mounted((vol)->dev_node, NULL))
36 #define EVMS_GET_DEVNAME(vol)   ((vol)->dev_node)
37 #endif
38                    
39 /********************
40  ********************
41  **                **
42  **  EVMS defines  **
43  **                **
44  ********************
45  ********************/
46  
47 extern plugin_record_t ext2_plugrec;
48 engine_functions_t *EngFncs;
49                  
50 /*  file system type ... used by the SetPluginID macro */
51 #define FS_TYPE_EXT2     7
52                  
53 /*  logging macros  */
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)
66
67 /*  useful macro for option code */
68 #define SET_STRING_FIELD(a,b)\
69 a = EngFncs->engine_alloc( strlen(b)+1 );\
70 if (a ) {\
71     strcpy(a, b);\
72 }\
73 else {\
74     return -ENOMEM;\
75 }
76
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)
80
81
82 /**********************************
83  **********************************
84  **                              **
85  **  fsck.jfs, mkfs.jfs defines  **
86  **                              **
87  **********************************
88  **********************************/
89
90 /* fsck.jfs, mkfs.jfs option counts */
91
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
99
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
106
107 /* fsck exit codes */
108 #define FSCK_OK                    0
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
114
115
116 /*
117  * EXT2/3 defines and structs
118  */
119
120 /* generic defines */
121 #define FSIM_SUCCESS            0
122 #define FSIM_ERROR             -1
123 #define GET                     0
124 #define PUT                     1
125
126 #define EXT2_SUPER_LOC          1024
127
128 #define EXT2_SUPER_MAGIC        0xEF53
129
130 #define EXT3_FEATURE_INCOMPAT_RECOVER           0x0004 /* Needs recovery */
131
132 #define EXT2_VALID_FS                   0x0001  /* Unmounted cleanly */
133 #define EXT2_ERROR_FS                   0x0002  /* Errors detected */
134
135 /*
136  * Structure of the ext2 super block
137  */
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 */
164         /*
165          * These fields are for EXT2_DYNAMIC_REV superblocks only.
166          *
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.
171          * 
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...
176          */
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 */
187         /*
188          * Performance hints.  Directory preallocation should only
189          * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
190          */
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;
194         /* 
195          * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
196          */
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 */
201         
202         u_int32_t       s_reserved[197];        /* Padding to the end of the block */
203 };
204
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 */
209
210 /*
211  *      buffer cache configuration
212  */
213 /* page size */
214 #ifdef PSIZE
215 #undef PSIZE
216 #endif
217 #define PSIZE           4096    /* page size (in byte) */
218
219 #define PBSIZE          512     /* physical block size (in byte) */
220
221 /*
222  * Minimum number of bytes supported for an ext2 partition
223  * (64k, quite small!)
224  */
225 #define MINEXT2         (64*1024)
226
227 /*
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.
231  */
232 #define SIZE_OF_SUPER   sizeof(struct ext2_super_block)
233
234 /*
235  * SIZE_OF_MAP_PAGE defines the amount of disk space reserved for each page of
236  * the inode allocation map (to hold iag)
237  */
238 #define SIZE_OF_MAP_PAGE        PSIZE
239
240 /*
241  *      directory configuration
242  */
243 #define JFS_NAME_MAX    255
244 #define JFS_PATH_MAX    BPSIZE      
245
246 /*
247  *      file system state (superblock state)
248  */
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 
252                                          * when mounted or 
253                                          * commit failure occurred while being mounted:
254                                              * fsck() must be run to repair 
255                                              */
256 #define FM_LOGREDO 0x00000004   /* log based recovery (logredo()) failed:
257                                                  * fsck() must be run to repair 
258                                                  */
259 #define FM_EXTENDFS 0x00000008  /* file system extendfs() in progress */
260
261
262 /*******************
263  *******************
264  **               **
265  **  Common code  **
266  **               **
267  *******************
268  *******************/
269
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 );