The Pedigree Project 0.1
Filesystem.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef FILESYSTEM_H
21#define FILESYSTEM_H
22
23#include "pedigree/kernel/Atomic.h"
24#include "pedigree/kernel/compiler.h"
25#include "pedigree/kernel/machine/DiskPaging.h"
26#include "pedigree/kernel/process/FilesystemContext.h"
27#include "pedigree/kernel/process/OperationBarrier.h"
28#include "pedigree/kernel/processor/types.h"
29#include "pedigree/kernel/utilities/String.h"
30
31#include "Directory.h"
32#include "Quota.h"
33
34class Disk;
35class File;
36class StringView;
37class Thread;
38
44class EXPORTED_PUBLIC Filesystem {
45 friend class Directory;
46
48 friend class VFS;
49 friend class VfsMountView;
50
51 public:
52 enum class SyncStatus { Success, Unsupported, NoMemory, IoError };
53
54 //
55 // Public interface
56 //
57
59 Filesystem();
61 virtual ~Filesystem();
62
65 virtual bool initialise(Disk* pDisk) = 0;
66
70 typedef Filesystem* (*ProbeCallback)(Disk*);
71
79 virtual File* find(const StringView& path);
80 virtual File* find(const String& path);
81 virtual File* find(const StringView& path, File* pStartNode);
82 virtual File* find(const String& path, File* pStartNode);
83
88 File* findRetained(const StringView& path, Directory::ChildLease& result,
89 File* pStartNode = nullptr);
90
92 virtual File* getRoot() const = 0;
93
95 virtual const String& getVolumeLabel() const = 0;
96
98 virtual bool getUuid(String& uuid) const {
99 uuid.clear();
100 return false;
101 }
102
104 virtual FileHandleStatus encodeFileHandle(File& file, FileHandle& handle);
105 virtual FileHandleStatus decodeFileHandle(const FileHandle& handle, RetainedFile& file);
106 virtual FileHandleStatus fileHandleFsid(FileSystemId& id);
107
109 virtual SyncStatus sync();
111 virtual SyncStatus shutdown();
113 virtual bool deviceRemoved(bool deviceAvailable = false);
114 bool tryAcquireOperation(OperationBarrier::Lease& operation) const;
115 bool isDeviceRemoved() const;
116 virtual QuotaStatus quotaControl(const QuotaRequest&, QuotaResponse&, File* quotaFile = nullptr);
117
120 bool createFile(const StringView& path, uint32_t mask, File* pStartNode = 0);
121
124 bool createDirectory(const StringView& path, uint32_t mask, File* pStartNode = 0);
125
127 bool createSymlink(const StringView& path, const String& value, File* pStartNode = 0);
128
130 bool createLink(const StringView& path, File* target, File* pStartNode = 0);
131
135 bool remove(const StringView& path, File* pStartNode = 0);
136
138 bool remove(const StringView& path, File* pStartNode, File* expected);
139
141 bool rename(const StringView& oldPath, File* oldStart, const StringView& newPath, File* newStart,
142 bool noReplace = false);
143
146 return m_pDisk;
147 }
148
150 bool isReadOnly() {
151 return m_bReadOnly;
152 }
153
155 virtual bool isCaseSensitive() {
156 return true;
157 }
158
160 bool remove(File* parent, File* file);
161
162 protected:
164 virtual bool createFile(File* parent, const String& filename, uint32_t mask) = 0;
166 virtual bool createDirectory(File* parent, const String& filename, uint32_t mask) = 0;
168 virtual bool createSymlink(File* parent, const String& filename, const String& value) = 0;
170 virtual bool createLink(File* parent, const String& filename, File* target);
177 virtual bool removeNode(File* parent, const String& filename, File* file) = 0;
183 virtual bool renameNode(Directory* oldParent, const String& oldName, File* source,
184 Directory* newParent, const String& newName, File* replaced);
189 DiskUse m_DiskUse;
190 mutable OperationBarrier m_Operations;
191 bool beginDeviceRemoval(bool deviceAvailable);
192
193 private:
194 Atomic<Thread*> m_RemovalOwner = nullptr;
195#if !THREADS
196 bool m_RemovalWrites = false;
197#endif
201 bool removeChild(File* parent, const String& filename, File* expected,
202 const FilesystemPathRef* parentPath = nullptr);
203 bool renameChildren(File* oldParent, const String& oldName, File* newParent,
204 const String& newName, bool noReplace, bool sourceMustBeDirectory,
205 const FilesystemPathRef* oldPath = nullptr,
206 const FilesystemPathRef* newPath = nullptr);
207
211 File* findNode(File* pNode, StringView path);
212
214 File* findNode(File* pNode, StringView path, File* stableStart, File* trueRoot,
215 File** retainedResult);
216
221 File* findParent(StringView path, File* pStartNode, String& filename,
222 File** retainedParent = nullptr);
223
229 void operator=(const Filesystem&);
230};
231
232#endif
Definition Disk.h:35
Definition File.h:75
virtual bool removeNode(File *parent, const String &filename, File *file)=0
Filesystem(const Filesystem &)
Disk * m_pDisk
Definition Filesystem.h:188
virtual bool initialise(Disk *pDisk)=0
bool m_bReadOnly
Definition Filesystem.h:186
virtual const String & getVolumeLabel() const =0
virtual bool isCaseSensitive()
Definition Filesystem.h:155
virtual bool getUuid(String &uuid) const
Definition Filesystem.h:98
Disk * getDisk()
Definition Filesystem.h:145
virtual bool createDirectory(File *parent, const String &filename, uint32_t mask)=0
static Mutex m_StructureLock
Definition Filesystem.h:199
void operator=(const Filesystem &)
bool isReadOnly()
Definition Filesystem.h:150
virtual bool createFile(File *parent, const String &filename, uint32_t mask)=0
virtual File * getRoot() const =0
virtual bool createSymlink(File *parent, const String &filename, const String &value)=0
Definition Mutex.h:56
Definition VFS.h:58