xref: /haiku/headers/private/kernel/boot/vfs.h (revision 24159a0c7d6d6dcba9f2a0c1a7c08d2c8167f21b)
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 /* function prototypes */
77 
78 extern status_t vfs_init(stage2_args *args);
79 extern status_t register_boot_file_system(Directory *directory);
80 extern Directory *get_boot_file_system(stage2_args *args);
81 extern status_t mount_file_systems(stage2_args *args);
82 extern int open_node(Node *node, int mode);
83 extern int open_from(Directory *directory, const char *path, int mode);
84 
85 extern Node *get_node_from(int fd);
86 
87 extern status_t add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice = false);
88 extern status_t add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice = false);
89 
90 #endif	/* __cplusplus */
91 
92 #endif	/* KERNEL_BOOT_VFS_H */
93