1 1.25 mlelstv /* $NetBSD: ulfs_inode.h,v 1.25 2024/02/17 09:08:21 mlelstv Exp $ */ 2 1.20 dholland /* from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp */ 3 1.1 dholland 4 1.1 dholland /* 5 1.1 dholland * Copyright (c) 1982, 1989, 1993 6 1.1 dholland * The Regents of the University of California. All rights reserved. 7 1.1 dholland * (c) UNIX System Laboratories, Inc. 8 1.1 dholland * All or some portions of this file are derived from material licensed 9 1.1 dholland * to the University of California by American Telephone and Telegraph 10 1.1 dholland * Co. or Unix System Laboratories, Inc. and are reproduced herein with 11 1.1 dholland * the permission of UNIX System Laboratories, Inc. 12 1.1 dholland * 13 1.1 dholland * Redistribution and use in source and binary forms, with or without 14 1.1 dholland * modification, are permitted provided that the following conditions 15 1.1 dholland * are met: 16 1.1 dholland * 1. Redistributions of source code must retain the above copyright 17 1.1 dholland * notice, this list of conditions and the following disclaimer. 18 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright 19 1.1 dholland * notice, this list of conditions and the following disclaimer in the 20 1.1 dholland * documentation and/or other materials provided with the distribution. 21 1.1 dholland * 3. Neither the name of the University nor the names of its contributors 22 1.1 dholland * may be used to endorse or promote products derived from this software 23 1.1 dholland * without specific prior written permission. 24 1.1 dholland * 25 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 1.1 dholland * SUCH DAMAGE. 36 1.1 dholland * 37 1.1 dholland * @(#)inode.h 8.9 (Berkeley) 5/14/95 38 1.1 dholland */ 39 1.1 dholland 40 1.3 dholland #ifndef _UFS_LFS_ULFS_INODE_H_ 41 1.3 dholland #define _UFS_LFS_ULFS_INODE_H_ 42 1.1 dholland 43 1.1 dholland #include <sys/vnode.h> 44 1.6 dholland #include <ufs/lfs/lfs_inode.h> 45 1.2 dholland #include <ufs/lfs/ulfs_dinode.h> 46 1.2 dholland #include <ufs/lfs/ulfs_quotacommon.h> 47 1.1 dholland 48 1.10 dholland /* 49 1.10 dholland * These macros are used to bracket ULFS directory ops, so that we can 50 1.10 dholland * identify all the pages touched during directory ops which need to 51 1.10 dholland * be ordered and flushed atomically, so that they may be recovered. 52 1.10 dholland * 53 1.10 dholland * Because we have to mark nodes VU_DIROP in order to prevent 54 1.10 dholland * the cache from reclaiming them while a dirop is in progress, we must 55 1.10 dholland * also manage the number of nodes so marked (otherwise we can run out). 56 1.10 dholland * We do this by setting lfs_dirvcount to the number of marked vnodes; it 57 1.10 dholland * is decremented during segment write, when VU_DIROP is taken off. 58 1.10 dholland */ 59 1.10 dholland #define MARK_VNODE(vp) lfs_mark_vnode(vp) 60 1.10 dholland #define UNMARK_VNODE(vp) lfs_unmark_vnode(vp) 61 1.10 dholland int lfs_set_dirop(struct vnode *, struct vnode *); 62 1.12 dholland void lfs_unset_dirop(struct lfs *, struct vnode *, const char *); 63 1.10 dholland 64 1.8 dholland /* Misc. definitions */ 65 1.8 dholland #define BW_CLEAN 1 /* Flag for lfs_bwrite_ext() */ 66 1.8 dholland #define PG_DELWRI PG_PAGER1 /* Local def for delayed pageout */ 67 1.8 dholland 68 1.8 dholland /* Resource limits */ 69 1.8 dholland #define LFS_MAX_RESOURCE(x, u) (((x) >> 2) - 10 * (u)) 70 1.8 dholland #define LFS_WAIT_RESOURCE(x, u) (((x) >> 1) - ((x) >> 3) - 10 * (u)) 71 1.8 dholland #define LFS_INVERSE_MAX_RESOURCE(x, u) (((x) + 10 * (u)) << 2) 72 1.23 chs #define LFS_MAX_BUFS lfs_max_bufs() 73 1.23 chs #define LFS_WAIT_BUFS lfs_wait_bufs() 74 1.8 dholland #define LFS_INVERSE_MAX_BUFS(n) LFS_INVERSE_MAX_RESOURCE(n, 1) 75 1.8 dholland #define LFS_MAX_BYTES LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE) 76 1.8 dholland #define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE) 77 1.8 dholland #define LFS_WAIT_BYTES LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE) 78 1.8 dholland #define LFS_MAX_DIROP ((desiredvnodes >> 2) + (desiredvnodes >> 3)) 79 1.15 dholland #define SIZEOF_DIROP(fs) (2 * (lfs_sb_getbsize(fs) + DINOSIZE(fs))) 80 1.8 dholland #define LFS_MAX_FSDIROP(fs) \ 81 1.14 dholland (lfs_sb_getnclean(fs) <= lfs_sb_getresvseg(fs) ? 0 : \ 82 1.14 dholland ((lfs_sb_getnclean(fs) - lfs_sb_getresvseg(fs)) * lfs_sb_getssize(fs)) / \ 83 1.8 dholland (2 * SIZEOF_DIROP(fs))) 84 1.8 dholland #define LFS_MAX_PAGES lfs_max_pages() 85 1.8 dholland #define LFS_WAIT_PAGES lfs_wait_pages() 86 1.8 dholland #define LFS_BUFWAIT 2 /* How long to wait if over *_WAIT_* */ 87 1.8 dholland 88 1.8 dholland #ifdef _KERNEL 89 1.8 dholland extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */ 90 1.8 dholland 91 1.8 dholland int lfs_wait_pages(void); 92 1.8 dholland int lfs_max_pages(void); 93 1.8 dholland #endif /* _KERNEL */ 94 1.8 dholland 95 1.8 dholland /* How starved can we be before we start holding back page writes */ 96 1.14 dholland #define LFS_STARVED_FOR_SEGS(fs) (lfs_sb_getnclean(fs) < lfs_sb_getresvseg(fs)) 97 1.8 dholland 98 1.8 dholland /* 99 1.8 dholland * Reserved blocks for lfs_malloc 100 1.8 dholland */ 101 1.8 dholland 102 1.8 dholland /* Structure to keep reserved blocks */ 103 1.8 dholland typedef struct lfs_res_blk { 104 1.8 dholland void *p; 105 1.8 dholland LIST_ENTRY(lfs_res_blk) res; 106 1.8 dholland int size; 107 1.8 dholland char inuse; 108 1.8 dholland } res_t; 109 1.8 dholland 110 1.8 dholland /* Types for lfs_newbuf and lfs_malloc */ 111 1.8 dholland #define LFS_NB_UNKNOWN -1 112 1.8 dholland #define LFS_NB_SUMMARY 0 113 1.8 dholland #define LFS_NB_SBLOCK 1 114 1.8 dholland #define LFS_NB_IBLOCK 2 115 1.8 dholland #define LFS_NB_CLUSTER 3 116 1.8 dholland #define LFS_NB_CLEAN 4 117 1.8 dholland #define LFS_NB_BLKIOV 5 118 1.8 dholland #define LFS_NB_COUNT 6 /* always last */ 119 1.8 dholland 120 1.8 dholland /* Number of reserved memory blocks of each type */ 121 1.8 dholland #define LFS_N_SUMMARIES 2 122 1.8 dholland #define LFS_N_SBLOCKS 1 /* Always 1, to throttle superblock writes */ 123 1.8 dholland #define LFS_N_IBLOCKS 16 /* In theory ssize/bsize; in practice around 2 */ 124 1.8 dholland #define LFS_N_CLUSTERS 16 /* In theory ssize/MAXPHYS */ 125 1.8 dholland #define LFS_N_CLEAN 0 126 1.8 dholland #define LFS_N_BLKIOV 1 127 1.8 dholland 128 1.8 dholland /* Total count of "large" (non-pool) types */ 129 1.8 dholland #define LFS_N_TOTAL (LFS_N_SUMMARIES + LFS_N_SBLOCKS + LFS_N_IBLOCKS + \ 130 1.8 dholland LFS_N_CLUSTERS + LFS_N_CLEAN + LFS_N_BLKIOV) 131 1.8 dholland 132 1.8 dholland /* Counts for pool types */ 133 1.8 dholland #define LFS_N_CL LFS_N_CLUSTERS 134 1.8 dholland #define LFS_N_BPP 2 135 1.8 dholland #define LFS_N_SEG 2 136 1.8 dholland 137 1.8 dholland /* 138 1.8 dholland * "struct buf" associated definitions 139 1.8 dholland */ 140 1.8 dholland 141 1.8 dholland /* Determine if a buffer belongs to the ifile */ 142 1.8 dholland #define IS_IFILE(bp) (VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM) 143 1.8 dholland 144 1.8 dholland #ifdef _KERNEL 145 1.8 dholland /* This overlays the fid structure (see fstypes.h). */ 146 1.8 dholland struct ulfs_ufid { 147 1.21 dholland uint16_t ufid_len; /* Length of structure. */ 148 1.21 dholland uint16_t ufid_pad; /* Force 32-bit alignment. */ 149 1.22 dholland uint32_t ufid_ino; /* File number (ino). XXX should be 64 */ 150 1.25 mlelstv int32_t ufid_gen; /* Generation number. */ 151 1.8 dholland }; 152 1.8 dholland /* Filehandle structure for exported LFSes */ 153 1.8 dholland struct lfid { 154 1.8 dholland struct ulfs_ufid lfid_ufid; 155 1.8 dholland #define lfid_len lfid_ufid.ufid_len 156 1.8 dholland #define lfid_ino lfid_ufid.ufid_ino 157 1.8 dholland #define lfid_gen lfid_ufid.ufid_gen 158 1.8 dholland uint32_t lfid_ident; 159 1.8 dholland }; 160 1.8 dholland #endif /* _KERNEL */ 161 1.8 dholland 162 1.8 dholland /* Address calculations for metadata located in the inode */ 163 1.8 dholland #define S_INDIR(fs) -ULFS_NDADDR 164 1.9 christos #define D_INDIR(fs) (S_INDIR(fs) - LFS_NINDIR(fs) - 1) 165 1.9 christos #define T_INDIR(fs) (D_INDIR(fs) - LFS_NINDIR(fs) * LFS_NINDIR(fs) - 1) 166 1.8 dholland 167 1.8 dholland /* 168 1.8 dholland * "struct vnode" associated definitions 169 1.8 dholland */ 170 1.8 dholland 171 1.8 dholland /* Heuristic emptiness measure */ 172 1.8 dholland #define VPISEMPTY(vp) (LIST_EMPTY(&(vp)->v_dirtyblkhd) && \ 173 1.8 dholland !(vp->v_type == VREG && (vp)->v_iflag & VI_ONWORKLST) &&\ 174 1.8 dholland VTOI(vp)->i_lfs_nbtree == 0) 175 1.8 dholland 176 1.8 dholland #define WRITEINPROG(vp) ((vp)->v_numoutput > 0 || \ 177 1.8 dholland (!LIST_EMPTY(&(vp)->v_dirtyblkhd) && \ 178 1.24 maya !(VTOI(vp)->i_state & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING)))) 179 1.8 dholland 180 1.8 dholland 181 1.8 dholland 182 1.8 dholland 183 1.8 dholland 184 1.1 dholland #if defined(_KERNEL) 185 1.1 dholland 186 1.1 dholland /* 187 1.1 dholland * The DIP macro is used to access fields in the dinode that are 188 1.1 dholland * not cached in the inode itself. 189 1.1 dholland */ 190 1.1 dholland #define DIP(ip, field) \ 191 1.3 dholland (((ip)->i_ump->um_fstype == ULFS1) ? \ 192 1.16 dholland (ip)->i_din->u_32.di_##field : (ip)->i_din->u_64.di_##field) 193 1.1 dholland 194 1.1 dholland #define DIP_ASSIGN(ip, field, value) \ 195 1.1 dholland do { \ 196 1.3 dholland if ((ip)->i_ump->um_fstype == ULFS1) \ 197 1.16 dholland (ip)->i_din->u_32.di_##field = (value); \ 198 1.1 dholland else \ 199 1.16 dholland (ip)->i_din->u_64.di_##field = (value); \ 200 1.1 dholland } while(0) 201 1.1 dholland 202 1.1 dholland #define DIP_ADD(ip, field, value) \ 203 1.1 dholland do { \ 204 1.3 dholland if ((ip)->i_ump->um_fstype == ULFS1) \ 205 1.16 dholland (ip)->i_din->u_32.di_##field += (value); \ 206 1.1 dholland else \ 207 1.16 dholland (ip)->i_din->u_64.di_##field += (value); \ 208 1.1 dholland } while(0) 209 1.1 dholland 210 1.16 dholland /* XXX rework this better */ 211 1.1 dholland #define SHORTLINK(ip) \ 212 1.3 dholland (((ip)->i_ump->um_fstype == ULFS1) ? \ 213 1.16 dholland (void *)(ip)->i_din->u_32.di_db : (void *)(ip)->i_din->u_64.di_db) 214 1.1 dholland 215 1.1 dholland 216 1.1 dholland /* 217 1.1 dholland * Structure used to pass around logical block paths generated by 218 1.3 dholland * ulfs_getlbns and used by truncate and bmap code. 219 1.1 dholland */ 220 1.1 dholland struct indir { 221 1.1 dholland daddr_t in_lbn; /* Logical block number. */ 222 1.1 dholland int in_off; /* Offset in buffer. */ 223 1.1 dholland int in_exists; /* Flag if the block exists. */ 224 1.1 dholland }; 225 1.1 dholland 226 1.1 dholland /* Convert between inode pointers and vnode pointers. */ 227 1.1 dholland #define VTOI(vp) ((struct inode *)(vp)->v_data) 228 1.1 dholland #define ITOV(ip) ((ip)->i_vnode) 229 1.1 dholland 230 1.1 dholland #endif /* _KERNEL */ 231 1.1 dholland 232 1.3 dholland #endif /* !_UFS_LFS_ULFS_INODE_H_ */ 233