Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
Dave Chinner | f5ea110 | 2013-04-24 18:58:02 +1000 | [diff] [blame] | 3 | * Copyright (c) 2013 Red Hat, Inc. |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * published by the Free Software Foundation. |
| 9 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 10 | * This program is distributed in the hope that it would be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
| 19 | #ifndef __XFS_DA_BTREE_H__ |
| 20 | #define __XFS_DA_BTREE_H__ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | struct xfs_bmap_free; |
| 23 | struct xfs_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | struct xfs_trans; |
| 25 | struct zone; |
Dave Chinner | 32c5483 | 2013-10-29 22:11:46 +1100 | [diff] [blame] | 26 | struct xfs_dir_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /*======================================================================== |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * Btree searching and modification structure definitions. |
| 30 | *========================================================================*/ |
| 31 | |
| 32 | /* |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 33 | * Search comparison results |
| 34 | */ |
| 35 | enum xfs_dacmp { |
| 36 | XFS_CMP_DIFFERENT, /* names are completely different */ |
| 37 | XFS_CMP_EXACT, /* names are exactly the same */ |
| 38 | XFS_CMP_CASE /* names are same but differ in case */ |
| 39 | }; |
| 40 | |
| 41 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * Structure to ease passing around component names. |
| 43 | */ |
| 44 | typedef struct xfs_da_args { |
Christoph Hellwig | a568778 | 2009-02-09 08:37:39 +0100 | [diff] [blame] | 45 | const __uint8_t *name; /* string (maybe not NULL terminated) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | int namelen; /* length of string (maybe no NULL) */ |
Dave Chinner | 0cb9776 | 2013-08-12 20:50:09 +1000 | [diff] [blame] | 47 | __uint8_t filetype; /* filetype of inode for directories */ |
Christoph Hellwig | a568778 | 2009-02-09 08:37:39 +0100 | [diff] [blame] | 48 | __uint8_t *value; /* set of bytes (maybe contain NULLs) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | int valuelen; /* length of value */ |
| 50 | int flags; /* argument flags (eg: ATTR_NOCREATE) */ |
| 51 | xfs_dahash_t hashval; /* hash value of name */ |
| 52 | xfs_ino_t inumber; /* input/output inode number */ |
| 53 | struct xfs_inode *dp; /* directory inode to manipulate */ |
| 54 | xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */ |
| 55 | struct xfs_bmap_free *flist; /* ptr to freelist for bmap_finish */ |
| 56 | struct xfs_trans *trans; /* current trans (changes over time) */ |
| 57 | xfs_extlen_t total; /* total blocks needed, for 1st bmap */ |
| 58 | int whichfork; /* data or attribute fork */ |
| 59 | xfs_dablk_t blkno; /* blkno of attr leaf of interest */ |
| 60 | int index; /* index of attr of interest in blk */ |
| 61 | xfs_dablk_t rmtblkno; /* remote attr value starting blkno */ |
| 62 | int rmtblkcnt; /* remote attr value block count */ |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame^] | 63 | int rmtvaluelen; /* remote attr value length in bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */ |
| 65 | int index2; /* index of 2nd attr in blk */ |
| 66 | xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */ |
| 67 | int rmtblkcnt2; /* remote attr value block count */ |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame^] | 68 | int rmtvaluelen2; /* remote attr value length in bytes */ |
Barry Naujok | 6a17810 | 2008-05-21 16:42:05 +1000 | [diff] [blame] | 69 | int op_flags; /* operation flags */ |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 70 | enum xfs_dacmp cmpresult; /* name compare result for lookups */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } xfs_da_args_t; |
| 72 | |
| 73 | /* |
Barry Naujok | 6a17810 | 2008-05-21 16:42:05 +1000 | [diff] [blame] | 74 | * Operation flags: |
| 75 | */ |
| 76 | #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */ |
| 77 | #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */ |
| 78 | #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */ |
| 79 | #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */ |
Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 80 | #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */ |
Barry Naujok | 6a17810 | 2008-05-21 16:42:05 +1000 | [diff] [blame] | 81 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 82 | #define XFS_DA_OP_FLAGS \ |
| 83 | { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ |
| 84 | { XFS_DA_OP_RENAME, "RENAME" }, \ |
| 85 | { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ |
| 86 | { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ |
| 87 | { XFS_DA_OP_CILOOKUP, "CILOOKUP" } |
| 88 | |
Barry Naujok | 6a17810 | 2008-05-21 16:42:05 +1000 | [diff] [blame] | 89 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * Storage for holding state during Btree searches and split/join ops. |
| 91 | * |
| 92 | * Only need space for 5 intermediate nodes. With a minimum of 62-way |
| 93 | * fanout to the Btree, we can support over 900 million directory blocks, |
| 94 | * which is slightly more than enough. |
| 95 | */ |
| 96 | typedef struct xfs_da_state_blk { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 97 | struct xfs_buf *bp; /* buffer containing block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | xfs_dablk_t blkno; /* filesystem blkno of buffer */ |
| 99 | xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */ |
| 100 | int index; /* relevant index into block */ |
| 101 | xfs_dahash_t hashval; /* last hash value in block */ |
| 102 | int magic; /* blk's magic number, ie: blk type */ |
| 103 | } xfs_da_state_blk_t; |
| 104 | |
| 105 | typedef struct xfs_da_state_path { |
| 106 | int active; /* number of active levels */ |
| 107 | xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH]; |
| 108 | } xfs_da_state_path_t; |
| 109 | |
| 110 | typedef struct xfs_da_state { |
| 111 | xfs_da_args_t *args; /* filename arguments */ |
| 112 | struct xfs_mount *mp; /* filesystem mount point */ |
| 113 | unsigned int blocksize; /* logical block size */ |
| 114 | unsigned int node_ents; /* how many entries in danode */ |
| 115 | xfs_da_state_path_t path; /* search/split paths */ |
| 116 | xfs_da_state_path_t altpath; /* alternate path for join */ |
| 117 | unsigned char inleaf; /* insert into 1->lf, 0->splf */ |
| 118 | unsigned char extravalid; /* T/F: extrablk is in use */ |
| 119 | unsigned char extraafter; /* T/F: extrablk is after new */ |
Malcolm Parsons | 9da096f | 2009-03-29 09:55:42 +0200 | [diff] [blame] | 120 | xfs_da_state_blk_t extrablk; /* for double-splits on leaves */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /* for dirv2 extrablk is data */ |
| 122 | } xfs_da_state_t; |
| 123 | |
| 124 | /* |
| 125 | * Utility macros to aid in logging changed structure fields. |
| 126 | */ |
| 127 | #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE)) |
| 128 | #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \ |
| 129 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \ |
| 130 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1) |
| 131 | |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 132 | /* |
| 133 | * Name ops for directory and/or attr name operations |
| 134 | */ |
| 135 | struct xfs_nameops { |
| 136 | xfs_dahash_t (*hashname)(struct xfs_name *); |
Dave Chinner | 2bc7542 | 2010-01-20 10:47:17 +1100 | [diff] [blame] | 137 | enum xfs_dacmp (*compname)(struct xfs_da_args *, |
| 138 | const unsigned char *, int); |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 139 | }; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /*======================================================================== |
Barry Naujok | 847fff5 | 2008-10-30 17:05:38 +1100 | [diff] [blame] | 143 | * Function prototypes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | *========================================================================*/ |
| 145 | |
| 146 | /* |
| 147 | * Routines used for growing the Btree. |
| 148 | */ |
Dave Chinner | f5ea110 | 2013-04-24 18:58:02 +1000 | [diff] [blame] | 149 | int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno, |
| 150 | int level, struct xfs_buf **bpp, int whichfork); |
| 151 | int xfs_da3_split(xfs_da_state_t *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Routines used for shrinking the Btree. |
| 155 | */ |
Dave Chinner | f5ea110 | 2013-04-24 18:58:02 +1000 | [diff] [blame] | 156 | int xfs_da3_join(xfs_da_state_t *state); |
| 157 | void xfs_da3_fixhashpath(struct xfs_da_state *state, |
| 158 | struct xfs_da_state_path *path_to_to_fix); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | /* |
| 161 | * Routines used for finding things in the Btree. |
| 162 | */ |
Dave Chinner | f5ea110 | 2013-04-24 18:58:02 +1000 | [diff] [blame] | 163 | int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result); |
| 164 | int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | int forward, int release, int *result); |
| 166 | /* |
| 167 | * Utility routines. |
| 168 | */ |
Dave Chinner | f5ea110 | 2013-04-24 18:58:02 +1000 | [diff] [blame] | 169 | int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | xfs_da_state_blk_t *new_blk); |
Dave Chinner | f5ea110 | 2013-04-24 18:58:02 +1000 | [diff] [blame] | 171 | int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp, |
Dave Chinner | d9392a4 | 2012-11-12 22:54:17 +1100 | [diff] [blame] | 172 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
| 173 | struct xfs_buf **bpp, int which_fork); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * Utility routines. |
| 177 | */ |
| 178 | int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno); |
Christoph Hellwig | 77936d0 | 2011-07-13 13:43:49 +0200 | [diff] [blame] | 179 | int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno, |
| 180 | int count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
| 182 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 183 | struct xfs_buf **bp, int whichfork); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
| 185 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
Dave Chinner | 4bb20a8 | 2012-11-12 22:54:10 +1100 | [diff] [blame] | 186 | struct xfs_buf **bpp, int whichfork, |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 187 | const struct xfs_buf_ops *ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | xfs_daddr_t xfs_da_reada_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 189 | xfs_dablk_t bno, xfs_daddr_t mapped_bno, |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 190 | int whichfork, const struct xfs_buf_ops *ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 192 | struct xfs_buf *dead_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Christoph Hellwig | a568778 | 2009-02-09 08:37:39 +0100 | [diff] [blame] | 194 | uint xfs_da_hashname(const __uint8_t *name_string, int name_length); |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 195 | enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, |
Dave Chinner | 2bc7542 | 2010-01-20 10:47:17 +1100 | [diff] [blame] | 196 | const unsigned char *name, int len); |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 197 | |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | xfs_da_state_t *xfs_da_state_alloc(void); |
| 200 | void xfs_da_state_free(xfs_da_state_t *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | extern struct kmem_zone *xfs_da_state_zone; |
Hannes Eder | 2441849 | 2009-03-04 19:33:48 +0100 | [diff] [blame] | 203 | extern const struct xfs_nameops xfs_default_nameops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | #endif /* __XFS_DA_BTREE_H__ */ |