1235537Sgber/*-
2235537Sgber * Copyright (c) 2010-2012 Semihalf
3235537Sgber * Copyright (c) 2008, 2009 Reinoud Zandijk
4235537Sgber * All rights reserved.
5235537Sgber *
6235537Sgber * Redistribution and use in source and binary forms, with or without
7235537Sgber * modification, are permitted provided that the following conditions
8235537Sgber * are met:
9235537Sgber * 1. Redistributions of source code must retain the above copyright
10235537Sgber *    notice, this list of conditions and the following disclaimer.
11235537Sgber * 2. Redistributions in binary form must reproduce the above copyright
12235537Sgber *    notice, this list of conditions and the following disclaimer in the
13235537Sgber *    documentation and/or other materials provided with the distribution.
14235537Sgber *
15235537Sgber * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16235537Sgber * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17235537Sgber * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18235537Sgber * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19235537Sgber * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20235537Sgber * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21235537Sgber * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22235537Sgber * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23235537Sgber * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24235537Sgber * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25235537Sgber *
26235537Sgber * From: NetBSD: nilfs_subr.h,v 1.1 2009/07/18 16:31:42 reinoud
27235537Sgber *
28235537Sgber * $FreeBSD$
29235537Sgber */
30235537Sgber
31235537Sgber#ifndef _FS_NANDFS_NANDFS_SUBR_H_
32235537Sgber#define _FS_NANDFS_NANDFS_SUBR_H_
33235537Sgber
34235537Sgberstruct nandfs_mdt;
35235537Sgber
36235537Sgberstruct nandfs_alloc_request
37235537Sgber{
38235537Sgber	uint64_t	entrynum;
39235537Sgber	struct buf	*bp_desc;
40235537Sgber	struct buf	*bp_bitmap;
41235537Sgber	struct buf	*bp_entry;
42235537Sgber};
43235537Sgber
44235537Sgber/* Segment creation */
45235537Sgbervoid nandfs_wakeup_wait_sync(struct nandfs_device *, int);
46235537Sgberint nandfs_segment_constructor(struct nandfsmount *, int);
47235537Sgberint nandfs_sync_file(struct vnode *);
48235537Sgber
49235537Sgber/* Basic calculators */
50235537Sgberuint64_t nandfs_get_segnum_of_block(struct nandfs_device *, nandfs_daddr_t);
51235537Sgbervoid nandfs_get_segment_range(struct nandfs_device *, uint64_t, uint64_t *,
52235537Sgber    uint64_t *);
53235537Sgbervoid nandfs_calc_mdt_consts(struct nandfs_device *, struct nandfs_mdt *, int);
54235537Sgber
55235537Sgber/* Log reading / volume helpers */
56235537Sgberint nandfs_search_super_root(struct nandfs_device *);
57235537Sgber
58235537Sgber/* Reading */
59235537Sgberint nandfs_dev_bread(struct nandfs_device *, nandfs_daddr_t, struct ucred *,
60235537Sgber    int, struct buf **);
61235537Sgberint nandfs_bread(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
62235537Sgber    struct buf **);
63235537Sgberint nandfs_bread_meta(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
64235537Sgber    struct buf **);
65235537Sgberint nandfs_bdestroy(struct nandfs_node *, nandfs_daddr_t);
66235537Sgberint nandfs_bcreate(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
67235537Sgber    struct buf **);
68235537Sgberint nandfs_bcreate_meta(struct nandfs_node *, nandfs_lbn_t, struct ucred *,
69235537Sgber    int, struct buf **);
70235537Sgberint nandfs_bread_create(struct nandfs_node *, nandfs_lbn_t, struct ucred *,
71235537Sgber    int, struct buf **);
72235537Sgber
73235537Sgber/* vtop operations */
74235537Sgberint nandfs_vtop(struct nandfs_node *, nandfs_daddr_t, nandfs_daddr_t *);
75235537Sgber
76235537Sgber/* Node action implementators */
77235537Sgberint nandfs_vinit(struct vnode *, uint64_t);
78235537Sgberint nandfs_get_node(struct nandfsmount *, uint64_t, struct nandfs_node **);
79235537Sgberint nandfs_get_node_raw(struct nandfs_device *, struct nandfsmount *, uint64_t,
80235537Sgber    struct nandfs_inode *, struct nandfs_node **);
81235537Sgbervoid nandfs_dispose_node(struct nandfs_node **);
82235537Sgber
83235537Sgbervoid nandfs_itimes(struct vnode *);
84235537Sgberint nandfs_lookup_name_in_dir(struct vnode *, const char *, int, uint64_t *,
85235537Sgber    int *, uint64_t *);
86235537Sgberint nandfs_create_node(struct vnode *, struct vnode **, struct vattr *,
87235537Sgber    struct componentname *);
88235537Sgbervoid nandfs_delete_node(struct nandfs_node *);
89235537Sgber
90235537Sgberint nandfs_chsize(struct vnode *, u_quad_t, struct ucred *);
91235537Sgberint nandfs_dir_detach(struct nandfsmount *, struct nandfs_node *,
92235537Sgber    struct nandfs_node *, struct componentname *);
93235537Sgberint nandfs_dir_attach(struct nandfsmount *, struct nandfs_node *,
94235537Sgber    struct nandfs_node *, struct vattr *, struct componentname *);
95235537Sgber
96235537Sgberint nandfs_dirty_buf(struct buf *, int);
97235537Sgberint nandfs_dirty_buf_meta(struct buf *, int);
98235537Sgberint nandfs_fs_full(struct nandfs_device *);
99235537Sgbervoid nandfs_undirty_buf_fsdev(struct nandfs_device *, struct buf *);
100235537Sgbervoid nandfs_undirty_buf(struct buf *);
101235537Sgber
102235537Sgbervoid nandfs_clear_buf(struct buf *);
103235537Sgbervoid nandfs_buf_set(struct buf *, uint32_t);
104235537Sgbervoid nandfs_buf_clear(struct buf *, uint32_t);
105235537Sgberint nandfs_buf_check(struct buf *, uint32_t);
106235537Sgber
107235537Sgberint  nandfs_find_free_entry(struct nandfs_mdt *, struct nandfs_node *,
108235537Sgber    struct nandfs_alloc_request *);
109235537Sgberint  nandfs_find_entry(struct nandfs_mdt *, struct nandfs_node *,
110235537Sgber    struct nandfs_alloc_request *);
111235537Sgberint  nandfs_alloc_entry(struct nandfs_mdt *, struct nandfs_alloc_request *);
112235537Sgbervoid nandfs_abort_entry(struct nandfs_alloc_request *);
113235537Sgberint  nandfs_free_entry(struct nandfs_mdt *, struct nandfs_alloc_request *);
114235537Sgberint nandfs_get_entry_block(struct nandfs_mdt *, struct nandfs_node *,
115235537Sgber    struct nandfs_alloc_request *, uint32_t *, int);
116235537Sgber
117235537Sgber/* inode managment */
118235537Sgberint  nandfs_node_create(struct nandfsmount *, struct nandfs_node **, uint16_t);
119235537Sgberint nandfs_node_destroy(struct nandfs_node *);
120235537Sgberint nandfs_node_update(struct nandfs_node *);
121235537Sgberint nandfs_get_node_entry(struct nandfsmount *, struct nandfs_inode **,
122235537Sgber    uint64_t, struct buf **);
123235537Sgbervoid nandfs_mdt_trans_blk(struct nandfs_mdt *, uint64_t, uint64_t *,
124235537Sgber    uint64_t *, nandfs_lbn_t *, uint32_t *);
125235537Sgber
126235537Sgber/* vblock management */
127235537Sgbervoid nandfs_mdt_trans(struct nandfs_mdt *, uint64_t, nandfs_lbn_t *, uint32_t *);
128235537Sgberint nandfs_vblock_alloc(struct nandfs_device *, nandfs_daddr_t *);
129235537Sgberint nandfs_vblock_end(struct nandfs_device *, nandfs_daddr_t);
130235537Sgberint nandfs_vblock_assign(struct nandfs_device *, nandfs_daddr_t,
131235537Sgber    nandfs_lbn_t);
132235537Sgberint nandfs_vblock_free(struct nandfs_device *, nandfs_daddr_t);
133235537Sgber
134235537Sgber/* Checkpoint management */
135235537Sgberint nandfs_get_checkpoint(struct nandfs_device *, struct nandfs_node *,
136235537Sgber    uint64_t);
137235537Sgberint nandfs_set_checkpoint(struct nandfs_device *, struct nandfs_node *,
138235537Sgber    uint64_t, struct nandfs_inode *, uint64_t);
139235537Sgber
140235537Sgber/* Segment management */
141235537Sgberint nandfs_alloc_segment(struct nandfs_device *, uint64_t *);
142235537Sgberint nandfs_update_segment(struct nandfs_device *, uint64_t, uint32_t);
143235537Sgberint nandfs_free_segment(struct nandfs_device *, uint64_t);
144235537Sgberint nandfs_clear_segment(struct nandfs_device *, uint64_t);
145235537Sgberint nandfs_touch_segment(struct nandfs_device *, uint64_t);
146235537Sgberint nandfs_markgc_segment(struct nandfs_device *, uint64_t);
147235537Sgber
148235537Sgberint nandfs_bmap_insert_block(struct nandfs_node *, nandfs_lbn_t, struct buf *);
149235537Sgberint nandfs_bmap_update_block(struct nandfs_node *, struct buf *, nandfs_lbn_t);
150235537Sgberint nandfs_bmap_update_dat(struct nandfs_node *, nandfs_daddr_t, struct buf *);
151235537Sgberint nandfs_bmap_dirty_blocks(struct nandfs_node *, struct buf *, int);
152235537Sgberint nandfs_bmap_truncate_mapping(struct nandfs_node *, nandfs_lbn_t,
153235537Sgber    nandfs_lbn_t);
154235537Sgberint nandfs_bmap_lookup(struct nandfs_node *, nandfs_lbn_t, nandfs_daddr_t *);
155235537Sgber
156235537Sgber/* dirent */
157235537Sgberint nandfs_add_dirent(struct vnode *, uint64_t, char *, long, uint8_t);
158235537Sgberint nandfs_remove_dirent(struct vnode *, struct nandfs_node *,
159235537Sgber    struct componentname *);
160235537Sgberint nandfs_update_dirent(struct vnode *, struct nandfs_node *,
161235537Sgber    struct nandfs_node *);
162235537Sgberint nandfs_init_dir(struct vnode *, uint64_t, uint64_t);
163235537Sgberint nandfs_update_parent_dir(struct vnode *, uint64_t);
164235537Sgber
165235537Sgbervoid nandfs_vblk_set(struct buf *, nandfs_daddr_t);
166235537Sgbernandfs_daddr_t nandfs_vblk_get(struct buf *);
167235537Sgber
168235537Sgbervoid nandfs_inode_init(struct nandfs_inode *, uint16_t);
169235537Sgbervoid nandfs_inode_destroy(struct nandfs_inode *);
170235537Sgber
171235537Sgber/* ioctl */
172235537Sgberint nandfs_get_seg_stat(struct nandfs_device *, struct nandfs_seg_stat *);
173235537Sgberint nandfs_chng_cpmode(struct nandfs_node *, struct nandfs_cpmode *);
174235537Sgberint nandfs_get_cpinfo_ioctl(struct nandfs_node *, struct nandfs_argv *);
175235537Sgberint nandfs_delete_cp(struct nandfs_node *, uint64_t start, uint64_t);
176235537Sgberint nandfs_make_snap(struct nandfs_device *, uint64_t *);
177235537Sgberint nandfs_delete_snap(struct nandfs_device *, uint64_t);
178235537Sgberint nandfs_get_cpstat(struct nandfs_node *, struct nandfs_cpstat *);
179235537Sgberint nandfs_get_segment_info_ioctl(struct nandfs_device *, struct nandfs_argv *);
180235537Sgberint nandfs_get_dat_vinfo_ioctl(struct nandfs_device *, struct nandfs_argv *);
181235537Sgberint nandfs_get_dat_bdescs_ioctl(struct nandfs_device *, struct nandfs_argv *);
182235537Sgberint nandfs_get_fsinfo(struct nandfsmount *, struct nandfs_fsinfo *);
183235537Sgber
184235537Sgberint nandfs_get_cpinfo(struct nandfs_node *, uint64_t, uint16_t,
185235537Sgber    struct nandfs_cpinfo *, uint32_t, uint32_t *);
186235537Sgber
187235537Sgbernandfs_lbn_t nandfs_get_maxfilesize(struct nandfs_device *);
188235537Sgber
189235537Sgberint nandfs_write_superblock(struct nandfs_device *);
190235537Sgber
191235537Sgberextern int nandfs_sync_interval;
192235537Sgberextern int nandfs_max_dirty_segs;
193235537Sgberextern int nandfs_cps_between_sblocks;
194235537Sgber
195235537Sgberstruct buf *nandfs_geteblk(int, int);
196235537Sgber
197235537Sgbervoid nandfs_dirty_bufs_increment(struct nandfs_device *);
198235537Sgbervoid nandfs_dirty_bufs_decrement(struct nandfs_device *);
199235537Sgber
200235537Sgberint nandfs_start_cleaner(struct nandfs_device *);
201235537Sgberint nandfs_stop_cleaner(struct nandfs_device *);
202235537Sgber
203235537Sgberint nandfs_segsum_valid(struct nandfs_segment_summary *);
204235537Sgberint nandfs_load_segsum(struct nandfs_device *, nandfs_daddr_t,
205235537Sgber    struct nandfs_segment_summary *);
206235537Sgberint nandfs_get_segment_info(struct nandfs_device *, struct nandfs_suinfo *,
207235537Sgber    uint32_t, uint64_t);
208235537Sgberint nandfs_get_segment_info_filter(struct nandfs_device *,
209235537Sgber    struct nandfs_suinfo *, uint32_t, uint64_t, uint64_t *, uint32_t, uint32_t);
210235537Sgberint nandfs_get_dat_vinfo(struct nandfs_device *, struct nandfs_vinfo *,
211235537Sgber    uint32_t);
212235537Sgberint nandfs_get_dat_bdescs(struct nandfs_device *, struct nandfs_bdesc *,
213235537Sgber    uint32_t);
214235537Sgber
215235537Sgber#define	NANDFS_VBLK_ASSIGNED	1
216235537Sgber
217235537Sgber#define	NANDFS_IS_INDIRECT(bp)	((bp)->b_lblkno < 0)
218235537Sgber
219235537Sgberint nandfs_erase(struct nandfs_device *, off_t, size_t);
220235537Sgber
221235537Sgber#define	NANDFS_VOP_ISLOCKED(vp)	nandfs_vop_islocked((vp))
222235537Sgberint nandfs_vop_islocked(struct vnode *vp);
223235537Sgber
224235537Sgbernandfs_daddr_t nandfs_block_to_dblock(struct nandfs_device *, nandfs_lbn_t);
225235537Sgber
226235537Sgber#define DEBUG_MODE
227235537Sgber#if defined(DEBUG_MODE)
228235537Sgber#define	nandfs_error		panic
229235537Sgber#define	nandfs_warning		printf
230235537Sgber#elif defined(TEST_MODE)
231235537Sgber#define	nandfs_error	printf
232235537Sgber#define	nandfs_warning	printf
233235537Sgber#else
234235537Sgber#define	nandfs_error(...)
235235537Sgber#define	nandfs_warning(...)
236235537Sgber#endif
237235537Sgber
238235537Sgber#endif	/* !_FS_NANDFS_NANDFS_SUBR_H_ */
239