summaryrefslogtreecommitdiff
path: root/subsys/fs/fat_ram_diskio.c
blob: 565e3037883c30a8890ac518869f58740cf5aeda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (c) 2016 Intel Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <string.h>
#include <stdint.h>
#include <misc/__assert.h>
#include <diskio.h>
#include <ff.h>

static uint8_t file_buff[CONFIG_FS_VOLUME_SIZE];

static void *lba_to_address(uint32_t lba)
{
	__ASSERT(((lba * _MIN_SS) < CONFIG_FS_VOLUME_SIZE), "FS bound error");
	return &file_buff[(lba * _MIN_SS)];
}

DSTATUS fat_disk_status(void)
{
	return RES_OK;
}

DSTATUS fat_disk_initialize(void)
{
	return RES_OK;
}

DRESULT fat_disk_read(void *buff, uint32_t sector, uint32_t count)
{
	memcpy(buff, lba_to_address(sector), count * _MIN_SS);

	return RES_OK;
}

DRESULT fat_disk_write(void *buff, uint32_t sector, uint32_t count)
{
	memcpy(lba_to_address(sector), buff, count * _MIN_SS);

	return RES_OK;
}

DRESULT fat_disk_ioctl(uint8_t cmd, void *buff)
{
	switch (cmd) {
	case CTRL_SYNC:
		return RES_OK;
	case GET_SECTOR_COUNT:
		*(uint32_t *) buff = CONFIG_FS_VOLUME_SIZE / _MIN_SS;
		return RES_OK;
	case GET_BLOCK_SIZE:
		*(uint32_t *) buff = CONFIG_FS_BLOCK_SIZE / _MIN_SS;
		return RES_OK;
	case CTRL_TRIM:
		break;
	}

	return RES_PARERR;
}