1/* 2 * Copyright (c) 2012 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29#ifndef MOCKFS_FSNODE_H 30#define MOCKFS_FSNODE_H 31 32#if MOCKFS 33 34#include <sys/kernel_types.h> 35 36/* 37 * Types for the filesystem nodes; for the moment, these will effectively serve as unique 38 * identifiers. This can be generalized later, but at least for the moment, the read-only 39 * nature of the filesystem and the terse semantics (you have VDIR and VREG, and VREG 40 * always represents the entire backing device) makes this sufficient for now. 41 * 42 * TODO: Should this include MOCKFS_SBIN? Right now we tell lookup that when looking in 43 * MOCKFS_ROOT, "sbin" resolves back onto MOCKFS_ROOT; this is a handy hack for aliasing, 44 * but may not mesh well with VFS. 45 */ 46enum mockfs_fsnode_type { 47 MOCKFS_ROOT, 48 MOCKFS_DEV, 49 MOCKFS_FILE 50}; 51 52/* 53 * For the moment, pretend everything is a directory with support for two entries; the 54 * executable binary is a one-to-one mapping with the backing devnode, so this may 55 * actually be all we're interested in. 56 * 57 * Stash the filesize in here too (this is easier then looking at the devnode for every 58 * VREG access). 59 */ 60struct mockfs_fsnode { 61 uint64_t size; /* Bytes of data; 0 unless type is MOCKFS_FILE */ 62 uint8_t type; /* Serves as a unique identifier for now */ 63 mount_t mnt; /* The mount that this node belongs to */ 64 vnode_t vp; /* vnode for this node (if one exists) */ 65 struct mockfs_fsnode * parent; /* Parent of this node (NULL for root) */ 66 /* TODO: Replace child_a/child_b with something more flexible */ 67 struct mockfs_fsnode * child_a; /* TEMPORARY */ 68 struct mockfs_fsnode * child_b; /* TEMPORARY */ 69}; 70 71typedef struct mockfs_fsnode * mockfs_fsnode_t; 72 73/* 74 * See mockfs_fsnode.c for function details. 75 */ 76int mockfs_fsnode_create(mount_t mp, uint8_t type, mockfs_fsnode_t * fsnpp); 77int mockfs_fsnode_destroy(mockfs_fsnode_t fsnp); 78int mockfs_fsnode_adopt(mockfs_fsnode_t parent, mockfs_fsnode_t child); 79int mockfs_fsnode_orphan(mockfs_fsnode_t fsnp); 80int mockfs_fsnode_child_by_type(mockfs_fsnode_t parent, uint8_t type, mockfs_fsnode_t * child); 81int mockfs_fsnode_vnode(mockfs_fsnode_t fsnp, vnode_t * vpp); 82int mockfs_fsnode_drop_vnode(mockfs_fsnode_t fsnp); 83 84#endif /* MOCKFS */ 85 86#endif /* MOCKFS_FSNODE_H */ 87 88