xref: /haiku/headers/private/kernel/boot/vfs.h (revision 4796acbc8c8fa3a5325a27722746b999009988d1)
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,
30 			size_t bufferSize) = 0;
31 		virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer,
32 			size_t bufferSize) = 0;
33 
34 		virtual status_t ReadLink(char* buffer, size_t bufferSize);
35 
36 		virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
37 		virtual status_t GetFileMap(struct file_map_run *runs, int32 *count);
38 		virtual int32 Type() const;
39 		virtual off_t Size() const;
40 		virtual ino_t Inode() const;
41 
42 		status_t Acquire();
43 		status_t Release();
44 
45 	protected:
46 		int32		fRefCount;
47 };
48 
49 typedef DoublyLinkedList<Node> NodeList;
50 typedef NodeList::Iterator NodeIterator;
51 
52 
53 class Directory : public Node {
54 	public:
55 		Directory();
56 
57 		virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize);
58 		virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize);
59 
60 		virtual int32 Type() const;
61 
62 		virtual Node* Lookup(const char* name, bool traverseLinks);
63 		virtual Node* LookupDontTraverse(const char* name) = 0;
64 
65 		virtual status_t GetNextEntry(void *cookie, char *nameBuffer, size_t bufferSize) = 0;
66 		virtual status_t GetNextNode(void *cookie, Node **_node) = 0;
67 		virtual status_t Rewind(void *cookie) = 0;
68 		virtual bool IsEmpty() = 0;
69 
70 		virtual status_t CreateFile(const char *name, mode_t permissions,
71 			Node **_node);
72 };
73 
74 /** The console based nodes don't need cookies for I/O, they
75  *	also don't support to change the stream position.
76  *	Live is simple in the boot loader :-)
77  */
78 
79 class ConsoleNode : public Node {
80 	public:
81 		ConsoleNode();
82 
83 		virtual ssize_t Read(void *buffer, size_t bufferSize);
84 		virtual ssize_t Write(const void *buffer, size_t bufferSize);
85 };
86 
87 
88 class MemoryDisk : public Node {
89 	public:
90 		MemoryDisk(const uint8* data, size_t size, const char* name);
91 
92 		virtual ssize_t ReadAt(void* cookie, off_t pos, void* buffer,
93 			size_t bufferSize);
94 		virtual ssize_t WriteAt(void* cookie, off_t pos, const void* buffer,
95 			size_t bufferSize);
96 
97 		virtual off_t Size() const;
98 		virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
99 
100 	private:
101 		const uint8*	fData;
102 		size_t			fSize;
103 		char			fName[64];
104 };
105 
106 
107 class BootVolume {
108 public:
109 								BootVolume();
110 								~BootVolume();
111 
112 		status_t				SetTo(Directory* rootDirectory);
113 		void					Unset();
114 
115 		bool					IsValid() const
116 									{ return fRootDirectory != NULL; }
117 
118 		Directory*				RootDirectory() const
119 									{ return fRootDirectory; }
120 		Directory*				SystemDirectory() const
121 									{ return fSystemDirectory; }
122 		bool					IsPackaged() const
123 									{ return fPackaged; }
124 
125 private:
126 			Directory*			fRootDirectory;
127 				// root directory of the volume
128 			Directory*			fSystemDirectory;
129 				// "system" directory of the volume; if packaged the root
130 				// directory of the mounted packagefs
131 			bool				fPackaged;
132 				// indicates whether the boot volume's system is packaged
133 };
134 
135 
136 /* function prototypes */
137 
138 extern status_t vfs_init(stage2_args *args);
139 extern status_t register_boot_file_system(BootVolume& bootVolume);
140 extern status_t get_boot_file_system(stage2_args* args,
141 			BootVolume& _bootVolume);
142 extern status_t mount_file_systems(stage2_args *args);
143 extern int open_node(Node *node, int mode);
144 extern int open_from(Directory *directory, const char *path, int mode,
145 			mode_t permissions = 0);
146 
147 extern Node *get_node_from(int fd);
148 
149 extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false);
150 extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false);
151 
152 #endif	/* __cplusplus */
153 
154 #endif	/* KERNEL_BOOT_VFS_H */
155