kernel+libc+stat: Add support for file times
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
The modification time is not updated though.
This commit is contained in:
parent
159c05c064
commit
4195e7f206
@ -2,7 +2,7 @@
|
|||||||
#include <os/FileSystem.h>
|
#include <os/FileSystem.h>
|
||||||
#include <os/Mode.h>
|
#include <os/Mode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <time.h>
|
||||||
|
|
||||||
static const char* file_type(mode_t mode)
|
static const char* file_type(mode_t mode)
|
||||||
{
|
{
|
||||||
@ -36,10 +36,20 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
char buf[11];
|
char buf[11];
|
||||||
os::format_mode(st.st_mode, buf);
|
os::format_mode(st.st_mode, buf);
|
||||||
|
|
||||||
printf(" File: %s\n", path.chars());
|
char atime[256];
|
||||||
printf(" Size: %zu (%s)\n", st.st_size, file_type(st.st_mode));
|
strftime(atime, sizeof(atime), "%Y-%m-%d %H:%M:%S", gmtime(&st.st_atim.tv_sec));
|
||||||
printf("Inode: %lu Links: %lu\n", st.st_ino, st.st_nlink);
|
char mtime[256];
|
||||||
printf(" Mode: (%#o/%s) UID: %u GID: %u\n", st.st_mode & ~S_IFMT, buf, st.st_uid, st.st_gid);
|
strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", gmtime(&st.st_mtim.tv_sec));
|
||||||
|
char ctime[256];
|
||||||
|
strftime(ctime, sizeof(ctime), "%Y-%m-%d %H:%M:%S", gmtime(&st.st_ctim.tv_sec));
|
||||||
|
|
||||||
|
printf(" File: %s\n", path.chars());
|
||||||
|
printf(" Size: %zu (%s)\n", st.st_size, file_type(st.st_mode));
|
||||||
|
printf(" Inode: %lu Links: %lu\n", st.st_ino, st.st_nlink);
|
||||||
|
printf(" Mode: (%#o/%s) UID: %u GID: %u\n", st.st_mode & ~S_IFMT, buf, st.st_uid, st.st_gid);
|
||||||
|
printf("Access: %s.%.9ld\n", atime, st.st_atim.tv_nsec);
|
||||||
|
printf("Modify: %s.%.9ld\n", mtime, st.st_mtim.tv_nsec);
|
||||||
|
printf("Change: %s.%.9ld\n", ctime, st.st_ctim.tv_nsec);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,9 @@ namespace Ext2
|
|||||||
inode->m_metadata.nlinks = inode->m_raw_inode.nlinks;
|
inode->m_metadata.nlinks = inode->m_raw_inode.nlinks;
|
||||||
inode->m_metadata.uid = inode->m_raw_inode.uid;
|
inode->m_metadata.uid = inode->m_raw_inode.uid;
|
||||||
inode->m_metadata.gid = inode->m_raw_inode.gid;
|
inode->m_metadata.gid = inode->m_raw_inode.gid;
|
||||||
|
inode->m_metadata.atime = { .tv_sec = inode->m_raw_inode.atime, .tv_nsec = 0 };
|
||||||
|
inode->m_metadata.mtime = { .tv_sec = inode->m_raw_inode.mtime, .tv_nsec = 0 };
|
||||||
|
inode->m_metadata.ctime = { .tv_sec = inode->m_raw_inode.create_time, .tv_nsec = 0 };
|
||||||
|
|
||||||
#ifdef EXT2_DEBUG
|
#ifdef EXT2_DEBUG
|
||||||
kdbgln("ext2: Read inode %lu with mode %#x (%#x + %#o), size %lu", inum, inode->m_raw_inode.mode,
|
kdbgln("ext2: Read inode %lu with mode %#x (%#x + %#o), size %lu", inum, inode->m_raw_inode.mode,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "fs/tmpfs/FileSystem.h"
|
#include "fs/tmpfs/FileSystem.h"
|
||||||
|
#include "arch/Timer.h"
|
||||||
#include "fs/devices/DeviceRegistry.h"
|
#include "fs/devices/DeviceRegistry.h"
|
||||||
#include "fs/tmpfs/Inode.h"
|
#include "fs/tmpfs/Inode.h"
|
||||||
#include <luna/Alloc.h>
|
#include <luna/Alloc.h>
|
||||||
@ -26,6 +27,7 @@ namespace TmpFS
|
|||||||
inode->set_fs(*this, {});
|
inode->set_fs(*this, {});
|
||||||
inode->set_inode_number(m_next_inode_number++, {});
|
inode->set_inode_number(m_next_inode_number++, {});
|
||||||
inode->m_metadata.mode = mode;
|
inode->m_metadata.mode = mode;
|
||||||
|
inode->m_metadata.atime = inode->m_metadata.ctime = inode->m_metadata.mtime = *Timer::realtime_clock();
|
||||||
return (SharedPtr<VFS::Inode>)inode;
|
return (SharedPtr<VFS::Inode>)inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ namespace TmpFS
|
|||||||
inode->set_fs(*this, {});
|
inode->set_fs(*this, {});
|
||||||
TRY(inode->set_link(link, {}));
|
TRY(inode->set_link(link, {}));
|
||||||
inode->set_inode_number(m_next_inode_number++, {});
|
inode->set_inode_number(m_next_inode_number++, {});
|
||||||
|
inode->m_metadata.atime = inode->m_metadata.ctime = inode->m_metadata.mtime = *Timer::realtime_clock();
|
||||||
return (SharedPtr<VFS::Inode>)inode;
|
return (SharedPtr<VFS::Inode>)inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +52,7 @@ namespace TmpFS
|
|||||||
inode->set_fs(*this, {});
|
inode->set_fs(*this, {});
|
||||||
inode->set_inode_number(m_next_inode_number++, {});
|
inode->set_inode_number(m_next_inode_number++, {});
|
||||||
inode->m_metadata.mode = mode;
|
inode->m_metadata.mode = mode;
|
||||||
|
inode->m_metadata.atime = inode->m_metadata.ctime = inode->m_metadata.mtime = *Timer::realtime_clock();
|
||||||
|
|
||||||
return (SharedPtr<VFS::Inode>)inode;
|
return (SharedPtr<VFS::Inode>)inode;
|
||||||
}
|
}
|
||||||
@ -65,6 +69,7 @@ namespace TmpFS
|
|||||||
// device ID atm.
|
// device ID atm.
|
||||||
inode->set_device_id(luna_dev_makedev(major, minor), {});
|
inode->set_device_id(luna_dev_makedev(major, minor), {});
|
||||||
inode->m_metadata.mode = mode;
|
inode->m_metadata.mode = mode;
|
||||||
|
inode->m_metadata.atime = inode->m_metadata.ctime = inode->m_metadata.mtime = *Timer::realtime_clock();
|
||||||
|
|
||||||
return (SharedPtr<VFS::Inode>)inode;
|
return (SharedPtr<VFS::Inode>)inode;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,9 @@ Result<u64> sys_fstatat(Registers*, SyscallArgs args)
|
|||||||
kstat.st_size = metadata.size;
|
kstat.st_size = metadata.size;
|
||||||
kstat.st_dev = inode->fs() ? inode->fs()->host_device_id() : 0;
|
kstat.st_dev = inode->fs() ? inode->fs()->host_device_id() : 0;
|
||||||
kstat.st_rdev = metadata.devid;
|
kstat.st_rdev = metadata.devid;
|
||||||
|
kstat.st_atim = metadata.atime;
|
||||||
|
kstat.st_mtim = metadata.mtime;
|
||||||
|
kstat.st_ctim = metadata.ctime;
|
||||||
|
|
||||||
if (!MemoryManager::copy_to_user_typed(st, &kstat)) return err(EFAULT);
|
if (!MemoryManager::copy_to_user_typed(st, &kstat)) return err(EFAULT);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#ifndef _BITS_STRUCT_STAT_H
|
#ifndef _BITS_STRUCT_STAT_H
|
||||||
#define _BITS_STRUCT_STAT_H
|
#define _BITS_STRUCT_STAT_H
|
||||||
|
|
||||||
|
#include <bits/timespec.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
struct stat
|
struct stat
|
||||||
@ -15,10 +16,13 @@ struct stat
|
|||||||
gid_t st_gid;
|
gid_t st_gid;
|
||||||
off_t st_size;
|
off_t st_size;
|
||||||
dev_t st_rdev;
|
dev_t st_rdev;
|
||||||
// FIXME: Actually fill these fields in.
|
struct timespec st_atim;
|
||||||
time_t st_atime;
|
struct timespec st_mtim;
|
||||||
time_t st_mtime;
|
struct timespec st_ctim;
|
||||||
time_t st_ctime;
|
|
||||||
|
#define st_atime st_atim.tv_sec
|
||||||
|
#define st_mtime st_mtim.tv_sec
|
||||||
|
#define st_ctime st_ctim.tv_sec
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user