Kernel, libc, userspace: Add file timestamps (atime,ctime,mtime)
This commit is contained in:
parent
8d46c9bbe2
commit
e640c6e245
@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
const char* mode_to_string(mode_t mode)
|
||||
{
|
||||
@ -55,6 +56,10 @@ int main(int argc, char** argv)
|
||||
printf("Owned by: %s\n", own->pw_name);
|
||||
printf("Mode: %s\n", mode_to_string(st.st_mode));
|
||||
|
||||
printf("Accessed on: %s", ctime(&st.st_atime));
|
||||
printf("Modified on: %s", ctime(&st.st_mtime));
|
||||
printf("Changed on: %s", ctime(&st.st_ctime));
|
||||
|
||||
endpwent();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -41,6 +41,9 @@ namespace VFS
|
||||
Node* link;
|
||||
int uid;
|
||||
int gid;
|
||||
uint64_t atime;
|
||||
uint64_t ctime;
|
||||
uint64_t mtime;
|
||||
mode_t mode;
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* ConsoleDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -16,6 +18,7 @@ VFS::Node* ConsoleDevice::create_new(const char* devname)
|
||||
dev->tty = 1;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0222;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ VFS::Node* devfs_root = nullptr;
|
||||
VFS::Node* devfs_files[DEVFS_MAX_FILES];
|
||||
int devfs_file_count = 0;
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* DeviceFS::get()
|
||||
{
|
||||
if (devfs_root) return devfs_root;
|
||||
@ -27,6 +29,7 @@ VFS::Node* DeviceFS::get()
|
||||
devfs_root->readdir_func = DeviceFS::readdir;
|
||||
devfs_root->mode = 0755;
|
||||
devfs_root->uid = devfs_root->gid = 0;
|
||||
devfs_root->atime = devfs_root->ctime = devfs_root->mtime = clock_boot();
|
||||
strncpy(devfs_root->name, "dev", sizeof(devfs_root->name));
|
||||
|
||||
devfs_files[devfs_file_count++] = VersionDevice::create_new("version");
|
||||
|
@ -16,6 +16,8 @@ int KeyboardDevice::would_block(VFS::Node*)
|
||||
return kbd_bufsize == 0;
|
||||
}
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* KeyboardDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -28,6 +30,7 @@ VFS::Node* KeyboardDevice::create_new(const char* devname)
|
||||
dev->tty = 1;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0444;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* NullDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -14,6 +16,7 @@ VFS::Node* NullDevice::create_new(const char* devname)
|
||||
dev->flags = 0;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0666;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* RandomDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -16,6 +18,7 @@ VFS::Node* RandomDevice::create_new(const char* devname)
|
||||
dev->flags = 0;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0444;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* SerialDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -15,6 +17,7 @@ VFS::Node* SerialDevice::create_new(const char* devname)
|
||||
dev->flags = 0;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0200;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "std/string.h"
|
||||
#include "thread/PIT.h"
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* UptimeDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -14,6 +16,7 @@ VFS::Node* UptimeDevice::create_new(const char* devname)
|
||||
dev->flags = 0;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0444;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern uint64_t clock_boot();
|
||||
|
||||
VFS::Node* VersionDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
@ -14,6 +16,7 @@ VFS::Node* VersionDevice::create_new(const char* devname)
|
||||
dev->flags = 0;
|
||||
dev->uid = dev->gid = 0;
|
||||
dev->mode = 0444;
|
||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -18,6 +18,9 @@ static bool initrd_initialized = false;
|
||||
|
||||
static VFS::Node initrd_root;
|
||||
|
||||
extern uint64_t clock_boot(); // defined in sys/clock.cpp
|
||||
extern uint64_t clock_now();
|
||||
|
||||
bool InitRD::is_initialized()
|
||||
{
|
||||
return initrd_initialized;
|
||||
@ -234,6 +237,7 @@ int initrd_mkdir(VFS::Node* node, const char* name, mode_t mode) // FIXME: Retur
|
||||
new_node.type = VFS_DIRECTORY;
|
||||
new_node.mode = mode;
|
||||
new_node.uid = new_node.gid = 0;
|
||||
new_node.atime = new_node.ctime = new_node.mtime = clock_now();
|
||||
strncpy(new_node.name, name, sizeof(new_node.name));
|
||||
InitRD::Directory dir;
|
||||
strncpy(dir.name, name, sizeof(dir.name));
|
||||
@ -293,6 +297,7 @@ static bool initrd_register_dir(InitRD::Directory& dir, uint64_t inode)
|
||||
node.length = 0;
|
||||
node.mode = 0755;
|
||||
node.uid = node.gid = 0;
|
||||
node.atime = node.ctime = node.mtime = clock_boot();
|
||||
strncpy(node.name, buffer, sizeof(node.name));
|
||||
strncpy(dir.name, buffer, sizeof(dir.name));
|
||||
|
||||
@ -354,6 +359,7 @@ static bool initrd_register_file(InitRD::File& f, uint64_t inode)
|
||||
node.type = VFS_FILE;
|
||||
node.mode = f.mode & 07555; // don't allow writing
|
||||
node.uid = node.gid = 0;
|
||||
node.atime = node.ctime = node.mtime = clock_boot();
|
||||
strncpy(node.name, buffer, sizeof(node.name));
|
||||
strncpy(f.name, buffer, sizeof(f.name));
|
||||
|
||||
@ -398,6 +404,7 @@ static void initrd_initialize_root()
|
||||
initrd_root.type |= VFS_DIRECTORY;
|
||||
initrd_root.mode = 0755;
|
||||
initrd_root.uid = initrd_root.gid = 0;
|
||||
initrd_root.atime = initrd_root.ctime = initrd_root.mtime = clock_boot();
|
||||
InitRD::Directory& root = dirs[0];
|
||||
total_dirs++;
|
||||
strncpy(initrd_root.name, "initrd", sizeof(initrd_root.name));
|
||||
|
@ -71,3 +71,13 @@ void clock_init()
|
||||
{
|
||||
unix_boot_time = unix_boottime(bootboot.datetime);
|
||||
}
|
||||
|
||||
uint64_t clock_now()
|
||||
{
|
||||
return unix_boot_time + (PIT::ms_since_boot / 1000);
|
||||
}
|
||||
|
||||
uint64_t clock_boot()
|
||||
{
|
||||
return unix_boot_time;
|
||||
}
|
@ -16,9 +16,9 @@ struct stat // FIXME: This struct is quite stubbed out.
|
||||
int st_dev; // FIXME: Implement this.
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
time_t st_atime; // Not implemented.
|
||||
time_t st_mtime; // Not implemented.
|
||||
time_t st_ctime; // Not implemented.
|
||||
time_t st_atime;
|
||||
time_t st_mtime;
|
||||
time_t st_ctime;
|
||||
};
|
||||
|
||||
void do_stat(Context* context, VFS::Node* node, struct stat* buf)
|
||||
@ -34,6 +34,9 @@ void do_stat(Context* context, VFS::Node* node, struct stat* buf)
|
||||
kstat->st_size = node->length;
|
||||
kstat->st_uid = node->uid;
|
||||
kstat->st_gid = node->gid;
|
||||
kstat->st_atime = node->atime;
|
||||
kstat->st_ctime = node->ctime;
|
||||
kstat->st_mtime = node->mtime;
|
||||
release_user_ref(kstat);
|
||||
context->rax = 0;
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ struct stat // FIXME: This struct is quite stubbed out.
|
||||
int st_dev; // Not implemented.
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
time_t st_atime; // Not implemented.
|
||||
time_t st_mtime; // Not implemented.
|
||||
time_t st_ctime; // Not implemented.
|
||||
time_t st_atime;
|
||||
time_t st_mtime;
|
||||
time_t st_ctime;
|
||||
};
|
||||
|
||||
/* Type of file. */
|
||||
|
Loading…
Reference in New Issue
Block a user