ext2fs.h revision abf23439d51a3ddbca475b931abebd381ff7ceea
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 Public
8 * License.
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 __cplusplus
22extern "C" {
23#endif
24
25/*
26 * Non-GNU C compilers won't necessarily understand inline
27 */
28#if (!defined(__GNUC__) && !defined(__WATCOMC__))
29#define NO_INLINE_FUNCS
30#endif
31
32/*
33 * Build in support for byte-swapping filesystems if we the feature
34 * has been configured or if we're being built on a CPU architecture
35 * with a non-native byte order.
36 */
37#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
38#define EXT2FS_ENABLE_SWAPFS
39#endif
40
41/*
42 * Where the master copy of the superblock is located, and how big
43 * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
44 * the size of the superblock structure is not necessarily trustworthy
45 * (some versions have the padding set up so that the superblock is
46 * 1032 bytes long).
47 */
48#define SUPERBLOCK_OFFSET	1024
49#define SUPERBLOCK_SIZE 	1024
50
51/*
52 * The last ext2fs revision level that this version of the library is
53 * able to support.
54 */
55#define EXT2_LIB_CURRENT_REV	EXT2_DYNAMIC_REV
56
57#ifdef HAVE_SYS_TYPES_H
58#include <sys/types.h>
59#endif
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64
65#if EXT2_FLAT_INCLUDES
66#include "e2_types.h"
67#include "ext2_fs.h"
68#else
69#include <ext2fs/ext2_types.h>
70#include <ext2fs/ext2_fs.h>
71#endif /* EXT2_FLAT_INCLUDES */
72
73typedef __u32		ext2_ino_t;
74typedef __u32		blk_t;
75typedef __u32		dgrp_t;
76typedef __u32		ext2_off_t;
77typedef __s64		e2_blkcnt_t;
78typedef __u32		ext2_dirhash_t;
79
80#if EXT2_FLAT_INCLUDES
81#include "com_err.h"
82#include "ext2_io.h"
83#include "ext2_err.h"
84#else
85#include <et/com_err.h>
86#include <ext2fs/ext2_io.h>
87#include <ext2fs/ext2_err.h>
88#endif
89
90/*
91 * Portability help for Microsoft Visual C++
92 */
93#ifdef _MSC_VER
94#define EXT2_QSORT_TYPE int __cdecl
95#else
96#define EXT2_QSORT_TYPE int
97#endif
98
99typedef struct struct_ext2_filsys *ext2_filsys;
100
101struct ext2fs_struct_generic_bitmap {
102	errcode_t	magic;
103	ext2_filsys 	fs;
104	__u32		start, end;
105	__u32		real_end;
106	char	*	description;
107	char	*	bitmap;
108	errcode_t	base_error_code;
109	__u32		reserved[7];
110};
111
112#define EXT2FS_MARK_ERROR 	0
113#define EXT2FS_UNMARK_ERROR 	1
114#define EXT2FS_TEST_ERROR	2
115
116typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
117typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
118typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
119
120#define EXT2_FIRST_INODE(s)	EXT2_FIRST_INO(s)
121
122
123/*
124 * Badblocks list definitions
125 */
126
127typedef struct ext2_struct_u32_list *ext2_badblocks_list;
128typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
129
130typedef struct ext2_struct_u32_list *ext2_u32_list;
131typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
132
133/* old */
134typedef struct ext2_struct_u32_list *badblocks_list;
135typedef struct ext2_struct_u32_iterate *badblocks_iterate;
136
137#define BADBLOCKS_FLAG_DIRTY	1
138
139/*
140 * ext2_dblist structure and abstractions (see dblist.c)
141 */
142struct ext2_db_entry {
143	ext2_ino_t	ino;
144	blk_t	blk;
145	int	blockcnt;
146};
147
148typedef struct ext2_struct_dblist *ext2_dblist;
149
150#define DBLIST_ABORT	1
151
152/*
153 * ext2_fileio definitions
154 */
155
156#define EXT2_FILE_WRITE		0x0001
157#define EXT2_FILE_CREATE	0x0002
158
159#define EXT2_FILE_MASK		0x00FF
160
161#define EXT2_FILE_BUF_DIRTY	0x4000
162#define EXT2_FILE_BUF_VALID	0x2000
163
164typedef struct ext2_file *ext2_file_t;
165
166#define EXT2_SEEK_SET	0
167#define EXT2_SEEK_CUR	1
168#define EXT2_SEEK_END	2
169
170/*
171 * Flags for the ext2_filsys structure and for ext2fs_open()
172 */
173#define EXT2_FLAG_RW			0x01
174#define EXT2_FLAG_CHANGED		0x02
175#define EXT2_FLAG_DIRTY			0x04
176#define EXT2_FLAG_VALID			0x08
177#define EXT2_FLAG_IB_DIRTY		0x10
178#define EXT2_FLAG_BB_DIRTY		0x20
179#define EXT2_FLAG_SWAP_BYTES		0x40
180#define EXT2_FLAG_SWAP_BYTES_READ	0x80
181#define EXT2_FLAG_SWAP_BYTES_WRITE	0x100
182#define EXT2_FLAG_MASTER_SB_ONLY	0x200
183#define EXT2_FLAG_FORCE			0x400
184#define EXT2_FLAG_SUPER_ONLY		0x800
185#define EXT2_FLAG_JOURNAL_DEV_OK	0x1000
186#define EXT2_FLAG_IMAGE_FILE		0x2000
187#define EXT2_FLAG_EXCLUSIVE		0x4000
188
189/*
190 * Special flag in the ext2 inode i_flag field that means that this is
191 * a new inode.  (So that ext2_write_inode() can clear extra fields.)
192 */
193#define EXT2_NEW_INODE_FL	0x80000000
194
195/*
196 * Flags for mkjournal
197 *
198 * EXT2_MKJOURNAL_V1_SUPER	Make a (deprecated) V1 journal superblock
199 */
200#define EXT2_MKJOURNAL_V1_SUPER	0x0000001
201
202struct struct_ext2_filsys {
203	errcode_t			magic;
204	io_channel			io;
205	int				flags;
206	char *				device_name;
207	struct ext2_super_block	* 	super;
208	unsigned int			blocksize;
209	int				fragsize;
210	dgrp_t				group_desc_count;
211	unsigned long			desc_blocks;
212	struct ext2_group_desc *	group_desc;
213	int				inode_blocks_per_group;
214	ext2fs_inode_bitmap		inode_map;
215	ext2fs_block_bitmap		block_map;
216	errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
217	errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
218	errcode_t (*write_bitmaps)(ext2_filsys fs);
219	errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
220				struct ext2_inode *inode);
221	errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
222				struct ext2_inode *inode);
223	ext2_badblocks_list		badblocks;
224	ext2_dblist			dblist;
225	__u32				stride;	/* for mke2fs */
226	struct ext2_super_block *	orig_super;
227	struct ext2_image_hdr *		image_header;
228	__u32				umask;
229	time_t				now;
230	/*
231	 * Reserved for future expansion
232	 */
233	__u32				reserved[7];
234
235	/*
236	 * Reserved for the use of the calling application.
237	 */
238	void *				priv_data;
239
240	/*
241	 * Inode cache
242	 */
243	struct ext2_inode_cache		*icache;
244	io_channel			image_io;
245};
246
247#if EXT2_FLAT_INCLUDES
248#include "e2_bitops.h"
249#else
250#include <ext2fs/bitops.h>
251#endif
252
253/*
254 * Return flags for the block iterator functions
255 */
256#define BLOCK_CHANGED	1
257#define BLOCK_ABORT	2
258#define BLOCK_ERROR	4
259
260/*
261 * Block interate flags
262 *
263 * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
264 * function should be called on blocks where the block number is zero.
265 * This is used by ext2fs_expand_dir() to be able to add a new block
266 * to an inode.  It can also be used for programs that want to be able
267 * to deal with files that contain "holes".
268 *
269 * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for
270 * the indirect, doubly indirect, etc. blocks should be called after
271 * all of the blocks containined in the indirect blocks are processed.
272 * This is useful if you are going to be deallocating blocks from an
273 * inode.
274 *
275 * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
276 * called for data blocks only.
277 *
278 * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
279 * ext2fs_block_iterate2 that large files won't be accepted.
280 */
281#define BLOCK_FLAG_APPEND	1
282#define BLOCK_FLAG_HOLE		1
283#define BLOCK_FLAG_DEPTH_TRAVERSE	2
284#define BLOCK_FLAG_DATA_ONLY	4
285
286#define BLOCK_FLAG_NO_LARGE	0x1000
287
288/*
289 * Magic "block count" return values for the block iterator function.
290 */
291#define BLOCK_COUNT_IND		(-1)
292#define BLOCK_COUNT_DIND	(-2)
293#define BLOCK_COUNT_TIND	(-3)
294#define BLOCK_COUNT_TRANSLATOR	(-4)
295
296#if 0
297/*
298 * Flags for ext2fs_move_blocks
299 */
300#define EXT2_BMOVE_GET_DBLIST	0x0001
301#define EXT2_BMOVE_DEBUG	0x0002
302#endif
303
304/*
305 * Flags for directory block reading and writing functions
306 */
307#define EXT2_DIRBLOCK_V2_STRUCT	0x0001
308
309/*
310 * Return flags for the directory iterator functions
311 */
312#define DIRENT_CHANGED	1
313#define DIRENT_ABORT	2
314#define DIRENT_ERROR	3
315
316/*
317 * Directory iterator flags
318 */
319
320#define DIRENT_FLAG_INCLUDE_EMPTY	1
321#define DIRENT_FLAG_INCLUDE_REMOVED	2
322
323#define DIRENT_DOT_FILE		1
324#define DIRENT_DOT_DOT_FILE	2
325#define DIRENT_OTHER_FILE	3
326#define DIRENT_DELETED_FILE	4
327
328/*
329 * Inode scan definitions
330 */
331typedef struct ext2_struct_inode_scan *ext2_inode_scan;
332
333/*
334 * ext2fs_scan flags
335 */
336#define EXT2_SF_CHK_BADBLOCKS	0x0001
337#define EXT2_SF_BAD_INODE_BLK	0x0002
338#define EXT2_SF_BAD_EXTRA_BYTES	0x0004
339#define EXT2_SF_SKIP_MISSING_ITABLE	0x0008
340#define EXT2_SF_DO_LAZY		0x0010
341
342/*
343 * ext2fs_check_if_mounted flags
344 */
345#define EXT2_MF_MOUNTED		1
346#define EXT2_MF_ISROOT		2
347#define EXT2_MF_READONLY	4
348#define EXT2_MF_SWAP		8
349#define EXT2_MF_BUSY		16
350
351/*
352 * Ext2/linux mode flags.  We define them here so that we don't need
353 * to depend on the OS's sys/stat.h, since we may be compiling on a
354 * non-Linux system.
355 */
356#define LINUX_S_IFMT  00170000
357#define LINUX_S_IFSOCK 0140000
358#define LINUX_S_IFLNK	 0120000
359#define LINUX_S_IFREG  0100000
360#define LINUX_S_IFBLK  0060000
361#define LINUX_S_IFDIR  0040000
362#define LINUX_S_IFCHR  0020000
363#define LINUX_S_IFIFO  0010000
364#define LINUX_S_ISUID  0004000
365#define LINUX_S_ISGID  0002000
366#define LINUX_S_ISVTX  0001000
367
368#define LINUX_S_IRWXU 00700
369#define LINUX_S_IRUSR 00400
370#define LINUX_S_IWUSR 00200
371#define LINUX_S_IXUSR 00100
372
373#define LINUX_S_IRWXG 00070
374#define LINUX_S_IRGRP 00040
375#define LINUX_S_IWGRP 00020
376#define LINUX_S_IXGRP 00010
377
378#define LINUX_S_IRWXO 00007
379#define LINUX_S_IROTH 00004
380#define LINUX_S_IWOTH 00002
381#define LINUX_S_IXOTH 00001
382
383#define LINUX_S_ISLNK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
384#define LINUX_S_ISREG(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
385#define LINUX_S_ISDIR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
386#define LINUX_S_ISCHR(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
387#define LINUX_S_ISBLK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
388#define LINUX_S_ISFIFO(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
389#define LINUX_S_ISSOCK(m)	(((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
390
391/*
392 * ext2 size of an inode
393 */
394#define EXT2_I_SIZE(i)	((i)->i_size | ((__u64) (i)->i_size_high << 32))
395
396/*
397 * ext2_icount_t abstraction
398 */
399#define EXT2_ICOUNT_OPT_INCREMENT	0x01
400
401typedef struct ext2_icount *ext2_icount_t;
402
403/*
404 * Flags for ext2fs_bmap
405 */
406#define BMAP_ALLOC	0x0001
407#define BMAP_SET	0x0002
408
409/*
410 * Flags for imager.c functions
411 */
412#define IMAGER_FLAG_INODEMAP	1
413#define IMAGER_FLAG_SPARSEWRITE	2
414
415/*
416 * For checking structure magic numbers...
417 */
418
419#define EXT2_CHECK_MAGIC(struct, code) \
420	  if ((struct)->magic != (code)) return (code)
421
422
423/*
424 * For ext2 compression support
425 */
426#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
427#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
428
429/*
430 * Features supported by this version of the library
431 */
432#define EXT2_LIB_FEATURE_COMPAT_SUPP	(EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
433					 EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
434					 EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
435					 EXT2_FEATURE_COMPAT_RESIZE_INODE|\
436					 EXT2_FEATURE_COMPAT_DIR_INDEX|\
437					 EXT2_FEATURE_COMPAT_LAZY_BG|\
438					 EXT2_FEATURE_COMPAT_EXT_ATTR)
439
440/* This #ifdef is temporary until compression is fully supported */
441#ifdef ENABLE_COMPRESSION
442#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
443/* If the below warning bugs you, then have
444   `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
445   environment at configure time. */
446 #warning "Compression support is experimental"
447#endif
448#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
449					 EXT2_FEATURE_INCOMPAT_COMPRESSION|\
450					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
451					 EXT2_FEATURE_INCOMPAT_META_BG|\
452					 EXT3_FEATURE_INCOMPAT_RECOVER)
453#else
454#define EXT2_LIB_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE|\
455					 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
456					 EXT2_FEATURE_INCOMPAT_META_BG|\
457					 EXT3_FEATURE_INCOMPAT_RECOVER)
458#endif
459#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
460					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
461/*
462 * function prototypes
463 */
464
465/* alloc.c */
466extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
467				  ext2fs_inode_bitmap map, ext2_ino_t *ret);
468extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
469				  ext2fs_block_bitmap map, blk_t *ret);
470extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
471					blk_t finish, int num,
472					ext2fs_block_bitmap map,
473					blk_t *ret);
474extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
475				    char *block_buf, blk_t *ret);
476
477/* alloc_sb.c */
478extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
479					dgrp_t group,
480					ext2fs_block_bitmap bmap);
481
482/* alloc_stats.c */
483void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
484void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
485			       int inuse, int isdir);
486void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
487
488/* alloc_tables.c */
489extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
490extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
491					     ext2fs_block_bitmap bmap);
492
493/* badblocks.c */
494extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
495extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
496extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
497extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
498extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
499					       ext2_u32_iterate *ret);
500extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
501extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
502extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
503extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
504
505extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
506					    int size);
507extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
508					   blk_t blk);
509extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
510				    blk_t blk);
511extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
512extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
513extern errcode_t
514	ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
515					    ext2_badblocks_iterate *ret);
516extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
517					 blk_t *blk);
518extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
519extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
520				       ext2_badblocks_list *dest);
521extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
522				  ext2_badblocks_list bb2);
523extern int ext2fs_u32_list_count(ext2_u32_list bb);
524
525/* bb_compat */
526extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
527extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
528extern int badblocks_list_test(badblocks_list bb, blk_t blk);
529extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
530					      badblocks_iterate *ret);
531extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
532extern void badblocks_list_iterate_end(badblocks_iterate iter);
533extern void badblocks_list_free(badblocks_list bb);
534
535/* bb_inode.c */
536extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
537					ext2_badblocks_list bb_list);
538
539/* bitmaps.c */
540extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
541extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
542extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
543extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
544extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
545						__u32 end,
546						__u32 real_end,
547						const char *descr,
548						ext2fs_generic_bitmap *ret);
549extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
550					      const char *descr,
551					      ext2fs_block_bitmap *ret);
552extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
553					      const char *descr,
554					      ext2fs_inode_bitmap *ret);
555extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
556					       ext2_ino_t end, ext2_ino_t *oend);
557extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
558					       blk_t end, blk_t *oend);
559extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
560extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
561extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
562extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
563
564/* block.c */
565extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
566				      ext2_ino_t	ino,
567				      int	flags,
568				      char *block_buf,
569				      int (*func)(ext2_filsys fs,
570						  blk_t	*blocknr,
571						  int	blockcnt,
572						  void	*priv_data),
573				      void *priv_data);
574errcode_t ext2fs_block_iterate2(ext2_filsys fs,
575				ext2_ino_t	ino,
576				int	flags,
577				char *block_buf,
578				int (*func)(ext2_filsys fs,
579					    blk_t	*blocknr,
580					    e2_blkcnt_t	blockcnt,
581					    blk_t	ref_blk,
582					    int		ref_offset,
583					    void	*priv_data),
584				void *priv_data);
585
586/* bmap.c */
587extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
588			     struct ext2_inode *inode,
589			     char *block_buf, int bmap_flags,
590			     blk_t block, blk_t *phys_blk);
591
592
593#if 0
594/* bmove.c */
595extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
596				    ext2fs_block_bitmap reserve,
597				    ext2fs_block_bitmap alloc_map,
598				    int flags);
599#endif
600
601/* check_desc.c */
602extern errcode_t ext2fs_check_desc(ext2_filsys fs);
603
604/* closefs.c */
605extern errcode_t ext2fs_close(ext2_filsys fs);
606extern errcode_t ext2fs_flush(ext2_filsys fs);
607extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
608extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
609				    dgrp_t group,
610				    blk_t *ret_super_blk,
611				    blk_t *ret_old_desc_blk,
612				    blk_t *ret_new_desc_blk,
613				    int *ret_meta_bg);
614extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
615
616/* cmp_bitmaps.c */
617extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
618					     ext2fs_block_bitmap bm2);
619extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
620					     ext2fs_inode_bitmap bm2);
621
622/* dblist.c */
623
624extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
625extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
626extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
627				      blk_t blk, int blockcnt);
628extern void ext2fs_dblist_sort(ext2_dblist dblist,
629			       EXT2_QSORT_TYPE (*sortfunc)(const void *,
630							   const void *));
631extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
632	int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
633		    void	*priv_data),
634       void *priv_data);
635extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
636				      blk_t blk, int blockcnt);
637extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
638				    ext2_dblist *dest);
639extern int ext2fs_dblist_count(ext2_dblist dblist);
640
641/* dblist_dir.c */
642extern errcode_t
643	ext2fs_dblist_dir_iterate(ext2_dblist dblist,
644				  int	flags,
645				  char	*block_buf,
646				  int (*func)(ext2_ino_t	dir,
647					      int		entry,
648					      struct ext2_dir_entry *dirent,
649					      int	offset,
650					      int	blocksize,
651					      char	*buf,
652					      void	*priv_data),
653				  void *priv_data);
654
655/* dirblock.c */
656extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
657				       void *buf);
658extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
659					void *buf, int flags);
660extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
661					void *buf);
662extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
663					 void *buf, int flags);
664
665/* dirhash.c */
666extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
667				const __u32 *seed,
668				ext2_dirhash_t *ret_hash,
669				ext2_dirhash_t *ret_minor_hash);
670
671
672/* dir_iterate.c */
673extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
674			      ext2_ino_t dir,
675			      int flags,
676			      char *block_buf,
677			      int (*func)(struct ext2_dir_entry *dirent,
678					  int	offset,
679					  int	blocksize,
680					  char	*buf,
681					  void	*priv_data),
682			      void *priv_data);
683extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
684			      ext2_ino_t dir,
685			      int flags,
686			      char *block_buf,
687			      int (*func)(ext2_ino_t	dir,
688					  int	entry,
689					  struct ext2_dir_entry *dirent,
690					  int	offset,
691					  int	blocksize,
692					  char	*buf,
693					  void	*priv_data),
694			      void *priv_data);
695
696/* dupfs.c */
697extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
698
699/* expanddir.c */
700extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
701
702/* ext_attr.c */
703extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
704extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
705				       void *buf);
706extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
707					   char *block_buf,
708					   int adjust, __u32 *newcount);
709
710/* fileio.c */
711extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
712				   struct ext2_inode *inode,
713				   int flags, ext2_file_t *ret);
714extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
715				  int flags, ext2_file_t *ret);
716extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
717extern errcode_t ext2fs_file_close(ext2_file_t file);
718extern errcode_t ext2fs_file_flush(ext2_file_t file);
719extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
720				  unsigned int wanted, unsigned int *got);
721extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
722				   unsigned int nbytes, unsigned int *written);
723extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
724				   int whence, __u64 *ret_pos);
725extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
726				   int whence, ext2_off_t *ret_pos);
727errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
728extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
729extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
730
731/* finddev.c */
732extern char *ext2fs_find_block_device(dev_t device);
733
734/* flushb.c */
735extern errcode_t ext2fs_sync_device(int fd, int flushb);
736
737/* freefs.c */
738extern void ext2fs_free(ext2_filsys fs);
739extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
740extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
741extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
742extern void ext2fs_free_dblist(ext2_dblist dblist);
743extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
744extern void ext2fs_u32_list_free(ext2_u32_list bb);
745
746/* getsize.c */
747extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
748					blk_t *retblocks);
749
750/* getsectsize.c */
751errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
752
753/* imager.c */
754extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
755extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
756extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
757extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
758extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
759extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
760
761/* ind_block.c */
762errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
763errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
764
765/* initialize.c */
766extern errcode_t ext2fs_initialize(const char *name, int flags,
767				   struct ext2_super_block *param,
768				   io_manager manager, ext2_filsys *ret_fs);
769
770/* icount.c */
771extern void ext2fs_free_icount(ext2_icount_t icount);
772extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
773				       unsigned int size,
774				       ext2_icount_t hint, ext2_icount_t *ret);
775extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
776				      unsigned int size,
777				      ext2_icount_t *ret);
778extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
779				     __u16 *ret);
780extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
781					 __u16 *ret);
782extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
783					 __u16 *ret);
784extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
785				     __u16 count);
786extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
787errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
788
789/* inode.c */
790extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
791extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
792					    ext2_ino_t *ino,
793					    struct ext2_inode *inode,
794					    int bufsize);
795extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
796				  ext2_inode_scan *ret_scan);
797extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
798extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
799			       struct ext2_inode *inode);
800extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
801						   int	group);
802extern void ext2fs_set_inode_callback
803	(ext2_inode_scan scan,
804	 errcode_t (*done_group)(ext2_filsys fs,
805				 ext2_inode_scan scan,
806				 dgrp_t group,
807				 void * priv_data),
808	 void *done_group_data);
809extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
810				   int clear_flags);
811extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
812					struct ext2_inode * inode,
813					int bufsize);
814extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
815			    struct ext2_inode * inode);
816extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
817					 struct ext2_inode * inode,
818					 int bufsize);
819extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
820			    struct ext2_inode * inode);
821extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
822			    struct ext2_inode * inode);
823extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
824extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
825
826/* inode_io.c */
827extern io_manager inode_io_manager;
828extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
829					char **name);
830extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
831					 struct ext2_inode *inode,
832					 char **name);
833
834/* ismounted.c */
835extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
836extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
837					  char *mtpt, int mtlen);
838
839/* namei.c */
840extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
841			 int namelen, char *buf, ext2_ino_t *inode);
842extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
843			const char *name, ext2_ino_t *inode);
844errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
845			      const char *name, ext2_ino_t *inode);
846extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
847			ext2_ino_t inode, ext2_ino_t *res_inode);
848
849/* native.c */
850int ext2fs_native_flag(void);
851
852/* newdir.c */
853extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
854				ext2_ino_t parent_ino, char **block);
855
856/* mkdir.c */
857extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
858			      const char *name);
859
860/* mkjournal.c */
861extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
862						  __u32 size, int flags,
863						  char  **ret_jsb);
864extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
865					   ext2_filsys journal_dev);
866extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
867					  int flags);
868
869/* openfs.c */
870extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
871			     unsigned int block_size, io_manager manager,
872			     ext2_filsys *ret_fs);
873extern errcode_t ext2fs_open2(const char *name, const char *io_options,
874			      int flags, int superblock,
875			      unsigned int block_size, io_manager manager,
876			      ext2_filsys *ret_fs);
877extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
878					 dgrp_t i);
879errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
880errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
881errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
882
883/* get_pathname.c */
884extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
885			       char **name);
886
887/* link.c */
888errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
889		      ext2_ino_t ino, int flags);
890errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
891			ext2_ino_t ino, int flags);
892
893/* read_bb.c */
894extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
895				      ext2_badblocks_list *bb_list);
896
897/* read_bb_file.c */
898extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
899				      ext2_badblocks_list *bb_list,
900				      void *priv_data,
901				      void (*invalid)(ext2_filsys fs,
902						      blk_t blk,
903						      char *badstr,
904						      void *priv_data));
905extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
906				     ext2_badblocks_list *bb_list,
907				     void (*invalid)(ext2_filsys fs,
908						     blk_t blk));
909
910/* res_gdt.c */
911extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
912
913/* rs_bitmap.c */
914extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
915					      __u32 new_real_end,
916					      ext2fs_generic_bitmap bmap);
917extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
918					    ext2fs_inode_bitmap bmap);
919extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
920					    ext2fs_block_bitmap bmap);
921extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
922				    ext2fs_generic_bitmap *dest);
923
924/* swapfs.c */
925extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
926				 int has_header);
927extern void ext2fs_swap_super(struct ext2_super_block * super);
928extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
929extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
930				   struct ext2_inode_large *f, int hostorder,
931				   int bufsize);
932extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
933			      struct ext2_inode *f, int hostorder);
934
935/* valid_blk.c */
936extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
937
938/* version.c */
939extern int ext2fs_parse_version_string(const char *ver_string);
940extern int ext2fs_get_library_version(const char **ver_string,
941				      const char **date_string);
942
943/* write_bb_file.c */
944extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
945				      unsigned int flags,
946				      FILE *f);
947
948
949/* inline functions */
950extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
951extern errcode_t ext2fs_free_mem(void *ptr);
952extern errcode_t ext2fs_resize_mem(unsigned long old_size,
953				   unsigned long size, void *ptr);
954extern void ext2fs_mark_super_dirty(ext2_filsys fs);
955extern void ext2fs_mark_changed(ext2_filsys fs);
956extern int ext2fs_test_changed(ext2_filsys fs);
957extern void ext2fs_mark_valid(ext2_filsys fs);
958extern void ext2fs_unmark_valid(ext2_filsys fs);
959extern int ext2fs_test_valid(ext2_filsys fs);
960extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
961extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
962extern int ext2fs_test_ib_dirty(ext2_filsys fs);
963extern int ext2fs_test_bb_dirty(ext2_filsys fs);
964extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
965extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
966extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group);
967extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
968extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
969				      struct ext2_inode *inode);
970extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
971
972/*
973 * The actual inlined functions definitions themselves...
974 *
975 * If NO_INLINE_FUNCS is defined, then we won't try to do inline
976 * functions at all!
977 */
978#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
979#ifdef INCLUDE_INLINE_FUNCS
980#define _INLINE_ extern
981#else
982#ifdef __GNUC__
983#define _INLINE_ extern __inline__
984#else				/* For Watcom C */
985#define _INLINE_ extern inline
986#endif
987#endif
988
989#ifndef EXT2_CUSTOM_MEMORY_ROUTINES
990#include <string.h>
991/*
992 *  Allocate memory
993 */
994_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
995{
996	void **pp = (void **)ptr;
997
998	*pp = malloc(size);
999	if (!*pp)
1000		return EXT2_ET_NO_MEMORY;
1001	return 0;
1002}
1003
1004/*
1005 * Free memory
1006 */
1007_INLINE_ errcode_t ext2fs_free_mem(void *ptr)
1008{
1009	void **pp = (void **)ptr;
1010
1011	free(*pp);
1012	*pp = 0;
1013	return 0;
1014}
1015
1016/*
1017 *  Resize memory
1018 */
1019_INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
1020				     unsigned long size, void *ptr)
1021{
1022	void *p;
1023
1024	/* Use "memcpy" for pointer assignments here to avoid problems
1025	 * with C99 strict type aliasing rules. */
1026	memcpy(&p, ptr, sizeof (p));
1027	p = realloc(p, size);
1028	if (!p)
1029		return EXT2_ET_NO_MEMORY;
1030	memcpy(ptr, &p, sizeof (p));
1031	return 0;
1032}
1033#endif	/* Custom memory routines */
1034
1035/*
1036 * Mark a filesystem superblock as dirty
1037 */
1038_INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
1039{
1040	fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
1041}
1042
1043/*
1044 * Mark a filesystem as changed
1045 */
1046_INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
1047{
1048	fs->flags |= EXT2_FLAG_CHANGED;
1049}
1050
1051/*
1052 * Check to see if a filesystem has changed
1053 */
1054_INLINE_ int ext2fs_test_changed(ext2_filsys fs)
1055{
1056	return (fs->flags & EXT2_FLAG_CHANGED);
1057}
1058
1059/*
1060 * Mark a filesystem as valid
1061 */
1062_INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
1063{
1064	fs->flags |= EXT2_FLAG_VALID;
1065}
1066
1067/*
1068 * Mark a filesystem as NOT valid
1069 */
1070_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
1071{
1072	fs->flags &= ~EXT2_FLAG_VALID;
1073}
1074
1075/*
1076 * Check to see if a filesystem is valid
1077 */
1078_INLINE_ int ext2fs_test_valid(ext2_filsys fs)
1079{
1080	return (fs->flags & EXT2_FLAG_VALID);
1081}
1082
1083/*
1084 * Mark the inode bitmap as dirty
1085 */
1086_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
1087{
1088	fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
1089}
1090
1091/*
1092 * Mark the block bitmap as dirty
1093 */
1094_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
1095{
1096	fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
1097}
1098
1099/*
1100 * Check to see if a filesystem's inode bitmap is dirty
1101 */
1102_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
1103{
1104	return (fs->flags & EXT2_FLAG_IB_DIRTY);
1105}
1106
1107/*
1108 * Check to see if a filesystem's block bitmap is dirty
1109 */
1110_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
1111{
1112	return (fs->flags & EXT2_FLAG_BB_DIRTY);
1113}
1114
1115/*
1116 * Return the group # of a block
1117 */
1118_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
1119{
1120	return (blk - fs->super->s_first_data_block) /
1121		fs->super->s_blocks_per_group;
1122}
1123
1124/*
1125 * Return the group # of an inode number
1126 */
1127_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
1128{
1129	return (ino - 1) / fs->super->s_inodes_per_group;
1130}
1131
1132/*
1133 * Return the first block (inclusive) in a group
1134 */
1135_INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
1136{
1137	return fs->super->s_first_data_block +
1138		(group * fs->super->s_blocks_per_group);
1139}
1140
1141/*
1142 * Return the last block (inclusive) in a group
1143 */
1144_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
1145{
1146	return (group == fs->group_desc_count - 1 ?
1147		fs->super->s_blocks_count - 1 :
1148		ext2fs_group_first_block(fs, group) +
1149			(fs->super->s_blocks_per_group - 1));
1150}
1151
1152_INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
1153					struct ext2_inode *inode)
1154{
1155       return inode->i_blocks -
1156              (inode->i_file_acl ? fs->blocksize >> 9 : 0);
1157}
1158
1159/*
1160 * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b)
1161 */
1162_INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
1163{
1164	if (!a)
1165		return 0;
1166	return ((a - 1) / b) + 1;
1167}
1168#undef _INLINE_
1169#endif
1170
1171#ifdef __cplusplus
1172}
1173#endif
1174
1175#endif /* _EXT2FS_EXT2FS_H */
1176