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