Devices: Add /dev/uptime
This file contains how many milliseconds have passed since boot at the time of reading it :)
This commit is contained in:
parent
1938a059a2
commit
47bdfecedb
9
kernel/include/fs/devices/Uptime.h
Normal file
9
kernel/include/fs/devices/Uptime.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "fs/VFS.h"
|
||||
|
||||
namespace UptimeDevice
|
||||
{
|
||||
VFS::Node* create_new(const char* devname);
|
||||
|
||||
ssize_t read(VFS::Node* node, size_t offset, size_t size, char* buffer);
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
#include "fs/devices/Keyboard.h"
|
||||
#include "fs/devices/Random.h"
|
||||
#include "fs/devices/Serial.h"
|
||||
#include "fs/devices/Uptime.h"
|
||||
#include "fs/devices/Version.h"
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
@ -29,6 +30,7 @@ VFS::Node* DeviceFS::get()
|
||||
devfs_files[devfs_file_count++] = SerialDevice::create_new("serial");
|
||||
devfs_files[devfs_file_count++] = RandomDevice::create_new("random");
|
||||
devfs_files[devfs_file_count++] = KeyboardDevice::create_new("kbd");
|
||||
devfs_files[devfs_file_count++] = UptimeDevice::create_new("uptime");
|
||||
return devfs_root;
|
||||
}
|
||||
|
||||
|
24
kernel/src/fs/devices/Uptime.cpp
Normal file
24
kernel/src/fs/devices/Uptime.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "fs/devices/Uptime.h"
|
||||
#include "std/stdio.h"
|
||||
#include "std/stdlib.h"
|
||||
#include "std/string.h"
|
||||
#include "thread/PIT.h"
|
||||
|
||||
VFS::Node* UptimeDevice::create_new(const char* devname)
|
||||
{
|
||||
VFS::Node* dev = new VFS::Node;
|
||||
dev->read_func = UptimeDevice::read;
|
||||
dev->inode = 0;
|
||||
dev->length = 0;
|
||||
dev->type = VFS_DEVICE;
|
||||
dev->flags = 0;
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
||||
ssize_t UptimeDevice::read(VFS::Node* node, size_t, size_t size, char* buffer)
|
||||
{
|
||||
if (!node) return -1;
|
||||
snprintf(buffer, size + 1, "%ld", PIT::ms_since_boot); // FIXME: Support offseting this read
|
||||
return (ssize_t)size;
|
||||
}
|
Loading…
Reference in New Issue
Block a user