2021-05-31 04:47:02 +03:00
|
|
|
/**
|
|
|
|
* @file kernel/vfs/zero.c
|
|
|
|
* @brief /dev/null and /dev/zero provider.
|
|
|
|
*
|
|
|
|
* @copyright
|
2018-03-16 15:56:19 +03:00
|
|
|
* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
2018-05-01 11:12:56 +03:00
|
|
|
* Copyright (C) 2014-2018 K. Lange
|
2018-03-16 15:56:19 +03:00
|
|
|
*/
|
|
|
|
|
2021-05-31 04:47:02 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <kernel/vfs.h>
|
|
|
|
#include <kernel/string.h>
|
2018-03-16 15:56:19 +03:00
|
|
|
|
2021-05-31 04:47:02 +03:00
|
|
|
static uint64_t read_null(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buffer) {
|
2018-03-16 15:56:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-31 04:47:02 +03:00
|
|
|
static uint64_t write_null(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buffer) {
|
2018-03-16 15:56:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void open_null(fs_node_t * node, unsigned int flags) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void close_null(fs_node_t * node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-31 04:47:02 +03:00
|
|
|
static uint64_t read_zero(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buffer) {
|
2018-03-16 15:56:19 +03:00
|
|
|
memset(buffer, 0x00, size);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-05-31 04:47:02 +03:00
|
|
|
static uint64_t write_zero(fs_node_t *node, uint64_t offset, uint64_t size, uint8_t *buffer) {
|
2018-03-16 15:56:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void open_zero(fs_node_t * node, unsigned int flags) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void close_zero(fs_node_t * node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static fs_node_t * null_device_create(void) {
|
|
|
|
fs_node_t * fnode = malloc(sizeof(fs_node_t));
|
|
|
|
memset(fnode, 0x00, sizeof(fs_node_t));
|
|
|
|
fnode->inode = 0;
|
|
|
|
strcpy(fnode->name, "null");
|
|
|
|
fnode->uid = 0;
|
|
|
|
fnode->gid = 0;
|
|
|
|
fnode->mask = 0666;
|
|
|
|
fnode->flags = FS_CHARDEVICE;
|
|
|
|
fnode->read = read_null;
|
|
|
|
fnode->write = write_null;
|
|
|
|
fnode->open = open_null;
|
|
|
|
fnode->close = close_null;
|
|
|
|
fnode->readdir = NULL;
|
|
|
|
fnode->finddir = NULL;
|
|
|
|
fnode->ioctl = NULL;
|
|
|
|
return fnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static fs_node_t * zero_device_create(void) {
|
|
|
|
fs_node_t * fnode = malloc(sizeof(fs_node_t));
|
|
|
|
memset(fnode, 0x00, sizeof(fs_node_t));
|
|
|
|
fnode->inode = 0;
|
|
|
|
strcpy(fnode->name, "zero");
|
|
|
|
fnode->uid = 0;
|
|
|
|
fnode->gid = 0;
|
|
|
|
fnode->mask = 0666;
|
|
|
|
fnode->flags = FS_CHARDEVICE;
|
|
|
|
fnode->read = read_zero;
|
|
|
|
fnode->write = write_zero;
|
|
|
|
fnode->open = open_zero;
|
|
|
|
fnode->close = close_zero;
|
|
|
|
fnode->readdir = NULL;
|
|
|
|
fnode->finddir = NULL;
|
|
|
|
fnode->ioctl = NULL;
|
|
|
|
return fnode;
|
|
|
|
}
|
|
|
|
|
2021-05-31 04:47:02 +03:00
|
|
|
void zero_initialize(void) {
|
2018-03-16 15:56:19 +03:00
|
|
|
vfs_mount("/dev/null", null_device_create());
|
|
|
|
vfs_mount("/dev/zero", zero_device_create());
|
|
|
|
}
|
|
|
|
|