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) {
13 if (!m_pExt2Fs->tryAcquireOperation(operation)) {
14 return false;
15 }
16 LockGuard<Mutex> inode(m_State->writebackLock);
17 LockGuard<Mutex> allocation(m_pExt2Fs->m_WriteLock);
18 if (m_pExt2Fs->isReadOnly()) {
19 SYSCALL_ERROR(ReadOnlyFilesystem);
20 return false;
21 }
22 if (m_State->quotaFile) {
23 SYSCALL_ERROR(NotEnoughPermissions);
24 return false;
25 }
26#if BITS_64
27 if ((changeUid && uid > UINT32_MAX) || (changeGid && gid > UINT32_MAX)) {
28 SYSCALL_ERROR(ValueTooLarge);
29 return false;
30 }
31#endif
32 if (!m_pExt2Fs->prepareInodeWrite(m_InodeNumber))
33 return false;
34 auto status = m_pExt2Fs->prepareQuotaInodeLocked(m_InodeNumber);
35 if (status == QuotaStatus::Success)
36 status = m_pExt2Fs->m_Quota.transfer(m_InodeNumber, changeUid ? uid : Ext2Owner::uid(*m_pInode),
37 changeGid ? gid : Ext2Owner::gid(*m_pInode));
38 if (!m_pExt2Fs->quotaSucceeded(status))
39 return false;
40 if (changeUid)
41 Ext2Owner::setUid(*m_pInode, uid);
42 if (changeGid)
43 Ext2Owner::setGid(*m_pInode, gid);
44 m_pInode->i_ctime = HOST_TO_LITTLE32(Time::getTime());
45 m_pExt2Fs->writeInode(m_InodeNumber);
46 return true;
47}
48
49bool Ext2File::changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
50 return changeInodeOwnership(uid, gid, changeUid, changeGid);
51}
52bool Ext2Directory::changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
53 return changeInodeOwnership(uid, gid, changeUid, changeGid);
54}
55bool Ext2Symlink::changeOwnership(size_t uid, size_t gid, bool changeUid, bool changeGid) {
56 return changeInodeOwnership(uid, gid, changeUid, changeGid);
57}
58
59bool Ext2File::allowResize(size_t, size_t) {
60 if (__atomic_load_n(&m_State->quotaFile, __ATOMIC_ACQUIRE)) {
61 SYSCALL_ERROR(NotEnoughPermissions);
62 return false;
63 }
64 return true;
65}
66
67bool Ext2File::allowPhysicalPage() const {
68 return !__atomic_load_n(&m_State->quotaFile, __ATOMIC_ACQUIRE);
69}
bool isReadOnly()
Definition Filesystem.h:150