rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
null_device.cpp
Go to the documentation of this file.
1/**
2 * @file zero_device.cpp
3 *
4 * @date Feb 12, 2021
5 * @author Matthew Kennedy, (c) 2021
6 *
7 * This file implements a special block device that simply reports "no media"
8 * Use it when you need to mount *something* but don't have an SD card available.
9 */
10
11#include "pch.h"
12
13#include <cstring>
14
15struct NullDevice {
16 const struct BaseBlockDeviceVMT *vmt;
17 _base_block_device_data
18};
19
20static bool nd_is_inserted(void*) {
21 // This function is the whole point - we have no media!
22 return false;
23}
24
25static bool nd_is_protected(void*) {
26 return false;
27}
28
29static bool nd_return_success(void*) {
30 return HAL_SUCCESS;
31}
32
33static bool nd_return_success_read(void*, uint32_t, uint8_t* buffer, uint32_t n) {
34 // write zeroes to the buffer to prevent somebody reading random memory
35 memset(buffer, 0, n);
36
37 return HAL_SUCCESS;
38}
39
40static bool nd_return_success_write(void*, uint32_t, const uint8_t*, uint32_t) {
41 return HAL_SUCCESS;
42}
43
44static bool nd_get_info(void*, BlockDeviceInfo* bdip) {
45 // We have to report non-zero size here because Windows
46 // will query the size of the block device even if we indicate
47 // that the device has no media
48 // If we report zeroes, it breaks USB until you unplug this device
49 bdip->blk_num = 1000;
50 bdip->blk_size = 512;
51 return HAL_SUCCESS;
52}
53
54static const struct BaseBlockDeviceVMT ndVmt = {
55 (size_t)0, // instanceOffset
58
59 // These functions just claim success to make the host happy
66};
67
68// This device is always ready and has no state
69NullDevice ND1 = { &ndVmt, BLK_READY };
static bool nd_return_success_read(void *, uint32_t, uint8_t *buffer, uint32_t n)
static bool nd_get_info(void *, BlockDeviceInfo *bdip)
static bool nd_return_success_write(void *, uint32_t, const uint8_t *, uint32_t)
static bool nd_is_protected(void *)
static bool nd_return_success(void *)
static bool nd_is_inserted(void *)
NullDevice ND1
static const struct BaseBlockDeviceVMT ndVmt
static BigBufferHandle buffer