blob: eb82008b7383840256a6856888d1fc1b49cc25fe (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Storage Class */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_storage.h"
#include "ux_host_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_storage_partition_read PORTABLE C */
/* 6.1.2 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function will analyze the partition table and parse all the */
/* partitions. It may happen that a partition entry points to a */
/* secondary partition table. */
/* */
/* INPUT */
/* */
/* storage Pointer to storage class */
/* sector_memory Pointer to memory for sector */
/* sector Sector number */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_host_class_storage_media_mount Mount media */
/* _ux_host_class_storage_media_open Open media */
/* _ux_utility_long_get Get 32-bit word */
/* */
/* CALLED BY */
/* */
/* _ux_host_class_storage_media_mount Mount media */
/* */
/**************************************************************************/
UINT _ux_host_class_storage_partition_read(UX_HOST_CLASS_STORAGE *storage, UCHAR *sector_memory, ULONG sector)
{
#if defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
UX_PARAMETER_NOT_USED(storage);
UX_PARAMETER_NOT_USED(sector_memory);
UX_PARAMETER_NOT_USED(sector);
return(UX_FUNCTION_NOT_SUPPORTED);
#else
UINT status = UX_ERROR;
UINT partition_index;
/* Check recursion/mount count before processing. */
if (storage -> ux_host_class_storage_mounted_partitions_count > UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT)
{
return UX_HOST_CLASS_STORAGE_ERROR_MEDIA_NOT_READ;
}
/* Point the sector buffer to the first partition entry. */
sector_memory += UX_HOST_CLASS_STORAGE_PARTITION_TABLE_START;
/* There are 4 partitions in a partition table. */
for (partition_index = 0; partition_index < 4; partition_index++)
{
/* Increment the mounted partition count for every entry processed. */
storage -> ux_host_class_storage_mounted_partitions_count++;
/* Check again after incrementing. */
if (storage -> ux_host_class_storage_mounted_partitions_count > UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT)
{
/* Too many partition entries processed, abort to prevent stack overflow. */
return UX_HOST_CLASS_STORAGE_ERROR_MEDIA_NOT_READ;
}
/* Check if we recognize this partition entry. */
switch(*(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_TYPE))
{
case UX_HOST_CLASS_STORAGE_PARTITION_FAT_12:
case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16:
case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16L:
case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16_LBA_MAPPED:
case UX_HOST_CLASS_STORAGE_PARTITION_FAT_32_1:
case UX_HOST_CLASS_STORAGE_PARTITION_FAT_32_2:
case UX_HOST_CLASS_STORAGE_PARTITION_EXFAT:
/* We have found a legal partition entry pointing to a potential boot sector. */
status = _ux_host_class_storage_media_open(storage, sector + _ux_utility_long_get(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_SECTORS_BEFORE));
break;
case UX_HOST_CLASS_STORAGE_PARTITION_EXTENDED:
case UX_HOST_CLASS_STORAGE_PARTITION_EXTENDED_LBA_MAPPED:
/* We have found an entry to an extended partition. We need to read that partition sector
and recursively mount all partitions found. */
status = _ux_host_class_storage_media_mount(storage, sector + _ux_utility_long_get(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_SECTORS_BEFORE));
break;
default:
/* We have found something which is not a DOS recognized partition, or an empty entry.
Ignore it and proceed with the rest. */
break;
}
/* Move to the next partition entry. */
sector_memory += UX_HOST_CLASS_STORAGE_PARTITION_TABLE_SIZE;
}
/* Return completion status. */
return(status);
#endif
}
|