Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ |
| 31 | */ |
| 32 | #ifndef __XFS_DIR_SF_H__ |
| 33 | #define __XFS_DIR_SF_H__ |
| 34 | |
| 35 | /* |
| 36 | * Directory layout when stored internal to an inode. |
| 37 | * |
| 38 | * Small directories are packed as tightly as possible so as to |
| 39 | * fit into the literal area of the inode. |
| 40 | */ |
| 41 | |
| 42 | typedef struct { __uint8_t i[sizeof(xfs_ino_t)]; } xfs_dir_ino_t; |
| 43 | |
| 44 | /* |
| 45 | * The parent directory has a dedicated field, and the self-pointer must |
| 46 | * be calculated on the fly. |
| 47 | * |
| 48 | * Entries are packed toward the top as tight as possible. The header |
| 49 | * and the elements much be memcpy'd out into a work area to get correct |
| 50 | * alignment for the inode number fields. |
| 51 | */ |
| 52 | typedef struct xfs_dir_shortform { |
| 53 | struct xfs_dir_sf_hdr { /* constant-structure header block */ |
| 54 | xfs_dir_ino_t parent; /* parent dir inode number */ |
| 55 | __uint8_t count; /* count of active entries */ |
| 56 | } hdr; |
| 57 | struct xfs_dir_sf_entry { |
| 58 | xfs_dir_ino_t inumber; /* referenced inode number */ |
| 59 | __uint8_t namelen; /* actual length of name (no NULL) */ |
| 60 | __uint8_t name[1]; /* name */ |
| 61 | } list[1]; /* variable sized array */ |
| 62 | } xfs_dir_shortform_t; |
| 63 | typedef struct xfs_dir_sf_hdr xfs_dir_sf_hdr_t; |
| 64 | typedef struct xfs_dir_sf_entry xfs_dir_sf_entry_t; |
| 65 | |
| 66 | /* |
| 67 | * We generate this then sort it, so that readdirs are returned in |
| 68 | * hash-order. Else seekdir won't work. |
| 69 | */ |
| 70 | typedef struct xfs_dir_sf_sort { |
| 71 | __uint8_t entno; /* .=0, ..=1, else entry# + 2 */ |
| 72 | __uint8_t seqno; /* sequence # with same hash value */ |
| 73 | __uint8_t namelen; /* length of name value (no null) */ |
| 74 | xfs_dahash_t hash; /* this entry's hash value */ |
| 75 | xfs_intino_t ino; /* this entry's inode number */ |
| 76 | char *name; /* name value, pointer into buffer */ |
| 77 | } xfs_dir_sf_sort_t; |
| 78 | |
| 79 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_GET_DIRINO) |
| 80 | void xfs_dir_sf_get_dirino(xfs_dir_ino_t *from, xfs_ino_t *to); |
| 81 | #define XFS_DIR_SF_GET_DIRINO(from,to) xfs_dir_sf_get_dirino(from, to) |
| 82 | #else |
| 83 | #define XFS_DIR_SF_GET_DIRINO(from,to) (*(to) = XFS_GET_DIR_INO8(*from)) |
| 84 | #endif |
| 85 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_PUT_DIRINO) |
| 86 | void xfs_dir_sf_put_dirino(xfs_ino_t *from, xfs_dir_ino_t *to); |
| 87 | #define XFS_DIR_SF_PUT_DIRINO(from,to) xfs_dir_sf_put_dirino(from, to) |
| 88 | #else |
| 89 | #define XFS_DIR_SF_PUT_DIRINO(from,to) XFS_PUT_DIR_INO8(*(from), *(to)) |
| 90 | #endif |
| 91 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_ENTSIZE_BYNAME) |
| 92 | int xfs_dir_sf_entsize_byname(int len); |
| 93 | #define XFS_DIR_SF_ENTSIZE_BYNAME(len) xfs_dir_sf_entsize_byname(len) |
| 94 | #else |
| 95 | #define XFS_DIR_SF_ENTSIZE_BYNAME(len) /* space a name uses */ \ |
| 96 | ((uint)sizeof(xfs_dir_sf_entry_t)-1 + (len)) |
| 97 | #endif |
| 98 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_ENTSIZE_BYENTRY) |
| 99 | int xfs_dir_sf_entsize_byentry(xfs_dir_sf_entry_t *sfep); |
| 100 | #define XFS_DIR_SF_ENTSIZE_BYENTRY(sfep) xfs_dir_sf_entsize_byentry(sfep) |
| 101 | #else |
| 102 | #define XFS_DIR_SF_ENTSIZE_BYENTRY(sfep) /* space an entry uses */ \ |
| 103 | ((uint)sizeof(xfs_dir_sf_entry_t)-1 + (sfep)->namelen) |
| 104 | #endif |
| 105 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_NEXTENTRY) |
| 106 | xfs_dir_sf_entry_t *xfs_dir_sf_nextentry(xfs_dir_sf_entry_t *sfep); |
| 107 | #define XFS_DIR_SF_NEXTENTRY(sfep) xfs_dir_sf_nextentry(sfep) |
| 108 | #else |
| 109 | #define XFS_DIR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ |
| 110 | ((xfs_dir_sf_entry_t *) \ |
| 111 | ((char *)(sfep) + XFS_DIR_SF_ENTSIZE_BYENTRY(sfep))) |
| 112 | #endif |
| 113 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_ALLFIT) |
| 114 | int xfs_dir_sf_allfit(int count, int totallen); |
| 115 | #define XFS_DIR_SF_ALLFIT(count,totallen) \ |
| 116 | xfs_dir_sf_allfit(count,totallen) |
| 117 | #else |
| 118 | #define XFS_DIR_SF_ALLFIT(count,totallen) /* will all entries fit? */ \ |
| 119 | ((uint)sizeof(xfs_dir_sf_hdr_t) + \ |
| 120 | ((uint)sizeof(xfs_dir_sf_entry_t)-1)*(count) + (totallen)) |
| 121 | #endif |
| 122 | |
| 123 | #if defined(XFS_DIR_TRACE) |
| 124 | |
| 125 | /* |
| 126 | * Kernel tracing support for directories. |
| 127 | */ |
| 128 | struct uio; |
| 129 | struct xfs_inode; |
| 130 | struct xfs_da_intnode; |
| 131 | struct xfs_dinode; |
| 132 | struct xfs_dir_leafblock; |
| 133 | struct xfs_dir_leaf_entry; |
| 134 | |
| 135 | #define XFS_DIR_TRACE_SIZE 4096 /* size of global trace buffer */ |
| 136 | extern ktrace_t *xfs_dir_trace_buf; |
| 137 | |
| 138 | /* |
| 139 | * Trace record types. |
| 140 | */ |
| 141 | #define XFS_DIR_KTRACE_G_DU 1 /* dp, uio */ |
| 142 | #define XFS_DIR_KTRACE_G_DUB 2 /* dp, uio, bno */ |
| 143 | #define XFS_DIR_KTRACE_G_DUN 3 /* dp, uio, node */ |
| 144 | #define XFS_DIR_KTRACE_G_DUL 4 /* dp, uio, leaf */ |
| 145 | #define XFS_DIR_KTRACE_G_DUE 5 /* dp, uio, leaf entry */ |
| 146 | #define XFS_DIR_KTRACE_G_DUC 6 /* dp, uio, cookie */ |
| 147 | |
| 148 | void xfs_dir_trace_g_du(char *where, struct xfs_inode *dp, struct uio *uio); |
| 149 | void xfs_dir_trace_g_dub(char *where, struct xfs_inode *dp, struct uio *uio, |
| 150 | xfs_dablk_t bno); |
| 151 | void xfs_dir_trace_g_dun(char *where, struct xfs_inode *dp, struct uio *uio, |
| 152 | struct xfs_da_intnode *node); |
| 153 | void xfs_dir_trace_g_dul(char *where, struct xfs_inode *dp, struct uio *uio, |
| 154 | struct xfs_dir_leafblock *leaf); |
| 155 | void xfs_dir_trace_g_due(char *where, struct xfs_inode *dp, struct uio *uio, |
| 156 | struct xfs_dir_leaf_entry *entry); |
| 157 | void xfs_dir_trace_g_duc(char *where, struct xfs_inode *dp, struct uio *uio, |
| 158 | xfs_off_t cookie); |
| 159 | void xfs_dir_trace_enter(int type, char *where, |
| 160 | void *a0, void *a1, void *a2, void *a3, |
| 161 | void *a4, void *a5, void *a6, void *a7, |
| 162 | void *a8, void *a9, void *a10, void *a11); |
| 163 | #else |
| 164 | #define xfs_dir_trace_g_du(w,d,u) |
| 165 | #define xfs_dir_trace_g_dub(w,d,u,b) |
| 166 | #define xfs_dir_trace_g_dun(w,d,u,n) |
| 167 | #define xfs_dir_trace_g_dul(w,d,u,l) |
| 168 | #define xfs_dir_trace_g_due(w,d,u,e) |
| 169 | #define xfs_dir_trace_g_duc(w,d,u,c) |
| 170 | #endif /* DEBUG */ |
| 171 | |
| 172 | #endif /* __XFS_DIR_SF_H__ */ |