1 /* $NetBSD: lfs_extern.h,v 1.126 2025/11/06 15:45:32 perseant Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Konrad E. Schroder <perseant (at) hhhh.org>. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 /*- 32 * Copyright (c) 1991, 1993, 1994 33 * The Regents of the University of California. All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the University nor the names of its contributors 44 * may be used to endorse or promote products derived from this software 45 * without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * SUCH DAMAGE. 58 * 59 * @(#)lfs_extern.h 8.6 (Berkeley) 5/8/95 60 */ 61 62 #ifndef _UFS_LFS_LFS_EXTERN_H_ 63 #define _UFS_LFS_LFS_EXTERN_H_ 64 65 #include <ufs/lfs/lfs.h> 66 67 #ifdef _KERNEL 68 #include <sys/mallocvar.h> 69 70 MALLOC_DECLARE(M_SEGMENT); 71 #endif 72 73 /* Copied from ext2fs for ITIMES. XXX This is a bogus use of v_tag. */ 74 #define IS_LFS_VNODE(vp) (vp->v_tag == VT_LFS) 75 76 /* 77 * Sysctl values for LFS. 78 */ 79 #define LFS_WRITEINDIR 1 /* flush indirect blocks on non-checkpoint writes */ 80 #define LFS_CLEAN_VNHEAD 2 /* put prev unrefed cleaned vnodes on head of free list */ 81 #define LFS_DOSTATS 3 82 #define LFS_MAXPAGES 4 83 #define LFS_FS_PAGETRIP 5 84 #define LFS_STATS 6 85 #define LFS_DO_RFW 7 86 #define LFS_DEBUG 8 87 #define LFS_DEBUG_FREELIST 1 88 #define LFS_DEBUG_LOG 2 89 #define LFS_IGNORE_LAZY_SYNC 9 90 #define LFS_RFW_LIMIT 10 91 92 /* not ours */ 93 struct fid; 94 struct mount; 95 struct nameidata; 96 struct proc; 97 struct statvfs; 98 struct timeval; 99 struct uio; 100 struct mbuf; 101 struct buf; 102 struct vnode; 103 struct work; 104 105 /* ours */ 106 struct inode; 107 union lfs_dinode; 108 struct dlfs; 109 struct lfs; 110 struct segment; 111 struct block_info; 112 struct lfs_inofuncarg; 113 struct lfs_finfofuncarg; 114 115 __BEGIN_DECLS 116 117 #if defined(_KERNEL) 118 119 extern kcondvar_t lfs_allclean_wakeup; 120 extern struct pool lfs_inode_pool; /* memory pool for inodes */ 121 extern struct pool lfs_dinode_pool; /* memory pool for dinodes */ 122 extern struct pool lfs_inoext_pool; /* memory pool for inode extension */ 123 extern struct pool lfs_lbnentry_pool; /* memory pool for balloc accounting */ 124 125 extern int locked_queue_count; 126 extern long locked_queue_bytes; 127 extern int lfs_do_check_freelist; 128 extern int lfs_subsys_pages; 129 extern int lfs_dirvcount; 130 extern kmutex_t lfs_lock; 131 extern int lfs_debug_log_subsys[]; 132 extern kcondvar_t lfs_writing_cv; 133 extern kcondvar_t locked_queue_cv; 134 extern int lfs_rfw_max_psegs; 135 136 /* lfs_alloc.c */ 137 int lfs_valloc(struct vnode *, int, kauth_cred_t, ino_t *, int *); 138 int lfs_valloc_fixed(struct lfs *, ino_t, int); 139 int lfs_vfree(struct vnode *, ino_t, int); 140 void lfs_order_freelist(struct lfs *, ino_t **, size_t *); 141 int lfs_extend_ifile(struct lfs *, kauth_cred_t); 142 void lfs_orphan(struct lfs *, struct vnode *); 143 void lfs_free_orphans(struct lfs *, ino_t *, size_t); 144 #ifdef DEBUG 145 void lfs_check_freelist(struct lfs *, const char *, int); 146 # define DEBUG_CHECK_FREELIST(fs) \ 147 do { \ 148 if (lfs_do_check_freelist) \ 149 lfs_check_freelist((fs), __func__, __LINE__); \ 150 } while (0) 151 #else /* ! DEBUG */ 152 # define DEBUG_CHECK_FREELIST(fs) 153 #endif /* DEBUG */ 154 155 /* lfs_balloc.c */ 156 int lfs_balloc(struct vnode *, off_t, int, kauth_cred_t, int, struct buf **); 157 void lfs_register_block(struct vnode *, daddr_t); 158 void lfs_deregister_block(struct vnode *, daddr_t); 159 void lfs_deregister_all(struct vnode *); 160 161 /* lfs_bio.c */ 162 int lfs_availwait(struct lfs *, int); 163 int lfs_bwrite_ext(struct buf *, int); 164 int lfs_fits(struct lfs *, int); 165 void lfs_flush_fs(struct lfs *, int); 166 void lfs_flush(struct lfs *, int, int); 167 int lfs_needsflush(struct lfs *); 168 int lfs_needswait(struct lfs *); 169 int lfs_check(struct vnode *, daddr_t, int); 170 void lfs_freebuf(struct lfs *, struct buf *); 171 struct buf *lfs_newbuf(struct lfs *, struct vnode *, daddr_t, size_t, int); 172 void lfs_countlocked(int *, long *, const char *); 173 int lfs_reserve(struct lfs *, struct vnode *, struct vnode *, int); 174 int lfs_max_bufs(void); 175 int lfs_wait_bufs(void); 176 177 /* lfs_debug.c */ 178 #ifdef DEBUG 179 int lfs_bwrite_log(struct buf *, const char *, int); 180 void lfs_dumplog(void); 181 void lfs_dump_super(struct lfs *); 182 void lfs_dump_dinode(struct lfs *, union lfs_dinode *); 183 void lfs_check_bpp(struct lfs *, struct segment *, char *, int); 184 void lfs_check_segsum(struct lfs *, struct segment *, char *, int); 185 void lfs_debug_log(int, const char *, ...); 186 #endif /* DEBUG */ 187 188 /* lfs_inode.c */ 189 int lfs_update(struct vnode *, const struct timespec *, const struct timespec *, 190 int); 191 int lfs_truncate(struct vnode *, off_t, int, kauth_cred_t); 192 union lfs_dinode *lfs_ifind(struct lfs *, ino_t, struct buf *); 193 void lfs_finalize_ino_seguse(struct lfs *, struct inode *); 194 void lfs_finalize_fs_seguse(struct lfs *); 195 196 /* lfs_kclean.c */ 197 int lfs_cleanctl(struct lfs *, struct lfs_autoclean_params *); 198 void lfs_cleanerd(void *); 199 int lfs_rewrite_file(struct lfs *, ino_t *, int, bool, int *, int *); 200 201 /* lfs_rename.c */ 202 int lfs_rename(void *); 203 204 /* lfs_rfw.c */ 205 #define CKSEG_NONE 0x0000 206 #define CKSEG_CKSUM 0x0001 207 #define CKSEG_AVAIL 0x0002 208 int lfs_skip_superblock(struct lfs *, daddr_t *); 209 int lfs_parse_pseg(struct lfs *, daddr_t *, u_int64_t, 210 kauth_cred_t, int *, struct lwp *, 211 int (*)(struct lfs_inofuncarg *), 212 int (*)(struct lfs_finfofuncarg *), 213 int, void *); 214 int lfs_rf_valloc(struct lfs *, ino_t, int, struct lwp *, struct vnode **, union lfs_dinode *); 215 void lfs_roll_forward(struct lfs *, struct mount *, struct lwp *); 216 int lfs_rewrite_segment(struct lfs *, int, int *, kauth_cred_t, struct lwp *); 217 int lfs_rewrite_segments(struct lfs *, int *, int, int *, int *, struct lwp *); 218 #if 0 219 int lfs_rewrite_file(struct lfs *, ino_t, struct lwp *); 220 #endif /* 0 */ 221 int lfs_checkempty(struct lfs *, int, kauth_cred_t, struct lwp *); 222 223 /* lfs_segment.c */ 224 void lfs_imtime(struct lfs *); 225 int lfs_vflush(struct vnode *); 226 int lfs_segwrite(struct mount *, int); 227 int lfs_writefile(struct lfs *, struct segment *, struct vnode *); 228 int lfs_writeinode(struct lfs *, struct segment *, struct inode *); 229 int lfs_gatherblock(struct segment *, struct buf *, kmutex_t *); 230 int lfs_gather(struct lfs *, struct segment *, struct vnode *, int (*match )(struct lfs *, struct buf *)); 231 int lfs_ungather(struct lfs *, struct segment *, struct vnode *, int (*match)(struct lfs *, struct buf *)); 232 void lfs_update_single(struct lfs *, struct segment *, struct vnode *, 233 daddr_t, daddr_t, int); 234 void lfs_updatemeta(struct segment *); 235 int lfs_rewind(struct lfs *, int); 236 int lfs_invalidate(struct lfs *, int); 237 int lfs_initseg(struct lfs *, uint16_t); 238 int lfs_writeseg(struct lfs *, struct segment *); 239 void lfs_writesuper(struct lfs *, daddr_t); 240 int lfs_match_data(struct lfs *, struct buf *); 241 int lfs_match_indir(struct lfs *, struct buf *); 242 int lfs_match_dindir(struct lfs *, struct buf *); 243 int lfs_match_tindir(struct lfs *, struct buf *); 244 void lfs_acquire_finfo(struct lfs *fs, ino_t, int); 245 void lfs_release_finfo(struct lfs *fs); 246 void lfs_cluster_work(struct work *wk, void *arg); 247 void lfs_super_work(struct work *wk, void *arg); 248 void lfs_free_work(struct work *wk, void *arg); 249 void lfs_free_aiodone(struct buf *); 250 251 /* lfs_subr.c */ 252 void lfs_setup_resblks(struct lfs *); 253 void lfs_pad_check(unsigned char *, int, char *, int); 254 void lfs_free_resblks(struct lfs *); 255 void *lfs_malloc(struct lfs *, size_t, int); 256 void lfs_free(struct lfs *, void *, int); 257 int lfs_seglock(struct lfs *, unsigned long); 258 void lfs_segunlock(struct lfs *); 259 void lfs_segunlock_relock(struct lfs *); 260 void lfs_writer_enter(struct lfs *, const char *); 261 int lfs_writer_tryenter(struct lfs *); 262 void lfs_writer_leave(struct lfs *); 263 void lfs_wakeup_cleaner(struct lfs *); 264 struct inode *lfs_create_marker(void); 265 void lfs_destroy_marker(struct inode *); 266 void lfs_setclean(struct lfs *, struct vnode *); 267 void lfs_clrclean(struct lfs *, struct vnode *); 268 int lfs_cleanerlock(struct lfs *); 269 int lfs_cleanerlock_held(struct lfs *); 270 void lfs_cleanerunlock(struct lfs *); 271 void lfs_seguse_clrflag_all(struct lfs *, uint32_t); 272 273 /* lfs_syscalls.c */ 274 int lfs_do_segclean(struct lfs *, unsigned long, kauth_cred_t, struct lwp *); 275 int lfs_markclean(struct lfs *, unsigned long, SEGUSE *, 276 kauth_cred_t, struct lwp *); 277 int lfs_segwait(fsid_t *, struct timeval *); 278 int lfs_bmapv(struct lwp *, fsid_t *, struct block_info *, int); 279 int lfs_markv(struct lwp *, fsid_t *, struct block_info *, int); 280 281 /* lfs_vfsops.c */ 282 VFS_PROTOS(lfs); 283 void lfs_vinit(struct mount *, struct vnode **); 284 int lfs_resize_fs(struct lfs *, int); 285 void lfs_reset_avail(struct lfs *); 286 287 /* lfs_vnops.c */ 288 void lfs_mark_vnode(struct vnode *); 289 void lfs_unmark_vnode(struct vnode *); 290 int lfs_gop_alloc(struct vnode *, off_t, off_t, int, kauth_cred_t); 291 void lfs_gop_size(struct vnode *, off_t, off_t *, int); 292 int lfs_putpages_ext(void *, int); 293 int lfs_gatherpages(struct vnode *); 294 int lfs_flush_dirops(struct lfs *); 295 int lfs_flush_pchain(struct lfs *); 296 297 int lfs_bwrite (void *); 298 int lfs_fsync (void *); 299 int lfs_symlink (void *); 300 int lfs_mknod (void *); 301 int lfs_create (void *); 302 int lfs_mkdir (void *); 303 int lfs_read (void *); 304 int lfs_remove (void *); 305 int lfs_rmdir (void *); 306 int lfs_link (void *); 307 int lfs_mmap (void *); 308 int lfs_rename (void *); 309 int lfs_getattr (void *); 310 int lfs_setattr (void *); 311 int lfs_close (void *); 312 int lfsspec_close(void *); 313 int lfsfifo_close(void *); 314 int lfs_fcntl (void *); 315 int lfs_inactive (void *); 316 int lfs_reclaim (void *); 317 int lfs_strategy (void *); 318 int lfs_write (void *); 319 int lfs_getpages (void *); 320 int lfs_putpages (void *); 321 322 int lfs_bufrd(struct vnode *, struct uio *, int, kauth_cred_t); 323 int lfs_bufwr(struct vnode *, struct uio *, int, kauth_cred_t); 324 325 extern int lfs_mount_type; 326 extern int (**lfs_vnodeop_p)(void *); 327 extern int (**lfs_specop_p)(void *); 328 extern int (**lfs_fifoop_p)(void *); 329 extern const struct genfs_ops lfs_genfsops; 330 331 #endif /* defined(_KERNEL) */ 332 333 /* lfs_cksum.c */ 334 uint32_t cksum(void *, size_t); 335 uint32_t lfs_cksum_part(void *, size_t, uint32_t); 336 #define lfs_cksum_fold(sum) (sum) 337 uint32_t lfs_sb_cksum(struct lfs *); 338 339 __END_DECLS 340 341 #endif /* !_UFS_LFS_LFS_EXTERN_H_ */ 342