|
| 1 | +/* |
| 2 | + * Copyright (c) 2015 Carnegie Mellon University. |
| 3 | + * All Rights Reserved. |
| 4 | + * |
| 5 | + * THIS SOFTWARE IS PROVIDED "AS IS," WITH NO WARRANTIES WHATSOEVER. CARNEGIE |
| 6 | + * MELLON UNIVERSITY EXPRESSLY DISCLAIMS TO THE FULLEST EXTENT PERMITTEDBY LAW |
| 7 | + * ALL EXPRESS, IMPLIED, AND STATUTORY WARRANTIES, INCLUDING, WITHOUT |
| 8 | + * LIMITATION, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| 9 | + * PURPOSE, AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS. |
| 10 | + * |
| 11 | + * Released under a modified BSD license. For full terms, please see mfs.txt in |
| 12 | + * the licenses folder or contact [email protected]. |
| 13 | + * |
| 14 | + * DM-0002621 |
| 15 | + * |
| 16 | + * Based on https://github.com/jdroot/mfs |
| 17 | + * |
| 18 | + * Copyright (C) 2017 Waldemar Kozaczuk |
| 19 | + * Inspired by original MFS implementation by James Root from 2015 |
| 20 | + * |
| 21 | + * This work is open source software, licensed under the terms of the |
| 22 | + * BSD license as described in the LICENSE file in the top-level directory. |
| 23 | + */ |
| 24 | + |
| 25 | +// |
| 26 | +// The Read-Only File System (ROFS) provides simple implementation of |
| 27 | +// a file system where data from disk can only be read from and never |
| 28 | +// written to. It is simple enough for many stateless applications |
| 29 | +// deployed on OSv which only need to read code from local disk and never |
| 30 | +// write to local disk. The ROFS is inspired and shares some ideas |
| 31 | +// from the original MFS implementation by James Root from 2015. |
| 32 | +// |
| 33 | +// This initial version of ROFS operates without cache. It reads as much data |
| 34 | +// from disk as requested per uio passed in to the read function and it does |
| 35 | +// not retain/cache it for any subsequent read of the same data. |
| 36 | +// |
| 37 | +// The structure of the data on disk is explained in scripts/gen-rofs-img.py |
| 38 | + |
| 39 | +#ifndef __INCLUDE_ROFS_H__ |
| 40 | +#define __INCLUDE_ROFS_H__ |
| 41 | + |
| 42 | +#include <osv/vnode.h> |
| 43 | +#include <osv/mount.h> |
| 44 | +#include <osv/dentry.h> |
| 45 | +#include <osv/prex.h> |
| 46 | +#include <osv/buf.h> |
| 47 | + |
| 48 | +#define ROFS_VERSION 1 |
| 49 | +#define ROFS_MAGIC 0xDEADBEAD |
| 50 | + |
| 51 | +#define ROFS_INODE_SIZE ((uint64_t)sizeof(struct rofs_inode)) |
| 52 | + |
| 53 | +#define ROFS_SUPERBLOCK_SIZE sizeof(struct rofs_super_block) |
| 54 | +#define ROFS_SUPERBLOCK_BLOCK 0 |
| 55 | + |
| 56 | +//#define ROFS_DEBUG_ENABLED 1 |
| 57 | + |
| 58 | +#if defined(ROFS_DEBUG_ENABLED) |
| 59 | +#define print(...) kprintf(__VA_ARGS__) |
| 60 | +#else |
| 61 | +#define print(...) |
| 62 | +#endif |
| 63 | + |
| 64 | +#define ROFS_DIAGNOSTICS_ENABLED 1 |
| 65 | + |
| 66 | +#if defined(ROFS_DIAGNOSTICS_ENABLED) |
| 67 | +#define ROFS_STOPWATCH_START auto begin = std::chrono::high_resolution_clock::now(); |
| 68 | +#define ROFS_STOPWATCH_END(total) auto end = std::chrono::high_resolution_clock::now(); \ |
| 69 | +std::chrono::duration<double> sec = end - begin; \ |
| 70 | +total += ((long)(sec.count() * 1000000)); |
| 71 | +//TODO: Review - avoid conversions |
| 72 | +#else |
| 73 | +#define ROFS_STOPWATCH_START |
| 74 | +#define ROFS_STOPWATCH_END(...) |
| 75 | +#endif |
| 76 | + |
| 77 | +extern struct vfsops rofs_vfsops; |
| 78 | +extern struct vnops rofs_vnops; |
| 79 | + |
| 80 | +struct rofs_super_block { |
| 81 | + uint64_t magic; |
| 82 | + uint64_t version; |
| 83 | + uint64_t block_size; |
| 84 | + uint64_t structure_info_first_block; |
| 85 | + uint64_t structure_info_blocks_count; |
| 86 | + uint64_t directory_entries_count; |
| 87 | + uint64_t symlinks_count; |
| 88 | + uint64_t inodes_count; |
| 89 | +}; |
| 90 | + |
| 91 | +struct rofs_inode { |
| 92 | + mode_t mode; |
| 93 | + uint64_t inode_no; |
| 94 | + uint64_t data_offset; |
| 95 | + union { |
| 96 | + uint64_t file_size; |
| 97 | + uint64_t dir_children_count; |
| 98 | + }; |
| 99 | +}; |
| 100 | + |
| 101 | +struct rofs_dir_entry { |
| 102 | + char *filename; |
| 103 | + uint64_t inode_no; |
| 104 | +}; |
| 105 | + |
| 106 | +struct rofs_info { |
| 107 | + struct rofs_super_block *sb; |
| 108 | + struct rofs_dir_entry *dir_entries; |
| 109 | + char **symlinks; |
| 110 | + struct rofs_inode *inodes; |
| 111 | +}; |
| 112 | + |
| 113 | +int rofs_read_blocks(struct device *device, uint64_t starting_block, uint64_t blocks_count, void *buf); |
| 114 | + |
| 115 | +void rofs_set_vnode(struct vnode *vnode, struct rofs_inode *inode); |
| 116 | + |
| 117 | +#endif |
0 commit comments