summaryrefslogtreecommitdiff
path: root/components/drivers/block/partitions/dfs.c
blob: 3fdad1a1d6a6c17eb1db78e27ed347a3f75a801b (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
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author        Notes
 * 2011-07-25     weety         first version
 * 2023-02-25     GuEe-GUI      make blk interface
 */

#include "efi.h"

#define DBG_TAG "blk.part.dfs"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

rt_err_t dfs_partition(struct rt_blk_disk *disk)
{
    rt_ssize_t res;
    struct dfs_partition part;
    rt_uint8_t *sector = rt_malloc(rt_blk_disk_get_logical_block_size(disk));

    if (!sector)
    {
        return -RT_ENOMEM;
    }

    res = disk->ops->read(disk, 0, sector, 1);

    if (res < 0)
    {
        rt_free(sector);
        return res;
    }

    for (rt_size_t i = 0; i < disk->max_partitions; ++i)
    {
        res = dfs_filesystem_get_partition(&part, sector, i);

        if (res)
        {
            break;
        }

        if (blk_put_partition(disk, "dfs", part.offset, part.size, i) == -RT_ENOMEM)
        {
            break;
        }
    }

    rt_free(sector);

    return RT_EOK;
}