ext2fs.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * ext2fs.h --- ext2fs
  4. *
  5. * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
  6. *
  7. * %Begin-Header%
  8. * This file may be redistributed under the terms of the GNU Public
  9. * License.
  10. * %End-Header%
  11. */
  12. #ifndef EXT2FS_EXT2FS_H
  13. #define EXT2FS_EXT2FS_H 1
  14. #define EXT2FS_ATTR(x)
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*
  19. * Where the master copy of the superblock is located, and how big
  20. * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
  21. * the size of the superblock structure is not necessarily trustworthy
  22. * (some versions have the padding set up so that the superblock is
  23. * 1032 bytes long).
  24. */
  25. #define SUPERBLOCK_OFFSET 1024
  26. #define SUPERBLOCK_SIZE 1024
  27. /*
  28. * The last ext2fs revision level that this version of the library is
  29. * able to support.
  30. */
  31. #define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV
  32. #ifdef HAVE_SYS_TYPES_H
  33. #include <sys/types.h>
  34. #endif
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include "ext2_types.h"
  38. #include "ext2_fs.h"
  39. typedef __u32 ext2_ino_t;
  40. typedef __u32 blk_t;
  41. typedef __u32 dgrp_t;
  42. typedef __u32 ext2_off_t;
  43. typedef __s64 e2_blkcnt_t;
  44. typedef __u32 ext2_dirhash_t;
  45. #include "ext2_io.h"
  46. #include "ext2_err.h"
  47. typedef struct struct_ext2_filsys *ext2_filsys;
  48. struct ext2fs_struct_generic_bitmap {
  49. errcode_t magic;
  50. ext2_filsys fs;
  51. __u32 start, end;
  52. __u32 real_end;
  53. char * description;
  54. char * bitmap;
  55. errcode_t base_error_code;
  56. __u32 reserved[7];
  57. };
  58. #define EXT2FS_MARK_ERROR 0
  59. #define EXT2FS_UNMARK_ERROR 1
  60. #define EXT2FS_TEST_ERROR 2
  61. typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
  62. typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
  63. typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
  64. #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
  65. /*
  66. * badblocks list definitions
  67. */
  68. typedef struct ext2_struct_u32_list *ext2_badblocks_list;
  69. typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
  70. typedef struct ext2_struct_u32_list *ext2_u32_list;
  71. typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
  72. /* old */
  73. typedef struct ext2_struct_u32_list *badblocks_list;
  74. typedef struct ext2_struct_u32_iterate *badblocks_iterate;
  75. #define BADBLOCKS_FLAG_DIRTY 1
  76. /*
  77. * ext2_dblist structure and abstractions (see dblist.c)
  78. */
  79. struct ext2_db_entry {
  80. ext2_ino_t ino;
  81. blk_t blk;
  82. int blockcnt;
  83. };
  84. typedef struct ext2_struct_dblist *ext2_dblist;
  85. #define DBLIST_ABORT 1
  86. /*
  87. * ext2_fileio definitions
  88. */
  89. #define EXT2_FILE_WRITE 0x0001
  90. #define EXT2_FILE_CREATE 0x0002
  91. #define EXT2_FILE_MASK 0x00FF
  92. #define EXT2_FILE_BUF_DIRTY 0x4000
  93. #define EXT2_FILE_BUF_VALID 0x2000
  94. typedef struct ext2_file *ext2_file_t;
  95. #define EXT2_SEEK_SET 0
  96. #define EXT2_SEEK_CUR 1
  97. #define EXT2_SEEK_END 2
  98. /*
  99. * Flags for the ext2_filsys structure and for ext2fs_open()
  100. */
  101. #define EXT2_FLAG_RW 0x01
  102. #define EXT2_FLAG_CHANGED 0x02
  103. #define EXT2_FLAG_DIRTY 0x04
  104. #define EXT2_FLAG_VALID 0x08
  105. #define EXT2_FLAG_IB_DIRTY 0x10
  106. #define EXT2_FLAG_BB_DIRTY 0x20
  107. #define EXT2_FLAG_SWAP_BYTES 0x40
  108. #define EXT2_FLAG_SWAP_BYTES_READ 0x80
  109. #define EXT2_FLAG_SWAP_BYTES_WRITE 0x100
  110. #define EXT2_FLAG_MASTER_SB_ONLY 0x200
  111. #define EXT2_FLAG_FORCE 0x400
  112. #define EXT2_FLAG_SUPER_ONLY 0x800
  113. #define EXT2_FLAG_JOURNAL_DEV_OK 0x1000
  114. #define EXT2_FLAG_IMAGE_FILE 0x2000
  115. /*
  116. * Special flag in the ext2 inode i_flag field that means that this is
  117. * a new inode. (So that ext2_write_inode() can clear extra fields.)
  118. */
  119. #define EXT2_NEW_INODE_FL 0x80000000
  120. /*
  121. * Flags for mkjournal
  122. *
  123. * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock
  124. */
  125. #define EXT2_MKJOURNAL_V1_SUPER 0x0000001
  126. struct struct_ext2_filsys {
  127. errcode_t magic;
  128. io_channel io;
  129. int flags;
  130. char * device_name;
  131. struct ext2_super_block * super;
  132. unsigned int blocksize;
  133. int fragsize;
  134. dgrp_t group_desc_count;
  135. unsigned long desc_blocks;
  136. struct ext2_group_desc * group_desc;
  137. int inode_blocks_per_group;
  138. ext2fs_inode_bitmap inode_map;
  139. ext2fs_block_bitmap block_map;
  140. errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
  141. errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
  142. errcode_t (*write_bitmaps)(ext2_filsys fs);
  143. errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
  144. struct ext2_inode *inode);
  145. errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
  146. struct ext2_inode *inode);
  147. ext2_badblocks_list badblocks;
  148. ext2_dblist dblist;
  149. __u32 stride; /* for mke2fs */
  150. struct ext2_super_block * orig_super;
  151. struct ext2_image_hdr * image_header;
  152. __u32 umask;
  153. /*
  154. * Reserved for future expansion
  155. */
  156. __u32 reserved[8];
  157. /*
  158. * Reserved for the use of the calling application.
  159. */
  160. void * priv_data;
  161. /*
  162. * Inode cache
  163. */
  164. struct ext2_inode_cache *icache;
  165. io_channel image_io;
  166. };
  167. #include "bitops.h"
  168. /*
  169. * Return flags for the block iterator functions
  170. */
  171. #define BLOCK_CHANGED 1
  172. #define BLOCK_ABORT 2
  173. #define BLOCK_ERROR 4
  174. /*
  175. * Block interate flags
  176. *
  177. * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
  178. * function should be called on blocks where the block number is zero.
  179. * This is used by ext2fs_expand_dir() to be able to add a new block
  180. * to an inode. It can also be used for programs that want to be able
  181. * to deal with files that contain "holes".
  182. *
  183. * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
  184. * indirect, doubly indirect, etc. blocks should be called after all
  185. * of the blocks containined in the indirect blocks are processed.
  186. * This is useful if you are going to be deallocating blocks from an
  187. * inode.
  188. *
  189. * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
  190. * called for data blocks only.
  191. *
  192. * BLOCK_FLAG_NO_LARGE is for internal use only. It informs
  193. * ext2fs_block_iterate2 that large files won't be accepted.
  194. */
  195. #define BLOCK_FLAG_APPEND 1
  196. #define BLOCK_FLAG_HOLE 1
  197. #define BLOCK_FLAG_DEPTH_TRAVERSE 2
  198. #define BLOCK_FLAG_DATA_ONLY 4
  199. #define BLOCK_FLAG_NO_LARGE 0x1000
  200. /*
  201. * Magic "block count" return values for the block iterator function.
  202. */
  203. #define BLOCK_COUNT_IND (-1)
  204. #define BLOCK_COUNT_DIND (-2)
  205. #define BLOCK_COUNT_TIND (-3)
  206. #define BLOCK_COUNT_TRANSLATOR (-4)
  207. #if 0
  208. /*
  209. * Flags for ext2fs_move_blocks
  210. */
  211. #define EXT2_BMOVE_GET_DBLIST 0x0001
  212. #define EXT2_BMOVE_DEBUG 0x0002
  213. #endif
  214. /*
  215. * Flags for directory block reading and writing functions
  216. */
  217. #define EXT2_DIRBLOCK_V2_STRUCT 0x0001
  218. /*
  219. * Return flags for the directory iterator functions
  220. */
  221. #define DIRENT_CHANGED 1
  222. #define DIRENT_ABORT 2
  223. #define DIRENT_ERROR 3
  224. /*
  225. * Directory iterator flags
  226. */
  227. #define DIRENT_FLAG_INCLUDE_EMPTY 1
  228. #define DIRENT_FLAG_INCLUDE_REMOVED 2
  229. #define DIRENT_DOT_FILE 1
  230. #define DIRENT_DOT_DOT_FILE 2
  231. #define DIRENT_OTHER_FILE 3
  232. #define DIRENT_DELETED_FILE 4
  233. /*
  234. * Inode scan definitions
  235. */
  236. typedef struct ext2_struct_inode_scan *ext2_inode_scan;
  237. /*
  238. * ext2fs_scan flags
  239. */
  240. #define EXT2_SF_CHK_BADBLOCKS 0x0001
  241. #define EXT2_SF_BAD_INODE_BLK 0x0002
  242. #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
  243. #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
  244. /*
  245. * ext2fs_check_if_mounted flags
  246. */
  247. #define EXT2_MF_MOUNTED 1
  248. #define EXT2_MF_ISROOT 2
  249. #define EXT2_MF_READONLY 4
  250. #define EXT2_MF_SWAP 8
  251. #define EXT2_MF_BUSY 16
  252. /*
  253. * Ext2/linux mode flags. We define them here so that we don't need
  254. * to depend on the OS's sys/stat.h, since we may be compiling on a
  255. * non-Linux system.
  256. */
  257. #define LINUX_S_IFMT 00170000
  258. #define LINUX_S_IFSOCK 0140000
  259. #define LINUX_S_IFLNK 0120000
  260. #define LINUX_S_IFREG 0100000
  261. #define LINUX_S_IFBLK 0060000
  262. #define LINUX_S_IFDIR 0040000
  263. #define LINUX_S_IFCHR 0020000
  264. #define LINUX_S_IFIFO 0010000
  265. #define LINUX_S_ISUID 0004000
  266. #define LINUX_S_ISGID 0002000
  267. #define LINUX_S_ISVTX 0001000
  268. #define LINUX_S_IRWXU 00700
  269. #define LINUX_S_IRUSR 00400
  270. #define LINUX_S_IWUSR 00200
  271. #define LINUX_S_IXUSR 00100
  272. #define LINUX_S_IRWXG 00070
  273. #define LINUX_S_IRGRP 00040
  274. #define LINUX_S_IWGRP 00020
  275. #define LINUX_S_IXGRP 00010
  276. #define LINUX_S_IRWXO 00007
  277. #define LINUX_S_IROTH 00004
  278. #define LINUX_S_IWOTH 00002
  279. #define LINUX_S_IXOTH 00001
  280. #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
  281. #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
  282. #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
  283. #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
  284. #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
  285. #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
  286. #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
  287. /*
  288. * ext2 size of an inode
  289. */
  290. #define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
  291. /*
  292. * ext2_icount_t abstraction
  293. */
  294. #define EXT2_ICOUNT_OPT_INCREMENT 0x01
  295. typedef struct ext2_icount *ext2_icount_t;
  296. /*
  297. * Flags for ext2fs_bmap
  298. */
  299. #define BMAP_ALLOC 0x0001
  300. #define BMAP_SET 0x0002
  301. /*
  302. * Flags for imager.c functions
  303. */
  304. #define IMAGER_FLAG_INODEMAP 1
  305. #define IMAGER_FLAG_SPARSEWRITE 2
  306. /*
  307. * For checking structure magic numbers...
  308. */
  309. #define EXT2_CHECK_MAGIC(struct, code) \
  310. if ((struct)->magic != (code)) return (code)
  311. /*
  312. * For ext2 compression support
  313. */
  314. #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
  315. #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
  316. /*
  317. * Features supported by this version of the library
  318. */
  319. #define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
  320. EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
  321. EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
  322. EXT2_FEATURE_COMPAT_RESIZE_INODE|\
  323. EXT2_FEATURE_COMPAT_DIR_INDEX|\
  324. EXT2_FEATURE_COMPAT_EXT_ATTR)
  325. /* This #ifdef is temporary until compression is fully supported */
  326. #ifdef ENABLE_COMPRESSION
  327. #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
  328. /* If the below warning bugs you, then have
  329. `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
  330. environment at configure time. */
  331. #warning "Compression support is experimental"
  332. #endif
  333. #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
  334. EXT2_FEATURE_INCOMPAT_COMPRESSION|\
  335. EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
  336. EXT2_FEATURE_INCOMPAT_META_BG|\
  337. EXT3_FEATURE_INCOMPAT_RECOVER)
  338. #else
  339. #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
  340. EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
  341. EXT2_FEATURE_INCOMPAT_META_BG|\
  342. EXT3_FEATURE_INCOMPAT_RECOVER)
  343. #endif
  344. #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
  345. EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
  346. /*
  347. * function prototypes
  348. */
  349. /* alloc.c */
  350. extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
  351. ext2fs_inode_bitmap map, ext2_ino_t *ret);
  352. extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
  353. ext2fs_block_bitmap map, blk_t *ret);
  354. extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
  355. blk_t finish, int num,
  356. ext2fs_block_bitmap map,
  357. blk_t *ret);
  358. extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
  359. char *block_buf, blk_t *ret);
  360. /* alloc_sb.c */
  361. extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
  362. dgrp_t group,
  363. ext2fs_block_bitmap bmap);
  364. /* alloc_stats.c */
  365. void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
  366. void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
  367. int inuse, int isdir);
  368. void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
  369. /* alloc_tables.c */
  370. extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
  371. extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
  372. ext2fs_block_bitmap bmap);
  373. /* badblocks.c */
  374. extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
  375. extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
  376. extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk);
  377. extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
  378. extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
  379. ext2_u32_iterate *ret);
  380. extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
  381. extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
  382. extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
  383. extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
  384. extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
  385. int size);
  386. extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
  387. blk_t blk);
  388. extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
  389. blk_t blk);
  390. extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk);
  391. extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk);
  392. extern errcode_t
  393. ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
  394. ext2_badblocks_iterate *ret);
  395. extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
  396. blk_t *blk);
  397. extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
  398. extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
  399. ext2_badblocks_list *dest);
  400. extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
  401. ext2_badblocks_list bb2);
  402. extern int ext2fs_u32_list_count(ext2_u32_list bb);
  403. /* bb_compat */
  404. extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
  405. extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
  406. extern int badblocks_list_test(badblocks_list bb, blk_t blk);
  407. extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
  408. badblocks_iterate *ret);
  409. extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
  410. extern void badblocks_list_iterate_end(badblocks_iterate iter);
  411. extern void badblocks_list_free(badblocks_list bb);
  412. /* bb_inode.c */
  413. extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
  414. ext2_badblocks_list bb_list);
  415. /* bitmaps.c */
  416. extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
  417. extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
  418. extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
  419. extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
  420. extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
  421. __u32 end,
  422. __u32 real_end,
  423. const char *descr,
  424. ext2fs_generic_bitmap *ret);
  425. extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
  426. const char *descr,
  427. ext2fs_block_bitmap *ret);
  428. extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
  429. const char *descr,
  430. ext2fs_inode_bitmap *ret);
  431. extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
  432. ext2_ino_t end, ext2_ino_t *oend);
  433. extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
  434. blk_t end, blk_t *oend);
  435. extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
  436. extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
  437. extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
  438. extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
  439. /* block.c */
  440. extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
  441. ext2_ino_t ino,
  442. int flags,
  443. char *block_buf,
  444. int (*func)(ext2_filsys fs,
  445. blk_t *blocknr,
  446. int blockcnt,
  447. void *priv_data),
  448. void *priv_data);
  449. errcode_t ext2fs_block_iterate2(ext2_filsys fs,
  450. ext2_ino_t ino,
  451. int flags,
  452. char *block_buf,
  453. int (*func)(ext2_filsys fs,
  454. blk_t *blocknr,
  455. e2_blkcnt_t blockcnt,
  456. blk_t ref_blk,
  457. int ref_offset,
  458. void *priv_data),
  459. void *priv_data);
  460. /* bmap.c */
  461. extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
  462. struct ext2_inode *inode,
  463. char *block_buf, int bmap_flags,
  464. blk_t block, blk_t *phys_blk);
  465. #if 0
  466. /* bmove.c */
  467. extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
  468. ext2fs_block_bitmap reserve,
  469. ext2fs_block_bitmap alloc_map,
  470. int flags);
  471. #endif
  472. /* check_desc.c */
  473. extern errcode_t ext2fs_check_desc(ext2_filsys fs);
  474. /* closefs.c */
  475. extern errcode_t ext2fs_close(ext2_filsys fs);
  476. extern errcode_t ext2fs_flush(ext2_filsys fs);
  477. extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
  478. extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
  479. dgrp_t group,
  480. blk_t *ret_super_blk,
  481. blk_t *ret_old_desc_blk,
  482. blk_t *ret_new_desc_blk,
  483. int *ret_meta_bg);
  484. extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
  485. /* cmp_bitmaps.c */
  486. extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
  487. ext2fs_block_bitmap bm2);
  488. extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
  489. ext2fs_inode_bitmap bm2);
  490. /* dblist.c */
  491. extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
  492. extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
  493. extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
  494. blk_t blk, int blockcnt);
  495. extern void ext2fs_dblist_sort(ext2_dblist dblist,
  496. int (*sortfunc)(const void *,
  497. const void *));
  498. extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
  499. int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
  500. void *priv_data),
  501. void *priv_data);
  502. extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
  503. blk_t blk, int blockcnt);
  504. extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
  505. ext2_dblist *dest);
  506. extern int ext2fs_dblist_count(ext2_dblist dblist);
  507. /* dblist_dir.c */
  508. extern errcode_t
  509. ext2fs_dblist_dir_iterate(ext2_dblist dblist,
  510. int flags,
  511. char *block_buf,
  512. int (*func)(ext2_ino_t dir,
  513. int entry,
  514. struct ext2_dir_entry *dirent,
  515. int offset,
  516. int blocksize,
  517. char *buf,
  518. void *priv_data),
  519. void *priv_data);
  520. /* dirblock.c */
  521. extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
  522. void *buf);
  523. extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
  524. void *buf, int flags);
  525. extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
  526. void *buf);
  527. extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
  528. void *buf, int flags);
  529. /* dirhash.c */
  530. extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
  531. const __u32 *seed,
  532. ext2_dirhash_t *ret_hash,
  533. ext2_dirhash_t *ret_minor_hash);
  534. /* dir_iterate.c */
  535. extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
  536. ext2_ino_t dir,
  537. int flags,
  538. char *block_buf,
  539. int (*func)(struct ext2_dir_entry *dirent,
  540. int offset,
  541. int blocksize,
  542. char *buf,
  543. void *priv_data),
  544. void *priv_data);
  545. extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs,
  546. ext2_ino_t dir,
  547. int flags,
  548. char *block_buf,
  549. int (*func)(ext2_ino_t dir,
  550. int entry,
  551. struct ext2_dir_entry *dirent,
  552. int offset,
  553. int blocksize,
  554. char *buf,
  555. void *priv_data),
  556. void *priv_data);
  557. /* dupfs.c */
  558. extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
  559. /* expanddir.c */
  560. extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
  561. /* ext_attr.c */
  562. extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
  563. extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
  564. void *buf);
  565. extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
  566. char *block_buf,
  567. int adjust, __u32 *newcount);
  568. /* fileio.c */
  569. extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino,
  570. struct ext2_inode *inode,
  571. int flags, ext2_file_t *ret);
  572. extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
  573. int flags, ext2_file_t *ret);
  574. extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
  575. extern errcode_t ext2fs_file_close(ext2_file_t file);
  576. extern errcode_t ext2fs_file_flush(ext2_file_t file);
  577. extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
  578. unsigned int wanted, unsigned int *got);
  579. extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
  580. unsigned int nbytes, unsigned int *written);
  581. extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
  582. int whence, __u64 *ret_pos);
  583. extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
  584. int whence, ext2_off_t *ret_pos);
  585. errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
  586. extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
  587. extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
  588. /* finddev.c */
  589. extern char *ext2fs_find_block_device(dev_t device);
  590. /* flushb.c */
  591. extern errcode_t ext2fs_sync_device(int fd, int flushb);
  592. /* freefs.c */
  593. extern void ext2fs_free(ext2_filsys fs);
  594. extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
  595. extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
  596. extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
  597. extern void ext2fs_free_dblist(ext2_dblist dblist);
  598. extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
  599. extern void ext2fs_u32_list_free(ext2_u32_list bb);
  600. /* getsize.c */
  601. extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
  602. blk_t *retblocks);
  603. /* getsectsize.c */
  604. errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
  605. /* imager.c */
  606. extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
  607. extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
  608. extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
  609. extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
  610. extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
  611. extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
  612. /* ind_block.c */
  613. errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf);
  614. errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf);
  615. /* initialize.c */
  616. extern errcode_t ext2fs_initialize(const char *name, int flags,
  617. struct ext2_super_block *param,
  618. io_manager manager, ext2_filsys *ret_fs);
  619. /* icount.c */
  620. extern void ext2fs_free_icount(ext2_icount_t icount);
  621. extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
  622. unsigned int size,
  623. ext2_icount_t hint, ext2_icount_t *ret);
  624. extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags,
  625. unsigned int size,
  626. ext2_icount_t *ret);
  627. extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
  628. __u16 *ret);
  629. extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
  630. __u16 *ret);
  631. extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
  632. __u16 *ret);
  633. extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
  634. __u16 count);
  635. extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
  636. errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
  637. /* inode.c */
  638. extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
  639. extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan,
  640. ext2_ino_t *ino,
  641. struct ext2_inode *inode,
  642. int bufsize);
  643. extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
  644. ext2_inode_scan *ret_scan);
  645. extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
  646. extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
  647. struct ext2_inode *inode);
  648. extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
  649. int group);
  650. extern void ext2fs_set_inode_callback
  651. (ext2_inode_scan scan,
  652. errcode_t (*done_group)(ext2_filsys fs,
  653. dgrp_t group,
  654. void * priv_data),
  655. void *done_group_data);
  656. extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
  657. int clear_flags);
  658. extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
  659. struct ext2_inode * inode,
  660. int bufsize);
  661. extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
  662. struct ext2_inode * inode);
  663. extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
  664. struct ext2_inode * inode,
  665. int bufsize);
  666. extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
  667. struct ext2_inode * inode);
  668. extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
  669. struct ext2_inode * inode);
  670. extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
  671. extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
  672. /* inode_io.c */
  673. extern io_manager inode_io_manager;
  674. extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
  675. char **name);
  676. extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
  677. struct ext2_inode *inode,
  678. char **name);
  679. /* ismounted.c */
  680. extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
  681. extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
  682. char *mtpt, int mtlen);
  683. /* namei.c */
  684. extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
  685. int namelen, char *buf, ext2_ino_t *inode);
  686. extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
  687. const char *name, ext2_ino_t *inode);
  688. errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
  689. const char *name, ext2_ino_t *inode);
  690. extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
  691. ext2_ino_t inode, ext2_ino_t *res_inode);
  692. /* native.c */
  693. int ext2fs_native_flag(void);
  694. /* newdir.c */
  695. extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
  696. ext2_ino_t parent_ino, char **block);
  697. /* mkdir.c */
  698. extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
  699. const char *name);
  700. /* mkjournal.c */
  701. extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
  702. __u32 size, int flags,
  703. char **ret_jsb);
  704. extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
  705. ext2_filsys journal_dev);
  706. extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
  707. int flags);
  708. /* openfs.c */
  709. extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
  710. unsigned int block_size, io_manager manager,
  711. ext2_filsys *ret_fs);
  712. extern errcode_t ext2fs_open2(const char *name, const char *io_options,
  713. int flags, int superblock,
  714. unsigned int block_size, io_manager manager,
  715. ext2_filsys *ret_fs);
  716. extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block,
  717. dgrp_t i);
  718. errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);
  719. errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io);
  720. errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io);
  721. /* get_pathname.c */
  722. extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
  723. char **name);
  724. /* link.c */
  725. errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
  726. ext2_ino_t ino, int flags);
  727. errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
  728. ext2_ino_t ino, int flags);
  729. /* read_bb.c */
  730. extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
  731. ext2_badblocks_list *bb_list);
  732. /* read_bb_file.c */
  733. extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
  734. ext2_badblocks_list *bb_list,
  735. void *priv_data,
  736. void (*invalid)(ext2_filsys fs,
  737. blk_t blk,
  738. char *badstr,
  739. void *priv_data));
  740. extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
  741. ext2_badblocks_list *bb_list,
  742. void (*invalid)(ext2_filsys fs,
  743. blk_t blk));
  744. /* res_gdt.c */
  745. extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
  746. /* rs_bitmap.c */
  747. extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
  748. __u32 new_real_end,
  749. ext2fs_generic_bitmap bmap);
  750. extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
  751. ext2fs_inode_bitmap bmap);
  752. extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
  753. ext2fs_block_bitmap bmap);
  754. extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
  755. ext2fs_generic_bitmap *dest);
  756. /* swapfs.c */
  757. extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
  758. int has_header);
  759. extern void ext2fs_swap_super(struct ext2_super_block * super);
  760. extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
  761. extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
  762. struct ext2_inode_large *f, int hostorder,
  763. int bufsize);
  764. extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
  765. struct ext2_inode *f, int hostorder);
  766. /* valid_blk.c */
  767. extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
  768. /* version.c */
  769. extern int ext2fs_parse_version_string(const char *ver_string);
  770. extern int ext2fs_get_library_version(const char **ver_string,
  771. const char **date_string);
  772. /* write_bb_file.c */
  773. extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
  774. unsigned int flags,
  775. FILE *f);
  776. /* inline functions */
  777. extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
  778. extern errcode_t ext2fs_free_mem(void *ptr);
  779. extern errcode_t ext2fs_resize_mem(unsigned long old_size,
  780. unsigned long size, void *ptr);
  781. extern void ext2fs_mark_super_dirty(ext2_filsys fs);
  782. extern void ext2fs_mark_changed(ext2_filsys fs);
  783. extern int ext2fs_test_changed(ext2_filsys fs);
  784. extern void ext2fs_mark_valid(ext2_filsys fs);
  785. extern void ext2fs_unmark_valid(ext2_filsys fs);
  786. extern int ext2fs_test_valid(ext2_filsys fs);
  787. extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
  788. extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
  789. extern int ext2fs_test_ib_dirty(ext2_filsys fs);
  790. extern int ext2fs_test_bb_dirty(ext2_filsys fs);
  791. extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
  792. extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
  793. extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
  794. struct ext2_inode *inode);
  795. #ifdef __cplusplus
  796. }
  797. #endif
  798. #endif