Rename struct "stat" to "kstat"

This commit is contained in:
EnderIce2 2024-04-01 04:49:06 +03:00
parent 7b5a486391
commit 91ca38fd77
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
5 changed files with 67 additions and 114 deletions

View File

@ -84,14 +84,7 @@
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
/**
* @struct stat
* @brief Structure holding information about a file, as returned by the stat function.
*
* The 'stat' structure provides information about a file, including its size, ownership, permissions,
* and other attributes. It is used with the stat function to query file status.
*/
struct stat
struct kstat
{
/** Device ID of the file. */
dev_t st_dev;
@ -123,45 +116,6 @@ struct stat
mode_t st_attr;
};
/**
* @struct stat64
* @brief Extended structure for large file support, holding information about a file.
*
* The 'stat64' structure is similar to 'struct stat' but is extended to support large files on 32-bit systems.
* It is used with the stat64 function for large file support.
*/
struct stat64
{
/** Device ID of the file. */
dev_t st_dev;
/** Inode number. */
ino64_t st_ino;
/** File type and mode. */
mode_t st_mode;
/** Number of hard links. */
nlink_t st_nlink;
/** User ID of the file's owner. */
uid_t st_uid;
/** Group ID of the file's owner. */
gid_t st_gid;
/** Device ID for special files. */
dev_t st_rdev;
/** Size of the file in bytes. */
off64_t st_size;
/** Time of last access. */
time_t st_atime;
/** Time of last modification. */
time_t st_mtime;
/** Time of last status change. */
time_t st_ctime;
/** Optimal I/O block size. */
blksize_t st_blksize;
/** Number of blocks allocated. */
blkcnt64_t st_blocks;
/** Additional file attributes. */
mode_t st_attr;
};
static inline int ConvertFileFlags(const char *Mode)
{
int Flags = 0;
@ -223,9 +177,9 @@ namespace vfs
virtual size_t read(uint8_t *Buffer, size_t Size, off_t Offset);
virtual size_t write(uint8_t *Buffer, size_t Size, off_t Offset);
virtual int ioctl(unsigned long Request, void *Argp);
// virtual int stat(struct stat *Stat);
// virtual int lstat(struct stat *Stat);
// virtual int fstat(struct stat *Stat);
// virtual int stat(struct kstat *Stat);
// virtual int lstat(struct kstat *Stat);
// virtual int fstat(struct kstat *Stat);
// virtual int unlink();
// virtual int mkdir(mode_t Mode);
// virtual int rmdir();
@ -424,9 +378,9 @@ namespace vfs
ssize_t _write(int fd, const void *buf, size_t count);
int _close(int fd);
off_t _lseek(int fd, off_t offset, int whence);
int _stat(const char *pathname, struct stat *statbuf);
int _fstat(int fd, struct stat *statbuf);
int _lstat(const char *pathname, struct stat *statbuf);
int _stat(const char *pathname, struct kstat *statbuf);
int _fstat(int fd, struct kstat *statbuf);
int _lstat(const char *pathname, struct kstat *statbuf);
int _dup(int oldfd);
int _dup2(int oldfd, int newfd);
int _ioctl(int fd, unsigned long request, void *argp);

View File

@ -271,7 +271,7 @@ struct linux_dirent64
char d_name[]; /* Filename (null-terminated) */
};
struct k_stat
struct linux_kstat
{
#if defined(a64)
__kernel_ulong_t st_dev;
@ -317,7 +317,7 @@ struct k_stat
#endif
};
struct k_stat64
struct linux_kstat64
{
unsigned long long st_dev;
unsigned char __pad0[4];

View File

@ -472,7 +472,7 @@ namespace vfs
}
int FileDescriptorTable::_stat(const char *pathname,
struct stat *statbuf)
struct kstat *statbuf)
{
if (pathname == nullptr)
return -EINVAL;
@ -505,7 +505,7 @@ namespace vfs
return 0;
}
int FileDescriptorTable::_fstat(int _fd, struct stat *statbuf)
int FileDescriptorTable::_fstat(int _fd, struct kstat *statbuf)
{
Fildes &fd = this->GetDescriptor(_fd);
if (fd == nullfd)
@ -533,7 +533,7 @@ namespace vfs
}
int FileDescriptorTable::_lstat(const char *pathname,
struct stat *statbuf)
struct kstat *statbuf)
{
if (pathname == nullptr)
return -EINVAL;

View File

@ -27,7 +27,7 @@ namespace vfs
debug("Operation not handled for %s(%#lx)",
this->FullPath, this);
return -ENODEV;
return -ENOSYS;
}
int Node::close()
@ -37,7 +37,7 @@ namespace vfs
debug("Operation not handled for %s(%#lx)",
this->FullPath, this);
return -ENODEV;
return -ENOSYS;
}
size_t Node::read(uint8_t *Buffer, size_t Size, off_t Offset)
@ -47,7 +47,7 @@ namespace vfs
debug("Operation not handled for %s(%#lx)",
this->FullPath, this);
return -ENODEV;
return -ENOSYS;
}
size_t Node::write(uint8_t *Buffer, size_t Size, off_t Offset)
@ -57,7 +57,7 @@ namespace vfs
debug("Operation not handled for %s(%#lx)",
this->FullPath, this);
return -ENODEV;
return -ENOSYS;
}
int Node::ioctl(unsigned long Request, void *Argp)
@ -67,7 +67,7 @@ namespace vfs
debug("Operation not handled for %s(%#lx)",
this->FullPath, this);
return -ENODEV;
return -ENOSYS;
}
RefNode *Node::CreateReference()

View File

@ -320,53 +320,53 @@ void SetSigActToLinux(const SignalAction *native, k_sigaction *linux)
debug("m0:%#lx m1:%#lx | n:%#lx", linux->mask[0], linux->mask[1], native->Mask);
}
struct stat KStatToStat(struct k_stat kstat)
struct kstat KStatToStat(struct linux_kstat linux_stat)
{
struct stat stat;
stat.st_dev = kstat.st_dev;
stat.st_ino = kstat.st_ino;
stat.st_nlink = (nlink_t)kstat.st_nlink;
stat.st_mode = kstat.st_mode;
stat.st_uid = kstat.st_uid;
stat.st_gid = kstat.st_gid;
stat.st_rdev = kstat.st_rdev;
stat.st_size = kstat.st_size;
stat.st_blksize = kstat.st_blksize;
stat.st_blocks = kstat.st_blocks;
stat.st_atime = kstat.st_atime;
// stat.st_atime_nsec = kstat.st_atime_nsec;
stat.st_mtime = kstat.st_mtime;
// stat.st_mtime_nsec = kstat.st_mtime_nsec;
stat.st_ctime = kstat.st_ctime;
// stat.st_ctime_nsec = kstat.st_ctime_nsec;
struct kstat stat;
stat.st_dev = linux_stat.st_dev;
stat.st_ino = linux_stat.st_ino;
stat.st_nlink = (nlink_t)linux_stat.st_nlink;
stat.st_mode = linux_stat.st_mode;
stat.st_uid = linux_stat.st_uid;
stat.st_gid = linux_stat.st_gid;
stat.st_rdev = linux_stat.st_rdev;
stat.st_size = linux_stat.st_size;
stat.st_blksize = linux_stat.st_blksize;
stat.st_blocks = linux_stat.st_blocks;
stat.st_atime = linux_stat.st_atime;
// stat.st_atime_nsec = linux_stat.st_atime_nsec;
stat.st_mtime = linux_stat.st_mtime;
// stat.st_mtime_nsec = linux_stat.st_mtime_nsec;
stat.st_ctime = linux_stat.st_ctime;
// stat.st_ctime_nsec = linux_stat.st_ctime_nsec;
return stat;
}
struct k_stat StatToKStat(struct stat stat)
struct linux_kstat StatToKStat(struct kstat stat)
{
struct k_stat kstat;
kstat.st_dev = stat.st_dev;
kstat.st_ino = stat.st_ino;
kstat.st_nlink = stat.st_nlink;
kstat.st_mode = stat.st_mode;
kstat.st_uid = stat.st_uid;
kstat.st_gid = stat.st_gid;
kstat.st_rdev = stat.st_rdev;
kstat.st_size = stat.st_size;
kstat.st_blksize = stat.st_blksize;
kstat.st_blocks = stat.st_blocks;
kstat.st_atime = stat.st_atime;
// kstat.st_atime_nsec = stat.st_atime_nsec;
kstat.st_mtime = stat.st_mtime;
// kstat.st_mtime_nsec = stat.st_mtime_nsec;
kstat.st_ctime = stat.st_ctime;
// kstat.st_ctime_nsec = stat.st_ctime_nsec;
return kstat;
struct linux_kstat linux_stat;
linux_stat.st_dev = stat.st_dev;
linux_stat.st_ino = stat.st_ino;
linux_stat.st_nlink = stat.st_nlink;
linux_stat.st_mode = stat.st_mode;
linux_stat.st_uid = stat.st_uid;
linux_stat.st_gid = stat.st_gid;
linux_stat.st_rdev = stat.st_rdev;
linux_stat.st_size = stat.st_size;
linux_stat.st_blksize = stat.st_blksize;
linux_stat.st_blocks = stat.st_blocks;
linux_stat.st_atime = stat.st_atime;
// linux_stat.st_atime_nsec = stat.st_atime_nsec;
linux_stat.st_mtime = stat.st_mtime;
// linux_stat.st_mtime_nsec = stat.st_mtime_nsec;
linux_stat.st_ctime = stat.st_ctime;
// linux_stat.st_ctime_nsec = stat.st_ctime_nsec;
return linux_stat;
}
struct stat OKStatToStat(struct __old_kernel_stat okstat)
struct kstat OKStatToStat(struct __old_kernel_stat okstat)
{
struct stat stat;
struct kstat stat;
stat.st_dev = okstat.st_dev;
stat.st_ino = okstat.st_ino;
stat.st_nlink = okstat.st_nlink;
@ -381,7 +381,7 @@ struct stat OKStatToStat(struct __old_kernel_stat okstat)
return stat;
}
struct __old_kernel_stat StatToOKStat(struct stat stat)
struct __old_kernel_stat StatToOKStat(struct kstat stat)
{
struct __old_kernel_stat okstat;
okstat.st_dev = (unsigned short)stat.st_dev;
@ -505,7 +505,7 @@ if __ARCH_WANT_OLD_STAT is defined
so what about __old_kernel_stat? when it is used? */
/* https://man7.org/linux/man-pages/man2/stat.2.html */
static int linux_stat(SysFrm *, const char *pathname, struct k_stat *statbuf)
static int linux_stat(SysFrm *, const char *pathname, struct linux_kstat *statbuf)
{
PCB *pcb = thisProcess;
vfs::FileDescriptorTable *fdt = pcb->FileDescriptors;
@ -519,14 +519,14 @@ static int linux_stat(SysFrm *, const char *pathname, struct k_stat *statbuf)
if (pStatbuf == nullptr)
return -EFAULT;
struct stat nstat = KStatToStat(*pStatbuf);
struct kstat nstat = KStatToStat(*pStatbuf);
int ret = fdt->_stat(pPathname, &nstat);
*pStatbuf = StatToKStat(nstat);
return ret;
}
/* https://man7.org/linux/man-pages/man2/fstat.2.html */
static int linux_fstat(SysFrm *, int fd, struct k_stat *statbuf)
static int linux_fstat(SysFrm *, int fd, struct linux_kstat *statbuf)
{
#undef fstat
PCB *pcb = thisProcess;
@ -537,16 +537,15 @@ static int linux_fstat(SysFrm *, int fd, struct k_stat *statbuf)
if (pStatbuf == nullptr)
return -EFAULT;
struct stat nstat = KStatToStat(*pStatbuf);
struct kstat nstat = KStatToStat(*pStatbuf);
int ret = fdt->_fstat(fd, &nstat);
*pStatbuf = StatToKStat(nstat);
return ret;
}
/* https://man7.org/linux/man-pages/man2/lstat.2.html */
static int linux_lstat(SysFrm *, const char *pathname, struct k_stat *statbuf)
static int linux_lstat(SysFrm *, const char *pathname, struct linux_kstat *statbuf)
{
#undef lstat
PCB *pcb = thisProcess;
vfs::FileDescriptorTable *fdt = pcb->FileDescriptors;
Memory::VirtualMemoryArea *vma = pcb->vma;
@ -556,7 +555,7 @@ static int linux_lstat(SysFrm *, const char *pathname, struct k_stat *statbuf)
if (pPathname == nullptr || pStatbuf == nullptr)
return -EFAULT;
struct stat nstat = KStatToStat(*pStatbuf);
struct kstat nstat = KStatToStat(*pStatbuf);
int ret = fdt->_lstat(pPathname, &nstat);
*pStatbuf = StatToKStat(nstat);
return ret;
@ -2614,7 +2613,7 @@ static int linux_openat(SysFrm *, int dirfd, const char *pathname, int flags, mo
/* Undocumented? */
static long linux_newfstatat(SysFrm *, int dirfd, const char *pathname,
struct k_stat *statbuf, int flag)
struct linux_kstat *statbuf, int flag)
{
/* FIXME: This function is not working at all? */
@ -2626,7 +2625,7 @@ static long linux_newfstatat(SysFrm *, int dirfd, const char *pathname,
fixme("flag %#x is stub", flag);
const char *pPathname = vma->UserCheckAndGetAddress(pathname);
struct k_stat *pStatbuf = vma->UserCheckAndGetAddress(statbuf);
struct linux_kstat *pStatbuf = vma->UserCheckAndGetAddress(statbuf);
if (pPathname == nullptr || pStatbuf == nullptr)
return -EFAULT;
@ -2641,7 +2640,7 @@ static long linux_newfstatat(SysFrm *, int dirfd, const char *pathname,
const char *absPath = new char[strlen(absoluteNode->node->FullPath) + 1];
strcpy((char *)absPath, absoluteNode->node->FullPath);
delete absoluteNode;
struct stat nstat = KStatToStat(*pStatbuf);
struct kstat nstat = KStatToStat(*pStatbuf);
int ret = fdt->_stat(absPath, &nstat);
*pStatbuf = StatToKStat(nstat);
delete[] absPath;
@ -2656,7 +2655,7 @@ static long linux_newfstatat(SysFrm *, int dirfd, const char *pathname,
return -EBADF;
}
struct stat nstat = KStatToStat(*pStatbuf);
struct kstat nstat = KStatToStat(*pStatbuf);
int ret = fdt->_stat(pPathname, &nstat);
*pStatbuf = StatToKStat(nstat);
return ret;