1*0a6a1f1dSLionel Sambuc /* $NetBSD: chfs_inode.h,v 1.10 2015/01/11 17:29:57 hannken Exp $ */ 2d65f6f70SBen Gras 3d65f6f70SBen Gras /*- 4d65f6f70SBen Gras * Copyright (c) 2010 Department of Software Engineering, 5d65f6f70SBen Gras * University of Szeged, Hungary 6d65f6f70SBen Gras * Copyright (C) 2010 Tamas Toth <ttoth@inf.u-szeged.hu> 7d65f6f70SBen Gras * Copyright (C) 2010 Adam Hoka <ahoka@NetBSD.org> 8d65f6f70SBen Gras * All rights reserved. 9d65f6f70SBen Gras * 10d65f6f70SBen Gras * This code is derived from software contributed to The NetBSD Foundation 11d65f6f70SBen Gras * by the Department of Software Engineering, University of Szeged, Hungary 12d65f6f70SBen Gras * 13d65f6f70SBen Gras * Redistribution and use in source and binary forms, with or without 14d65f6f70SBen Gras * modification, are permitted provided that the following conditions 15d65f6f70SBen Gras * are met: 16d65f6f70SBen Gras * 1. Redistributions of source code must retain the above copyright 17d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer. 18d65f6f70SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 19d65f6f70SBen Gras * notice, this list of conditions and the following disclaimer in the 20d65f6f70SBen Gras * documentation and/or other materials provided with the distribution. 21d65f6f70SBen Gras * 22d65f6f70SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23d65f6f70SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24d65f6f70SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25d65f6f70SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26d65f6f70SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27d65f6f70SBen Gras * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28d65f6f70SBen Gras * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29d65f6f70SBen Gras * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30d65f6f70SBen Gras * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31d65f6f70SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32d65f6f70SBen Gras * SUCH DAMAGE. 33d65f6f70SBen Gras */ 34d65f6f70SBen Gras 35d65f6f70SBen Gras #ifndef __CHFS_INODE_H__ 36d65f6f70SBen Gras #define __CHFS_INODE_H__ 37d65f6f70SBen Gras 3884d9c625SLionel Sambuc #ifdef _KERNEL 39d65f6f70SBen Gras #include <sys/vnode.h> 40d65f6f70SBen Gras #include <sys/stat.h> 41d65f6f70SBen Gras #include <ufs/ufs/ufsmount.h> 42d65f6f70SBen Gras #include <miscfs/genfs/genfs_node.h> 4384d9c625SLionel Sambuc #endif /* _KERNEL */ 44d65f6f70SBen Gras 4584d9c625SLionel Sambuc #define CHFS_ROOTINO 2 4684d9c625SLionel Sambuc 4784d9c625SLionel Sambuc /* chfs file types */ 4884d9c625SLionel Sambuc enum chtype { 4984d9c625SLionel Sambuc CHT_BLANK, /* empty type */ 5084d9c625SLionel Sambuc CHT_REG, /* regular file */ 5184d9c625SLionel Sambuc CHT_DIR, /* directory */ 5284d9c625SLionel Sambuc CHT_BLK, /* block device */ 5384d9c625SLionel Sambuc CHT_CHR, /* character device */ 5484d9c625SLionel Sambuc CHT_LNK, /* link */ 5584d9c625SLionel Sambuc CHT_SOCK, /* socket */ 5684d9c625SLionel Sambuc CHT_FIFO, /* fifo */ 5784d9c625SLionel Sambuc CHT_BAD /* bad type */ 5884d9c625SLionel Sambuc }; 5984d9c625SLionel Sambuc 6084d9c625SLionel Sambuc /* these macros are needed because the compatibility */ 6184d9c625SLionel Sambuc #define CHTTOVT(ch_type) (enum vtype)(ch_type) 6284d9c625SLionel Sambuc #define VTTOCHT(v_type) (enum chtype)(v_type) 6384d9c625SLionel Sambuc 6484d9c625SLionel Sambuc /* vtype replaced with chtype, these are only for backward compatibility */ 6584d9c625SLionel Sambuc static const enum chtype iftocht_tab[16] = { 6684d9c625SLionel Sambuc CHT_BLANK, CHT_FIFO, CHT_CHR, CHT_BLANK, 6784d9c625SLionel Sambuc CHT_DIR, CHT_BLANK, CHT_BLK, CHT_BLANK, 6884d9c625SLionel Sambuc CHT_REG, CHT_BLANK, CHT_LNK, CHT_BLANK, 6984d9c625SLionel Sambuc CHT_SOCK, CHT_BLANK, CHT_BLANK, CHT_BAD, 7084d9c625SLionel Sambuc }; 7184d9c625SLionel Sambuc 7284d9c625SLionel Sambuc #define IFTOCHT(mode) (iftocht_tab[((mode) & S_IFMT) >> 12]) 7384d9c625SLionel Sambuc 7484d9c625SLionel Sambuc #ifdef _KERNEL 75d65f6f70SBen Gras struct chfs_inode 76d65f6f70SBen Gras { 7784d9c625SLionel Sambuc struct genfs_node gnode; 78d65f6f70SBen Gras kmutex_t inode_lock; /* lock the fields of chfs_inode */ 79d65f6f70SBen Gras 80d65f6f70SBen Gras struct ufsmount *ump; /* ufs mount - TODO we should remove it */ 81d65f6f70SBen Gras struct chfs_mount *chmp; /* chfs mount point - TODO we should remove it */ 82d65f6f70SBen Gras 83d65f6f70SBen Gras struct vnode *vp; /* vnode associated with this inode */ 84d65f6f70SBen Gras ino_t ino; /* vnode identifier number */ 85d65f6f70SBen Gras 86d65f6f70SBen Gras struct vnode *devvp; /* vnode for block I/O */ 87d65f6f70SBen Gras dev_t dev; /* device associated with the inode */ 88d65f6f70SBen Gras 89d65f6f70SBen Gras struct chfs_vnode_cache *chvc; /* vnode cache of this node */ 90d65f6f70SBen Gras 91d65f6f70SBen Gras struct chfs_dirent *fd; /* full dirent of this node */ 92d65f6f70SBen Gras struct chfs_dirent_list dents; 93d65f6f70SBen Gras 94d65f6f70SBen Gras struct rb_tree fragtree; /* fragtree of inode */ 95d65f6f70SBen Gras 96d65f6f70SBen Gras uint64_t version; /* version number */ 97d65f6f70SBen Gras 98d65f6f70SBen Gras uint32_t mode; /* mode */ 9984d9c625SLionel Sambuc enum chtype ch_type; /* chfs file type */ 100d65f6f70SBen Gras uint64_t size; /* file byte count */ 101d65f6f70SBen Gras uint64_t write_size; /* increasing while write the file out to the flash */ 102d65f6f70SBen Gras uint32_t uid; /* file owner */ 103d65f6f70SBen Gras uint32_t gid; /* file group */ 104d65f6f70SBen Gras uint32_t atime; /* access time */ 105d65f6f70SBen Gras uint32_t mtime; /* modify time */ 106d65f6f70SBen Gras uint32_t ctime; /* creation time */ 107d65f6f70SBen Gras 108d65f6f70SBen Gras uint32_t iflag; /* flags, see below */ 109d65f6f70SBen Gras uint32_t flags; /* status flags (chflags) */ 110d65f6f70SBen Gras 111d65f6f70SBen Gras dev_t rdev; /* used if type is VCHR or VBLK or VFIFO*/ 112d65f6f70SBen Gras char *target; /* used if type is VLNK */ 113d65f6f70SBen Gras }; 114d65f6f70SBen Gras 115d65f6f70SBen Gras /* These flags are kept in chfs_inode->iflag. */ 116d65f6f70SBen Gras #define IN_ACCESS 0x0001 /* Access time update request. */ 117d65f6f70SBen Gras #define IN_CHANGE 0x0002 /* Inode change time update request. */ 118d65f6f70SBen Gras #define IN_UPDATE 0x0004 /* Inode was written to; update mtime. */ 119d65f6f70SBen Gras #define IN_MODIFY 0x2000 /* Modification time update request. */ 120d65f6f70SBen Gras #define IN_MODIFIED 0x0008 /* Inode has been modified. */ 121d65f6f70SBen Gras #define IN_ACCESSED 0x0010 /* Inode has been accessed. */ 122*0a6a1f1dSLionel Sambuc /* unused 0x0020 */ /* was IN_RENAME */ 123d65f6f70SBen Gras #define IN_SHLOCK 0x0040 /* File has shared lock. */ 124d65f6f70SBen Gras #define IN_EXLOCK 0x0080 /* File has exclusive lock. */ 125*0a6a1f1dSLionel Sambuc /* unused 0x0100 */ /* was LFS-only IN_CLEANING */ 126*0a6a1f1dSLionel Sambuc /* unused 0x0200 */ /* was LFS-only IN_ADIROP */ 127d65f6f70SBen Gras #define IN_SPACECOUNTED 0x0400 /* Blocks to be freed in free count. */ 128*0a6a1f1dSLionel Sambuc /* unused 0x1000 */ /* was LFS-only IN_PAGING */ 129d65f6f70SBen Gras 130d65f6f70SBen Gras 131d65f6f70SBen Gras #ifdef VTOI 132d65f6f70SBen Gras # undef VTOI 133d65f6f70SBen Gras #endif 134d65f6f70SBen Gras #ifdef ITOV 135d65f6f70SBen Gras # undef ITOV 136d65f6f70SBen Gras #endif 137d65f6f70SBen Gras 13884d9c625SLionel Sambuc /* struct vnode to struct chfs_inode */ 139d65f6f70SBen Gras #define VTOI(vp) ((struct chfs_inode *)(vp)->v_data) 14084d9c625SLionel Sambuc /* struct chfs_inode to struct vnode */ 141d65f6f70SBen Gras #define ITOV(ip) ((ip)->vp) 142d65f6f70SBen Gras 14384d9c625SLionel Sambuc /* XXX copied from ufs_dinode.h and should not be duplicated here */ 14484d9c625SLionel Sambuc #define UFS_NDADDR 12 /* Direct addresses in inode. */ 145d65f6f70SBen Gras 14684d9c625SLionel Sambuc /* XXX this should not be duplicated here */ 14784d9c625SLionel Sambuc #define UFS_ROOTINO ((ino_t)2) 148d65f6f70SBen Gras 149d65f6f70SBen Gras /* File permissions. */ 150d65f6f70SBen Gras #define IEXEC 0000100 /* Executable. */ 151d65f6f70SBen Gras #define IWRITE 0000200 /* Writable. */ 152d65f6f70SBen Gras #define IREAD 0000400 /* Readable. */ 153d65f6f70SBen Gras #define ISVTX 0001000 /* Sticky bit. */ 154d65f6f70SBen Gras #define ISGID 0002000 /* Set-gid. */ 155d65f6f70SBen Gras #define ISUID 0004000 /* Set-uid. */ 156d65f6f70SBen Gras 157d65f6f70SBen Gras /* File types. */ 158d65f6f70SBen Gras #define IFMT 0170000 /* Mask of file type. */ 159d65f6f70SBen Gras #define IFIFO 0010000 /* Named pipe (fifo). */ 160d65f6f70SBen Gras #define IFCHR 0020000 /* Character device. */ 161d65f6f70SBen Gras #define IFDIR 0040000 /* Directory file. */ 162d65f6f70SBen Gras #define IFBLK 0060000 /* Block device. */ 163d65f6f70SBen Gras #define IFREG 0100000 /* Regular file. */ 164d65f6f70SBen Gras #define IFLNK 0120000 /* Symbolic link. */ 165d65f6f70SBen Gras #define IFSOCK 0140000 /* UNIX domain socket. */ 166d65f6f70SBen Gras #define IFWHT 0160000 /* Whiteout. */ 167d65f6f70SBen Gras 16884d9c625SLionel Sambuc #endif /* _KERNEL */ 169d65f6f70SBen Gras #endif /* __CHFS_INODE_H__ */ 170