1// Copyright 2016 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <ddk/binding.h>
6#include <ddk/device.h>
7#include <ddk/driver.h>
8
9#include <zircon/types.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13
14// null is the /dev/null device.
15
16static zx_status_t null_read(void* ctx, void* buf, size_t count, zx_off_t off, size_t* actual) {
17    *actual = 0;
18    return ZX_OK;
19}
20
21static zx_status_t null_write(void* ctx, const void* buf, size_t count, zx_off_t off, size_t* actual) {
22    *actual = count;
23    return ZX_OK;
24}
25
26static zx_protocol_device_t null_device_proto = {
27    .version = DEVICE_OPS_VERSION,
28    .read = null_read,
29    .write = null_write,
30};
31
32zx_status_t null_bind(void* ctx, zx_device_t* parent, void** cookie) {
33    device_add_args_t args = {
34        .version = DEVICE_ADD_ARGS_VERSION,
35        .name = "null",
36        .ops = &null_device_proto,
37    };
38
39    zx_device_t* dev;
40    return device_add(parent, &args, &dev);
41}
42