Home | History | Annotate | Line # | Download | only in nilfs
nilfs_subr.h revision 1.1
      1  1.1  reinoud /* $NetBSD: nilfs_subr.h,v 1.1 2009/07/18 16:31:42 reinoud Exp $ */
      2  1.1  reinoud 
      3  1.1  reinoud /*
      4  1.1  reinoud  * Copyright (c) 2008, 2009 Reinoud Zandijk
      5  1.1  reinoud  * All rights reserved.
      6  1.1  reinoud  *
      7  1.1  reinoud  * Redistribution and use in source and binary forms, with or without
      8  1.1  reinoud  * modification, are permitted provided that the following conditions
      9  1.1  reinoud  * are met:
     10  1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     11  1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     12  1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     15  1.1  reinoud  *
     16  1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  reinoud  *
     27  1.1  reinoud  */
     28  1.1  reinoud 
     29  1.1  reinoud #ifndef _FS_NILFS_NILFS_SUBR_H_
     30  1.1  reinoud #define _FS_NILFS_NILFS_SUBR_H_
     31  1.1  reinoud 
     32  1.1  reinoud /* handies */
     33  1.1  reinoud #define	VFSTONILFS(mp)	((struct nilfs_mount *)mp->mnt_data)
     34  1.1  reinoud 
     35  1.1  reinoud /* basic calculators */
     36  1.1  reinoud uint64_t nilfs_get_segnum_of_block(struct nilfs_device *nilfsdev, uint64_t blocknr);
     37  1.1  reinoud void nilfs_get_segment_range(struct nilfs_device *nilfsdev, uint64_t segnum,
     38  1.1  reinoud 	uint64_t *seg_start, uint64_t *seg_end);
     39  1.1  reinoud void nilfs_calc_mdt_consts(struct nilfs_device *nilfsdev,
     40  1.1  reinoud 	struct nilfs_mdt *mdt, int entry_size);
     41  1.1  reinoud uint32_t crc32_le(uint32_t crc, const uint8_t *buf, size_t len);
     42  1.1  reinoud 
     43  1.1  reinoud /* log reading / volume helpers */
     44  1.1  reinoud int nilfs_get_segment_log(struct nilfs_device *nilfsdev, uint64_t *blocknr,
     45  1.1  reinoud 	uint64_t *offset, struct buf **bpp, int len, void *blob);
     46  1.1  reinoud void nilfs_search_super_root(struct nilfs_device *nilfsdev);
     47  1.1  reinoud 
     48  1.1  reinoud /* reading */
     49  1.1  reinoud int nilfs_bread(struct nilfs_node *node, uint64_t blocknr, struct kauth_cred *cred,
     50  1.1  reinoud 	int flags, struct buf **bpp);
     51  1.1  reinoud 
     52  1.1  reinoud /* btree operations */
     53  1.1  reinoud int nilfs_btree_nlookup(struct nilfs_node *node, uint64_t from, uint64_t blks, uint64_t *l2vmap);
     54  1.1  reinoud 
     55  1.1  reinoud /* vtop operations */
     56  1.1  reinoud int nilfs_nvtop(struct nilfs_node *node, uint64_t blks, uint64_t *l2vmap, uint64_t *v2pmap);
     57  1.1  reinoud 
     58  1.1  reinoud /* node action implementators */
     59  1.1  reinoud int nilfs_get_node(struct nilfs_mount *ump, uint64_t ino, struct nilfs_node **nodep);
     60  1.1  reinoud int nilfs_get_node_raw(struct nilfs_device *nilfsdev, struct nilfs_mount *ump, uint64_t ino, struct nilfs_inode *inode, struct nilfs_node **nodep);
     61  1.1  reinoud void nilfs_dispose_node(struct nilfs_node **node);
     62  1.1  reinoud 
     63  1.1  reinoud int nilfs_grow_node(struct nilfs_node *node, uint64_t new_size);
     64  1.1  reinoud int nilfs_shrink_node(struct nilfs_node *node, uint64_t new_size);
     65  1.1  reinoud void nilfs_itimes(struct nilfs_node *nilfs_node, struct timespec *acc,
     66  1.1  reinoud 	struct timespec *mod, struct timespec *birth);
     67  1.1  reinoud int  nilfs_update(struct vnode *node, struct timespec *acc,
     68  1.1  reinoud 	struct timespec *mod, struct timespec *birth, int updflags);
     69  1.1  reinoud 
     70  1.1  reinoud /* return vpp? */
     71  1.1  reinoud int nilfs_lookup_name_in_dir(struct vnode *dvp, const char *name, int namelen, uint64_t *ino, int *found);
     72  1.1  reinoud int nilfs_create_node(struct vnode *dvp, struct vnode **vpp, struct vattr *vap, struct componentname *cnp);
     73  1.1  reinoud void nilfs_delete_node(struct nilfs_node *nilfs_node);
     74  1.1  reinoud 
     75  1.1  reinoud int nilfs_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred);
     76  1.1  reinoud int nilfs_dir_detach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct componentname *cnp);
     77  1.1  reinoud int nilfs_dir_attach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct vattr *vap, struct componentname *cnp);
     78  1.1  reinoud 
     79  1.1  reinoud 
     80  1.1  reinoud /* vnode operations */
     81  1.1  reinoud int nilfs_inactive(void *v);
     82  1.1  reinoud int nilfs_reclaim(void *v);
     83  1.1  reinoud int nilfs_readdir(void *v);
     84  1.1  reinoud int nilfs_getattr(void *v);
     85  1.1  reinoud int nilfs_setattr(void *v);
     86  1.1  reinoud int nilfs_pathconf(void *v);
     87  1.1  reinoud int nilfs_open(void *v);
     88  1.1  reinoud int nilfs_close(void *v);
     89  1.1  reinoud int nilfs_access(void *v);
     90  1.1  reinoud int nilfs_read(void *v);
     91  1.1  reinoud int nilfs_write(void *v);
     92  1.1  reinoud int nilfs_trivial_bmap(void *v);
     93  1.1  reinoud int nilfs_vfsstrategy(void *v);
     94  1.1  reinoud int nilfs_lookup(void *v);
     95  1.1  reinoud int nilfs_create(void *v);
     96  1.1  reinoud int nilfs_mknod(void *v);
     97  1.1  reinoud int nilfs_link(void *);
     98  1.1  reinoud int nilfs_symlink(void *v);
     99  1.1  reinoud int nilfs_readlink(void *v);
    100  1.1  reinoud int nilfs_rename(void *v);
    101  1.1  reinoud int nilfs_remove(void *v);
    102  1.1  reinoud int nilfs_mkdir(void *v);
    103  1.1  reinoud int nilfs_rmdir(void *v);
    104  1.1  reinoud int nilfs_fsync(void *v);
    105  1.1  reinoud int nilfs_advlock(void *v);
    106  1.1  reinoud 
    107  1.1  reinoud #endif	/* !_FS_NILFS_NILFS_SUBR_H_ */
    108  1.1  reinoud 
    109  1.1  reinoud #if 0
    110  1.1  reinoud /* device information updating */
    111  1.1  reinoud int nilfs_update_trackinfo(struct nilfs_mount *ump, struct mmc_trackinfo *trackinfo);
    112  1.1  reinoud int nilfs_update_discinfo(struct nilfs_mount *ump);
    113  1.1  reinoud int nilfs_search_tracks(struct nilfs_mount *ump, struct nilfs_args *args,
    114  1.1  reinoud 		  int *first_tracknr, int *last_tracknr);
    115  1.1  reinoud int nilfs_search_writing_tracks(struct nilfs_mount *ump);
    116  1.1  reinoud int nilfs_setup_writeparams(struct nilfs_mount *ump);
    117  1.1  reinoud int nilfs_synchronise_caches(struct nilfs_mount *ump);
    118  1.1  reinoud 
    119  1.1  reinoud /* tags operations */
    120  1.1  reinoud int nilfs_fidsize(struct fileid_desc *fid);
    121  1.1  reinoud int nilfs_check_tag(void *blob);
    122  1.1  reinoud int nilfs_check_tag_payload(void *blob, uint32_t max_length);
    123  1.1  reinoud void nilfs_validate_tag_sum(void *blob);
    124  1.1  reinoud void nilfs_validate_tag_and_crc_sums(void *blob);
    125  1.1  reinoud int nilfs_tagsize(union dscrptr *dscr, uint32_t nilfs_sector_size);
    126  1.1  reinoud 
    127  1.1  reinoud /* read/write descriptors */
    128  1.1  reinoud int nilfs_read_phys_dscr(
    129  1.1  reinoud 		struct nilfs_mount *ump,
    130  1.1  reinoud 		uint32_t sector,
    131  1.1  reinoud 		struct malloc_type *mtype,		/* where to allocate */
    132  1.1  reinoud 		union dscrptr **dstp);			/* out */
    133  1.1  reinoud 
    134  1.1  reinoud int nilfs_write_phys_dscr_sync(struct nilfs_mount *ump, struct nilfs_node *nilfs_node,
    135  1.1  reinoud 		int what, union dscrptr *dscr,
    136  1.1  reinoud 		uint32_t sector, uint32_t logsector);
    137  1.1  reinoud int nilfs_write_phys_dscr_async(struct nilfs_mount *ump, struct nilfs_node *nilfs_node,
    138  1.1  reinoud 		      int what, union dscrptr *dscr,
    139  1.1  reinoud 		      uint32_t sector, uint32_t logsector,
    140  1.1  reinoud 		      void (*dscrwr_callback)(struct buf *));
    141  1.1  reinoud 
    142  1.1  reinoud /* read/write node descriptors */
    143  1.1  reinoud int nilfs_create_logvol_dscr(struct nilfs_mount *ump, struct nilfs_node *nilfs_node,
    144  1.1  reinoud 	struct long_ad *icb, union dscrptr **dscrptr);
    145  1.1  reinoud void nilfs_free_logvol_dscr(struct nilfs_mount *ump, struct long_ad *icb_loc,
    146  1.1  reinoud 	void *dscr);
    147  1.1  reinoud int nilfs_read_logvol_dscr(struct nilfs_mount *ump, struct long_ad *icb,
    148  1.1  reinoud 	union dscrptr **dscrptr);
    149  1.1  reinoud int nilfs_write_logvol_dscr(struct nilfs_node *nilfs_node, union dscrptr *dscr,
    150  1.1  reinoud 	struct long_ad *icb, int waitfor);
    151  1.1  reinoud 
    152  1.1  reinoud 
    153  1.1  reinoud /* volume descriptors readers and checkers */
    154  1.1  reinoud int nilfs_read_anchors(struct nilfs_mount *ump);
    155  1.1  reinoud int nilfs_read_vds_space(struct nilfs_mount *ump);
    156  1.1  reinoud int nilfs_process_vds(struct nilfs_mount *ump);
    157  1.1  reinoud int nilfs_read_vds_tables(struct nilfs_mount *ump);
    158  1.1  reinoud int nilfs_read_rootdirs(struct nilfs_mount *ump);
    159  1.1  reinoud 
    160  1.1  reinoud /* open/close and sync volumes */
    161  1.1  reinoud int nilfs_open_logvol(struct nilfs_mount *ump);
    162  1.1  reinoud int nilfs_close_logvol(struct nilfs_mount *ump, int mntflags);
    163  1.1  reinoud int nilfs_writeout_vat(struct nilfs_mount *ump);
    164  1.1  reinoud int nilfs_write_physical_partition_spacetables(struct nilfs_mount *ump, int waitfor);
    165  1.1  reinoud int nilfs_write_metadata_partition_spacetable(struct nilfs_mount *ump, int waitfor);
    166  1.1  reinoud void nilfs_do_sync(struct nilfs_mount *ump, kauth_cred_t cred, int waitfor);
    167  1.1  reinoud 
    168  1.1  reinoud /* translation services */
    169  1.1  reinoud int nilfs_translate_vtop(struct nilfs_mount *ump, struct long_ad *icb_loc,
    170  1.1  reinoud 		uint32_t *lb_numres, uint32_t *extres);
    171  1.1  reinoud void nilfs_translate_vtop_list(struct nilfs_mount *ump, uint32_t sectors,
    172  1.1  reinoud 		uint16_t vpart_num, uint64_t *lmapping, uint64_t *pmapping);
    173  1.1  reinoud int nilfs_translate_file_extent(struct nilfs_node *node,
    174  1.1  reinoud 		uint32_t from, uint32_t num_lb, uint64_t *map);
    175  1.1  reinoud void nilfs_get_adslot(struct nilfs_node *nilfs_node, int slot, struct long_ad *icb, int *eof);
    176  1.1  reinoud int nilfs_append_adslot(struct nilfs_node *nilfs_node, int *slot, struct long_ad *icb);
    177  1.1  reinoud 
    178  1.1  reinoud int nilfs_vat_read(struct nilfs_node *vat_node, uint8_t *blob, int size, uint32_t offset);
    179  1.1  reinoud int nilfs_vat_write(struct nilfs_node *vat_node, uint8_t *blob, int size, uint32_t offset);
    180  1.1  reinoud 
    181  1.1  reinoud /* disc allocation */
    182  1.1  reinoud void nilfs_late_allocate_buf(struct nilfs_mount *ump, struct buf *buf, uint64_t *lmapping, struct long_ad *node_ad_cpy, uint16_t *vpart_num);
    183  1.1  reinoud void nilfs_free_allocated_space(struct nilfs_mount *ump, uint32_t lb_num, uint16_t vpart_num, uint32_t num_lb);
    184  1.1  reinoud int nilfs_pre_allocate_space(struct nilfs_mount *ump, int nilfs_c_type, uint32_t num_lb, uint16_t vpartnr, uint64_t *lmapping);
    185  1.1  reinoud int nilfs_grow_node(struct nilfs_node *node, uint64_t new_size);
    186  1.1  reinoud int nilfs_shrink_node(struct nilfs_node *node, uint64_t new_size);
    187  1.1  reinoud 
    188  1.1  reinoud /* node readers and writers */
    189  1.1  reinoud uint64_t nilfs_advance_uniqueid(struct nilfs_mount *ump);
    190  1.1  reinoud 
    191  1.1  reinoud #define NILFS_LOCK_NODE(nilfs_node, flag) nilfs_lock_node(nilfs_node, (flag), __FILE__, __LINE__)
    192  1.1  reinoud #define NILFS_UNLOCK_NODE(nilfs_node, flag) nilfs_unlock_node(nilfs_node, (flag))
    193  1.1  reinoud void nilfs_lock_node(struct nilfs_node *nilfs_node, int flag, char const *fname, const int lineno);
    194  1.1  reinoud void nilfs_unlock_node(struct nilfs_node *nilfs_node, int flag);
    195  1.1  reinoud 
    196  1.1  reinoud int nilfs_get_node(struct nilfs_mount *ump, struct long_ad *icbloc, struct nilfs_node **noderes);
    197  1.1  reinoud int nilfs_writeout_node(struct nilfs_node *nilfs_node, int waitfor);
    198  1.1  reinoud int nilfs_dispose_node(struct nilfs_node *node);
    199  1.1  reinoud 
    200  1.1  reinoud /* node ops */
    201  1.1  reinoud int nilfs_resize_node(struct nilfs_node *node, uint64_t new_size, int *extended);
    202  1.1  reinoud int nilfs_extattr_search_intern(struct nilfs_node *node, uint32_t sattr, char const *sattrname, uint32_t *offsetp, uint32_t *lengthp);
    203  1.1  reinoud 
    204  1.1  reinoud /* node data buffer read/write */
    205  1.1  reinoud void nilfs_read_filebuf(struct nilfs_node *node, struct buf *buf);
    206  1.1  reinoud void nilfs_write_filebuf(struct nilfs_node *node, struct buf *buf);
    207  1.1  reinoud void nilfs_fixup_fid_block(uint8_t *blob, int lb_size, int rfix_pos, int max_rfix_pos, uint32_t lb_num);
    208  1.1  reinoud void nilfs_fixup_internal_extattr(uint8_t *blob, uint32_t lb_num);
    209  1.1  reinoud void nilfs_fixup_node_internals(struct nilfs_mount *ump, uint8_t *blob, int nilfs_c_type);
    210  1.1  reinoud 
    211  1.1  reinoud /* device strategy */
    212  1.1  reinoud void nilfs_discstrat_init(struct nilfs_mount *ump);
    213  1.1  reinoud void nilfs_discstrat_finish(struct nilfs_mount *ump);
    214  1.1  reinoud void nilfs_discstrat_queuebuf(struct nilfs_mount *ump, struct buf *nestbuf);
    215  1.1  reinoud 
    216  1.1  reinoud /* structure writers */
    217  1.1  reinoud int nilfs_write_terminator(struct nilfs_mount *ump, uint32_t sector);
    218  1.1  reinoud 
    219  1.1  reinoud /* structure creators */
    220  1.1  reinoud void nilfs_inittag(struct nilfs_mount *ump, struct desc_tag *tag, int tagid, uint32_t sector);
    221  1.1  reinoud void nilfs_set_regid(struct regid *regid, char const *name);
    222  1.1  reinoud void nilfs_add_domain_regid(struct nilfs_mount *ump, struct regid *regid);
    223  1.1  reinoud void nilfs_add_nilfs_regid(struct nilfs_mount *ump, struct regid *regid);
    224  1.1  reinoud void nilfs_add_impl_regid(struct nilfs_mount *ump, struct regid *regid);
    225  1.1  reinoud void nilfs_add_app_regid(struct nilfs_mount *ump, struct regid *regid);
    226  1.1  reinoud 
    227  1.1  reinoud /* directory operations and helpers */
    228  1.1  reinoud void nilfs_osta_charset(struct charspec *charspec);
    229  1.1  reinoud int nilfs_read_fid_stream(struct vnode *vp, uint64_t *offset, struct fileid_desc *fid, struct dirent *dirent);
    230  1.1  reinoud int nilfs_lookup_name_in_dir(struct vnode *vp, const char *name, int namelen, struct long_ad *icb_loc, int *found);
    231  1.1  reinoud int nilfs_create_node(struct vnode *dvp, struct vnode **vpp, struct vattr *vap, struct componentname *cnp);
    232  1.1  reinoud void nilfs_delete_node(struct nilfs_node *nilfs_node);
    233  1.1  reinoud 
    234  1.1  reinoud int nilfs_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred);
    235  1.1  reinoud int nilfs_dir_detach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct componentname *cnp);
    236  1.1  reinoud int nilfs_dir_attach(struct nilfs_mount *ump, struct nilfs_node *dir_node, struct nilfs_node *nilfs_node, struct vattr *vap, struct componentname *cnp);
    237  1.1  reinoud 
    238  1.1  reinoud /* update and times */
    239  1.1  reinoud void nilfs_add_to_dirtylist(struct nilfs_node *nilfs_node);
    240  1.1  reinoud void nilfs_remove_from_dirtylist(struct nilfs_node *nilfs_node);
    241  1.1  reinoud void nilfs_itimes(struct nilfs_node *nilfs_node, struct timespec *acc,
    242  1.1  reinoud 	struct timespec *mod, struct timespec *birth);
    243  1.1  reinoud int  nilfs_update(struct vnode *node, struct timespec *acc,
    244  1.1  reinoud 	struct timespec *mod, struct timespec *birth, int updflags);
    245  1.1  reinoud 
    246  1.1  reinoud /* helpers and converters */
    247  1.1  reinoud long nilfs_calchash(struct long_ad *icbptr);    /* for `inode' numbering */
    248  1.1  reinoud uint32_t nilfs_getaccessmode(struct nilfs_node *node);
    249  1.1  reinoud void nilfs_setaccessmode(struct nilfs_node *nilfs_node, mode_t mode);
    250  1.1  reinoud void nilfs_getownership(struct nilfs_node *nilfs_node, uid_t *uidp, gid_t *gidp);
    251  1.1  reinoud void nilfs_setownership(struct nilfs_node *nilfs_node, uid_t uid, gid_t gid);
    252  1.1  reinoud 
    253  1.1  reinoud void nilfs_to_unix_name(char *result, int result_len, char *id, int len, struct charspec *chsp);
    254  1.1  reinoud void unix_to_nilfs_name(char *result, uint8_t *result_len, char const *name, int name_len, struct charspec *chsp);
    255  1.1  reinoud 
    256  1.1  reinoud void nilfs_timestamp_to_timespec(struct nilfs_mount *ump, struct timestamp *timestamp, struct timespec *timespec);
    257  1.1  reinoud void nilfs_timespec_to_timestamp(struct timespec *timespec, struct timestamp *timestamp);
    258  1.1  reinoud #endif
    259