1 /*
2 * ext2fs.h --- ext2fs
3 *
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
5 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
9 * %End-Header%
10 */
11
12 #ifndef _EXT2FS_EXT2FS_H
13 #define _EXT2FS_EXT2FS_H
14
15 #ifdef __GNUC__
16 #define EXT2FS_ATTR(x) __attribute__(x)
17 #else
18 #define EXT2FS_ATTR(x)
19 #endif
20
21 #ifdef CONFIG_TDB
22 #define EXT2FS_NO_TDB_UNUSED
23 #else
24 #define EXT2FS_NO_TDB_UNUSED EXT2FS_ATTR((unused))
25 #endif
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /*
32 * Non-GNU C compilers won't necessarily understand inline
33 */
34 #if (!defined(__GNUC__) && !defined(__WATCOMC__))
35 #define NO_INLINE_FUNCS
36 #endif
37
38 /*
39 * Where the master copy of the superblock is located, and how big
40 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
41 * the size of the superblock structure is not necessarily trustworthy
42 * (some versions have the padding set up so that the superblock is
43 * 1032 bytes long).
44 */
45 #define SUPERBLOCK_OFFSET 1024
46 #define SUPERBLOCK_SIZE 1024
47
48 #define UUID_STR_SIZE 37
49
50 /*
51 * The last ext2fs revision level that this version of the library is
52 * able to support.
53 */
54 #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
55
56 #ifdef HAVE_SYS_TYPES_H
57 #include <sys/types.h>
58 #endif
59
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <time.h>
64 #include <errno.h>
65
66 #if EXT2_FLAT_INCLUDES
67 #include "e2_types.h"
68 #include "ext2_fs.h"
69 #include "ext3_extents.h"
70 #else
71 #include <ext2fs/ext2_types.h>
72 #include <ext2fs/ext2_fs.h>
73 #include <ext2fs/ext3_extents.h>
74 #endif /* EXT2_FLAT_INCLUDES */
75
76 typedef __u32 __bitwise ext2_ino_t;
77 typedef __u32 __bitwise blk_t;
78 typedef __u64 __bitwise blk64_t;
79 typedef __u32 __bitwise dgrp_t;
80 typedef __u32 __bitwise ext2_off_t;
81 typedef __u64 __bitwise ext2_off64_t;
82 typedef __s64 __bitwise e2_blkcnt_t;
83 typedef __u32 __bitwise ext2_dirhash_t;
84
85 #if EXT2_FLAT_INCLUDES
86 #include "com_err.h"
87 #include "ext2_io.h"
88 #include "ext2_err.h"
89 #include "ext2_ext_attr.h"
90 #else
91 #include <et/com_err.h>
92 #include <ext2fs/ext2_io.h>
93 #include <ext2fs/ext2_err.h>
94 #include <ext2fs/ext2_ext_attr.h>
95 #endif
96
97 #include "hashmap.h"
98
99 /*
100 * Portability help for Microsoft Visual C++
101 */
102 #ifdef _MSC_VER
103 #define EXT2_QSORT_TYPE int __cdecl
104 #else
105 #define EXT2_QSORT_TYPE int
106 #endif
107
108 typedef struct struct_ext2_filsys *ext2_filsys;
109
110 #define EXT2FS_MARK_ERROR 0
111 #define EXT2FS_UNMARK_ERROR 1
112 #define EXT2FS_TEST_ERROR 2
113
114 typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
115 typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
116 typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
117
118 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
119
120
121 /*
122 * Badblocks list definitions
123 */
124
125 typedef struct ext2_struct_u32_list *ext2_badblocks_list;
126 typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
127
128 typedef struct ext2_struct_u32_list *ext2_u32_list;
129 typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
130
131 /* old */
132 typedef struct ext2_struct_u32_list *badblocks_list;
133 typedef struct ext2_struct_u32_iterate *badblocks_iterate;
134
135 #define BADBLOCKS_FLAG_DIRTY 1
136
137 /*
138 * ext2_dblist structure and abstractions (see dblist.c)
139 */
140 struct ext2_db_entry2 {
141 ext2_ino_t ino;
142 blk64_t blk;
143 e2_blkcnt_t blockcnt;
144 };
145
146 /* Ye Olde 32-bit version */
147 struct ext2_db_entry {
148 ext2_ino_t ino;
149 blk_t blk;
150 int blockcnt;
151 };
152
153 typedef struct ext2_struct_dblist *ext2_dblist;
154
155 #define DBLIST_ABORT 1
156
157 /*
158 * ext2_fileio definitions
159 */
160
161 #define EXT2_FILE_WRITE 0x0001
162 #define EXT2_FILE_CREATE 0x0002
163
164 #define EXT2_FILE_MASK 0x00FF
165
166 #define EXT2_FILE_BUF_DIRTY 0x4000
167 #define EXT2_FILE_BUF_VALID 0x2000
168
169 typedef struct ext2_file *ext2_file_t;
170
171 #define EXT2_SEEK_SET 0
172 #define EXT2_SEEK_CUR 1
173 #define EXT2_SEEK_END 2
174
175 /*
176 * Flags for the ext2_filsys structure and for ext2fs_open()
177 */
178 #define EXT2_FLAG_RW 0x01
179 #define EXT2_FLAG_CHANGED 0x02
180 #define EXT2_FLAG_DIRTY 0x04
181 #define EXT2_FLAG_VALID 0x08
182 #define EXT2_FLAG_IB_DIRTY 0x10
183 #define EXT2_FLAG_BB_DIRTY 0x20
184 #define EXT2_FLAG_SWAP_BYTES 0x40
185 #define EXT2_FLAG_SWAP_BYTES_READ 0x80
186 #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
187 #define EXT2_FLAG_MASTER_SB_ONLY 0x200
188 #define EXT2_FLAG_FORCE 0x400
189 #define EXT2_FLAG_SUPER_ONLY 0x800
190 #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
191 #define EXT2_FLAG_IMAGE_FILE 0x2000
192 #define EXT2_FLAG_EXCLUSIVE 0x4000
193 #define EXT2_FLAG_SOFTSUPP_FEATURES 0x8000
194 #define EXT2_FLAG_NOFREE_ON_ERROR 0x10000
195 #define EXT2_FLAG_64BITS 0x20000
196 #define EXT2_FLAG_PRINT_PROGRESS 0x40000
197 #define EXT2_FLAG_DIRECT_IO 0x80000
198 #define EXT2_FLAG_SKIP_MMP 0x100000
199 #define EXT2_FLAG_IGNORE_CSUM_ERRORS 0x200000
200 #define EXT2_FLAG_SHARE_DUP 0x400000
201
202 /*
203 * Special flag in the ext2 inode i_flag field that means that this is
204 * a new inode. (So that ext2_write_inode() can clear extra fields.)
205 */
206 #define EXT2_NEW_INODE_FL 0x80000000
207
208 /*
209 * Flags for mkjournal
210 */
211 #define EXT2_MKJOURNAL_V1_SUPER 0x0000001 /* create V1 superblock (deprecated) */
212 #define EXT2_MKJOURNAL_LAZYINIT 0x0000002 /* don't zero journal inode before use*/
213 #define EXT2_MKJOURNAL_NO_MNT_CHECK 0x0000004 /* don't check mount status */
214
215 struct blk_alloc_ctx;
216 struct opaque_ext2_group_desc;
217
218 struct struct_ext2_filsys {
219 errcode_t magic;
220 io_channel io;
221 int flags;
222 char * device_name;
223 struct ext2_super_block * super;
224 unsigned int blocksize;
225 int fragsize;
226 dgrp_t group_desc_count;
227 unsigned long desc_blocks;
228 struct opaque_ext2_group_desc * group_desc;
229 unsigned int inode_blocks_per_group;
230 ext2fs_inode_bitmap inode_map;
231 ext2fs_block_bitmap block_map;
232 /* XXX FIXME-64: not 64-bit safe, but not used? */
233 errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
234 errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
235 errcode_t (*write_bitmaps)(ext2_filsys fs);
236 errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
237 struct ext2_inode *inode);
238 errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
239 struct ext2_inode *inode);
240 ext2_badblocks_list badblocks;
241 ext2_dblist dblist;
242 __u32 stride; /* for mke2fs */
243 struct ext2_super_block * orig_super;
244 struct ext2_image_hdr * image_header;
245 __u32 umask;
246 time_t now;
247 int cluster_ratio_bits;
248 __u16 default_bitmap_type;
249 __u16 pad;
250 /*
251 * Reserved for future expansion
252 */
253 __u32 reserved[5];
254
255 /*
256 * Reserved for the use of the calling application.
257 */
258 void * priv_data;
259
260 /*
261 * Inode cache
262 */
263 struct ext2_inode_cache *icache;
264 io_channel image_io;
265
266 /*
267 * More callback functions
268 */
269 errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
270 blk64_t *ret);
271 errcode_t (*get_alloc_block2)(ext2_filsys fs, blk64_t goal,
272 blk64_t *ret, struct blk_alloc_ctx *ctx);
273 void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse);
274
275 /*
276 * Buffers for Multiple mount protection(MMP) block.
277 */
278 void *mmp_buf;
279 void *mmp_cmp;
280 int mmp_fd;
281
282 /*
283 * Time at which e2fsck last updated the MMP block.
284 */
285 long mmp_last_written;
286
287 /* progress operation functions */
288 struct ext2fs_progress_ops *progress_ops;
289
290 /* Precomputed FS UUID checksum for seeding other checksums */
291 __u32 csum_seed;
292
293 io_channel journal_io;
294 char *journal_name;
295
296 /* New block range allocation hooks */
297 errcode_t (*new_range)(ext2_filsys fs, int flags, blk64_t goal,
298 blk64_t len, blk64_t *pblk, blk64_t *plen);
299 void (*block_alloc_stats_range)(ext2_filsys fs, blk64_t blk, blk_t num,
300 int inuse);
301
302 /* hashmap for SHA of data blocks */
303 struct ext2fs_hashmap* block_sha_map;
304 };
305
306 #if EXT2_FLAT_INCLUDES
307 #include "e2_bitops.h"
308 #else
309 #include <ext2fs/bitops.h>
310 #endif
311
312 /*
313 * 64-bit bitmap backend types
314 */
315 #define EXT2FS_BMAP64_BITARRAY 1
316 #define EXT2FS_BMAP64_RBTREE 2
317 #define EXT2FS_BMAP64_AUTODIR 3
318
319 /*
320 * Return flags for the block iterator functions
321 */
322 #define BLOCK_CHANGED 1
323 #define BLOCK_ABORT 2
324 #define BLOCK_ERROR 4
325 #define BLOCK_INLINE_DATA_CHANGED 8
326
327 /*
328 * Block interate flags
329 *
330 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
331 * function should be called on blocks where the block number is zero.
332 * This is used by ext2fs_expand_dir() to be able to add a new block
333 * to an inode. It can also be used for programs that want to be able
334 * to deal with files that contain "holes".
335 *
336 * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
337 * the indirect, doubly indirect, etc. blocks should be called after
338 * all of the blocks containined in the indirect blocks are processed.
339 * This is useful if you are going to be deallocating blocks from an
340 * inode.
341 *
342 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
343 * called for data blocks only.
344 *
345 * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not
346 * modify returned block number.
347 *
348 * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
349 * ext2fs_block_iterate2 that large files won't be accepted.
350 */
351 #define BLOCK_FLAG_APPEND 1
352 #define BLOCK_FLAG_HOLE 1
353 #define BLOCK_FLAG_DEPTH_TRAVERSE 2
354 #define BLOCK_FLAG_DATA_ONLY 4
355 #define BLOCK_FLAG_READ_ONLY 8
356
357 #define BLOCK_FLAG_NO_LARGE 0x1000
358
359 /*
360 * Magic "block count" return values for the block iterator function.
361 */
362 #define BLOCK_COUNT_IND (-1)
363 #define BLOCK_COUNT_DIND (-2)
364 #define BLOCK_COUNT_TIND (-3)
365 #define BLOCK_COUNT_TRANSLATOR (-4)
366
367 #define BLOCK_ALLOC_UNKNOWN 0
368 #define BLOCK_ALLOC_DATA 1
369 #define BLOCK_ALLOC_METADATA 2
370
371 struct blk_alloc_ctx {
372 ext2_ino_t ino;
373 struct ext2_inode *inode;
374 blk64_t lblk;
375 int flags;
376 };
377
378 #if 0
379 /*
380 * Flags for ext2fs_move_blocks
381 */
382 #define EXT2_BMOVE_GET_DBLIST 0x0001
383 #define EXT2_BMOVE_DEBUG 0x0002
384 #endif
385
386 /*
387 * Generic (non-filesystem layout specific) extents structure
388 */
389
390 #define EXT2_EXTENT_FLAGS_LEAF 0x0001
391 #define EXT2_EXTENT_FLAGS_UNINIT 0x0002
392 #define EXT2_EXTENT_FLAGS_SECOND_VISIT 0x0004
393
394 struct ext2fs_extent {
395 blk64_t e_pblk; /* first physical block */
396 blk64_t e_lblk; /* first logical block extent covers */
397 __u32 e_len; /* number of blocks covered by extent */
398 __u32 e_flags; /* extent flags */
399 };
400
401 typedef struct ext2_extent_handle *ext2_extent_handle_t;
402 typedef struct ext2_extent_path *ext2_extent_path_t;
403
404 /*
405 * Flags used by ext2fs_extent_get()
406 */
407 #define EXT2_EXTENT_CURRENT 0x0000
408 #define EXT2_EXTENT_MOVE_MASK 0x000F
409 #define EXT2_EXTENT_ROOT 0x0001
410 #define EXT2_EXTENT_LAST_LEAF 0x0002
411 #define EXT2_EXTENT_FIRST_SIB 0x0003
412 #define EXT2_EXTENT_LAST_SIB 0x0004
413 #define EXT2_EXTENT_NEXT_SIB 0x0005
414 #define EXT2_EXTENT_PREV_SIB 0x0006
415 #define EXT2_EXTENT_NEXT_LEAF 0x0007
416 #define EXT2_EXTENT_PREV_LEAF 0x0008
417 #define EXT2_EXTENT_NEXT 0x0009
418 #define EXT2_EXTENT_PREV 0x000A
419 #define EXT2_EXTENT_UP 0x000B
420 #define EXT2_EXTENT_DOWN 0x000C
421 #define EXT2_EXTENT_DOWN_AND_LAST 0x000D
422
423 /*
424 * Flags used by ext2fs_extent_insert()
425 */
426 #define EXT2_EXTENT_INSERT_AFTER 0x0001 /* insert after handle loc'n */
427 #define EXT2_EXTENT_INSERT_NOSPLIT 0x0002 /* insert may not cause split */
428
429 /*
430 * Flags used by ext2fs_extent_delete()
431 */
432 #define EXT2_EXTENT_DELETE_KEEP_EMPTY 0x001 /* keep node if last extnt gone */
433
434 /*
435 * Flags used by ext2fs_extent_set_bmap()
436 */
437 #define EXT2_EXTENT_SET_BMAP_UNINIT 0x0001
438
439 /*
440 * Data structure returned by ext2fs_extent_get_info()
441 */
442 struct ext2_extent_info {
443 int curr_entry;
444 int curr_level;
445 int num_entries;
446 int max_entries;
447 int max_depth;
448 int bytes_avail;
449 blk64_t max_lblk;
450 blk64_t max_pblk;
451 __u32 max_len;
452 __u32 max_uninit_len;
453 };
454
455 /*
456 * Flags for directory block reading and writing functions
457 */
458 #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
459
460 /*
461 * Return flags for the directory iterator functions
462 */
463 #define DIRENT_CHANGED 1
464 #define DIRENT_ABORT 2
465 #define DIRENT_ERROR 3
466
467 /*
468 * Directory iterator flags
469 */
470
471 #define DIRENT_FLAG_INCLUDE_EMPTY 1
472 #define DIRENT_FLAG_INCLUDE_REMOVED 2
473 #define DIRENT_FLAG_INCLUDE_CSUM 4
474 #define DIRENT_FLAG_INCLUDE_INLINE_DATA 8
475
476 #define DIRENT_DOT_FILE 1
477 #define DIRENT_DOT_DOT_FILE 2
478 #define DIRENT_OTHER_FILE 3
479 #define DIRENT_DELETED_FILE 4
480 #define DIRENT_CHECKSUM 5
481
482 /*
483 * Inode scan definitions
484 */
485 typedef struct ext2_struct_inode_scan *ext2_inode_scan;
486
487 /*
488 * ext2fs_scan flags
489 */
490 #define EXT2_SF_CHK_BADBLOCKS 0x0001
491 #define EXT2_SF_BAD_INODE_BLK 0x0002
492 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
493 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
494 #define EXT2_SF_DO_LAZY 0x0010
495 #define EXT2_SF_WARN_GARBAGE_INODES 0x0020
496
497 /*
498 * ext2fs_check_if_mounted flags
499 */
500 #define EXT2_MF_MOUNTED 1
501 #define EXT2_MF_ISROOT 2
502 #define EXT2_MF_READONLY 4
503 #define EXT2_MF_SWAP 8
504 #define EXT2_MF_BUSY 16
505
506 /*
507 * Ext2/linux mode flags. We define them here so that we don't need
508 * to depend on the OS's sys/stat.h, since we may be compiling on a
509 * non-Linux system.
510 */
511 #define LINUX_S_IFMT 00170000
512 #define LINUX_S_IFSOCK 0140000
513 #define LINUX_S_IFLNK 0120000
514 #define LINUX_S_IFREG 0100000
515 #define LINUX_S_IFBLK 0060000
516 #define LINUX_S_IFDIR 0040000
517 #define LINUX_S_IFCHR 0020000
518 #define LINUX_S_IFIFO 0010000
519 #define LINUX_S_ISUID 0004000
520 #define LINUX_S_ISGID 0002000
521 #define LINUX_S_ISVTX 0001000
522
523 #define LINUX_S_IRWXU 00700
524 #define LINUX_S_IRUSR 00400
525 #define LINUX_S_IWUSR 00200
526 #define LINUX_S_IXUSR 00100
527
528 #define LINUX_S_IRWXG 00070
529 #define LINUX_S_IRGRP 00040
530 #define LINUX_S_IWGRP 00020
531 #define LINUX_S_IXGRP 00010
532
533 #define LINUX_S_IRWXO 00007
534 #define LINUX_S_IROTH 00004
535 #define LINUX_S_IWOTH 00002
536 #define LINUX_S_IXOTH 00001
537
538 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
539 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
540 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
541 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
542 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
543 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
544 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
545
546 /*
547 * ext2 size of an inode
548 */
549 #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
550
551 /*
552 * ext2_icount_t abstraction
553 */
554 #define EXT2_ICOUNT_OPT_INCREMENT 0x01
555
556 typedef struct ext2_icount *ext2_icount_t;
557
558 /*
559 * Flags for ext2fs_bmap
560 */
561 #define BMAP_ALLOC 0x0001
562 #define BMAP_SET 0x0002
563 #define BMAP_UNINIT 0x0004
564 #define BMAP_ZERO 0x0008
565
566 /*
567 * Returned flags from ext2fs_bmap
568 */
569 #define BMAP_RET_UNINIT 0x0001
570
571 /*
572 * Flags for imager.c functions
573 */
574 #define IMAGER_FLAG_INODEMAP 1
575 #define IMAGER_FLAG_SPARSEWRITE 2
576
577 /*
578 * For checking structure magic numbers...
579 */
580
581 #define EXT2_CHECK_MAGIC(struct, code) \
582 if ((struct)->magic != (code)) return (code)
583
584 /*
585 * Features supported by this version of the library
586 */
587 #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
588 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
589 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
590 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
591 EXT2_FEATURE_COMPAT_DIR_INDEX|\
592 EXT2_FEATURE_COMPAT_EXT_ATTR|\
593 EXT4_FEATURE_COMPAT_SPARSE_SUPER2)
594
595 #ifdef CONFIG_MMP
596 #define EXT4_LIB_INCOMPAT_MMP EXT4_FEATURE_INCOMPAT_MMP
597 #else
598 #define EXT4_LIB_INCOMPAT_MMP (0)
599 #endif
600
601 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
602 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
603 EXT2_FEATURE_INCOMPAT_META_BG|\
604 EXT3_FEATURE_INCOMPAT_RECOVER|\
605 EXT3_FEATURE_INCOMPAT_EXTENTS|\
606 EXT4_FEATURE_INCOMPAT_FLEX_BG|\
607 EXT4_LIB_INCOMPAT_MMP|\
608 EXT4_FEATURE_INCOMPAT_64BIT|\
609 EXT4_FEATURE_INCOMPAT_INLINE_DATA|\
610 EXT4_FEATURE_INCOMPAT_ENCRYPT|\
611 EXT4_FEATURE_INCOMPAT_CSUM_SEED)
612
613 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
614 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
615 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
616 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
617 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\
618 EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\
619 EXT4_FEATURE_RO_COMPAT_BIGALLOC|\
620 EXT4_FEATURE_RO_COMPAT_QUOTA|\
621 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|\
622 EXT4_FEATURE_RO_COMPAT_READONLY |\
623 EXT4_FEATURE_RO_COMPAT_PROJECT |\
624 EXT4_FEATURE_RO_COMPAT_SHARED_BLOCKS)
625
626 /*
627 * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
628 * to ext2fs_openfs()
629 */
630 #define EXT2_LIB_SOFTSUPP_INCOMPAT (0)
631 #define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_REPLICA)
632
633
634 /* Translate a block number to a cluster number */
635 #define EXT2FS_CLUSTER_RATIO(fs) (1 << (fs)->cluster_ratio_bits)
636 #define EXT2FS_CLUSTER_MASK(fs) (EXT2FS_CLUSTER_RATIO(fs) - 1)
637 #define EXT2FS_B2C(fs, blk) ((blk) >> (fs)->cluster_ratio_bits)
638 /* Translate a cluster number to a block number */
639 #define EXT2FS_C2B(fs, cluster) ((cluster) << (fs)->cluster_ratio_bits)
640 /* Translate # of blks to # of clusters */
641 #define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
642 (fs)->cluster_ratio_bits)
643
644 #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
645 typedef struct stat64 ext2fs_struct_stat;
646 #else
647 typedef struct stat ext2fs_struct_stat;
648 #endif
649
650 /*
651 * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to
652 * avoid the fsync call.
653 */
654 #define EXT2_FLAG_FLUSH_NO_SYNC 1
655
656 /*
657 * Modify and iterate extended attributes
658 */
659 struct ext2_xattr_handle;
660 #define XATTR_ABORT 1
661 #define XATTR_CHANGED 2
662
663 /*
664 * function prototypes
665 */
ext2fs_has_group_desc_csum(ext2_filsys fs)666 static inline int ext2fs_has_group_desc_csum(ext2_filsys fs)
667 {
668 return ext2fs_has_feature_metadata_csum(fs->super) ||
669 ext2fs_has_feature_gdt_csum(fs->super);
670 }
671
672 /* The LARGE_FILE feature should be set if we have stored files 2GB+ in size */
ext2fs_needs_large_file_feature(unsigned long long file_size)673 static inline int ext2fs_needs_large_file_feature(unsigned long long file_size)
674 {
675 return file_size >= 0x80000000ULL;
676 }
677
678 /* alloc.c */
679 extern void ext2fs_clear_block_uninit(ext2_filsys fs, dgrp_t group);
680 extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
681 ext2fs_inode_bitmap map, ext2_ino_t *ret);
682 extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
683 ext2fs_block_bitmap map, blk_t *ret);
684 extern errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
685 ext2fs_block_bitmap map, blk64_t *ret);
686 extern errcode_t ext2fs_new_block3(ext2_filsys fs, blk64_t goal,
687 ext2fs_block_bitmap map, blk64_t *ret,
688 struct blk_alloc_ctx *ctx);
689 extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
690 blk_t finish, int num,
691 ext2fs_block_bitmap map,
692 blk_t *ret);
693 extern errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start,
694 blk64_t finish, int num,
695 ext2fs_block_bitmap map,
696 blk64_t *ret);
697 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
698 char *block_buf, blk_t *ret);
699 extern errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal,
700 char *block_buf, blk64_t *ret);
701 extern errcode_t ext2fs_alloc_block3(ext2_filsys fs, blk64_t goal,
702 char *block_buf, blk64_t *ret,
703 struct blk_alloc_ctx *ctx);
704
705 extern void ext2fs_set_alloc_block_callback(ext2_filsys fs,
706 errcode_t (*func)(ext2_filsys fs,
707 blk64_t goal,
708 blk64_t *ret),
709 errcode_t (**old)(ext2_filsys fs,
710 blk64_t goal,
711 blk64_t *ret));
712 blk64_t ext2fs_find_inode_goal(ext2_filsys fs, ext2_ino_t ino,
713 struct ext2_inode *inode, blk64_t lblk);
714 extern void ext2fs_set_new_range_callback(ext2_filsys fs,
715 errcode_t (*func)(ext2_filsys fs, int flags, blk64_t goal,
716 blk64_t len, blk64_t *pblk, blk64_t *plen),
717 errcode_t (**old)(ext2_filsys fs, int flags, blk64_t goal,
718 blk64_t len, blk64_t *pblk, blk64_t *plen));
719 extern void ext2fs_set_block_alloc_stats_range_callback(ext2_filsys fs,
720 void (*func)(ext2_filsys fs, blk64_t blk,
721 blk_t num, int inuse),
722 void (**old)(ext2_filsys fs, blk64_t blk,
723 blk_t num, int inuse));
724 #define EXT2_NEWRANGE_FIXED_GOAL (0x1)
725 #define EXT2_NEWRANGE_MIN_LENGTH (0x2)
726 #define EXT2_NEWRANGE_ALL_FLAGS (0x3)
727 errcode_t ext2fs_new_range(ext2_filsys fs, int flags, blk64_t goal,
728 blk64_t len, ext2fs_block_bitmap map, blk64_t *pblk,
729 blk64_t *plen);
730 #define EXT2_ALLOCRANGE_FIXED_GOAL (0x1)
731 #define EXT2_ALLOCRANGE_ZERO_BLOCKS (0x2)
732 #define EXT2_ALLOCRANGE_ALL_FLAGS (0x3)
733 errcode_t ext2fs_alloc_range(ext2_filsys fs, int flags, blk64_t goal,
734 blk_t len, blk64_t *ret);
735
736 /* alloc_sb.c */
737 extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
738 dgrp_t group,
739 ext2fs_block_bitmap bmap);
740 extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
741 void (*func)(ext2_filsys fs,
742 blk64_t blk,
743 int inuse),
744 void (**old)(ext2_filsys fs,
745 blk64_t blk,
746 int inuse));
747
748 /* alloc_stats.c */
749 void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
750 void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
751 int inuse, int isdir);
752 void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
753 void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse);
754 void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk,
755 blk_t num, int inuse);
756
757 /* alloc_tables.c */
758 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
759 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
760 ext2fs_block_bitmap bmap);
761
762 /* badblocks.c */
763 extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
764 extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
765 extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
766 extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
767 extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
768 ext2_u32_iterate *ret);
769 extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
770 extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
771 extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
772 extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
773
774 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
775 int size);
776 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
777 blk_t blk);
778 extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
779 blk_t blk);
780 extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
781 extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
782 extern errcode_t
783 ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
784 ext2_badblocks_iterate *ret);
785 extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
786 blk_t *blk);
787 extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
788 extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
789 ext2_badblocks_list *dest);
790 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
791 ext2_badblocks_list bb2);
792 extern int ext2fs_u32_list_count(ext2_u32_list bb);
793
794 /* bb_compat */
795 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
796 extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
797 extern int badblocks_list_test(badblocks_list bb, blk_t blk);
798 extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
799 badblocks_iterate *ret);
800 extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
801 extern void badblocks_list_iterate_end(badblocks_iterate iter);
802 extern void badblocks_list_free(badblocks_list bb);
803
804 /* bb_inode.c */
805 extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
806 ext2_badblocks_list bb_list);
807
808 /* bitmaps.c */
809 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
810 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
811 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
812 ext2fs_generic_bitmap *dest);
813 extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
814 extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
815 extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
816 extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
817 extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
818 const char *descr,
819 ext2fs_block_bitmap *ret);
820 extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
821 const char *descr,
822 ext2fs_block_bitmap *ret);
823 extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap);
824 extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
825 const char *descr,
826 ext2fs_inode_bitmap *ret);
827 extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
828 ext2_ino_t end, ext2_ino_t *oend);
829 extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
830 blk_t end, blk_t *oend);
831 extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
832 blk64_t end, blk64_t *oend);
833 extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
834 extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
835 extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
836 extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
837 extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
838 ext2fs_inode_bitmap bmap);
839 extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end,
840 __u64 new_real_end,
841 ext2fs_inode_bitmap bmap);
842 extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
843 ext2fs_block_bitmap bmap);
844 extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end,
845 __u64 new_real_end,
846 ext2fs_block_bitmap bmap);
847 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
848 ext2fs_block_bitmap bm2);
849 extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
850 ext2fs_inode_bitmap bm2);
851 extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
852 ext2_ino_t start, unsigned int num,
853 void *in);
854 extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
855 __u64 start, size_t num,
856 void *in);
857 extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
858 ext2_ino_t start, unsigned int num,
859 void *out);
860 extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
861 __u64 start, size_t num,
862 void *out);
863 extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
864 blk_t start, unsigned int num,
865 void *in);
866 extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
867 blk64_t start, size_t num,
868 void *in);
869 extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
870 blk_t start, unsigned int num,
871 void *out);
872 extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
873 blk64_t start, size_t num,
874 void *out);
875
876 /* blknum.c */
877 extern __u32 ext2fs_inode_bitmap_checksum(ext2_filsys fs, dgrp_t group);
878 extern __u32 ext2fs_block_bitmap_checksum(ext2_filsys fs, dgrp_t group);
879 extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t);
880 extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group);
881 extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group);
882 extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group);
883 extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs,
884 struct ext2_inode *inode);
885 extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs,
886 struct ext2_inode *inode);
887 extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super);
888 extern void ext2fs_blocks_count_set(struct ext2_super_block *super,
889 blk64_t blk);
890 extern void ext2fs_blocks_count_add(struct ext2_super_block *super,
891 blk64_t blk);
892 extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super);
893 extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super,
894 blk64_t blk);
895 extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super,
896 blk64_t blk);
897 extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super);
898 extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super,
899 blk64_t blk);
900 extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super,
901 blk64_t blk);
902 /* Block group descriptor accessor functions */
903 extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs,
904 struct opaque_ext2_group_desc *gdp,
905 dgrp_t group);
906 extern blk64_t ext2fs_block_bitmap_csum(ext2_filsys fs, dgrp_t group);
907 extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group);
908 extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
909 blk64_t blk);
910 extern __u32 ext2fs_inode_bitmap_csum(ext2_filsys fs, dgrp_t group);
911 extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group);
912 extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group,
913 blk64_t blk);
914 extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group);
915 extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group,
916 blk64_t blk);
917 extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group);
918 extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group,
919 __u32 n);
920 extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group);
921 extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group,
922 __u32 n);
923 extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group);
924 extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group,
925 __u32 n);
926 extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group);
927 extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group,
928 __u32 n);
929 extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group);
930 extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group);
931 extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag);
932 extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
933 extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags);
934 extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group);
935 extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum);
936 extern blk64_t ext2fs_file_acl_block(ext2_filsys fs,
937 const struct ext2_inode *inode);
938 extern void ext2fs_file_acl_block_set(ext2_filsys fs,
939 struct ext2_inode *inode, blk64_t blk);
940 extern errcode_t ext2fs_inode_size_set(ext2_filsys fs, struct ext2_inode *inode,
941 ext2_off64_t size);
942
943 /* block.c */
944 extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
945 ext2_ino_t ino,
946 int flags,
947 char *block_buf,
948 int (*func)(ext2_filsys fs,
949 blk_t *blocknr,
950 int blockcnt,
951 void *priv_data),
952 void *priv_data);
953 errcode_t ext2fs_block_iterate2(ext2_filsys fs,
954 ext2_ino_t ino,
955 int flags,
956 char *block_buf,
957 int (*func)(ext2_filsys fs,
958 blk_t *blocknr,
959 e2_blkcnt_t blockcnt,
960 blk_t ref_blk,
961 int ref_offset,
962 void *priv_data),
963 void *priv_data);
964 errcode_t ext2fs_block_iterate3(ext2_filsys fs,
965 ext2_ino_t ino,
966 int flags,
967 char *block_buf,
968 int (*func)(ext2_filsys fs,
969 blk64_t *blocknr,
970 e2_blkcnt_t blockcnt,
971 blk64_t ref_blk,
972 int ref_offset,
973 void *priv_data),
974 void *priv_data);
975
976 /* bmap.c */
977 extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
978 struct ext2_inode *inode,
979 char *block_buf, int bmap_flags,
980 blk_t block, blk_t *phys_blk);
981 extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino,
982 struct ext2_inode *inode,
983 char *block_buf, int bmap_flags, blk64_t block,
984 int *ret_flags, blk64_t *phys_blk);
985 errcode_t ext2fs_map_cluster_block(ext2_filsys fs, ext2_ino_t ino,
986 struct ext2_inode *inode, blk64_t lblk,
987 blk64_t *pblk);
988
989 #if 0
990 /* bmove.c */
991 extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
992 ext2fs_block_bitmap reserve,
993 ext2fs_block_bitmap alloc_map,
994 int flags);
995 #endif
996
997 /* check_desc.c */
998 extern errcode_t ext2fs_check_desc(ext2_filsys fs);
999
1000 /* closefs.c */
1001 extern errcode_t ext2fs_close(ext2_filsys fs);
1002 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
1003 extern errcode_t ext2fs_close_free(ext2_filsys *fs);
1004 extern errcode_t ext2fs_flush(ext2_filsys fs);
1005 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
1006 extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
1007 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
1008 dgrp_t group,
1009 blk64_t *ret_super_blk,
1010 blk64_t *ret_old_desc_blk,
1011 blk64_t *ret_new_desc_blk,
1012 blk_t *ret_used_blks);
1013 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
1014 dgrp_t group,
1015 blk_t *ret_super_blk,
1016 blk_t *ret_old_desc_blk,
1017 blk_t *ret_new_desc_blk,
1018 int *ret_meta_bg);
1019 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
1020
1021 /* crc32c.c */
1022 extern __u32 ext2fs_crc32_be(__u32 crc, unsigned char const *p, size_t len);
1023 extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len);
1024
1025 /* csum.c */
1026 extern void ext2fs_init_csum_seed(ext2_filsys fs);
1027 extern errcode_t ext2fs_mmp_csum_set(ext2_filsys fs, struct mmp_struct *mmp);
1028 extern int ext2fs_mmp_csum_verify(ext2_filsys, struct mmp_struct *mmp);
1029 extern int ext2fs_verify_csum_type(ext2_filsys fs, struct ext2_super_block *sb);
1030 extern errcode_t ext2fs_superblock_csum_set(ext2_filsys fs,
1031 struct ext2_super_block *sb);
1032 extern int ext2fs_superblock_csum_verify(ext2_filsys fs,
1033 struct ext2_super_block *sb);
1034 extern errcode_t ext2fs_ext_attr_block_csum_set(ext2_filsys fs,
1035 ext2_ino_t inum, blk64_t block,
1036 struct ext2_ext_attr_header *hdr);
1037 extern int ext2fs_ext_attr_block_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1038 blk64_t block,
1039 struct ext2_ext_attr_header *hdr);
1040 #define EXT2_DIRENT_TAIL(block, blocksize) \
1041 ((struct ext2_dir_entry_tail *)(((char *)(block)) + \
1042 (blocksize) - sizeof(struct ext2_dir_entry_tail)))
1043
1044 extern void ext2fs_initialize_dirent_tail(ext2_filsys fs,
1045 struct ext2_dir_entry_tail *t);
1046 extern int ext2fs_dirent_has_tail(ext2_filsys fs,
1047 struct ext2_dir_entry *dirent);
1048 extern int ext2fs_dirent_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1049 struct ext2_dir_entry *dirent);
1050 extern int ext2fs_dir_block_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1051 struct ext2_dir_entry *dirent);
1052 extern errcode_t ext2fs_dir_block_csum_set(ext2_filsys fs, ext2_ino_t inum,
1053 struct ext2_dir_entry *dirent);
1054 extern errcode_t ext2fs_get_dx_countlimit(ext2_filsys fs,
1055 struct ext2_dir_entry *dirent,
1056 struct ext2_dx_countlimit **cc,
1057 int *offset);
1058 extern errcode_t ext2fs_extent_block_csum_set(ext2_filsys fs,
1059 ext2_ino_t inum,
1060 struct ext3_extent_header *eh);
1061 extern int ext2fs_extent_block_csum_verify(ext2_filsys fs,
1062 ext2_ino_t inum,
1063 struct ext3_extent_header *eh);
1064 extern errcode_t ext2fs_block_bitmap_csum_set(ext2_filsys fs, dgrp_t group,
1065 char *bitmap, int size);
1066 extern int ext2fs_block_bitmap_csum_verify(ext2_filsys fs, dgrp_t group,
1067 char *bitmap, int size);
1068 extern errcode_t ext2fs_inode_bitmap_csum_set(ext2_filsys fs, dgrp_t group,
1069 char *bitmap, int size);
1070 extern int ext2fs_inode_bitmap_csum_verify(ext2_filsys fs, dgrp_t group,
1071 char *bitmap, int size);
1072 extern errcode_t ext2fs_inode_csum_set(ext2_filsys fs, ext2_ino_t inum,
1073 struct ext2_inode_large *inode);
1074 extern int ext2fs_inode_csum_verify(ext2_filsys fs, ext2_ino_t inum,
1075 struct ext2_inode_large *inode);
1076 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
1077 extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group);
1078 extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
1079 extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group);
1080
1081 /* dblist.c */
1082 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
1083 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
1084 blk_t blk, int blockcnt);
1085 extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
1086 blk64_t blk, e2_blkcnt_t blockcnt);
1087 extern void ext2fs_dblist_sort(ext2_dblist dblist,
1088 EXT2_QSORT_TYPE (*sortfunc)(const void *,
1089 const void *));
1090 extern void ext2fs_dblist_sort2(ext2_dblist dblist,
1091 EXT2_QSORT_TYPE (*sortfunc)(const void *,
1092 const void *));
1093 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
1094 int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
1095 void *priv_data),
1096 void *priv_data);
1097 extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist,
1098 int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
1099 void *priv_data),
1100 void *priv_data);
1101 extern errcode_t ext2fs_dblist_iterate3(ext2_dblist dblist,
1102 int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info,
1103 void *priv_data),
1104 unsigned long long start,
1105 unsigned long long count,
1106 void *priv_data);
1107 extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
1108 blk_t blk, int blockcnt);
1109 extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino,
1110 blk64_t blk, e2_blkcnt_t blockcnt);
1111 extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
1112 ext2_dblist *dest);
1113 extern int ext2fs_dblist_count(ext2_dblist dblist);
1114 extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist);
1115 extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist,
1116 struct ext2_db_entry **entry);
1117 extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist,
1118 struct ext2_db_entry2 **entry);
1119 extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist);
1120
1121 /* dblist_dir.c */
1122 extern errcode_t
1123 ext2fs_dblist_dir_iterate(ext2_dblist dblist,
1124 int flags,
1125 char *block_buf,
1126 int (*func)(ext2_ino_t dir,
1127 int entry,
1128 struct ext2_dir_entry *dirent,
1129 int offset,
1130 int blocksize,
1131 char *buf,
1132 void *priv_data),
1133 void *priv_data);
1134
1135 #if 0
1136 /* digest_encode.c */
1137 #define EXT2FS_DIGEST_SIZE EXT2FS_SHA256_LENGTH
1138 extern int ext2fs_digest_encode(const char *src, int len, char *dst);
1139 extern int ext2fs_digest_decode(const char *src, int len, char *dst);
1140 #endif
1141
1142 /* dirblock.c */
1143 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
1144 void *buf);
1145 extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
1146 void *buf, int flags);
1147 extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
1148 void *buf, int flags);
1149 extern errcode_t ext2fs_read_dir_block4(ext2_filsys fs, blk64_t block,
1150 void *buf, int flags, ext2_ino_t ino);
1151 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
1152 void *buf);
1153 extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
1154 void *buf, int flags);
1155 extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
1156 void *buf, int flags);
1157 extern errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block,
1158 void *buf, int flags, ext2_ino_t ino);
1159
1160 /* dirhash.c */
1161 extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
1162 const __u32 *seed,
1163 ext2_dirhash_t *ret_hash,
1164 ext2_dirhash_t *ret_minor_hash);
1165
1166
1167 /* dir_iterate.c */
1168 extern errcode_t ext2fs_get_rec_len(ext2_filsys fs,
1169 struct ext2_dir_entry *dirent,
1170 unsigned int *rec_len);
1171 extern errcode_t ext2fs_set_rec_len(ext2_filsys fs,
1172 unsigned int len,
1173 struct ext2_dir_entry *dirent);
1174 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
1175 ext2_ino_t dir,
1176 int flags,
1177 char *block_buf,
1178 int (*func)(struct ext2_dir_entry *dirent,
1179 int offset,
1180 int blocksize,
1181 char *buf,
1182 void *priv_data),
1183 void *priv_data);
1184 extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
1185 ext2_ino_t dir,
1186 int flags,
1187 char *block_buf,
1188 int (*func)(ext2_ino_t dir,
1189 int entry,
1190 struct ext2_dir_entry *dirent,
1191 int offset,
1192 int blocksize,
1193 char *buf,
1194 void *priv_data),
1195 void *priv_data);
1196
1197 /* dupfs.c */
1198 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
1199
1200 /* expanddir.c */
1201 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
1202
1203 /* ext_attr.c */
1204 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
1205 void *data);
1206 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
1207 extern errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block,
1208 void *buf);
1209 extern errcode_t ext2fs_read_ext_attr3(ext2_filsys fs, blk64_t block,
1210 void *buf, ext2_ino_t inum);
1211 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
1212 void *buf);
1213 extern errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block,
1214 void *buf);
1215 extern errcode_t ext2fs_write_ext_attr3(ext2_filsys fs, blk64_t block,
1216 void *buf, ext2_ino_t inum);
1217 extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
1218 char *block_buf,
1219 int adjust, __u32 *newcount);
1220 extern errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk,
1221 char *block_buf,
1222 int adjust, __u32 *newcount);
1223 extern errcode_t ext2fs_adjust_ea_refcount3(ext2_filsys fs, blk64_t blk,
1224 char *block_buf,
1225 int adjust, __u32 *newcount,
1226 ext2_ino_t inum);
1227 errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle);
1228 errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle);
1229 errcode_t ext2fs_xattrs_iterate(struct ext2_xattr_handle *h,
1230 int (*func)(char *name, char *value,
1231 size_t value_len, void *data),
1232 void *data);
1233 errcode_t ext2fs_xattr_get(struct ext2_xattr_handle *h, const char *key,
1234 void **value, size_t *value_len);
1235 errcode_t ext2fs_xattr_set(struct ext2_xattr_handle *handle,
1236 const char *key,
1237 const void *value,
1238 size_t value_len);
1239 errcode_t ext2fs_xattr_remove(struct ext2_xattr_handle *handle,
1240 const char *key);
1241 errcode_t ext2fs_xattrs_open(ext2_filsys fs, ext2_ino_t ino,
1242 struct ext2_xattr_handle **handle);
1243 errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle);
1244 errcode_t ext2fs_free_ext_attr(ext2_filsys fs, ext2_ino_t ino,
1245 struct ext2_inode_large *inode);
1246 errcode_t ext2fs_xattrs_count(struct ext2_xattr_handle *handle, size_t *count);
1247 errcode_t ext2fs_xattr_inode_max_size(ext2_filsys fs, ext2_ino_t ino,
1248 size_t *size);
1249
1250 /* extent.c */
1251 extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
1252 extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino,
1253 ext2_extent_handle_t *handle);
1254 extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino,
1255 struct ext2_inode *inode,
1256 ext2_extent_handle_t *ret_handle);
1257 extern void ext2fs_extent_free(ext2_extent_handle_t handle);
1258 extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle,
1259 int flags, struct ext2fs_extent *extent);
1260 extern errcode_t ext2fs_extent_node_split(ext2_extent_handle_t handle);
1261 extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags,
1262 struct ext2fs_extent *extent);
1263 extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags,
1264 struct ext2fs_extent *extent);
1265 extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle,
1266 blk64_t logical, blk64_t physical,
1267 int flags);
1268 extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags);
1269 extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle,
1270 struct ext2_extent_info *info);
1271 extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle,
1272 blk64_t blk);
1273 extern errcode_t ext2fs_extent_goto2(ext2_extent_handle_t handle,
1274 int leaf_level, blk64_t blk);
1275 extern errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle);
1276 size_t ext2fs_max_extent_depth(ext2_extent_handle_t handle);
1277
1278 /* fallocate.c */
1279 #define EXT2_FALLOCATE_ZERO_BLOCKS (0x1)
1280 #define EXT2_FALLOCATE_FORCE_INIT (0x2)
1281 #define EXT2_FALLOCATE_FORCE_UNINIT (0x4)
1282 #define EXT2_FALLOCATE_INIT_BEYOND_EOF (0x8)
1283 #define EXT2_FALLOCATE_ALL_FLAGS (0xF)
1284 errcode_t ext2fs_fallocate(ext2_filsys fs, int flags, ext2_ino_t ino,
1285 struct ext2_inode *inode, blk64_t goal,
1286 blk64_t start, blk64_t len);
1287
1288 /* fileio.c */
1289 extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
1290 struct ext2_inode *inode,
1291 int flags, ext2_file_t *ret);
1292 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
1293 int flags, ext2_file_t *ret);
1294 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
1295 struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file);
1296 extern ext2_ino_t ext2fs_file_get_inode_num(ext2_file_t file);
1297 extern errcode_t ext2fs_file_close(ext2_file_t file);
1298 extern errcode_t ext2fs_file_flush(ext2_file_t file);
1299 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
1300 unsigned int wanted, unsigned int *got);
1301 extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
1302 unsigned int nbytes, unsigned int *written);
1303 extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
1304 int whence, __u64 *ret_pos);
1305 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
1306 int whence, ext2_off_t *ret_pos);
1307 errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
1308 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
1309 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
1310 extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size);
1311
1312 /* finddev.c */
1313 extern char *ext2fs_find_block_device(dev_t device);
1314
1315 /* flushb.c */
1316 extern errcode_t ext2fs_sync_device(int fd, int flushb);
1317
1318 /* freefs.c */
1319 extern void ext2fs_free(ext2_filsys fs);
1320 extern void ext2fs_free_dblist(ext2_dblist dblist);
1321 extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
1322 extern void ext2fs_u32_list_free(ext2_u32_list bb);
1323
1324 /* gen_bitmap.c */
1325 extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
1326 extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
1327 __u32 start, __u32 end,
1328 __u32 real_end,
1329 const char *descr, char *init_map,
1330 ext2fs_generic_bitmap *ret);
1331 extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
1332 __u32 end,
1333 __u32 real_end,
1334 const char *descr,
1335 ext2fs_generic_bitmap *ret);
1336 extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
1337 ext2fs_generic_bitmap *dest);
1338 extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
1339 extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
1340 errcode_t magic,
1341 errcode_t neq,
1342 ext2_ino_t end,
1343 ext2_ino_t *oend);
1344 extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
1345 extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
1346 __u32 new_end,
1347 __u32 new_real_end,
1348 ext2fs_generic_bitmap bmap);
1349 extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
1350 ext2fs_generic_bitmap bm1,
1351 ext2fs_generic_bitmap bm2);
1352 extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1353 errcode_t magic,
1354 __u32 start, __u32 num,
1355 void *out);
1356 extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
1357 errcode_t magic,
1358 __u32 start, __u32 num,
1359 void *in);
1360 extern errcode_t ext2fs_find_first_zero_generic_bitmap(ext2fs_generic_bitmap bitmap,
1361 __u32 start, __u32 end,
1362 __u32 *out);
1363 extern errcode_t ext2fs_find_first_set_generic_bitmap(ext2fs_generic_bitmap bitmap,
1364 __u32 start, __u32 end,
1365 __u32 *out);
1366
1367 /* gen_bitmap64.c */
1368 void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap);
1369 errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic,
1370 int type, __u64 start, __u64 end,
1371 __u64 real_end,
1372 const char *descr,
1373 ext2fs_generic_bitmap *ret);
1374 errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src,
1375 ext2fs_generic_bitmap *dest);
1376 void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
1377 errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap,
1378 errcode_t neq,
1379 __u64 end, __u64 *oend);
1380 void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap);
1381 errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
1382 __u64 new_end,
1383 __u64 new_real_end);
1384 errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
1385 ext2fs_generic_bitmap bm1,
1386 ext2fs_generic_bitmap bm2);
1387 errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,
1388 __u64 start, unsigned int num,
1389 void *out);
1390 errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,
1391 __u64 start, unsigned int num,
1392 void *in);
1393 errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
1394 ext2fs_block_bitmap *bitmap);
1395
1396 /* get_num_dirs.c */
1397 extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
1398
1399 /* getsize.c */
1400 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
1401 blk_t *retblocks);
1402 extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
1403 blk64_t *retblocks);
1404
1405 /* getsectsize.c */
1406 extern int ext2fs_get_dio_alignment(int fd);
1407 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
1408 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize);
1409
1410 /* i_block.c */
1411 errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode,
1412 blk64_t num_blocks);
1413 errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode,
1414 blk64_t num_blocks);
1415 errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b);
1416
1417 /* imager.c */
1418 extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
1419 extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
1420 extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
1421 extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
1422 extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
1423 extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
1424
1425 /* ind_block.c */
1426 errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1427 errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
1428
1429 /* initialize.c */
1430 extern errcode_t ext2fs_initialize(const char *name, int flags,
1431 struct ext2_super_block *param,
1432 io_manager manager, ext2_filsys *ret_fs);
1433
1434 /* icount.c */
1435 extern void ext2fs_free_icount(ext2_icount_t icount);
1436 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
1437 int flags, ext2_icount_t *ret);
1438 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
1439 unsigned int size,
1440 ext2_icount_t hint, ext2_icount_t *ret);
1441 extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
1442 unsigned int size,
1443 ext2_icount_t *ret);
1444 extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
1445 __u16 *ret);
1446 extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
1447 __u16 *ret);
1448 extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
1449 __u16 *ret);
1450 extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
1451 __u16 count);
1452 extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
1453 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
1454
1455 /* inline.c */
1456
1457 extern errcode_t ext2fs_get_memalign(unsigned long size,
1458 unsigned long align, void *ptr);
1459
1460 /* inline_data.c */
1461 extern errcode_t ext2fs_inline_data_init(ext2_filsys fs, ext2_ino_t ino);
1462 extern errcode_t ext2fs_inline_data_size(ext2_filsys fs, ext2_ino_t ino,
1463 size_t *size);
1464 extern errcode_t ext2fs_inline_data_get(ext2_filsys fs, ext2_ino_t ino,
1465 struct ext2_inode *inode,
1466 void *buf, size_t *size);
1467 extern errcode_t ext2fs_inline_data_set(ext2_filsys fs, ext2_ino_t ino,
1468 struct ext2_inode *inode,
1469 void *buf, size_t size);
1470
1471 /* inode.c */
1472 extern errcode_t ext2fs_create_inode_cache(ext2_filsys fs,
1473 unsigned int cache_size);
1474 extern void ext2fs_free_inode_cache(struct ext2_inode_cache *icache);
1475 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
1476 extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
1477 ext2_ino_t *ino,
1478 struct ext2_inode *inode,
1479 int bufsize);
1480 #define EXT2_INODE_SCAN_DEFAULT_BUFFER_BLOCKS 8
1481 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
1482 ext2_inode_scan *ret_scan);
1483 extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
1484 extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
1485 struct ext2_inode *inode);
1486 extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
1487 int group);
1488 extern void ext2fs_set_inode_callback
1489 (ext2_inode_scan scan,
1490 errcode_t (*done_group)(ext2_filsys fs,
1491 ext2_inode_scan scan,
1492 dgrp_t group,
1493 void * priv_data),
1494 void *done_group_data);
1495 extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
1496 int clear_flags);
1497 extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
1498 struct ext2_inode * inode,
1499 int bufsize);
1500 extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
1501 struct ext2_inode * inode);
1502 extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
1503 struct ext2_inode * inode,
1504 int bufsize);
1505 extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
1506 struct ext2_inode * inode);
1507 extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
1508 struct ext2_inode * inode);
1509 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
1510 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
1511
1512 /* inode_io.c */
1513 extern io_manager inode_io_manager;
1514 extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
1515 char **name);
1516 extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
1517 struct ext2_inode *inode,
1518 char **name);
1519
1520 /* ismounted.c */
1521 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
1522 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
1523 char *mtpt, int mtlen);
1524
1525 /* punch.c */
1526 /*
1527 * NOTE: This function removes from an inode the blocks "start", "end", and
1528 * every block in between.
1529 */
1530 extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
1531 struct ext2_inode *inode,
1532 char *block_buf, blk64_t start,
1533 blk64_t end);
1534
1535 /* namei.c */
1536 extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
1537 int namelen, char *buf, ext2_ino_t *inode);
1538 extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1539 const char *name, ext2_ino_t *inode);
1540 errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1541 const char *name, ext2_ino_t *inode);
1542 extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
1543 ext2_ino_t inode, ext2_ino_t *res_inode);
1544
1545 /* native.c */
1546 int ext2fs_native_flag(void);
1547
1548 /* newdir.c */
1549 extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
1550 ext2_ino_t parent_ino, char **block);
1551 extern errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs, ext2_ino_t dir_ino,
1552 ext2_ino_t parent_ino, __u32 *iblock);
1553
1554 /* mkdir.c */
1555 extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
1556 const char *name);
1557
1558 /* mkjournal.c */
1559 extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
1560 blk_t *ret_blk, int *ret_count);
1561 extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
1562 blk64_t *ret_blk, int *ret_count);
1563 extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
1564 __u32 num_blocks, int flags,
1565 char **ret_jsb);
1566 extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
1567 ext2_filsys journal_dev);
1568 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks,
1569 int flags);
1570 extern errcode_t ext2fs_add_journal_inode2(ext2_filsys fs, blk_t num_blocks,
1571 blk64_t goal, int flags);
1572 extern int ext2fs_default_journal_size(__u64 num_blocks);
1573 extern int ext2fs_journal_sb_start(int blocksize);
1574
1575 /* openfs.c */
1576 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
1577 unsigned int block_size, io_manager manager,
1578 ext2_filsys *ret_fs);
1579 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
1580 int flags, int superblock,
1581 unsigned int block_size, io_manager manager,
1582 ext2_filsys *ret_fs);
1583 /*
1584 * The dgrp_t argument to these two functions is not actually a group number
1585 * but a block number offset within a group table! Convert with the formula
1586 * (group_number / groups_per_block).
1587 */
1588 extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs,
1589 blk64_t group_block, dgrp_t i);
1590 extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
1591 dgrp_t i);
1592 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
1593 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
1594 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
1595
1596 /* get_pathname.c */
1597 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
1598 char **name);
1599
1600 /* link.c */
1601 errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
1602 ext2_ino_t ino, int flags);
1603 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
1604 ext2_ino_t ino, int flags);
1605
1606 /* symlink.c */
1607 errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
1608 const char *name, const char *target);
1609
1610 /* mmp.c */
1611 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1612 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf);
1613 errcode_t ext2fs_mmp_clear(ext2_filsys fs);
1614 errcode_t ext2fs_mmp_init(ext2_filsys fs);
1615 errcode_t ext2fs_mmp_start(ext2_filsys fs);
1616 errcode_t ext2fs_mmp_update(ext2_filsys fs);
1617 errcode_t ext2fs_mmp_update2(ext2_filsys fs, int immediately);
1618 errcode_t ext2fs_mmp_stop(ext2_filsys fs);
1619 unsigned ext2fs_mmp_new_seq(void);
1620
1621 /* read_bb.c */
1622 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
1623 ext2_badblocks_list *bb_list);
1624
1625 /* read_bb_file.c */
1626 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
1627 ext2_badblocks_list *bb_list,
1628 void *priv_data,
1629 void (*invalid)(ext2_filsys fs,
1630 blk_t blk,
1631 char *badstr,
1632 void *priv_data));
1633 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
1634 ext2_badblocks_list *bb_list,
1635 void (*invalid)(ext2_filsys fs,
1636 blk_t blk));
1637
1638 /* res_gdt.c */
1639 extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
1640
1641 /*sha256.c */
1642 #define EXT2FS_SHA256_LENGTH 32
1643 #if 0
1644 extern void ext2fs_sha256(const unsigned char *in, unsigned long in_size,
1645 unsigned char out[EXT2FS_SHA256_LENGTH]);
1646 #endif
1647
1648 /* sha512.c */
1649 #define EXT2FS_SHA512_LENGTH 64
1650 extern void ext2fs_sha512(const unsigned char *in, unsigned long in_size,
1651 unsigned char out[EXT2FS_SHA512_LENGTH]);
1652
1653 /* swapfs.c */
1654 extern errcode_t ext2fs_dirent_swab_in2(ext2_filsys fs, char *buf, size_t size,
1655 int flags);
1656 extern errcode_t ext2fs_dirent_swab_in(ext2_filsys fs, char *buf, int flags);
1657 extern errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf, size_t size,
1658 int flags);
1659 extern errcode_t ext2fs_dirent_swab_out(ext2_filsys fs, char *buf, int flags);
1660 extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
1661 int has_header);
1662 extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
1663 struct ext2_ext_attr_header *from_hdr);
1664 extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
1665 struct ext2_ext_attr_entry *from_entry);
1666 extern void ext2fs_swap_super(struct ext2_super_block * super);
1667 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
1668 extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp);
1669 extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
1670 struct ext2_inode_large *f, int hostorder,
1671 int bufsize);
1672 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
1673 struct ext2_inode *f, int hostorder);
1674 extern void ext2fs_swap_mmp(struct mmp_struct *mmp);
1675
1676 /* unix_io.c */
1677 extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode);
1678 extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf);
1679 extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
1680
1681 /* valid_blk.c */
1682 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
1683 extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs,
1684 struct ext2_inode *inode);
1685
1686 /* version.c */
1687 extern int ext2fs_parse_version_string(const char *ver_string);
1688 extern int ext2fs_get_library_version(const char **ver_string,
1689 const char **date_string);
1690
1691 /* write_bb_file.c */
1692 extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
1693 unsigned int flags,
1694 FILE *f);
1695
1696
1697 /* inline functions */
1698 #ifdef NO_INLINE_FUNCS
1699 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
1700 extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr);
1701 extern errcode_t ext2fs_get_array(unsigned long count,
1702 unsigned long size, void *ptr);
1703 extern errcode_t ext2fs_get_arrayzero(unsigned long count,
1704 unsigned long size, void *ptr);
1705 extern errcode_t ext2fs_free_mem(void *ptr);
1706 extern errcode_t ext2fs_resize_mem(unsigned long old_size,
1707 unsigned long size, void *ptr);
1708 extern void ext2fs_mark_super_dirty(ext2_filsys fs);
1709 extern void ext2fs_mark_changed(ext2_filsys fs);
1710 extern int ext2fs_test_changed(ext2_filsys fs);
1711 extern void ext2fs_mark_valid(ext2_filsys fs);
1712 extern void ext2fs_unmark_valid(ext2_filsys fs);
1713 extern int ext2fs_test_valid(ext2_filsys fs);
1714 extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
1715 extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
1716 extern int ext2fs_test_ib_dirty(ext2_filsys fs);
1717 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
1718 extern dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
1719 extern dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
1720 extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
1721 extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
1722 extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1723 struct ext2_inode *inode);
1724 extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
1725 extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b);
1726 extern int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry);
1727 extern void ext2fs_dirent_set_name_len(struct ext2_dir_entry *entry, int len);
1728 extern int ext2fs_dirent_file_type(const struct ext2_dir_entry *entry);
1729 extern void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type);
1730 extern struct ext2_inode *ext2fs_inode(struct ext2_inode_large * large_inode);
1731 extern const struct ext2_inode *ext2fs_const_inode(const struct ext2_inode_large * large_inode);
1732
1733 #endif
1734
1735 /*
1736 * The actual inlined functions definitions themselves...
1737 *
1738 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
1739 * functions at all!
1740 */
1741 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
1742 #ifdef INCLUDE_INLINE_FUNCS
1743 #define _INLINE_ extern
1744 #else
1745 #if (__STDC_VERSION__ >= 199901L)
1746 #define _INLINE_ inline
1747 #else
1748 #ifdef __GNUC__
1749 #define _INLINE_ extern __inline__
1750 #else /* For Watcom C */
1751 #define _INLINE_ extern inline
1752 #endif /* __GNUC__ */
1753 #endif /* __STDC_VERSION__ >= 199901L */
1754 #endif
1755
1756 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
1757 #include <string.h>
1758 /*
1759 * Allocate memory. The 'ptr' arg must point to a pointer.
1760 */
ext2fs_get_mem(unsigned long size,void * ptr)1761 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
1762 {
1763 void *pp;
1764
1765 pp = malloc(size);
1766 if (!pp)
1767 return EXT2_ET_NO_MEMORY;
1768 memcpy(ptr, &pp, sizeof (pp));
1769 return 0;
1770 }
1771
ext2fs_get_memzero(unsigned long size,void * ptr)1772 _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
1773 {
1774 void *pp;
1775
1776 pp = malloc(size);
1777 if (!pp)
1778 return EXT2_ET_NO_MEMORY;
1779 memset(pp, 0, size);
1780 memcpy(ptr, &pp, sizeof(pp));
1781 return 0;
1782 }
1783
ext2fs_get_array(unsigned long count,unsigned long size,void * ptr)1784 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
1785 {
1786 if (count && (~0UL)/count < size)
1787 return EXT2_ET_NO_MEMORY;
1788 return ext2fs_get_mem(count*size, ptr);
1789 }
1790
ext2fs_get_arrayzero(unsigned long count,unsigned long size,void * ptr)1791 _INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count,
1792 unsigned long size, void *ptr)
1793 {
1794 void *pp;
1795
1796 if (count && (~0UL)/count < size)
1797 return EXT2_ET_NO_MEMORY;
1798 pp = calloc(count, size);
1799 if (!pp)
1800 return EXT2_ET_NO_MEMORY;
1801 memcpy(ptr, &pp, sizeof(pp));
1802 return 0;
1803 }
1804
1805 /*
1806 * Free memory. The 'ptr' arg must point to a pointer.
1807 */
ext2fs_free_mem(void * ptr)1808 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1809 {
1810 void *p;
1811
1812 memcpy(&p, ptr, sizeof(p));
1813 free(p);
1814 p = 0;
1815 memcpy(ptr, &p, sizeof(p));
1816 return 0;
1817 }
1818
1819 /*
1820 * Resize memory. The 'ptr' arg must point to a pointer.
1821 */
ext2fs_resize_mem(unsigned long EXT2FS_ATTR ((unused))old_size,unsigned long size,void * ptr)1822 _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1823 unsigned long size, void *ptr)
1824 {
1825 void *p;
1826
1827 /* Use "memcpy" for pointer assignments here to avoid problems
1828 * with C99 strict type aliasing rules. */
1829 memcpy(&p, ptr, sizeof(p));
1830 p = realloc(p, size);
1831 if (!p)
1832 return EXT2_ET_NO_MEMORY;
1833 memcpy(ptr, &p, sizeof(p));
1834 return 0;
1835 }
1836 #endif /* Custom memory routines */
1837
1838 /*
1839 * Mark a filesystem superblock as dirty
1840 */
ext2fs_mark_super_dirty(ext2_filsys fs)1841 _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1842 {
1843 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1844 }
1845
1846 /*
1847 * Mark a filesystem as changed
1848 */
ext2fs_mark_changed(ext2_filsys fs)1849 _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1850 {
1851 fs->flags |= EXT2_FLAG_CHANGED;
1852 }
1853
1854 /*
1855 * Check to see if a filesystem has changed
1856 */
ext2fs_test_changed(ext2_filsys fs)1857 _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1858 {
1859 return (fs->flags & EXT2_FLAG_CHANGED);
1860 }
1861
1862 /*
1863 * Mark a filesystem as valid
1864 */
ext2fs_mark_valid(ext2_filsys fs)1865 _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1866 {
1867 fs->flags |= EXT2_FLAG_VALID;
1868 }
1869
1870 /*
1871 * Mark a filesystem as NOT valid
1872 */
ext2fs_unmark_valid(ext2_filsys fs)1873 _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1874 {
1875 fs->flags &= ~EXT2_FLAG_VALID;
1876 }
1877
1878 /*
1879 * Check to see if a filesystem is valid
1880 */
ext2fs_test_valid(ext2_filsys fs)1881 _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1882 {
1883 return (fs->flags & EXT2_FLAG_VALID);
1884 }
1885
1886 /*
1887 * Mark the inode bitmap as dirty
1888 */
ext2fs_mark_ib_dirty(ext2_filsys fs)1889 _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1890 {
1891 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1892 }
1893
1894 /*
1895 * Mark the block bitmap as dirty
1896 */
ext2fs_mark_bb_dirty(ext2_filsys fs)1897 _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1898 {
1899 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1900 }
1901
1902 /*
1903 * Check to see if a filesystem's inode bitmap is dirty
1904 */
ext2fs_test_ib_dirty(ext2_filsys fs)1905 _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1906 {
1907 return (fs->flags & EXT2_FLAG_IB_DIRTY);
1908 }
1909
1910 /*
1911 * Check to see if a filesystem's block bitmap is dirty
1912 */
ext2fs_test_bb_dirty(ext2_filsys fs)1913 _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1914 {
1915 return (fs->flags & EXT2_FLAG_BB_DIRTY);
1916 }
1917
1918 /*
1919 * Return the group # of a block
1920 */
ext2fs_group_of_blk(ext2_filsys fs,blk_t blk)1921 _INLINE_ dgrp_t ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1922 {
1923 return ext2fs_group_of_blk2(fs, blk);
1924 }
1925 /*
1926 * Return the group # of an inode number
1927 */
ext2fs_group_of_ino(ext2_filsys fs,ext2_ino_t ino)1928 _INLINE_ dgrp_t ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1929 {
1930 return (ino - 1) / fs->super->s_inodes_per_group;
1931 }
1932
1933 /*
1934 * Return the first block (inclusive) in a group
1935 */
ext2fs_group_first_block(ext2_filsys fs,dgrp_t group)1936 _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
1937 {
1938 return (blk_t) ext2fs_group_first_block2(fs, group);
1939 }
1940
1941 /*
1942 * Return the last block (inclusive) in a group
1943 */
ext2fs_group_last_block(ext2_filsys fs,dgrp_t group)1944 _INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
1945 {
1946 return (blk_t) ext2fs_group_last_block2(fs, group);
1947 }
1948
ext2fs_inode_data_blocks(ext2_filsys fs,struct ext2_inode * inode)1949 _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1950 struct ext2_inode *inode)
1951 {
1952 return (blk_t) ext2fs_inode_data_blocks2(fs, inode);
1953 }
1954
1955 /*
1956 * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
1957 */
ext2fs_div_ceil(unsigned int a,unsigned int b)1958 _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
1959 {
1960 if (!a)
1961 return 0;
1962 return ((a - 1) / b) + 1;
1963 }
1964
ext2fs_div64_ceil(__u64 a,__u64 b)1965 _INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b)
1966 {
1967 if (!a)
1968 return 0;
1969 return ((a - 1) / b) + 1;
1970 }
1971
ext2fs_dirent_name_len(const struct ext2_dir_entry * entry)1972 _INLINE_ int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry)
1973 {
1974 return entry->name_len & 0xff;
1975 }
1976
ext2fs_dirent_set_name_len(struct ext2_dir_entry * entry,int len)1977 _INLINE_ void ext2fs_dirent_set_name_len(struct ext2_dir_entry *entry, int len)
1978 {
1979 entry->name_len = (entry->name_len & 0xff00) | (len & 0xff);
1980 }
1981
ext2fs_dirent_file_type(const struct ext2_dir_entry * entry)1982 _INLINE_ int ext2fs_dirent_file_type(const struct ext2_dir_entry *entry)
1983 {
1984 return entry->name_len >> 8;
1985 }
1986
ext2fs_dirent_set_file_type(struct ext2_dir_entry * entry,int type)1987 _INLINE_ void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type)
1988 {
1989 entry->name_len = (entry->name_len & 0xff) | (type << 8);
1990 }
1991
ext2fs_inode(struct ext2_inode_large * large_inode)1992 _INLINE_ struct ext2_inode *ext2fs_inode(struct ext2_inode_large * large_inode)
1993 {
1994 /* It is always safe to convert large inode to a small inode */
1995 return (struct ext2_inode *) large_inode;
1996 }
1997
1998 _INLINE_ const struct ext2_inode *
ext2fs_const_inode(const struct ext2_inode_large * large_inode)1999 ext2fs_const_inode(const struct ext2_inode_large * large_inode)
2000 {
2001 /* It is always safe to convert large inode to a small inode */
2002 return (const struct ext2_inode *) large_inode;
2003 }
2004
2005 #undef _INLINE_
2006 #endif
2007
2008 #ifdef __cplusplus
2009 }
2010 #endif
2011
2012 #endif /* _EXT2FS_EXT2FS_H */
2013