zero.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2014-2018 K. Lange
  5. *
  6. * Null Device
  7. *
  8. */
  9. #include <kernel/system.h>
  10. #include <kernel/fs.h>
  11. #include <kernel/module.h>
  12. static uint32_t read_null(fs_node_t *node, uint64_t offset, uint32_t size, uint8_t *buffer) {
  13. return 0;
  14. }
  15. static uint32_t write_null(fs_node_t *node, uint64_t offset, uint32_t size, uint8_t *buffer) {
  16. return 0;
  17. }
  18. static void open_null(fs_node_t * node, unsigned int flags) {
  19. return;
  20. }
  21. static void close_null(fs_node_t * node) {
  22. return;
  23. }
  24. static uint32_t read_zero(fs_node_t *node, uint64_t offset, uint32_t size, uint8_t *buffer) {
  25. memset(buffer, 0x00, size);
  26. return 1;
  27. }
  28. static uint32_t write_zero(fs_node_t *node, uint64_t offset, uint32_t size, uint8_t *buffer) {
  29. return 0;
  30. }
  31. static void open_zero(fs_node_t * node, unsigned int flags) {
  32. return;
  33. }
  34. static void close_zero(fs_node_t * node) {
  35. return;
  36. }
  37. static fs_node_t * null_device_create(void) {
  38. fs_node_t * fnode = malloc(sizeof(fs_node_t));
  39. memset(fnode, 0x00, sizeof(fs_node_t));
  40. fnode->inode = 0;
  41. strcpy(fnode->name, "null");
  42. fnode->uid = 0;
  43. fnode->gid = 0;
  44. fnode->mask = 0666;
  45. fnode->flags = FS_CHARDEVICE;
  46. fnode->read = read_null;
  47. fnode->write = write_null;
  48. fnode->open = open_null;
  49. fnode->close = close_null;
  50. fnode->readdir = NULL;
  51. fnode->finddir = NULL;
  52. fnode->ioctl = NULL;
  53. return fnode;
  54. }
  55. static fs_node_t * zero_device_create(void) {
  56. fs_node_t * fnode = malloc(sizeof(fs_node_t));
  57. memset(fnode, 0x00, sizeof(fs_node_t));
  58. fnode->inode = 0;
  59. strcpy(fnode->name, "zero");
  60. fnode->uid = 0;
  61. fnode->gid = 0;
  62. fnode->mask = 0666;
  63. fnode->flags = FS_CHARDEVICE;
  64. fnode->read = read_zero;
  65. fnode->write = write_zero;
  66. fnode->open = open_zero;
  67. fnode->close = close_zero;
  68. fnode->readdir = NULL;
  69. fnode->finddir = NULL;
  70. fnode->ioctl = NULL;
  71. return fnode;
  72. }
  73. static int zero_initialize(void) {
  74. vfs_mount("/dev/null", null_device_create());
  75. vfs_mount("/dev/zero", zero_device_create());
  76. return 0;
  77. }
  78. static int zero_finalize(void) {
  79. return 0;
  80. }
  81. MODULE_DEF(zero, zero_initialize, zero_finalize);