The Pedigree Project 0.1
Ext2Directory.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 EXT2_DIRECTORY_H
21#define EXT2_DIRECTORY_H
22
23#include "pedigree/kernel/process/Mutex.h"
24#include "pedigree/kernel/processor/types.h"
25#include "pedigree/kernel/utilities/String.h"
26
27#include "Ext2Node.h"
28#include "modules/system/vfs/Directory.h"
29
30class File;
31struct Inode;
32struct Dir;
33
35class Ext2Directory : public Directory, public Ext2Node {
36 friend class Ext2Filesystem;
37
38 private:
39 struct RenameRecord {
42 Ext2Directory* owner;
43 uint32_t block;
44 uintptr_t buffer;
45 size_t offset;
46 Dir* entry;
47 Dir* split;
48 uint16_t splitLength;
49 uint16_t length;
50 };
51 bool prepareRenameRecord(const String& name, uint32_t inode, RenameRecord& record);
52 bool prepareRenameSpace(const String& name, RenameRecord& record, const RenameRecord* source);
55 Ext2Directory& operator=(const Ext2Directory&);
56
57 public:
59 Ext2Directory(const String& name, uintptr_t inode_num, Inode* inode, class Ext2Filesystem* pFs,
60 File* pParent);
62 ~Ext2Directory() override;
63
64 void truncate() override {}
65
66 using Directory::sync;
67 bool sync() override;
68
70 virtual bool addEntry(const String& filename, File* pFile, size_t type);
72 virtual bool removeEntry(const String& filename, Ext2Node* pFile);
73
75 void fileAttributeChanged() override;
76 Attributes getAttributes() const override;
77
78 XattrStatus getExtendedAttribute(const StringView&, void*, size_t, size_t&) override;
79 XattrStatus listExtendedAttributes(void*, size_t, size_t&) override;
80 XattrStatus setExtendedAttribute(const StringView&, const void*, size_t, unsigned) override;
81 XattrStatus removeExtendedAttribute(const StringView&) override;
82
83 protected:
84 void updateAttributes(const Attributes& attributes, uint32_t mask) override;
85 bool changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) override;
86
87 private:
88 struct ParsedEntry {
89 uint32_t inode;
90 uint16_t recordLength;
91 uint16_t nameLength;
92 uint8_t fileType;
93 char name[256];
94 };
95
96 LookupStatus resolveChild(const StringView& name, File*& child) override;
97 LookupStatus resolveChildAt(uint64_t cookie, const StringView& name, File*& child) override;
98 ReadStatus readDirectory(uint64_t& cookie, DirectoryEntryEmitter emitter, void* context) override;
99
100 bool readBytes(uint64_t offset, size_t length, void* buffer);
101 ReadStatus readEntry(uint64_t offset, ParsedEntry& entry);
102 LookupStatus resolveEntry(const ParsedEntry& entry, const StringView& name, File*& child);
103 LookupStatus resolveChildLocked(const StringView& name, File*& child);
104 bool removeEntryLocked(const String& filename, Ext2Node* pFile);
105 bool removeFromParent(Ext2Directory* parent, const String& filename);
106 bool syncDirectoryBlock(uint32_t block);
107 void queueSyncDependency(uint32_t block);
108
109 Mutex m_DirectoryLock;
110 bool m_Removed;
111};
112
113#endif
ReadStatus readDirectory(uint64_t &cookie, DirectoryEntryEmitter emitter, void *context) override
Ext2Directory(const Ext2Directory &file)
virtual bool removeEntry(const String &filename, Ext2Node *pFile)
bool sync() override
~Ext2Directory() override
LookupStatus resolveChildAt(uint64_t cookie, const StringView &name, File *&child) override
void fileAttributeChanged() override
XattrStatus getExtendedAttribute(const StringView &, void *, size_t, size_t &) override
void truncate() override
bool removeEntryLocked(const String &filename, Ext2Node *pFile)
LookupStatus resolveChild(const StringView &name, File *&child) override
virtual bool addEntry(const String &filename, File *pFile, size_t type)
Definition File.h:74
virtual bool sync()
Definition File.cc:563
Definition Mutex.h:56
Definition ext2.h:201
Definition ext2.h:152