1 /* 2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the OpenBeOS License. 4 */ 5 #ifndef KERNEL_BOOT_VFS_H 6 #define KERNEL_BOOT_VFS_H 7 8 9 #include <SupportDefs.h> 10 11 #include <util/list.h> 12 #include <boot/stage2_args.h> 13 14 15 #ifdef __cplusplus 16 17 /** This is the base class for all VFS nodes */ 18 19 class Node { 20 public: 21 Node(); 22 virtual ~Node(); 23 24 virtual status_t Open(void **_cookie, int mode); 25 virtual status_t Close(void *cookie); 26 27 virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) = 0; 28 virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) = 0; 29 30 virtual status_t GetName(char *nameBuffer, size_t bufferSize) const; 31 virtual int32 Type() const; 32 virtual off_t Size() const; 33 34 status_t Acquire(); 35 status_t Release(); 36 37 protected: 38 list_link fLink; 39 int32 fRefCount; 40 }; 41 42 43 class Directory : public Node { 44 public: 45 Directory(); 46 47 virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); 48 virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); 49 50 virtual int32 Type() const; 51 52 virtual Node *Lookup(const char *name, bool traverseLinks) = 0; 53 54 virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize) = 0; 55 virtual status_t GetNextNode(void *cookie, Node **_node) = 0; 56 virtual status_t Rewind(void *cookie) = 0; 57 virtual bool IsEmpty() = 0; 58 59 virtual status_t AddNode(Node *node); 60 }; 61 62 /** The console based nodes don't need cookies for I/O, they 63 * also don't support to change the stream position. 64 * Live is simple in the boot loader :-) 65 */ 66 67 class ConsoleNode : public Node { 68 public: 69 ConsoleNode(); 70 71 virtual ssize_t Read(void *buffer, size_t bufferSize); 72 virtual ssize_t Write(const void *buffer, size_t bufferSize); 73 }; 74 75 /** The root file system */ 76 extern Directory *gRoot; 77 78 /* function prototypes */ 79 80 extern status_t vfs_init(stage2_args *args); 81 extern Directory *get_boot_file_system(stage2_args *args); 82 extern status_t mount_file_systems(stage2_args *args); 83 extern int open_node(Node *node, int mode); 84 extern int open_from(Directory *directory, const char *path, int mode); 85 86 extern status_t add_partitions_for(int fd, bool mountFileSystems); 87 extern status_t add_partitions_for(Node *device, bool mountFileSystems); 88 89 #endif /* __cplusplus */ 90 91 #endif /* KERNEL_BOOT_VFS_H */ 92