vfs: check userland buffers before reading them.
[haiku.git] / headers / private / storage / NotOwningEntryRef.h
blobb781d54ff455d271d1e12a404bcadde29fc288eb
1 /*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
8 #ifndef _NOT_OWNING_ENTRY_REF_H
9 #define _NOT_OWNING_ENTRY_REF_H
12 #include <Entry.h>
13 #include <Node.h>
16 namespace BPrivate {
19 /*! entry_ref subclass that avoids cloning the entry name.
21 Therefore initialization is cheaper and cannot fail. It derives from
22 entry_ref for convenience. However, care must be taken that:
23 - the name remains valid while the object is in use,
24 - the object isn't passed as an entry_ref to a function that modifies it.
26 class NotOwningEntryRef : public entry_ref {
27 public:
28 NotOwningEntryRef()
32 NotOwningEntryRef(dev_t device, ino_t directory, const char* name)
34 SetTo(device, directory, name);
37 NotOwningEntryRef(const node_ref& directoryRef, const char* name)
39 SetTo(directoryRef, name);
42 NotOwningEntryRef(const entry_ref& other)
44 *this = other;
47 ~NotOwningEntryRef()
49 name = NULL;
52 NotOwningEntryRef& SetTo(dev_t device, ino_t directory, const char* name)
54 this->device = device;
55 this->directory = directory;
56 this->name = const_cast<char*>(name);
57 return *this;
60 NotOwningEntryRef& SetTo(const node_ref& directoryRef, const char* name)
62 return SetTo(directoryRef.device, directoryRef.node, name);
65 node_ref DirectoryNodeRef() const
67 return node_ref(device, directory);
70 NotOwningEntryRef& SetDirectoryNodeRef(const node_ref& directoryRef)
72 device = directoryRef.device;
73 directory = directoryRef.node;
74 return *this;
77 NotOwningEntryRef& operator=(const entry_ref& other)
79 return SetTo(other.device, other.directory, other.name);
84 } // namespace BPrivate
87 using ::BPrivate::NotOwningEntryRef;
90 #endif // _NOT_OWNING_ENTRY_REF_H