1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1991, 1993, 1994
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef _UFS_FFS_EXTERN_H
33#define	_UFS_FFS_EXTERN_H
34
35#ifndef _KERNEL
36#error "No user-serving parts inside"
37#else
38
39struct buf;
40struct cg;
41struct fid;
42struct fs;
43struct inode;
44struct malloc_type;
45struct mount;
46struct thread;
47struct sockaddr;
48struct statfs;
49struct ucred;
50struct vnode;
51struct vop_fsync_args;
52struct vop_reallocblks_args;
53struct workhead;
54
55int	ffs_alloc(struct inode *, ufs2_daddr_t, ufs2_daddr_t, int, int,
56	    struct ucred *, ufs2_daddr_t *);
57int	ffs_balloc_ufs1(struct vnode *a_vp, off_t a_startoffset, int a_size,
58            struct ucred *a_cred, int a_flags, struct buf **a_bpp);
59int	ffs_balloc_ufs2(struct vnode *a_vp, off_t a_startoffset, int a_size,
60            struct ucred *a_cred, int a_flags, struct buf **a_bpp);
61void	ffs_blkfree(struct ufsmount *, struct fs *, struct vnode *,
62	    ufs2_daddr_t, long, ino_t, __enum_uint8(vtype), struct workhead *,
63	    uint64_t);
64ufs2_daddr_t ffs_blkpref_ufs1(struct inode *, ufs_lbn_t, int, ufs1_daddr_t *);
65ufs2_daddr_t ffs_blkpref_ufs2(struct inode *, ufs_lbn_t, int, ufs2_daddr_t *);
66void	ffs_blkrelease_finish(struct ufsmount *, uint64_t);
67uint64_t ffs_blkrelease_start(struct ufsmount *, struct vnode *, ino_t);
68uint32_t ffs_calc_sbhash(struct fs *);
69int	ffs_checkfreefile(struct fs *, struct vnode *, ino_t);
70void	ffs_clrblock(struct fs *, uint8_t *, ufs1_daddr_t);
71void	ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
72void	ffs_bdflush(struct bufobj *, struct buf *);
73int	ffs_copyonwrite(struct vnode *, struct buf *);
74int	ffs_flushfiles(struct mount *, int, struct thread *);
75void	ffs_fragacct(struct fs *, int, int32_t [], int);
76int	ffs_freefile(struct ufsmount *, struct fs *, struct vnode *, ino_t,
77	    int, struct workhead *);
78void	ffs_fserr(struct fs *, ino_t, char *);
79int	ffs_getcg(struct fs *, struct vnode *, uint64_t, int, struct buf **,
80	    struct cg **);
81int	ffs_inotovp(struct mount *, ino_t, uint64_t, int, struct vnode **,
82	    int);
83int	ffs_isblock(struct fs *, uint8_t *, ufs1_daddr_t);
84int	ffs_isfreeblock(struct fs *, uint8_t *, ufs1_daddr_t);
85void	ffs_oldfscompat_write(struct fs *, struct ufsmount *);
86int	ffs_own_mount(const struct mount *mp);
87int	ffs_sbsearch(void *, struct fs **, int, struct malloc_type *,
88	    int (*)(void *, off_t, void **, int));
89int	ffs_reallocblks(struct vop_reallocblks_args *);
90int	ffs_realloccg(struct inode *, ufs2_daddr_t, ufs2_daddr_t,
91	    ufs2_daddr_t, int, int, int, struct ucred *, struct buf **);
92int	ffs_reload(struct mount *, int);
93int	ffs_sbget(void *, struct fs **, off_t, int, struct malloc_type *,
94	    int (*)(void *, off_t, void **, int));
95int	ffs_sbput(void *, struct fs *, off_t, int (*)(void *, off_t, void *,
96	    int));
97int	ffs_sbupdate(struct ufsmount *, int, int);
98void	ffs_setblock(struct fs *, uint8_t *, ufs1_daddr_t);
99int	ffs_snapblkfree(struct fs *, struct vnode *, ufs2_daddr_t, long, ino_t,
100	    __enum_uint8(vtype), struct workhead *);
101void	ffs_snapremove(struct vnode *vp);
102int	ffs_snapshot(struct mount *mp, char *snapfile);
103void	ffs_snapshot_mount(struct mount *mp);
104void	ffs_snapshot_unmount(struct mount *mp);
105void	ffs_susp_initialize(void);
106void	ffs_susp_uninitialize(void);
107void	ffs_sync_snap(struct mount *, int);
108int	ffs_syncvnode(struct vnode *vp, int waitfor, int flags);
109int	ffs_truncate(struct vnode *, off_t, int, struct ucred *);
110int	ffs_update(struct vnode *, int);
111void	ffs_update_dinode_ckhash(struct fs *, struct ufs2_dinode *);
112int	ffs_verify_dinode_ckhash(struct fs *, struct ufs2_dinode *);
113int	ffs_valloc(struct vnode *, int, struct ucred *, struct vnode **);
114int	ffs_vfree(struct vnode *, ino_t, int);
115vfs_vget_t ffs_vget;
116int	ffs_vgetf(struct mount *, ino_t, int, struct vnode **, int);
117void	process_deferred_inactive(struct mount *mp);
118int	ffs_fsfail_cleanup(struct ufsmount *, int);
119int	ffs_fsfail_cleanup_locked(struct ufsmount *, int);
120int	ffs_breadz(struct ufsmount *, struct vnode *, daddr_t, daddr_t, int,
121	    daddr_t *, int *, int, struct ucred *, int, void (*)(struct buf *),
122	    struct buf **);
123
124/*
125 * Flags to ffs_vgetf
126 */
127#define	FFSV_FORCEINSMQ		0x0001	/* Force insertion into mount list */
128#define	FFSV_REPLACE		0x0002	/* Replace existing vnode */
129#define	FFSV_REPLACE_DOOMED	0x0004	/* Replace existing vnode if it is
130					   doomed */
131#define	FFSV_FORCEINODEDEP	0x0008	/* Force allocation of inodedep, ignore
132					   MNT_SOFTDEP */
133#define	FFSV_NEWINODE		0x0010	/* Newly allocated inode */
134
135/*
136 * Flags to ffs_reload
137 */
138#define	FFSR_FORCE	0x0001
139#define	FFSR_UNSUSPEND	0x0002
140
141/*
142 * Definitions for TRIM interface
143 *
144 * Special keys and recommended hash table size
145 */
146#define	NOTRIM_KEY	1	/* never written, so don't call trim for it */
147#define	SINGLETON_KEY	2	/* only block being freed, so trim it now */
148#define	FIRST_VALID_KEY	3	/* first valid key describing a block range */
149#define	MAXTRIMIO	1024	/* maximum expected outstanding trim requests */
150
151extern struct vop_vector ffs_vnodeops1;
152extern struct vop_vector ffs_fifoops1;
153extern struct vop_vector ffs_vnodeops2;
154extern struct vop_vector ffs_fifoops2;
155
156/*
157 * Soft update function prototypes.
158 */
159
160int	softdep_check_suspend(struct mount *, struct vnode *,
161	  int, int, int, int);
162void	softdep_get_depcounts(struct mount *, int *, int *);
163void	softdep_initialize(void);
164void	softdep_uninitialize(void);
165int	softdep_mount(struct vnode *, struct mount *, struct fs *,
166	    struct ucred *);
167void	softdep_unmount(struct mount *);
168void	softdep_handle_error(struct buf *);
169int	softdep_move_dependencies(struct buf *, struct buf *);
170int	softdep_flushworklist(struct mount *, int *, struct thread *);
171int	softdep_flushfiles(struct mount *, int, struct thread *);
172void	softdep_update_inodeblock(struct inode *, struct buf *, int);
173void	softdep_load_inodeblock(struct inode *);
174void	softdep_freefile(struct vnode *, ino_t, int);
175int	softdep_request_cleanup(struct fs *, struct vnode *,
176	    struct ucred *, int);
177int	softdep_prerename(struct vnode *, struct vnode *, struct vnode *,
178	    struct vnode *);
179int	softdep_prelink(struct vnode *, struct vnode *,
180	    struct componentname *);
181void	softdep_setup_freeblocks(struct inode *, off_t, int);
182void	softdep_setup_inomapdep(struct buf *, struct inode *, ino_t, int);
183void	softdep_setup_blkmapdep(struct buf *, struct mount *, ufs2_daddr_t,
184	    int, int);
185void	softdep_setup_allocdirect(struct inode *, ufs_lbn_t, ufs2_daddr_t,
186	    ufs2_daddr_t, long, long, struct buf *);
187void	softdep_setup_allocext(struct inode *, ufs_lbn_t, ufs2_daddr_t,
188	    ufs2_daddr_t, long, long, struct buf *);
189void	softdep_setup_allocindir_meta(struct buf *, struct inode *,
190	    struct buf *, int, ufs2_daddr_t);
191void	softdep_setup_allocindir_page(struct inode *, ufs_lbn_t,
192	    struct buf *, int, ufs2_daddr_t, ufs2_daddr_t, struct buf *);
193void	softdep_setup_blkfree(struct mount *, struct buf *, ufs2_daddr_t, int,
194	    struct workhead *, bool);
195void	softdep_setup_inofree(struct mount *, struct buf *, ino_t,
196	    struct workhead *, bool);
197void	softdep_setup_sbupdate(struct ufsmount *, struct fs *, struct buf *);
198void	softdep_fsync_mountdev(struct vnode *);
199int	softdep_sync_metadata(struct vnode *);
200int	softdep_sync_buf(struct vnode *, struct buf *, int);
201int     softdep_fsync(struct vnode *);
202int	softdep_prealloc(struct vnode *, int);
203int	softdep_journal_lookup(struct mount *, struct vnode **);
204void	softdep_journal_freeblocks(struct inode *, struct ucred *, off_t, int);
205void	softdep_journal_fsync(struct inode *);
206void	softdep_buf_append(struct buf *, struct workhead *);
207void	softdep_inode_append(struct inode *, struct ucred *, struct workhead *);
208void	softdep_freework(struct workhead *);
209
210/*
211 * Things to request flushing in softdep_request_cleanup()
212 */
213#define	FLUSH_INODES		1
214#define	FLUSH_INODES_WAIT	2
215#define	FLUSH_BLOCKS		3
216#define	FLUSH_BLOCKS_WAIT	4
217/*
218 * Flag to ffs_syncvnode() to request flushing of data only,
219 * but skip the ffs_update() on the inode itself. Used to avoid
220 * deadlock when flushing snapshot inodes while holding snaplk.
221 */
222#define	NO_INO_UPDT		0x00000001
223/*
224 * Request data sync only from ffs_syncvnode(), not touching even more
225 * metadata than NO_INO_UPDT.
226 */
227#define	DATA_ONLY		0x00000002
228
229int	ffs_rdonly(struct inode *);
230
231TAILQ_HEAD(snaphead, inode);
232
233struct snapdata {
234	LIST_ENTRY(snapdata) sn_link;
235	struct snaphead sn_head;
236	daddr_t sn_listsize;
237	daddr_t *sn_blklist;
238	struct lock sn_lock;
239};
240
241#endif /* _KERNEL */
242
243#endif /* !_UFS_FFS_EXTERN_H */
244