The Pedigree Project 0.1
Ext2Node-quota.cc
1/* Copyright (c) 2026, Pedigree Developers. */
2#include "pedigree/kernel/LockGuard.h"
3#include "pedigree/kernel/syscallError.h"
4
5#include "Ext2Directory.h"
6#include "Ext2File.h"
7#include "Ext2Filesystem.h"
8#include "Ext2Symlink.h"
9#include "ext2.h"
10
11bool Ext2Node::changeInodeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
12 LockGuard<Mutex> inode(m_State->writebackLock);
13 LockGuard<Mutex> allocation(m_pExt2Fs->m_WriteLock);
14 if (m_pExt2Fs->isReadOnly()) {
15 SYSCALL_ERROR(ReadOnlyFilesystem);
16 return false;
17 }
18 if (m_State->quotaFile) {
19 SYSCALL_ERROR(NotEnoughPermissions);
20 return false;
21 }
22#if BITS_64
23 if ((changeUid && uid > UINT32_MAX) || (changeGid && gid > UINT32_MAX)) {
24 SYSCALL_ERROR(ValueTooLarge);
25 return false;
26 }
27#endif
28 if (!m_pExt2Fs->prepareInodeWrite(m_InodeNumber))
29 return false;
30 auto status = m_pExt2Fs->prepareQuotaInodeLocked(m_InodeNumber);
31 if (status == QuotaStatus::Success)
32 status = m_pExt2Fs->m_Quota.transfer(m_InodeNumber, changeUid ? uid : Ext2Owner::uid(*m_pInode),
33 changeGid ? gid : Ext2Owner::gid(*m_pInode));
34 if (!m_pExt2Fs->quotaSucceeded(status))
35 return false;
36 if (changeUid)
37 Ext2Owner::setUid(*m_pInode, uid);
38 if (changeGid)
39 Ext2Owner::setGid(*m_pInode, gid);
40 m_pInode->i_ctime = HOST_TO_LITTLE32(Time::getTime());
41 m_pExt2Fs->writeInode(m_InodeNumber);
42 return true;
43}
44
45bool Ext2File::changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
46 return changeInodeOwnership(uid, gid, changeUid, changeGid);
47}
48bool Ext2Directory::changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
49 return changeInodeOwnership(uid, gid, changeUid, changeGid);
50}
51bool Ext2Symlink::changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
52 return changeInodeOwnership(uid, gid, changeUid, changeGid);
53}
54
55bool Ext2File::allowResize(size_t, size_t) {
56 if (__atomic_load_n(&m_State->quotaFile, __ATOMIC_ACQUIRE)) {
57 SYSCALL_ERROR(NotEnoughPermissions);
58 return false;
59 }
60 return true;
61}
62
63bool Ext2File::allowPhysicalPage() const {
64 return !__atomic_load_n(&m_State->quotaFile, __ATOMIC_ACQUIRE);
65}
bool isReadOnly()
Definition Filesystem.h:142