Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * irel.h |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame^] | 3 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 4 | * Copyright (C) 1996, 1997 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 | struct ext2_inode_reference { |
| 13 | blk_t block; |
| 14 | __u16 offset; |
| 15 | }; |
| 16 | |
| 17 | struct ext2_inode_relocate_entry { |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 18 | ext2_ino_t new; |
| 19 | ext2_ino_t orig; |
| 20 | __u16 flags; |
| 21 | __u16 max_refs; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | typedef struct ext2_inode_relocation_table *ext2_irel; |
| 25 | |
| 26 | struct ext2_inode_relocation_table { |
| 27 | __u32 magic; |
| 28 | char *name; |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 29 | ext2_ino_t current; |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 30 | void *priv_data; |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Add an inode relocation entry. |
| 34 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 35 | errcode_t (*put)(ext2_irel irel, ext2_ino_t old, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 36 | struct ext2_inode_relocate_entry *ent); |
| 37 | /* |
| 38 | * Get an inode relocation entry. |
| 39 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 40 | errcode_t (*get)(ext2_irel irel, ext2_ino_t old, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 41 | struct ext2_inode_relocate_entry *ent); |
| 42 | |
| 43 | /* |
| 44 | * Get an inode relocation entry by its original inode number |
| 45 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 46 | errcode_t (*get_by_orig)(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 47 | struct ext2_inode_relocate_entry *ent); |
| 48 | |
| 49 | /* |
| 50 | * Initialize for iterating over the inode relocation entries. |
| 51 | */ |
| 52 | errcode_t (*start_iter)(ext2_irel irel); |
| 53 | |
| 54 | /* |
| 55 | * The iterator function for the inode relocation entries. |
| 56 | * Returns an inode number of 0 when out of entries. |
| 57 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 58 | errcode_t (*next)(ext2_irel irel, ext2_ino_t *old, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 59 | struct ext2_inode_relocate_entry *ent); |
| 60 | |
| 61 | /* |
| 62 | * Add an inode reference (i.e., note the fact that a |
| 63 | * particular block/offset contains a reference to an inode) |
| 64 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 65 | errcode_t (*add_ref)(ext2_irel irel, ext2_ino_t ino, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 66 | struct ext2_inode_reference *ref); |
| 67 | |
| 68 | /* |
| 69 | * Initialize for iterating over the inode references for a |
| 70 | * particular inode. |
| 71 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 72 | errcode_t (*start_iter_ref)(ext2_irel irel, ext2_ino_t ino); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * The iterator function for the inode references for an |
| 76 | * inode. The references for only one inode can be interator |
| 77 | * over at a time, as the iterator state is stored in ext2_irel. |
| 78 | */ |
| 79 | errcode_t (*next_ref)(ext2_irel irel, |
| 80 | struct ext2_inode_reference *ref); |
| 81 | |
| 82 | /* |
| 83 | * Move the inode relocation table from one inode number to |
| 84 | * another. Note that the inode references also must move. |
| 85 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 86 | errcode_t (*move)(ext2_irel irel, ext2_ino_t old, ext2_ino_t new); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Remove an inode relocation entry, along with all of the |
| 90 | * inode references. |
| 91 | */ |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 92 | errcode_t (*delete)(ext2_irel irel, ext2_ino_t old); |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Free the inode relocation table. |
| 96 | */ |
| 97 | errcode_t (*free)(ext2_irel irel); |
| 98 | }; |
| 99 | |
Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 100 | errcode_t ext2fs_irel_memarray_create(char *name, ext2_ino_t max_inode, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 101 | ext2_irel *irel); |
| 102 | |
| 103 | #define ext2fs_irel_put(irel, old, ent) ((irel)->put((irel), old, ent)) |
| 104 | #define ext2fs_irel_get(irel, old, ent) ((irel)->get((irel), old, ent)) |
| 105 | #define ext2fs_irel_get_by_orig(irel, orig, old, ent) \ |
| 106 | ((irel)->get_by_orig((irel), orig, old, ent)) |
| 107 | #define ext2fs_irel_start_iter(irel) ((irel)->start_iter((irel))) |
| 108 | #define ext2fs_irel_next(irel, old, ent) ((irel)->next((irel), old, ent)) |
| 109 | #define ext2fs_irel_add_ref(irel, ino, ref) ((irel)->add_ref((irel), ino, ref)) |
| 110 | #define ext2fs_irel_start_iter_ref(irel, ino) ((irel)->start_iter_ref((irel), ino)) |
| 111 | #define ext2fs_irel_next_ref(irel, ref) ((irel)->next_ref((irel), ref)) |
| 112 | #define ext2fs_irel_move(irel, old, new) ((irel)->move((irel), old, new)) |
| 113 | #define ext2fs_irel_delete(irel, old) ((irel)->delete((irel), old)) |
| 114 | #define ext2fs_irel_free(irel) ((irel)->free((irel))) |