1 \input texinfo @c -*-texinfo-*-
3 @setfilename libext2fs.info
4 @settitle The EXT2FS Library (version 1.26)
6 @comment %**end of header
9 @dircategory Development
12 * libext2fs: (libext2fs.info). The EXT2FS library.
23 @c Note: the edition number is listed in *three* places; please update
24 @c all three. Also, update the month and year where appropriate.
26 @c ==> Update edition number for settitle and subtitle, and in the
27 @c ==> following paragraph; update date, too.
31 This file documents the ext2fs library, a library for manipulating the
34 Copyright (C) 1997, 1998, 1999, 2000, 2001 Theodore Ts'o
36 Permission is granted to make and distribute verbatim copies of
37 this manual provided the copyright notice and this permission notice
38 are preserved on all copies.
41 Permission is granted to process this file through TeX and print the
42 results, provided the printed document carries copying permission
43 notice identical to this one except for the removal of this paragraph
44 (this paragraph not being relevant to the printed manual).
47 Permission is granted to copy and distribute modified versions of this
48 manual under the conditions for verbatim copying, provided that the entire
49 resulting derived work is distributed under the terms of a permission
50 notice identical to this one.
52 Permission is granted to copy and distribute translations of this manual
53 into another language, under the above conditions for modified versions,
54 except that this permission notice may be stated in a translation approved
60 @c use the new format for titles
62 @title The EXT2FS Library
63 @subtitle The EXT2FS Library
64 @subtitle Version 1.26
65 @subtitle "December 2001
67 @author by Theodore Ts'o
69 @c Include the Distribution inside the titlepage so
70 @c that headings are turned off.
75 \global\baselineskip=13pt
79 @vskip 0pt plus 1filll
80 Copyright @copyright{} 1997, 1998, 1999, 2000, 2001 Theodore Ts'o
84 Permission is granted to make and distribute verbatim copies of
85 this manual provided the copyright notice and this permission notice
86 are preserved on all copies.
88 Permission is granted to copy and distribute modified versions of this
89 manual under the conditions for verbatim copying, provided that the entire
90 resulting derived work is distributed under the terms of a permission
91 notice identical to this one.
93 Permission is granted to copy and distribute translations of this manual
94 into another language, under the above conditions for modified versions,
95 except that this permission notice may be stated in a translation approved
101 @node Top, Introduction to the EXT2FS Library, (dir), (dir)
103 @top The EXT2FS Library
105 This manual documents the EXT2FS Library, version 1.26.
110 * Introduction to the EXT2FS Library::
111 * EXT2FS Library Functions::
116 @c ----------------------------------------------------------------------
118 @node Introduction to the EXT2FS Library, EXT2FS Library Functions, Top, Top
119 @comment node-name, next, previous, up
120 @chapter Introduction to the EXT2FS Library
122 The EXT2FS library is designed to allow user-level programs to
123 manipulate an ext2 filesystem.
125 @node EXT2FS Library Functions, Concept Index, Introduction to the EXT2FS Library, Top
126 @comment node-name, next, previous, up
127 @chapter EXT2FS Library Functions
130 * Filesystem-level functions::
132 * Directory functions::
134 * EXT2 data abstractions::
135 * Byte-swapping functions::
139 @c ----------------------------------------------------------------------
141 @node Filesystem-level functions, Inode Functions, EXT2FS Library Functions, EXT2FS Library Functions
142 @comment node-name, next, previous, up
143 @section Filesystem-level functions
145 The following functions operate on a filesystem handle. Most EXT2FS
146 Library functions require a filesystem handle as their first argument.
147 There are two functions which create a filesystem handle,
148 @code{ext2fs_open} and @code{ext2fs_initialize}.
150 The filesystem can also be closed using @code{ext2fs_close}, and any
151 changes to the superblock and group descripts can be written out to disk
152 using @code{ext2fs_flush}.
155 * Opening an ext2 filesystem::
156 * Closing and flushing out changes::
157 * Initializing a filesystem::
158 * Filesystem flag functions::
161 @c ----------------------------------------------------------------------
163 @node Opening an ext2 filesystem, Closing and flushing out changes, Filesystem-level functions, Filesystem-level functions
164 @comment node-name, next, previous, up
165 @subsection Opening an ext2 filesystem
167 Most libext2fs functions take a filesystem handle of type
168 @code{ext2_filsys}. A filesystem handle is created either by opening
169 an existing function using @code{ext2fs_open}, or by initializing a new
170 filesystem using @code{ext2fs_initialize}.
172 @deftypefun errcode_t ext2fs_open (const char *@var{name}, int @var{flags}, int @var{superblock}, int @var{block_size}, io_manager @var{manager}, ext2_filsys *@var{ret_fs})
174 Opens a filesystem named @var{name}, using the the io_manager
175 @var{manager} to define the input/output routines needed to read and
176 write the filesystem. In the case of the @code{unix_io} io_manager,
177 @var{name} is interpreted as the Unix filename of the filesystem image.
178 This is often a device file, such as @file{/dev/hda1}.
180 The @var{superblock} parameter specifies the block number of the
181 superblock which should be used when opening the filesystem.
182 If @var{superblock} is zero, @code{ext2fs_open} will use the primary
183 superblock located at offset 1024 bytes from the start of the filesystem
186 The @var{block_size} parameter specifies the block size used by the
187 filesystem. Normally this is determined automatically from the
188 filesystem uperblock. If @var{block_size} is non-zero, it must match
189 the block size found in the superblock, or the error
190 @code{EXT2_ET_UNEXPECTED_BLOCK_SIZE} will be returned. The
191 @var{block_size} parameter is also used to help fund the superblock when
192 @var{superblock} is non-zero.
194 The @var{flags} argument contains a bitmask of flags which control how
195 the filesystem open should be handled.
199 Open the filesystem for reading and writing. Without this flag, the
200 filesystem is opened for reading only.
202 @item EXT2_FLAG_FORCE
203 Open the filesystem regardless of the feature sets listed in the
209 @c ----------------------------------------------------------------------
211 @node Closing and flushing out changes, Initializing a filesystem, Opening an ext2 filesystem, Filesystem-level functions
212 @comment node-name, next, previous, up
213 @subsection Closing and flushing out changes
215 @deftypefun errcode_t ext2fs_flush (ext2_filsys @var{fs})
217 Write any changes to the high-level filesystem data structures in the
218 @var{fs} filesystem. The following data structures will be written out:
221 @item The filesystem superblock
222 @item The filesystem group descriptors
223 @item The filesystem bitmaps, if read in via @code{ext2fs_read_bitmaps}.
228 @deftypefun void ext2fs_free (ext2_filsys @var{fs})
230 Close the io_manager abstraction for @var{fs} and release all memory
231 associated with the filesystem handle.
234 @deftypefun errcode_t ext2fs_close (ext2_filsys @var{fs})
236 Flush out any changes to the high-level filesystem data structures using
237 @code{ext2fs_flush} if the filesystem is marked dirty; then close and
238 free the filesystem using @code{ext2fs_free}.
242 @c ----------------------------------------------------------------------
244 @node Initializing a filesystem, Filesystem flag functions, Closing and flushing out changes, Filesystem-level functions
245 @comment node-name, next, previous, up
246 @subsection Initializing a filesystem
248 An ext2 filesystem is initializing by the @code{mke2fs} program. The
249 two functions described here, @code{ext2fs_initialize} and
250 @code{ext2fs_allocate_tables} do much of the initial work for setting up
251 a filesystem. However, they don't do the whole job. @code{mke2fs}
252 calls @code{ext2fs_initialize} to set up the filesystem superblock, and
253 calls @code{ext2fs_allocate_tables} to allocate space for the inode
254 table, and the inode and block bitmaps. In addition, @code{mke2fs} must
255 also initialize the inode tables by clearing them with zeros, create the
256 root and lost+found directories, and reserve the reserved inodes.
258 @deftypefun errcode_t ext2fs_initialize (const char *@var{name}, int @var{flags}, struct ext2_super_block *@var{param}, io_manager @var{manager}, ext2_filsys *@var{ret_fs})
260 This function is used by the @code{mke2fs} program to initialize a
261 filesystem. The @code{ext2fs_initialize} function creates a filesystem
262 handle which is returned in @var{ret_fs} that has been properly setup
263 for a filesystem to be located in @var{name}, using the io_manager
264 @var{manager}. The prototype superblock in @var{param} is used to
265 supply parameters such as the number of blocks in the filesystem, the
268 The @code{ext2fs_initialize} function does not actually do any I/O; that
269 will be done when the application program calls @code{ext2fs_close} or
270 @code{ext2fs_flush}. Also, this function only initializes the
271 superblock and group descriptor structures. It does not create the
272 inode table or the root directory. This must be done by the calling
273 application, such as @code{mke2fs}.
275 The following values may be set in the @var{param} prototype superblock;
276 if a value of 0 is found in a field, @code{ext2fs_initialize} will use a
277 default value. The calling application should zero out the prototype
278 entire superblock, and then fill in any appropriate values.
283 The number of blocks in the filesystem. This parameter is mandatory and
284 must be set by the calling application.
287 The number of inodes in the filesystem. The
288 default value is determined by calculating the size of the filesystem,
289 and creating one inode for every 4096 bytes.
291 @item s_r_blocks_count
292 The number of blocks which should be reserved for the superuser. The
293 default value is zero blocks.
295 @item s_log_block_size
296 The blocksize of the filesystem. Valid values are 0 (1024 bytes), 1
297 (2048 bytes), or 2 (4096 bytes). The default blocksize is 1024 bytes.
299 @item s_log_frag_size
300 The size of fragments. The ext2 filesystem does not support fragments
301 (and may never support fragments). Currently this field must be the
302 same as @code{s_log_block_size}.
304 @item s_first_data_block
305 The first data block for the filesystem. For filesystem with a
306 blocksize of 1024 bytes, this value must be at least 1, since the
307 superblock is located in block number 1. For filesystems with larger
308 blocksizes, the superblock is still located at an offset of 1024 bytes,
309 so the superblock is located in block number 0. By default, this value
310 is set to 1 for filesystems with a block size of 1024 bytes, or 0 for
311 filesystems with larger blocksizes.
313 @item s_max_mnt_count
314 This field defines the number of times that the filesystem can be
315 mounted before it should be checked using @code{e2fsck}. When
316 @code{e2fsck} is run without the @samp{-f} option, @code{e2fsck} will
317 skip the filesystem check if the number of times that the filesystem has
318 been mounted is less than @code{s_max_mnt_count} and if the interval
319 between the last time a filesystem check was performed and the current
320 time is less than @code{s_checkinterval} (see below). The default value
321 of @code{s_max_mnt_count} is 20.
323 @item s_checkinterval
324 This field defines the minimal interval between filesystem checks. See
325 the previous entry for a discussion of how this field is used by
326 @code{e2fsck}. The default value of this field is 180 days (six
330 This field defines the behavior which should be used by the kernel of
331 errors are detected in the filesystem. Possible values include:
334 @item EXT2_ERRORS_CONTINUE
335 Continue execution when errors are detected.
338 Remount the filesystem read-only.
340 @item EXT2_ERRORS_PANIC
345 The default behavior is @samp{EXT2_ERRORS_CONTINUE}.
351 @deftypefun errcode_t ext2fs_allocate_tables (ext2_filsys @var{fs})
352 Allocate space for the inode table and the block and inode bitmaps. The
353 inode tables and block and inode bitmaps aren't actually initialized;
354 this function just allocates the space for them.
357 @c ----------------------------------------------------------------------
359 @node Filesystem flag functions, , Initializing a filesystem, Filesystem-level functions
360 @comment node-name, next, previous, up
361 @subsection Filesystem flag functions
363 The filesystem handle has a number of flags which can be manipulated
364 using the following function. Some of these flags affect how the
365 libext2fs filesystem behaves; others are provided solely for the
366 application's convenience.
368 @deftypefun void ext2fs_mark_changed (ext2_filsys @var{fs})
369 @deftypefunx int ext2fs_test_changed (ext2_filsys @var{fs})
370 This flag indicates whether or not the filesystem has been changed.
371 It is not used by the ext2fs library.
374 @deftypefun void ext2fs_mark_super_dirty (ext2_filsys @var{fs})
375 Mark the filesystem @var{fs} as being dirty; this will cause
376 the superblock information to be flushed out when @code{ext2fs_close} is
377 called. @code{ext2fs_mark_super_dirty} will also set the filesystem
378 changed flag. The dirty flag is automatically cleared by
379 @code{ext2fs_flush} when the superblock is written to disk.
382 @deftypefun void ext2fs_mark_valid (ext2_filsys @var{fs})
383 @deftypefunx void ext2fs_unmark_valid (ext2_filsys @var{fs})
384 @deftypefunx int ext2fs_test_valid (ext2_filsys @var{fs})
385 This flag indicates whether or not the filesystem is free of errors.
386 It is not used by libext2fs, and is solely for the application's
390 @deftypefun void ext2fs_mark_ib_dirty (ext2_filsys @var{fs})
391 @deftypefunx void ext2fs_mark_bb_dirty (ext2_filsys @var{fs})
392 @deftypefunx int ext2fs_test_ib_dirty (ext2_filsys @var{fs})
393 @deftypefunx int ext2fs_test_bb_dirty (ext2_filsys @var{fs})
394 These flags indicate whether or not the inode or block bitmaps have been
395 modified. If the flag is set, it will cause the appropriate bitmap
396 to be written when the filesystem is closed or flushed.
401 @c ----------------------------------------------------------------------
403 @node Inode Functions, Directory functions, Filesystem-level functions, EXT2FS Library Functions
404 @comment node-name, next, previous, up
405 @section Inode Functions
408 * Reading and writing inodes::
409 * Iterating over inodes in a filesystem::
410 * Iterating over blocks in an inode::
411 * Inode Convenience Functions::
414 @c ----------------------------------------------------------------------
416 @node Reading and writing inodes, Iterating over inodes in a filesystem, Inode Functions, Inode Functions
417 @comment node-name, next, previous, up
418 @subsection Reading and writing inodes
420 @deftypefun errcode_t ext2fs_read_inode (ext2_filsys @var{fs}, ext2_ino_t @var{ino}, struct ext2_inode *@var{inode})
421 Read the inode number @var{ino} into @var{inode}.
424 @deftypefun errcode_t ext2fs_write_inode (ext2_filsys @var{fs}, ext2_ino_t @var{ino}, struct ext2_inode *@var{inode})
425 Write @var{inode} to inode @var{ino}.
429 @c ----------------------------------------------------------------------
431 @node Iterating over inodes in a filesystem, Iterating over blocks in an inode, Reading and writing inodes, Inode Functions
432 @comment node-name, next, previous, up
433 @subsection Iterating over inodes in a filesystem
435 The inode_scan abstraction is useful for iterating over all the inodes
438 @deftypefun errcode_t ext2fs_open_inode_scan (ext2_filsys @var{fs}, int @var{buffer_blocks}, ext2_inode_scan *@var{scan})
439 Initialize the iteration variable @var{scan}. This variable is used by
440 @code{ext2fs_get_next_inode}. The @var{buffer_blocks} parameter
441 controls how many blocks of the inode table are read in at a time. A
442 large number of blocks requires more memory, but reduces the overhead in
443 seeking and reading from the disk. If @var{buffer_blocks} is zero, a
444 suitable default value will be used.
447 @deftypefun void ext2fs_close_inode_scan (ext2_inode_scan @var{scan})
448 Release the memory associated with @var{scan} and invalidate it.
451 @deftypefun errcode_t ext2fs_get_next_inode (ext2_inode_scan @var{scan}, ext2_ino_t *@var{ino}, struct ext2_inode *@var{inode})
453 This function returns the next inode from the filesystem; the inode
454 number of the inode is stored in @var{ino}, and the inode is stored in
457 If the inode is located in a block that has been marked as bad,
458 @code{ext2fs_get_next_inode} will return the error
459 @code{EXT2_ET_BAD_BLOCK_IN_INODE_TABLE}.
462 @deftypefun errcode_t ext2fs_inode_scan_goto_blockgroup (ext2_inode_scan @var{scan}, int @var{group})
463 Start the inode scan at a particular ext2 blockgroup, @var{group}.
464 This function may be safely called at any time while @var{scan} is valid.
467 @deftypefun void ext2fs_set_inode_callback (ext2_inode_scan @var{scan}, errcode_t (*done_group)(ext2_filsys @var{fs}, ext2_inode_scan @var{scan}, dgrp_t @var{group}, void * @var{private}), void *@var{done_group_data})
468 Register a callback function which will be called by
469 @code{ext2_get_next_inode} when all of the inodes in a block group have
473 @deftypefun int ext2fs_inode_scan_flags (ext2_inode_scan @var{scan}, int @var{set_flags}, int @var{clear_flags})
475 Set the scan_flags @var{set_flags} and clear the scan_flags @var{clear_flags}.
476 The following flags can be set using this interface:
480 @item EXT2_SF_SKIP_MISSING_ITABLE
481 When a block group is missing an inode table, skip it. If this flag is
482 not set @code{ext2fs_get_next_inode} will return the error
483 EXT2_ET_MISSING_INODE_TABLE.
489 @c ----------------------------------------------------------------------
491 @node Iterating over blocks in an inode, Inode Convenience Functions, Iterating over inodes in a filesystem, Inode Functions
492 @comment node-name, next, previous, up
493 @subsection Iterating over blocks in an inode
495 @deftypefun errcode_t ext2fs_block_iterate (ext2_filsys @var{fs}, ext2_ino_t @var{ino}, int @var{flags}, char *block_buf, int (*func)(ext2_filsys @var{fs}, blk_t *@var{blocknr}, int @var{blockcnt}, void *@var{private}), void *@var{private})
498 @deftypefun errcode_t ext2fs_block_iterate2 (ext2_filsys @var{fs}, ext2_ino_t @var{ino}, int @var{flags}, char *@var{block}_buf, int (*func)(ext2_filsys @var{fs}, blk_t *@var{blocknr}, e2_blkcnt_t @var{blockcnt}, blk_t @var{ref_blk}, int @var{ref_offset}, void *@var{private}), void *@var{private})
501 @c ----------------------------------------------------------------------
503 @node Inode Convenience Functions, , Iterating over blocks in an inode, Inode Functions
504 @comment node-name, next, previous, up
505 @subsection Convenience functions for Inodes
507 @deftypefun errcode_t ext2fs_get_blocks (ext2_filsys @var{fs}, ext2_ino_t @var{ino}, blk_t *@var{blocks})
509 Returns an array of blocks corresponding to the direct,
510 indirect, doubly indirect, and triply indirect blocks as stored in the
514 @deftypefun errcode_t ext2fs_check_directory (ext2_filsys @var{fs}, ext2_ino_t @var{ino})
515 Returns 0 if @var{ino} is a directory, and @code{ENOTDIR} if it is not.
518 @deftypefun int ext2_inode_has_valid_blocks (struct ext2_inode *@var{inode})
520 Returns 1 if the inode's block entries actually valid block entries, and
521 0 if not. Inodes which represent devices and fast symbolic links do not
522 contain valid block entries.
525 @c ----------------------------------------------------------------------
527 @node Directory functions, Bitmap Functions, Inode Functions, EXT2FS Library Functions
528 @comment node-name, next, previous, up
529 @section Directory functions
532 * Directory block functions::
533 * Iterating over a directory::
534 * Creating and expanding directories::
535 * Creating and removing directory entries::
536 * Looking up filenames::
537 * Translating inode numbers to filenames::
540 @c ----------------------------------------------------------------------
542 @node Directory block functions, Iterating over a directory, Directory functions, Directory functions
543 @comment node-name, next, previous, up
544 @subsection Directory block functions
546 @deftypefun errcode_t ext2fs_read_dir_block (ext2_filsys @var{fs}, blk_t @var{block}, void *@var{buf})
549 @deftypefun errcode_t ext2fs_write_dir_block (ext2_filsys @var{fs}, blk_t @var{block}, void *@var{buf})
552 @deftypefun errcode_t ext2fs_new_dir_block (ext2_filsys @var{fs}, ext2_ino_t @var{dir}_ino, ext2_ino_t @var{parent_ino}, char **@var{block})
555 @c ----------------------------------------------------------------------
557 @node Iterating over a directory, Creating and expanding directories, Directory block functions, Directory functions
558 @comment node-name, next, previous, up
559 @subsection Iterating over a directory
561 @deftypefun errcode_t ext2fs_dir_iterate (ext2_filsys @var{fs}, ext2_ino_t @var{dir}, int @var{flags}, char *@var{block_buf}, int (*@var{func})(struct ext2_dir_entry *@var{dirent}, int @var{offset}, int @var{blocksize}, char *@var{buf}, void *@var{private}), void *@var{private})
564 @c ----------------------------------------------------------------------
566 @node Creating and expanding directories, Creating and removing directory entries, Iterating over a directory, Directory functions
567 @comment node-name, next, previous, up
568 @subsection Creating and expanding directories
570 @deftypefun errcode_t ext2fs_mkdir (ext2_filsys @var{fs}, ext2_ino_t @var{parent}, ext2_ino_t @var{inum}, const char *@var{name})
573 @deftypefun errcode_t ext2fs_expand_dir (ext2_filsys @var{fs}, ext2_ino_t @var{dir})
576 @c ----------------------------------------------------------------------
578 @node Creating and removing directory entries, Looking up filenames, Creating and expanding directories, Directory functions
579 @comment node-name, next, previous, up
580 @subsection Creating and removing directory entries
582 @deftypefun errcode_t ext2fs_link (ext2_filsys @var{fs}, ext2_ino_t @var{dir}, const char *@var{name}, ext2_ino_t @var{ino}, int flags)
585 @deftypefun errcode_t ext2fs_unlink (ext2_filsys @var{fs}, ext2_ino_t @var{dir}, const char *@var{name}, ext2_ino_t @var{ino}, int @var{flags})
588 @c ----------------------------------------------------------------------
590 @node Looking up filenames, Translating inode numbers to filenames, Creating and removing directory entries, Directory functions
591 @comment node-name, next, previous, up
592 @subsection Looking up filenames
594 @deftypefun errcode_t ext2fs_lookup (ext2_filsys @var{fs}, ext2_ino_t @var{dir}, const char *@var{name}, int @var{namelen}, char *@var{buf}, ext2_ino_t *@var{inode})
597 @deftypefun errcode_t ext2fs_namei (ext2_filsys @var{fs}, ext2_ino_t @var{root}, ext2_ino_t @var{cwd}, const char *@var{name}, ext2_ino_t *@var{inode})
600 @deftypefun errcode_t ext2fs_namei_follow (ext2_filsys @var{fs}, ext2_ino_t @var{root}, ext2_ino_t @var{cwd}, const char *@var{name}, ext2_ino_t *@var{inode})
603 @deftypefun errcode_t ext2fs_follow_link (ext2_filsys @var{fs}, ext2_ino_t @var{root}, ext2_ino_t @var{cwd}, ext2_ino_t @var{inode}, ext2_ino_t *@var{res}_inode)
606 @c ----------------------------------------------------------------------
608 @node Translating inode numbers to filenames, , Looking up filenames, Directory functions
609 @comment node-name, next, previous, up
610 @subsection Translating inode numbers to filenames
612 @deftypefun errcode_t ext2fs_get_pathname (ext2_filsys @var{fs}, ext2_ino_t @var{dir}, ext2_ino_t @var{ino}, char **@var{name})
616 @c ----------------------------------------------------------------------
618 @node Bitmap Functions, EXT2 data abstractions, Directory functions, EXT2FS Library Functions
619 @comment node-name, next, previous, up
620 @section Bitmap Functions
623 * Reading and Writing Bitmaps::
624 * Allocating Bitmaps::
626 * Bitmap Operations::
627 * Comparing bitmaps::
628 * Modifying Bitmaps::
633 @c ----------------------------------------------------------------------
635 @node Reading and Writing Bitmaps, Allocating Bitmaps, Bitmap Functions, Bitmap Functions
636 @comment node-name, next, previous, up
637 @subsection Reading and Writing Bitmaps
639 @deftypefun errcode_t ext2fs_write_inode_bitmap (ext2_filsys @var{fs})
642 @deftypefun errcode_t ext2fs_write_block_bitmap (ext2_filsys @var{fs})
645 @deftypefun errcode_t ext2fs_read_inode_bitmap (ext2_filsys @var{fs})
648 @deftypefun errcode_t ext2fs_read_block_bitmap (ext2_filsys @var{fs})
651 @deftypefun errcode_t ext2fs_read_bitmaps (ext2_filsys @var{fs})
654 @deftypefun errcode_t ext2fs_write_bitmaps (ext2_filsys @var{fs})
657 @c ----------------------------------------------------------------------
659 @node Allocating Bitmaps, Free bitmaps, Reading and Writing Bitmaps, Bitmap Functions
660 @comment node-name, next, previous, up
661 @subsection Allocating Bitmaps
663 @deftypefun errcode_t ext2fs_allocate_generic_bitmap (__u32 @var{start}, __u32 @var{end}, _u32 @var{real_end}, const char *@var{descr}, ext2fs_generic_bitmap *@var{ret})
666 @deftypefun errcode_t ext2fs_allocate_block_bitmap (ext2_filsys @var{fs}, const char *@var{descr}, ext2fs_block_bitmap *@var{ret})
669 @deftypefun errcode_t ext2fs_allocate_inode_bitmap (ext2_filsys @var{fs}, const char *@var{descr}, ext2fs_inode_bitmap *@var{ret})
672 @c ----------------------------------------------------------------------
674 @node Free bitmaps, Bitmap Operations, Allocating Bitmaps, Bitmap Functions
675 @comment node-name, next, previous, up
676 @subsection Freeing bitmaps
679 @deftypefun void ext2fs_free_generic_bitmap (ext2fs_inode_bitmap @var{bitmap})
682 @deftypefun void ext2fs_free_block_bitmap (ext2fs_block_bitmap @var{bitmap})
685 @deftypefun void ext2fs_free_inode_bitmap (ext2fs_inode_bitmap @var{bitmap})
689 @c ----------------------------------------------------------------------
691 @node Bitmap Operations, Comparing bitmaps, Free bitmaps, Bitmap Functions
692 @comment node-name, next, previous, up
693 @subsection Bitmap Operations
695 @deftypefun void ext2fs_mark_block_bitmap (ext2fs_block_bitmap @var{bitmap}, blk_t @var{block})
697 @deftypefunx void ext2fs_unmark_block_bitmap (ext2fs_block_bitmap @var{bitmap}, blk_t @var{block})
699 @deftypefunx int ext2fs_test_block_bitmap (ext2fs_block_bitmap @var{bitmap}, blk_t @var{block})
701 These functions set, clear, and test bits in a block bitmap @var{bitmap}.
705 @deftypefun void ext2fs_mark_inode_bitmap (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{inode})
707 @deftypefunx void ext2fs_unmark_inode_bitmap (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{inode})
709 @deftypefunx int ext2fs_test_inode_bitmap (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{inode})
711 These functions set, clear, and test bits in an inode bitmap @var{bitmap}.
714 @deftypefun void ext2fs_fast_mark_block_bitmap (ext2fs_block_bitmap @var{bitmap}, blk_t @var{block})
716 @deftypefunx void ext2fs_fast_unmark_block_bitmap (ext2fs_block_bitmap @var{bitmap}, blk_t @var{block})
718 @deftypefunx int ext2fs_fast_test_block_bitmap (ext2fs_block_bitmap @var{bitmap}, blk_t @var{block})
720 @deftypefunx void ext2fs_fast_mark_inode_bitmap (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{inode})
722 @deftypefunx void ext2fs_fast_unmark_inode_bitmap (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{inode})
724 @deftypefunx int ext2fs_fast_test_inode_bitmap (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{inode})
726 These ``fast'' functions are like their normal counterparts; however,
727 they are implemented as inline functions and do not perform bounds
728 checks on the inode number or block number; they are assumed to be
729 correct. They should only be used in speed-critical applications, where
730 the inode or block number has already been validated by other means.
733 @deftypefun blk_t ext2fs_get_block_bitmap_start (ext2fs_block_bitmap @var{bitmap})
734 @deftypefunx ext2_ino_t ext2fs_get_inode_bitmap_start (ext2fs_inode_bitmap @var{bitmap})
735 Return the first inode or block which is stored in the bitmap.
738 @deftypefun blk_t ext2fs_get_block_bitmap_end (ext2fs_block_bitmap @var{bitmap})
739 @deftypefunx ext2_ino_t ext2fs_get_inode_bitmap_end (ext2fs_inode_bitmap @var{bitmap})
741 Return the first inode or block which is stored in the bitmap.
745 @c ----------------------------------------------------------------------
747 @node Comparing bitmaps, Modifying Bitmaps, Bitmap Operations, Bitmap Functions
748 @comment node-name, next, previous, up
749 @subsection Comparing bitmaps
751 @deftypefun errcode_t ext2fs_compare_block_bitmap (ext2fs_block_bitmap @var{bm1}, ext2fs_block_bitmap @var{bm2})
754 @deftypefun errcode_t ext2fs_compare_inode_bitmap (ext2fs_inode_bitmap @var{bm1}, ext2fs_inode_bitmap @var{bm2})
758 @c ----------------------------------------------------------------------
760 @node Modifying Bitmaps, Resizing Bitmaps, Comparing bitmaps, Bitmap Functions
761 @comment node-name, next, previous, up
762 @subsection Modifying Bitmaps
764 @deftypefun errcode_t ext2fs_fudge_inode_bitmap_end (ext2fs_inode_bitmap @var{bitmap}, ext2_ino_t @var{end}, ext2_ino_t *@var{oend})
767 @deftypefun errcode_t ext2fs_fudge_block_bitmap_end (ext2fs_block_bitmap @var{bitmap}, blk_t @var{end}, blk_t *@var{oend})
770 @c ----------------------------------------------------------------------
772 @node Resizing Bitmaps, Clearing Bitmaps, Modifying Bitmaps, Bitmap Functions
773 @comment node-name, next, previous, up
774 @subsection Resizing Bitmaps
776 @deftypefun errcode_t ext2fs_resize_generic_bitmap (__u32 @var{new_end}, __u32 @var{new_real_end}, ext2fs_generic_bitmap @var{bmap})
779 @deftypefun errcode_t ext2fs_resize_inode_bitmap (__u32 @var{new_end}, __u32 @var{new_real_end}, ext2fs_inode_bitmap @var{bmap})
782 @deftypefun errcode_t ext2fs_resize_block_bitmap (__u32 @var{new_end}, __u32 @var{new_real_end}, ext2fs_block_bitmap @var{bmap})
786 @c ----------------------------------------------------------------------
788 @node Clearing Bitmaps, , Resizing Bitmaps, Bitmap Functions
789 @comment node-name, next, previous, up
790 @subsection Clearing Bitmaps
792 @deftypefun void ext2fs_clear_inode_bitmap (ext2fs_inode_bitmap @var{bitmap})
795 @deftypefun void ext2fs_clear_block_bitmap (ext2fs_block_bitmap @var{bitmap})
799 @c ----------------------------------------------------------------------
801 @node EXT2 data abstractions, Byte-swapping functions, Bitmap Functions, EXT2FS Library Functions
802 @comment node-name, next, previous, up
803 @section EXT2 data abstractions
805 The ext2 library has a number of abstractions which are useful for ext2
809 * Badblocks list management::
810 * Directory-block list management::
811 * Inode count functions::
814 @c ----------------------------------------------------------------------
816 @node Badblocks list management, Directory-block list management, EXT2 data abstractions, EXT2 data abstractions
817 @comment node-name, next, previous, up
818 @subsection Badblocks list management
821 @deftypefun errcode_t ext2fs_badblocks_list_create (ext2_badblocks_list *@var{ret}, int @var{size})
824 @deftypefun void ext2fs_badblocks_list_free (ext2_badblocks_list @var{bb})
827 @deftypefun errcode_t ext2fs_badblocks_list_add (ext2_badblocks_list @var{bb}, blk_t @var{blk})
830 @deftypefun int ext2fs_badblocks_list_test (ext2_badblocks_list @var{bb}, blk_t @var{blk})
833 @deftypefun errcode_t ext2fs_badblocks_list_iterate_begin (ext2_badblocks_list @var{bb}, ext2_badblocks_iterate *@var{ret})
836 @deftypefun int ext2fs_badblocks_list_iterate (ext2_badblocks_iterate iter, blk_t *@var{blk})
839 @deftypefun void ext2fs_badblocks_list_iterate_end (ext2_badblocks_iterate @var{iter})
842 @deftypefun errcode_t ext2fs_update_bb_inode (ext2_filsys @var{fs}, ext2_badblocks_list @var{bb_list})
845 @deftypefun errcode_t ext2fs_read_bb_inode (ext2_filsys @var{fs}, ext2_badblocks_list *@var{bb_list})
848 @deftypefun errcode_t ext2fs_read_bb_FILE (ext2_filsys @var{fs}, FILE *f, ext2_badblocks_list *@var{bb_list}, void (*invalid)(ext2_filsys @var{fs}, blk_t @var{blk}))
852 @c ----------------------------------------------------------------------
854 @node Directory-block list management, Inode count functions, Badblocks list management, EXT2 data abstractions
855 @comment node-name, next, previous, up
856 @subsection Directory-block list management
858 The dblist abstraction stores a list of blocks belonging to
859 directories. This list can be useful when a program needs to interate
860 over all directory entries in a filesystem; @code{e2fsck} does this in
861 pass 2 of its operations, and @code{debugfs} needs to do this when it is
862 trying to turn an inode number into a pathname.
864 @deftypefun errcode_t ext2fs_init_dblist (ext2_filsys @var{fs}, ext2_dblist *@var{ret_dblist})
866 Creates a dblist data structure and return it in @var{ret_dblist}.
869 @deftypefun void ext2fs_free_dblist (ext2_dblist @var{dblist})
871 Free a dblist data structure.
874 @deftypefun errcode_t ext2fs_add_dir_block (ext2_dblist @var{dblist}, ext2_ino_t @var{ino}, blk_t @var{blk}, int @var{blockcnt})
876 Add an entry to the dblist data structure. This call records the fact
877 that block number @var{blockcnt} of directory inode @var{ino} is stored
881 @deftypefun errcode_t ext2fs_set_dir_block (ext2_dblist @var{dblist}, ext2_ino_t @var{ino}, blk_t @var{blk}, int @var{blockcnt})
883 Change an entry in the dblist data structure; this changes the location
884 of block number @var{blockcnt} of directory indoe @var{ino} to be block
888 @deftypefun errcode_t ext2fs_dblist_iterate (ext2_dblist @var{dblist}, int (*func)(ext2_filsys @var{fs}, struct ext2_db_entry *@var{db_info}, void *@var{private}), void *@var{private})
890 This iterator calls @var{func} for every entry in the dblist data structure.
893 @deftypefun errcode_t ext2fs_dblist_dir_iterate (ext2_dblist @var{dblist}, int flags, char *@var{block_buf}, int (*func)(ext2_ino_t @var{dir}, int @var{entry}, struct ext2_dir_entry *@var{dirent}, int @var{offset}, int @var{blocksize}, char *@var{buf}, void *@var{private}), void *@var{private})
895 This iterator takes reads in the directory block indicated in each
896 dblist entry, and calls @var{func} for each directory entry in each
897 directory block. If @var{dblist} contains all the directory blocks in a
898 filesystem, this function provides a convenient way to iterate over all
899 directory entries for that filesystem.
902 @c ----------------------------------------------------------------------
904 @node Inode count functions, , Directory-block list management, EXT2 data abstractions
905 @comment node-name, next, previous, up
906 @subsection Inode count functions
908 The icount abstraction is a specialized data type used by @code{e2fsck}
909 to store how many times a particular inode is referenced by the
910 filesystem. This is used twice; once to store the actual number of times
911 that the inode is reference; and once to store the claimed number of times
912 the inode is referenced according to the inode structure.
914 This abstraction is designed to be extremely efficient for storing this
915 sort of information, by taking advantage of the following properties of
916 inode counts, namely (1) inode counts are very often zero (because
917 the inode is currrently not in use), and (2) many files have a inode
918 count of 1 (because they are a file which has no additional hard links).
920 @deftypefun errcode_t ext2fs_create_icount2 (ext2_filsys @var{fs}, int @var{flags}, int @var{size}, ext2_icount_t @var{hint}, ext2_icount_t *@var{ret})
922 Creates an icount stucture for a filesystem @var{fs}, with initial space
923 for @var{size} inodes whose count is greater than 1. The @var{flags}
924 parameter is either 0 or @code{EXT2_ICOUNT_OPT_INCREMENT}, which
925 indicates that icount structure should be able to increment inode counts
926 quickly. The icount structure is returned in @var{ret}. The returned
927 icount structure initially has a count of zero for all inodes.
929 The @var{hint} parameter allows the caller to optionally pass in another
930 icount structure which is used to initialize the array of inodes whose
931 count is greater than 1. It is used purely as a speed optimization so
932 that the icount structure can determine in advance which inodes are
933 likely to contain a count grater than 1.
936 @deftypefun void ext2fs_free_icount (ext2_icount_t @var{icount})
938 Frees an icount structure.
941 @deftypefun errcode_t ext2fs_icount_fetch (ext2_icount_t @var{icount}, ext2_ino_t @var{ino}, __u16 *@var{ret})
943 Returns in @var{ret} fetches the count for a particular inode @var{ino}.
946 @deftypefun errcode_t ext2fs_icount_increment (ext2_icount_t @var{icount}, ext2_ino_t @var{ino}, __u16 *@var{ret})
948 Increments the ref count for inode @var{ino}.
951 @deftypefun errcode_t ext2fs_icount_decrement (ext2_icount_t @var{icount}, ext2_ino_t @var{ino}, __u16 *@var{ret})
953 Decrements the ref count for inode @var{ino}.
956 @deftypefun errcode_t ext2fs_icount_store (ext2_icount_t @var{icount}, ext2_ino_t @var{ino}, __u16 @var{count})
958 Sets the reference count for inode @var{ino} to be @var{count}.
961 @deftypefun ext2_ino_t ext2fs_get_icount_size (ext2_icount_t @var{icount})
963 Returns the current number of inodes in @var{icount} which has a count
967 @deftypefun errcode_t ext2fs_icount_validate (ext2_icount_t @var{icount}, FILE *@var{f})
969 Validates the internal rep invariant of @var{icount}; if there are any
970 problems, print out debugging information to @var{f}. This function is
971 intended for debugging and testing use only.
975 @c ----------------------------------------------------------------------
977 @node Byte-swapping functions, Other functions, EXT2 data abstractions, EXT2FS Library Functions
978 @comment node-name, next, previous, up
979 @section Byte-swapping functions
981 @deftypefun void ext2fs_swap_super (struct ext2_super_block * @var{super})
984 @deftypefun void ext2fs_swap_group_desc (struct ext2_group_desc *@var{gdp})
987 @deftypefun void ext2fs_swap_inode (ext2_filsys @var{fs}, struct ext2_inode *@var{to}, struct ext2_inode *@var{from}, int @var{hostorder})
990 @deftypefun int ext2fs_native_flag (void)
994 @c ----------------------------------------------------------------------
996 @node Other functions, , Byte-swapping functions, EXT2FS Library Functions
997 @comment node-name, next, previous, up
998 @section Other functions
1001 @deftypefun errcode_t ext2fs_new_inode (ext2_filsys @var{fs}, ext2_ino_t @var{dir}, int @var{mode}, ext2fs_inode_bitmap @var{map}, ext2_ino_t *@var{ret})
1004 @deftypefun errcode_t ext2fs_new_block (ext2_filsys @var{fs}, blk_t @var{goal}, ext2fs_block_bitmap @var{map}, blk_t *@var{ret})
1007 @deftypefun errcode_t ext2fs_get_free_blocks (ext2_filsys @var{fs}, blk_t @var{start}, blk_t @var{finish}, int @var{num}, ext2fs_block_bitmap @var{map}, blk_t *@var{ret})
1011 @deftypefun errcode_t ext2fs_check_desc (ext2_filsys @var{fs})
1014 @deftypefun errcode_t ext2_get_num_dirs (ext2_filsys @var{fs}, ext2_ino_t *@var{ret_num_dirs})
1019 @deftypefun errcode_t ext2fs_get_device_size (const char *@var{file}, int @var{blocksize}, blk_t *@var{retblocks})
1024 @deftypefun errcode_t ext2fs_check_if_mounted (const char *@var{file}, int *@var{mount_flags})
1029 @deftypefun int ext2fs_get_library_version (const char **@var{ver_string}, const char **@var{date_string})
1031 This function returns the current version of the ext2 library. The
1032 return value contains an integer version code, which consists of the
1033 major version number of the library multiplied by 100, plus the minor
1034 version number of the library. Hence, if the library version is 1.08,
1035 the returned value will be 108.
1037 If @var{ver_string} and/or @var{date_string} are non-NULL, they will be
1038 set to point at a constant string containing the library version and/or
1039 release date, respectively.
1042 @deftypefun int ext2fs_parse_version_string (const char *@var{ver_string})
1044 This function takes a version string which may included in an
1045 application and returns a version code using the same algorithm used by
1046 @code{ext2fs_get_library_version}. It can be used by programs included
1047 in the @code{e2fsprogs} distribution to assure that they are using an
1048 up-to-date ext2 shared library.
1051 /* inline functions */
1052 @deftypefun int ext2fs_group_of_blk (ext2_filsys @var{fs}, blk_t @var{blk})
1055 @deftypefun int ext2fs_group_of_ino (ext2_filsys @var{fs}, ext2_ino_t @var{ino})
1059 @c ----------------------------------------------------------------------
1061 @node Concept Index, Function Index, EXT2FS Library Functions, Top
1062 @comment node-name, next, previous, up
1063 @unnumbered Concept Index
1066 @c ----------------------------------------------------------------------
1068 @node Function Index, , Concept Index, Top
1069 @comment node-name, next, previous, up
1070 @unnumbered Function and Type Index