119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o/*
219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * irel.h
3efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o *
419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Copyright (C) 1996, 1997 Theodore Ts'o.
519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %Begin-Header%
7543547a52a20cb7e69d74921b2f691078fd55d83Theodore Ts'o * This file may be redistributed under the terms of the GNU Library
8543547a52a20cb7e69d74921b2f691078fd55d83Theodore Ts'o * General Public License, version 2.
919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %End-Header%
1019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o */
1119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
1219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct ext2_inode_reference {
13e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall	blk64_t	block;
1419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	__u16 offset;
1519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
1619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
1719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct ext2_inode_relocate_entry {
1831dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	ext2_ino_t	new;
1931dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	ext2_ino_t	orig;
2031dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	__u16		flags;
2131dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	__u16		max_refs;
2219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
2319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'otypedef struct ext2_inode_relocation_table *ext2_irel;
2519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
2619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'ostruct ext2_inode_relocation_table {
2719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	__u32	magic;
2819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	char	*name;
2931dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	ext2_ino_t	current;
30b5abe6fac9c9e7caf4710501d1657d30e4857ef6Theodore Ts'o	void	*priv_data;
3119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
3219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
3319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Add an inode relocation entry.
3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
3531dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*put)(ext2_irel irel, ext2_ino_t old,
3619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			      struct ext2_inode_relocate_entry *ent);
3719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
3819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Get an inode relocation entry.
3919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
4031dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*get)(ext2_irel irel, ext2_ino_t old,
4119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			      struct ext2_inode_relocate_entry *ent);
4219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
4319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
4419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Get an inode relocation entry by its original inode number
4519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
4631dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*get_by_orig)(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old,
4719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o				 struct ext2_inode_relocate_entry *ent);
4819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
4919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
5019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Initialize for iterating over the inode relocation entries.
5119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
5219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t (*start_iter)(ext2_irel irel);
5319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
5419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
5519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * The iterator function for the inode relocation entries.
5619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Returns an inode number of 0 when out of entries.
5719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
5831dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*next)(ext2_irel irel, ext2_ino_t *old,
5919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			  struct ext2_inode_relocate_entry *ent);
6019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
6119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
6219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Add an inode reference (i.e., note the fact that a
6319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * particular block/offset contains a reference to an inode)
6419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
6531dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*add_ref)(ext2_irel irel, ext2_ino_t ino,
6619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			     struct ext2_inode_reference *ref);
6719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
6819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
6919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Initialize for iterating over the inode references for a
7019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * particular inode.
7119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
7231dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*start_iter_ref)(ext2_irel irel, ext2_ino_t ino);
7319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
7419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
7519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * The iterator function for the inode references for an
7619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * inode.  The references for only one inode can be interator
7719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * over at a time, as the iterator state is stored in ext2_irel.
7819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
7919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t (*next_ref)(ext2_irel irel,
8019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			      struct ext2_inode_reference *ref);
8119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
8219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
8319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Move the inode relocation table from one inode number to
8419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * another.  Note that the inode references also must move.
8519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
8631dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*move)(ext2_irel irel, ext2_ino_t old, ext2_ino_t new);
8719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
8819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
8919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Remove an inode relocation entry, along with all of the
9019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * inode references.
9119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
9231dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'o	errcode_t (*delete)(ext2_irel irel, ext2_ino_t old);
9319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
9419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	/*
9519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 * Free the inode relocation table.
9619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	 */
9719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o	errcode_t (*free)(ext2_irel irel);
9819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o};
9919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
10031dbecd482405e0d3a67eb58e1a1c8cb9f2ad83eTheodore Ts'oerrcode_t ext2fs_irel_memarray_create(char *name, ext2_ino_t max_inode,
10119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o				    ext2_irel *irel);
10219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o
10319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_put(irel, old, ent) ((irel)->put((irel), old, ent))
10419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_get(irel, old, ent) ((irel)->get((irel), old, ent))
10519c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_get_by_orig(irel, orig, old, ent) \
10619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o			((irel)->get_by_orig((irel), orig, old, ent))
10719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_start_iter(irel) ((irel)->start_iter((irel)))
10819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_next(irel, old, ent) ((irel)->next((irel), old, ent))
10919c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_add_ref(irel, ino, ref) ((irel)->add_ref((irel), ino, ref))
11019c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_start_iter_ref(irel, ino) ((irel)->start_iter_ref((irel), ino))
11119c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_next_ref(irel, ref) ((irel)->next_ref((irel), ref))
11219c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_move(irel, old, new) ((irel)->move((irel), old, new))
11319c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_delete(irel, old) ((irel)->delete((irel), old))
11419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o#define ext2fs_irel_free(irel) ((irel)->free((irel)))
115