xref: /haiku/headers/private/kernel/boot/vfs.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef KERNEL_BOOT_VFS_H
6 #define KERNEL_BOOT_VFS_H
7 
8 
9 #include <SupportDefs.h>
10 
11 #include <util/DoublyLinkedList.h>
12 #include <boot/stage2_args.h>
13 
14 
15 #ifdef __cplusplus
16 
17 struct file_map_run;
18 
19 /** This is the base class for all VFS nodes */
20 
21 class Node : public DoublyLinkedListLinkImpl<Node> {
22 	public:
23 		Node();
24 		virtual ~Node();
25 
26 		virtual status_t Open(void **_cookie, int mode);
27 		virtual status_t Close(void *cookie);
28 
29 		virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) = 0;
30 		virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) = 0;
31 
32 		virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
33 		virtual status_t GetFileMap(struct file_map_run *runs, int32 *count);
34 		virtual int32 Type() const;
35 		virtual off_t Size() const;
36 		virtual ino_t Inode() const;
37 
38 		status_t Acquire();
39 		status_t Release();
40 
41 	protected:
42 		int32		fRefCount;
43 };
44 
45 typedef DoublyLinkedList<Node> NodeList;
46 typedef NodeList::Iterator NodeIterator;
47 
48 
49 class Directory : public Node {
50 	public:
51 		Directory();
52 
53 		virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
54 		virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
55 
56 		virtual int32 Type() const;
57 
58 		virtual Node *Lookup(const char *name, bool traverseLinks) = 0;
59 
60 		virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize) = 0;
61 		virtual status_t GetNextNode(void *cookie, Node **_node) = 0;
62 		virtual status_t Rewind(void *cookie) = 0;
63 		virtual bool IsEmpty() = 0;
64 };
65 
66 /** The console based nodes don't need cookies for I/O, they
67  *	also don't support to change the stream position.
68  *	Live is simple in the boot loader :-)
69  */
70 
71 class ConsoleNode : public Node {
72 	public:
73 		ConsoleNode();
74 
75 		virtual ssize_t Read(void *buffer, size_t bufferSize);
76 		virtual ssize_t Write(const void *buffer, size_t bufferSize);
77 };
78 
79 
80 class MemoryDisk : public Node {
81 	public:
82 		MemoryDisk(const uint8* data, size_t size, const char* name);
83 
84 		virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer,
85 			size_t bufferSize);
86 		virtual ssize_t WriteAt(void* cookie, off_t pos, const void* buffer,
87 			size_t bufferSize);
88 
89 		virtual off_t Size() const;
90 		virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
91 
92 	private:
93 		const uint8*	fData;
94 		size_t			fSize;
95 		char			fName[64];
96 };
97 
98 
99 /* function prototypes */
100 
101 extern status_t vfs_init(stage2_args *args);
102 extern status_t register_boot_file_system(Directory *directory);
103 extern Directory *get_boot_file_system(stage2_args *args);
104 extern status_t mount_file_systems(stage2_args *args);
105 extern int open_node(Node *node, int mode);
106 extern int open_from(Directory *directory, const char *path, int mode);
107 
108 extern Node *get_node_from(int fd);
109 
110 extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false);
111 extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false);
112 
113 #endif	/* __cplusplus */
114 
115 #endif	/* KERNEL_BOOT_VFS_H */
116