X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/f6ab9c9ababa2cf6e5c723b83ffb9362094054e8..f044ca812256b421e793c4335ce1ffed74710a70:/lunaix-os/hal/char/devnull.c diff --git a/lunaix-os/hal/char/devnull.c b/lunaix-os/hal/char/devnull.c new file mode 100644 index 0000000..12bd007 --- /dev/null +++ b/lunaix-os/hal/char/devnull.c @@ -0,0 +1,49 @@ +#include +#include + +static int +__null_wr_pg(struct device* dev, void* buf, size_t offset) +{ + // do nothing + return PG_SIZE; +} + +static int +__null_wr(struct device* dev, void* buf, size_t offset, size_t len) +{ + // do nothing + return len; +} + +static int +__null_rd_pg(struct device* dev, void* buf, size_t offset) +{ + // do nothing + return 0; +} + +static int +__null_rd(struct device* dev, void* buf, size_t offset, size_t len) +{ + // do nothing + return 0; +} + +static int +pdev_nulldev_init(struct device_def*) +{ + struct device* devnull = device_addseq(NULL, NULL, "null"); + devnull->ops.write_page = __null_wr_pg; + devnull->ops.write = __null_wr; + devnull->ops.read_page = __null_rd_pg; + devnull->ops.read = __null_rd; + + return 0; +} + +static struct device_def devnull_def = { + .name = "null", + .class = DEVCLASS(DEVIF_NON, DEVFN_PSEUDO, 0, 0), + .init = pdev_nulldev_init +}; +EXPORT_DEVICE(nulldev, &devnull_def, load_earlystage);