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