mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
kernel: pseudodevices (null, full and zero)
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include <kernel/tmpfs.h>
|
#include <kernel/tmpfs.h>
|
||||||
#include <kernel/initrd.h>
|
#include <kernel/initrd.h>
|
||||||
#include <kernel/devfs.h>
|
#include <kernel/devfs.h>
|
||||||
|
#include <kernel/pseudodevices.h>
|
||||||
|
|
||||||
static cpu_t bsp_cpu;
|
static cpu_t bsp_cpu;
|
||||||
|
|
||||||
@@ -55,5 +56,7 @@ void kernel_entry() {
|
|||||||
printf("mounting devfs on /dev\n");
|
printf("mounting devfs on /dev\n");
|
||||||
__assert(vfs_mount(NULL, vfsroot, "/dev", "devfs", NULL) == 0);
|
__assert(vfs_mount(NULL, vfsroot, "/dev", "devfs", NULL) == 0);
|
||||||
|
|
||||||
|
pseudodevices_init();
|
||||||
|
|
||||||
__assert(!"kernel entry end");
|
__assert(!"kernel entry end");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
#include <kernel/vfs.h>
|
#include <kernel/vfs.h>
|
||||||
|
|
||||||
|
#define DEV_MAJOR_NULL 1
|
||||||
|
#define DEV_MAJOR_FULL 2
|
||||||
|
#define DEV_MAJOR_ZERO 3
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int (*open)(int minor, int flags);
|
int (*open)(int minor, int flags);
|
||||||
int (*close)(int minor, int flags);
|
int (*close)(int minor, int flags);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef _PSEUDODEVICES_H
|
||||||
|
#define _PSEUDODEVICES_H
|
||||||
|
|
||||||
|
void pseudodevices_init();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#include <kernel/devfs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <logging.h>
|
||||||
|
|
||||||
|
static int null_write(int minor, void *buffer, size_t count, uintmax_t offset, int flags, size_t *wcount) {
|
||||||
|
*wcount = count;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int full_write(int minor, void *buffer, size_t count, uintmax_t offset, int flags, size_t *wcount) {
|
||||||
|
return ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int zero_read(int minor, void *buffer, size_t count, uintmax_t offset, int flags, size_t *rcount) {
|
||||||
|
*rcount = count;
|
||||||
|
memset(buffer, 0, count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int null_read(int minor, void *buffer, size_t count, uintmax_t offset, int flags, size_t *rcount) {
|
||||||
|
*rcount = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static devops_t nullops = {
|
||||||
|
.read = null_read,
|
||||||
|
.write = null_write
|
||||||
|
};
|
||||||
|
|
||||||
|
static devops_t fullops = {
|
||||||
|
.read = zero_read,
|
||||||
|
.write = full_write
|
||||||
|
};
|
||||||
|
|
||||||
|
static devops_t zeroops = {
|
||||||
|
.read = zero_read,
|
||||||
|
.write = null_write
|
||||||
|
};
|
||||||
|
|
||||||
|
void pseudodevices_init() {
|
||||||
|
__assert(devfs_register(&nullops, "null", V_TYPE_CHDEV, DEV_MAJOR_NULL, 0, 0644) == 0);
|
||||||
|
__assert(devfs_register(&fullops, "full", V_TYPE_CHDEV, DEV_MAJOR_FULL, 0, 0644) == 0);
|
||||||
|
__assert(devfs_register(&zeroops, "zero", V_TYPE_CHDEV, DEV_MAJOR_ZERO, 0, 0644) == 0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user