]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/nandfs/nandfs_subr.h
fusefs: correctly handle short reads
[FreeBSD/FreeBSD.git] / sys / fs / nandfs / nandfs_subr.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2010-2012 Semihalf
5  * Copyright (c) 2008, 2009 Reinoud Zandijk
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * From: NetBSD: nilfs_subr.h,v 1.1 2009/07/18 16:31:42 reinoud
29  *
30  * $FreeBSD$
31  */
32
33 #ifndef _FS_NANDFS_NANDFS_SUBR_H_
34 #define _FS_NANDFS_NANDFS_SUBR_H_
35
36 struct nandfs_mdt;
37
38 struct nandfs_alloc_request
39 {
40         uint64_t        entrynum;
41         struct buf      *bp_desc;
42         struct buf      *bp_bitmap;
43         struct buf      *bp_entry;
44 };
45
46 /* Segment creation */
47 void nandfs_wakeup_wait_sync(struct nandfs_device *, int);
48 int nandfs_segment_constructor(struct nandfsmount *, int);
49 int nandfs_sync_file(struct vnode *);
50
51 /* Basic calculators */
52 uint64_t nandfs_get_segnum_of_block(struct nandfs_device *, nandfs_daddr_t);
53 void nandfs_get_segment_range(struct nandfs_device *, uint64_t, uint64_t *,
54     uint64_t *);
55 void nandfs_calc_mdt_consts(struct nandfs_device *, struct nandfs_mdt *, int);
56
57 /* Log reading / volume helpers */
58 int nandfs_search_super_root(struct nandfs_device *);
59
60 /* Reading */
61 int nandfs_dev_bread(struct nandfs_device *, nandfs_daddr_t, struct ucred *,
62     int, struct buf **);
63 int nandfs_bread(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
64     struct buf **);
65 int nandfs_bread_meta(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
66     struct buf **);
67 int nandfs_bdestroy(struct nandfs_node *, nandfs_daddr_t);
68 int nandfs_bcreate(struct nandfs_node *, nandfs_lbn_t, struct ucred *, int,
69     struct buf **);
70 int nandfs_bcreate_meta(struct nandfs_node *, nandfs_lbn_t, struct ucred *,
71     int, struct buf **);
72 int nandfs_bread_create(struct nandfs_node *, nandfs_lbn_t, struct ucred *,
73     int, struct buf **);
74
75 /* vtop operations */
76 int nandfs_vtop(struct nandfs_node *, nandfs_daddr_t, nandfs_daddr_t *);
77
78 /* Node action implementators */
79 int nandfs_vinit(struct vnode *, uint64_t);
80 int nandfs_get_node(struct nandfsmount *, uint64_t, struct nandfs_node **);
81 int nandfs_get_node_raw(struct nandfs_device *, struct nandfsmount *, uint64_t,
82     struct nandfs_inode *, struct nandfs_node **);
83 void nandfs_dispose_node(struct nandfs_node **);
84
85 void nandfs_itimes(struct vnode *);
86 int nandfs_lookup_name_in_dir(struct vnode *, const char *, int, uint64_t *,
87     int *, uint64_t *);
88 int nandfs_create_node(struct vnode *, struct vnode **, struct vattr *,
89     struct componentname *);
90 void nandfs_delete_node(struct nandfs_node *);
91
92 int nandfs_chsize(struct vnode *, u_quad_t, struct ucred *);
93 int nandfs_dir_detach(struct nandfsmount *, struct nandfs_node *,
94     struct nandfs_node *, struct componentname *);
95 int nandfs_dir_attach(struct nandfsmount *, struct nandfs_node *,
96     struct nandfs_node *, struct vattr *, struct componentname *);
97
98 int nandfs_dirty_buf(struct buf *, int);
99 int nandfs_dirty_buf_meta(struct buf *, int);
100 int nandfs_fs_full(struct nandfs_device *);
101 void nandfs_undirty_buf_fsdev(struct nandfs_device *, struct buf *);
102 void nandfs_undirty_buf(struct buf *);
103
104 void nandfs_clear_buf(struct buf *);
105 void nandfs_buf_set(struct buf *, uint32_t);
106 void nandfs_buf_clear(struct buf *, uint32_t);
107 int nandfs_buf_check(struct buf *, uint32_t);
108
109 int  nandfs_find_free_entry(struct nandfs_mdt *, struct nandfs_node *,
110     struct nandfs_alloc_request *);
111 int  nandfs_find_entry(struct nandfs_mdt *, struct nandfs_node *,
112     struct nandfs_alloc_request *);
113 int  nandfs_alloc_entry(struct nandfs_mdt *, struct nandfs_alloc_request *);
114 void nandfs_abort_entry(struct nandfs_alloc_request *);
115 int  nandfs_free_entry(struct nandfs_mdt *, struct nandfs_alloc_request *);
116 int nandfs_get_entry_block(struct nandfs_mdt *, struct nandfs_node *,
117     struct nandfs_alloc_request *, uint32_t *, int);
118
119 /* Inode management. */
120 int  nandfs_node_create(struct nandfsmount *, struct nandfs_node **, uint16_t);
121 int nandfs_node_destroy(struct nandfs_node *);
122 int nandfs_node_update(struct nandfs_node *);
123 int nandfs_get_node_entry(struct nandfsmount *, struct nandfs_inode **,
124     uint64_t, struct buf **);
125 void nandfs_mdt_trans_blk(struct nandfs_mdt *, uint64_t, uint64_t *,
126     uint64_t *, nandfs_lbn_t *, uint32_t *);
127
128 /* vblock management */
129 void nandfs_mdt_trans(struct nandfs_mdt *, uint64_t, nandfs_lbn_t *, uint32_t *);
130 int nandfs_vblock_alloc(struct nandfs_device *, nandfs_daddr_t *);
131 int nandfs_vblock_end(struct nandfs_device *, nandfs_daddr_t);
132 int nandfs_vblock_assign(struct nandfs_device *, nandfs_daddr_t,
133     nandfs_lbn_t);
134 int nandfs_vblock_free(struct nandfs_device *, nandfs_daddr_t);
135
136 /* Checkpoint management */
137 int nandfs_get_checkpoint(struct nandfs_device *, struct nandfs_node *,
138     uint64_t);
139 int nandfs_set_checkpoint(struct nandfs_device *, struct nandfs_node *,
140     uint64_t, struct nandfs_inode *, uint64_t);
141
142 /* Segment management */
143 int nandfs_alloc_segment(struct nandfs_device *, uint64_t *);
144 int nandfs_update_segment(struct nandfs_device *, uint64_t, uint32_t);
145 int nandfs_free_segment(struct nandfs_device *, uint64_t);
146 int nandfs_clear_segment(struct nandfs_device *, uint64_t);
147 int nandfs_touch_segment(struct nandfs_device *, uint64_t);
148 int nandfs_markgc_segment(struct nandfs_device *, uint64_t);
149
150 int nandfs_bmap_insert_block(struct nandfs_node *, nandfs_lbn_t, struct buf *);
151 int nandfs_bmap_update_block(struct nandfs_node *, struct buf *, nandfs_lbn_t);
152 int nandfs_bmap_update_dat(struct nandfs_node *, nandfs_daddr_t, struct buf *);
153 int nandfs_bmap_dirty_blocks(struct nandfs_node *, struct buf *, int);
154 int nandfs_bmap_truncate_mapping(struct nandfs_node *, nandfs_lbn_t,
155     nandfs_lbn_t);
156 int nandfs_bmap_lookup(struct nandfs_node *, nandfs_lbn_t, nandfs_daddr_t *);
157
158 /* dirent */
159 int nandfs_add_dirent(struct vnode *, uint64_t, char *, long, uint8_t);
160 int nandfs_remove_dirent(struct vnode *, struct nandfs_node *,
161     struct componentname *);
162 int nandfs_update_dirent(struct vnode *, struct nandfs_node *,
163     struct nandfs_node *);
164 int nandfs_init_dir(struct vnode *, uint64_t, uint64_t);
165 int nandfs_update_parent_dir(struct vnode *, uint64_t);
166
167 void nandfs_vblk_set(struct buf *, nandfs_daddr_t);
168 nandfs_daddr_t nandfs_vblk_get(struct buf *);
169
170 void nandfs_inode_init(struct nandfs_inode *, uint16_t);
171 void nandfs_inode_destroy(struct nandfs_inode *);
172
173 /* ioctl */
174 int nandfs_get_seg_stat(struct nandfs_device *, struct nandfs_seg_stat *);
175 int nandfs_chng_cpmode(struct nandfs_node *, struct nandfs_cpmode *);
176 int nandfs_get_cpinfo_ioctl(struct nandfs_node *, struct nandfs_argv *);
177 int nandfs_delete_cp(struct nandfs_node *, uint64_t start, uint64_t);
178 int nandfs_make_snap(struct nandfs_device *, uint64_t *);
179 int nandfs_delete_snap(struct nandfs_device *, uint64_t);
180 int nandfs_get_cpstat(struct nandfs_node *, struct nandfs_cpstat *);
181 int nandfs_get_segment_info_ioctl(struct nandfs_device *, struct nandfs_argv *);
182 int nandfs_get_dat_vinfo_ioctl(struct nandfs_device *, struct nandfs_argv *);
183 int nandfs_get_dat_bdescs_ioctl(struct nandfs_device *, struct nandfs_argv *);
184 int nandfs_get_fsinfo(struct nandfsmount *, struct nandfs_fsinfo *);
185
186 int nandfs_get_cpinfo(struct nandfs_node *, uint64_t, uint16_t,
187     struct nandfs_cpinfo *, uint32_t, uint32_t *);
188
189 nandfs_lbn_t nandfs_get_maxfilesize(struct nandfs_device *);
190
191 int nandfs_write_superblock(struct nandfs_device *);
192
193 extern int nandfs_sync_interval;
194 extern int nandfs_max_dirty_segs;
195 extern int nandfs_cps_between_sblocks;
196
197 struct buf *nandfs_geteblk(int, int);
198
199 void nandfs_dirty_bufs_increment(struct nandfs_device *);
200 void nandfs_dirty_bufs_decrement(struct nandfs_device *);
201
202 int nandfs_start_cleaner(struct nandfs_device *);
203 int nandfs_stop_cleaner(struct nandfs_device *);
204
205 int nandfs_segsum_valid(struct nandfs_segment_summary *);
206 int nandfs_load_segsum(struct nandfs_device *, nandfs_daddr_t,
207     struct nandfs_segment_summary *);
208 int nandfs_get_segment_info(struct nandfs_device *, struct nandfs_suinfo *,
209     uint32_t, uint64_t);
210 int nandfs_get_segment_info_filter(struct nandfs_device *,
211     struct nandfs_suinfo *, uint32_t, uint64_t, uint64_t *, uint32_t, uint32_t);
212 int nandfs_get_dat_vinfo(struct nandfs_device *, struct nandfs_vinfo *,
213     uint32_t);
214 int nandfs_get_dat_bdescs(struct nandfs_device *, struct nandfs_bdesc *,
215     uint32_t);
216
217 #define NANDFS_VBLK_ASSIGNED    1
218
219 #define NANDFS_IS_INDIRECT(bp)  ((bp)->b_lblkno < 0)
220
221 int nandfs_erase(struct nandfs_device *, off_t, size_t);
222
223 #define NANDFS_VOP_ISLOCKED(vp) nandfs_vop_islocked((vp))
224 int nandfs_vop_islocked(struct vnode *vp);
225
226 nandfs_daddr_t nandfs_block_to_dblock(struct nandfs_device *, nandfs_lbn_t);
227
228 #define DEBUG_MODE
229 #if defined(DEBUG_MODE)
230 #define nandfs_error            panic
231 #define nandfs_warning          printf
232 #elif defined(TEST_MODE)
233 #define nandfs_error    printf
234 #define nandfs_warning  printf
235 #else
236 #define nandfs_error(...)
237 #define nandfs_warning(...)
238 #endif
239
240 #endif  /* !_FS_NANDFS_NANDFS_SUBR_H_ */