vfs: check userland buffers before reading them.
[haiku.git] / src / build / libroot / fs_descriptors.h
blob0df18381bb8ddc6fb2259da17b72613c378cce2b
1 /*
2 * Copyright 2005-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef FS_DESCRIPTORS_H
6 #define FS_DESCRIPTORS_H
8 #include <dirent.h>
10 #include <string>
12 #include <StorageDefs.h>
13 #include <SupportDefs.h>
15 #include "NodeRef.h"
17 using std::string;
19 struct stat;
21 namespace BPrivate {
23 // Descriptor
24 struct Descriptor {
25 int fd;
27 virtual ~Descriptor();
29 virtual status_t Close() = 0;
30 virtual status_t Dup(Descriptor *&clone) = 0;
31 virtual status_t GetStat(bool traverseLink, struct stat *st) = 0;
33 virtual bool IsSystemFD() const;
34 virtual status_t GetPath(string& path) const;
36 virtual status_t GetNodeRef(NodeRef &ref);
39 // FileDescriptor
40 struct FileDescriptor : Descriptor {
41 FileDescriptor(int fd);
42 virtual ~FileDescriptor();
44 virtual status_t Close();
45 virtual status_t Dup(Descriptor *&clone);
46 virtual status_t GetStat(bool traverseLink, struct stat *st);
48 virtual bool IsSystemFD() const;
51 // DirectoryDescriptor
52 struct DirectoryDescriptor : Descriptor {
53 DIR *dir;
54 NodeRef ref;
56 DirectoryDescriptor(DIR *dir, const NodeRef &ref);
57 virtual ~DirectoryDescriptor();
59 virtual status_t Close();
60 virtual status_t Dup(Descriptor *&clone);
61 virtual status_t GetStat(bool traverseLink, struct stat *st);
63 virtual status_t GetNodeRef(NodeRef &ref);
66 // SymlinkDescriptor
67 struct SymlinkDescriptor : Descriptor {
68 string path;
70 SymlinkDescriptor(const char *path);
72 virtual status_t Close();
73 virtual status_t Dup(Descriptor *&clone);
74 virtual status_t GetStat(bool traverseLink, struct stat *st);
76 virtual status_t GetPath(string& path) const;
79 // AttributeDescriptor
80 struct AttributeDescriptor : Descriptor {
81 AttributeDescriptor(int fileFD,
82 const char* attribute, uint32 type,
83 int openMode);
84 virtual ~AttributeDescriptor();
86 status_t Init();
87 status_t Write(off_t offset, const void* buffer,
88 size_t bufferSize);
90 int FileFD() const { return fFileFD; }
91 const char* Attribute() const { return fAttribute; }
92 uint32 Type() const { return fType; }
93 int OpenMode() const { return fOpenMode; }
95 virtual status_t Close();
96 virtual status_t Dup(Descriptor*& clone);
97 virtual status_t GetStat(bool traverseLink, struct stat* st);
99 private:
100 int fFileFD;
101 char fAttribute[B_ATTR_NAME_LENGTH];
102 uint32 fType;
103 int fOpenMode;
104 uint8* fData;
105 size_t fDataSize;
108 // AttrDirDescriptor
109 struct AttrDirDescriptor : DirectoryDescriptor {
111 AttrDirDescriptor(DIR *dir, const NodeRef &ref);
112 virtual ~AttrDirDescriptor();
114 virtual status_t Close();
115 virtual status_t Dup(Descriptor *&clone);
116 virtual status_t GetStat(bool traverseLink, struct stat *st);
118 virtual status_t GetNodeRef(NodeRef &ref);
122 Descriptor* get_descriptor(int fd);
123 int add_descriptor(Descriptor *descriptor);
124 status_t delete_descriptor(int fd);
125 bool is_unknown_or_system_descriptor(int fd);
127 } // namespace BPrivate
129 #endif // FS_DESCRIPTORS_H