vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / FileInfo.h
blobca41768fd2260fe15dba895a23575388ff854f59
1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
8 #ifndef FILEINFO_H
9 #define FILEINFO_H
12 #include <stdlib.h>
13 #include <string.h>
15 #include <lock.h>
16 #include <SupportDefs.h>
17 #include <util/KernelReferenceable.h>
20 #define NFS4_FHSIZE 128
22 struct FileHandle {
23 uint8 fSize;
24 uint8 fData[NFS4_FHSIZE];
26 inline FileHandle();
27 inline FileHandle(const FileHandle& fh);
28 inline FileHandle& operator=(const FileHandle& fh);
31 inline bool operator==(const FileHandle& handle) const;
32 inline bool operator!=(const FileHandle& handle) const;
33 inline bool operator>(const FileHandle& handle) const;
34 inline bool operator<(const FileHandle& handle) const;
37 struct InodeNames;
39 struct InodeName : public SinglyLinkedListLinkImpl<InodeName> {
40 InodeName(InodeNames* parent, const char* name);
41 ~InodeName();
43 InodeNames* fParent;
44 const char* fName;
47 struct InodeNames : public KernelReferenceable {
48 InodeNames();
49 ~InodeNames();
51 status_t AddName(InodeNames* parent, const char* name);
52 bool RemoveName(InodeNames* parent,
53 const char* name);
55 mutex fLock;
56 SinglyLinkedList<InodeName> fNames;
57 FileHandle fHandle;
60 class FileSystem;
61 class RequestBuilder;
63 // Complete information needed to identify a file in any situation.
64 // Unfortunately just a FileHandle is not enough even when they are persistent
65 // since OPEN requires both parent FileHandle and file name (just like LOOKUP).
66 struct FileInfo {
67 uint64 fFileId;
68 FileHandle fHandle;
70 InodeNames* fNames;
72 FileHandle fAttrDir;
74 FileInfo();
75 ~FileInfo();
76 FileInfo(const FileInfo& fi);
77 FileInfo& operator=(const FileInfo& fi);
79 status_t UpdateFileHandles(FileSystem* fs);
82 struct FileSystemId {
83 uint64 fMajor;
84 uint64 fMinor;
86 inline bool operator==(const FileSystemId& fsid) const;
87 inline bool operator!=(const FileSystemId& fsid) const;
91 inline
92 FileHandle::FileHandle()
94 fSize(0)
99 inline
100 FileHandle::FileHandle(const FileHandle& fh)
102 fSize(fh.fSize)
104 memcpy(fData, fh.fData, fSize);
108 inline FileHandle&
109 FileHandle::operator=(const FileHandle& fh)
111 fSize = fh.fSize;
112 memcpy(fData, fh.fData, fSize);
113 return *this;
117 inline bool
118 FileHandle::operator==(const FileHandle& handle) const
120 if (fSize != handle.fSize)
121 return false;
122 return memcmp(fData, handle.fData, fSize) == 0;
126 inline bool
127 FileHandle::operator!=(const FileHandle& handle) const
129 return !operator==(handle);
133 inline bool
134 FileHandle::operator>(const FileHandle& handle) const
136 if (fSize > handle.fSize)
137 return true;
138 return memcmp(fData, handle.fData, fSize) > 0;
142 inline bool
143 FileHandle::operator<(const FileHandle& handle) const
145 if (fSize < handle.fSize)
146 return true;
147 return memcmp(fData, handle.fData, fSize) < 0;
151 inline bool
152 FileSystemId::operator==(const FileSystemId& fsid) const
154 return fMajor == fsid.fMajor && fMinor == fsid.fMinor;
158 inline bool
159 FileSystemId::operator!=(const FileSystemId& fsid) const
161 return !operator==(fsid);
165 #endif // FILEHINFO_H