The Pedigree Project 0.1
FatFile.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 FAT_FILE_H
21#define FAT_FILE_H
22
23#include "pedigree/kernel/process/Mutex.h"
24#include "pedigree/kernel/processor/types.h"
25#include "pedigree/kernel/time/Time.h"
26#include "pedigree/kernel/utilities/Cache.h"
27#include "pedigree/kernel/utilities/String.h"
28#include "pedigree/kernel/utilities/Vector.h"
29
30#include "modules/system/vfs/File.h"
31
32class FatFilesystem;
33
35class FatFile : public File {
36 friend class FatFilesystem;
37 friend class FatWritebackTestPeer;
38
39 private:
41 FatFile(const File& file);
42 File& operator=(const File&);
43
44 public:
45 struct State {
46 explicit State(FatFilesystem* owner);
47 ~State();
48 FatFilesystem* filesystem;
49 CacheState cache;
50 Mutex dataLock;
51 Mutex writeLock;
52 size_t pageLoans = 0;
53 Time::Timestamp accessed = 0;
54 Time::Timestamp modified = 0;
55 Time::Timestamp changed = 0;
56 size_t size = 0;
57 uintptr_t inode = 0;
58 uintptr_t identifier = 0;
59 uint32_t directoryCluster = 0;
60 uint32_t directoryOffset = 0;
61 bool metadataDirty = false;
62 bool trimPending = false;
63 bool unlinked = false;
64 bool registered = false;
65 bool retiring = false;
66 size_t syncReferences = 0;
67 FatFile* aliases = nullptr;
68 State* next = nullptr;
69 Vector<uint32_t> retiredClusters;
70 Vector<uint32_t> clusters;
71 uint64_t chainRevision = 0;
72 };
73
74 void truncate() override;
75 size_t getSize() override;
76 void setInode(uintptr_t inode) override;
77 uint64_t maximumFileSize() const override;
78 uintptr_t futexIdentity() override;
79 void fileAttributeChanged() override;
80 bool syncPages(const uint64_t* offsets, size_t count) override;
81
83 FatFile(String name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime,
84 Time::Timestamp creationTime, uintptr_t inode, class Filesystem* pFs, size_t size,
85 uint32_t dirClus = 0, uint32_t dirOffset = 0, File* pParent = 0);
87 ~FatFile() override;
88
89 uint32_t getDirCluster() {
90 return m_DirClus;
91 }
92 void setDirCluster(uint32_t custom) {
93 m_DirClus = custom;
94 }
95 uint32_t getDirOffset() {
96 return m_DirOffset;
97 }
98 void setDirOffset(uint32_t custom) {
99 m_DirOffset = custom;
100 }
101
102 uintptr_t readBlock(uint64_t location) override;
103 void writeBlock(uint64_t location, uintptr_t addr) override;
104
105 void extend(size_t newSize) override;
106 void extend(size_t newSize, uint64_t location, uint64_t size) override;
107
108 Attributes getAttributes() const override;
109 bool sync() override;
110 bool sync(size_t offset, bool async) override;
111
112 bool pinBlock(uint64_t location) override;
113 void unpinBlock(uint64_t location) override;
114
115 protected:
116 CacheState& cacheState() override;
117 Mutex& dataMutationLock() override;
118 Mutex& writeSerializationLock() override;
119 size_t& physicalPageLoans() override;
120 bool useFillCache() const override;
121 bool readPage(uint64_t location, uintptr_t destination) override;
122 bool prepareShrink(const ShrinkContext& context,
123 UniquePointer<PreparedShrink>& prepared) override;
124 bool resizeFile(size_t size) override;
125
126 private:
127 void copyStateAttributes();
128 explicit FatFile(State& state);
129 static bool checkedBatchCallback(const Cache::WritebackPage*, size_t, void*);
130 static bool checkedWriteCallback(CacheConstants::CallbackCause cause, uintptr_t location,
131 uintptr_t page, void* meta);
132
133 State* m_State;
134 FatFile* m_NextAlias = nullptr;
135 bool m_Proxy = false;
136 uint32_t& m_DirClus;
137 uint32_t& m_DirOffset;
138 bool& m_MetadataDirty;
139 bool& m_TrimPending;
140 Vector<uint32_t>& m_RetiredClusters;
141};
142
143#endif
uintptr_t readBlock(uint64_t location) override
Definition FatFile.cc:93
FatFile(const File &file)
uint64_t maximumFileSize() const override
bool syncPages(const uint64_t *offsets, size_t count) override
Definition FatFile.cc:191
uintptr_t futexIdentity() override
Definition FatFile.cc:80
bool readPage(uint64_t location, uintptr_t destination) override
Definition FatFile.cc:134
bool useFillCache() const override
Definition FatFile.cc:121
void truncate() override
void extend(size_t newSize) override
~FatFile() override
Definition FatFile.cc:60
bool pinBlock(uint64_t location) override
Definition FatFile.cc:219
void writeBlock(uint64_t location, uintptr_t addr) override
Definition FatFile.cc:145
void unpinBlock(uint64_t location) override
Definition FatFile.cc:223
bool sync() override
Definition FatFile.cc:168
Definition File.h:75
Definition Mutex.h:56
A vector / dynamic array.
Definition Vector.h:33