1 /*
2 * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include "volume_metadata_fetcher.h"
8
9 #include <CppUTest/TestHarness.h>
10 #include <cstring>
11
12 #include "media/volume/volume.h"
13
volume_metadata_fetcher(const struct uuid_octets * partition_guid,struct block_store * block_store)14 volume_metadata_fetcher::volume_metadata_fetcher(const struct uuid_octets *partition_guid,
15 struct block_store *block_store)
16 : metadata_fetcher()
17 , m_meta_block_volume()
18 , m_meta_volume(NULL)
19 {
20 int status = block_volume_init(&m_meta_block_volume, block_store, partition_guid,
21 &m_meta_volume);
22 LONGS_EQUAL(0, status);
23 CHECK_TRUE(m_meta_volume);
24 }
25
~volume_metadata_fetcher()26 volume_metadata_fetcher::~volume_metadata_fetcher()
27 {
28 block_volume_deinit(&m_meta_block_volume);
29 }
30
open(void)31 void volume_metadata_fetcher::open(void)
32 {
33 int status = volume_open(m_meta_volume);
34 LONGS_EQUAL(0, status);
35 }
36
close(void)37 void volume_metadata_fetcher::close(void)
38 {
39 volume_close(m_meta_volume);
40 }
41
fetch(uint8_t * buf,size_t buf_size)42 void volume_metadata_fetcher::fetch(uint8_t *buf, size_t buf_size)
43 {
44 /* Trash the old data */
45 memset(buf, 0xff, buf_size);
46
47 int status = volume_seek(m_meta_volume, IO_SEEK_SET, 0);
48 LONGS_EQUAL(0, status);
49
50 size_t length_read = 0;
51
52 status = volume_read(m_meta_volume, (uintptr_t)buf, buf_size, &length_read);
53
54 LONGS_EQUAL(0, status);
55 UNSIGNED_LONGS_EQUAL(buf_size, length_read);
56 }
57