xref: /haiku/headers/private/kernel/boot/vfs.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
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 /** This is the base class for all VFS nodes */
18 
19 class Node : public DoublyLinkedListLinkImpl<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 		virtual ino_t Inode() const;
34 
35 		status_t Acquire();
36 		status_t Release();
37 
38 	protected:
39 		int32		fRefCount;
40 };
41 
42 typedef DoublyLinkedList<Node> NodeList;
43 typedef NodeList::Iterator NodeIterator;
44 
45 
46 class Directory : public Node {
47 	public:
48 		Directory();
49 
50 		virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
51 		virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
52 
53 		virtual int32 Type() const;
54 
55 		virtual Node *Lookup(const char *name, bool traverseLinks) = 0;
56 
57 		virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize) = 0;
58 		virtual status_t GetNextNode(void *cookie, Node **_node) = 0;
59 		virtual status_t Rewind(void *cookie) = 0;
60 		virtual bool IsEmpty() = 0;
61 };
62 
63 /** The console based nodes don't need cookies for I/O, they
64  *	also don't support to change the stream position.
65  *	Live is simple in the boot loader :-)
66  */
67 
68 class ConsoleNode : public Node {
69 	public:
70 		ConsoleNode();
71 
72 		virtual ssize_t Read(void *buffer, size_t bufferSize);
73 		virtual ssize_t Write(const void *buffer, size_t bufferSize);
74 };
75 
76 
77 class MemoryDisk : public Node {
78 	public:
79 		MemoryDisk(const uint8* data, size_t size, const char* name);
80 
81 		virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer,
82 			size_t bufferSize);
83 		virtual ssize_t WriteAt(void* cookie, off_t pos, const void* buffer,
84 			size_t bufferSize);
85 
86 		virtual off_t Size() const;
87 		virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
88 
89 	private:
90 		const uint8*	fData;
91 		size_t			fSize;
92 		char			fName[64];
93 };
94 
95 
96 /* function prototypes */
97 
98 extern status_t vfs_init(stage2_args *args);
99 extern status_t register_boot_file_system(Directory *directory);
100 extern Directory *get_boot_file_system(stage2_args *args);
101 extern status_t mount_file_systems(stage2_args *args);
102 extern int open_node(Node *node, int mode);
103 extern int open_from(Directory *directory, const char *path, int mode);
104 
105 extern Node *get_node_from(int fd);
106 
107 extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false);
108 extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false);
109 
110 #endif	/* __cplusplus */
111 
112 #endif	/* KERNEL_BOOT_VFS_H */
113