1/* $NetBSD$ */ 2 3/*- 4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef _V7FS_INODE_H_ 33#define _V7FS_INODE_H_ 34 35/* Software implementation of inode. (memory image) */ 36struct v7fs_inode { 37 v7fs_ino_t inode_number; /* inode location */ 38 /* attr */ 39 uint16_t mode; 40 int16_t nlink; 41 int16_t uid; 42 int16_t gid; 43 v7fs_time_t atime; 44 v7fs_time_t mtime; 45 v7fs_time_t ctime; 46 /* open mode */ 47 bool append_mode; 48 49 v7fs_dev_t device; /* for special file.(cdev, bdev) */ 50 /* payload. */ 51 v7fs_off_t filesize; /* size of file (byte) */ 52 v7fs_daddr_t addr[V7FS_NADDR]; /* data block address list */ 53}; 54 55#define v7fs_inode_filesize(i) ((i)->filesize) 56#define v7fs_inode_allocated(i) ((i)->mode) 57#define v7fs_inode_nlink(i) ((i)->nlink) 58/* V7 original */ 59#define v7fs_inode_isdir(i) (((i)->mode & V7FS_IFMT) == V7FS_IFDIR) 60#define v7fs_inode_isfile(i) (((i)->mode & V7FS_IFMT) == V7FS_IFREG) 61#define v7fs_inode_iscdev(i) (((i)->mode & V7FS_IFMT) == V7FS_IFCHR) 62#define v7fs_inode_isbdev(i) (((i)->mode & V7FS_IFMT) == V7FS_IFBLK) 63/* 2BSD extension (implementation is different) */ 64#define v7fs_inode_islnk(i) (((i)->mode & V7FS_IFMT) == V7FSBSD_IFLNK) 65#define v7fs_inode_issock(i) (((i)->mode & V7FS_IFMT) == V7FSBSD_IFSOCK) 66/* NetBSD Extension */ 67#define v7fs_inode_isfifo(i) (((i)->mode & V7FS_IFMT) == V7FSBSD_IFFIFO) 68 69__BEGIN_DECLS 70/* Free inode access ops. */ 71int v7fs_inode_allocate(struct v7fs_self *, v7fs_ino_t *); 72void v7fs_inode_deallocate(struct v7fs_self *, v7fs_ino_t); 73 74/* Disk I/O ops. */ 75int v7fs_inode_load(struct v7fs_self *, struct v7fs_inode *, v7fs_ino_t); 76int v7fs_inode_writeback(struct v7fs_self *, struct v7fs_inode *); 77void v7fs_inode_setup_memory_image(const struct v7fs_self *, 78 struct v7fs_inode *, struct v7fs_inode_diskimage *); 79 80/* Check. */ 81int v7fs_inode_number_sanity(const struct v7fs_superblock *, v7fs_ino_t); 82 83/* Util. */ 84void v7fs_inode_chmod(struct v7fs_inode *, v7fs_mode_t); 85void v7fs_inode_dump(const struct v7fs_inode *); 86 87/* Loop over all inode in ilist. */ 88int v7fs_ilist_foreach(struct v7fs_self *, int (*)(struct v7fs_self *, void *, 89 struct v7fs_inode *, v7fs_ino_t), void *); 90__END_DECLS 91#endif /*!_V7FS_INODE_H_ */ 92