Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ set(DMOD_MAL_IMPLS dmdrvi)
dmod_add_library(${DMOD_MODULE_NAME} ${DMOD_MODULE_VERSION}
# List of source files - can include C and C++ files
src/dmdevfs.c
src/partitions.c
)

# Link to other DMOD modules (will be downloaded on build time)
Expand All @@ -92,6 +91,7 @@ dmod_link_modules(${DMOD_MODULE_NAME}
dmini
dmlist
dmosi
dmpart
libsystemd
)

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,14 @@ partition table and creates one node per partition next to it:

| Table | Detected by | Numbers |
|-------|-------------|---------|
| MBR | `0x55AA` signature, valid status bytes, entries inside the medium; a FAT boot sector (superfloppy) is *not* taken for an MBR | primaries `1`-`4` by slot (empty slots leave gaps), logical partitions of an extended partition (`0x05`, `0x0F`, `0x85`) from `5` in chain order |
| MBR | `0x55AA` signature, valid status bytes, entries inside the medium; a FAT or exFAT boot sector (superfloppy) is *not* taken for an MBR | primaries `1`-`4` by slot (empty slots leave gaps), logical partitions of an extended partition (`0x05`, `0x0F`, `0x85`) from `5` in chain order |
| GPT | protective MBR (`0xEE`), then the `EFI PART` header at LBA 1 with valid header and entry array CRC32; if the primary header is damaged, the backup at the last LBA | entry index + 1 |

The table is parsed by [dmpart](https://github.com/choco-technologies/dmblkid/tree/main/libs/dmpart)
(released with dmblkid) - the same parser dmblkid uses, so a medium that
gets partition nodes here is always reported by dmblkid as a partition
table, never as a filesystem to mount whole.

A medium without a valid table (blank, superfloppy, damaged GPT with both
headers corrupted) gets no partition nodes - the whole-medium node is the
only one, as before. Block sizes of 512 to 4096 bytes are supported.
Expand Down Expand Up @@ -581,8 +586,7 @@ dmdevfs/
├── include/
│ └── dmdevfs.h # Public header
├── src/
│ ├── dmdevfs.c # Main DMDEVFS implementation
│ └── partitions.c/.h # MBR/GPT partition table parser
│ └── dmdevfs.c # Main DMDEVFS implementation
├── services/
│ └── dmdevmon/ # generic monitor service (rules + unit in configs/)
├── tests/
Expand Down
14 changes: 9 additions & 5 deletions src/dmdevfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "dmdrvi.h"
#include "dmosi.h"
#include "libsystemd.h"
#include "partitions.h"
#include "dmpart.h"
#include <errno.h>
#include <string.h>

Expand Down Expand Up @@ -3125,7 +3125,7 @@ typedef struct
} partition_scan_t;

/**
* @brief dmdevfs_part_read_t through the parent's driver
* @brief dmpart_read_t through the parent's driver
*/
static int partition_read( void* ctx, uint64_t offset, void* buffer, size_t size )
{
Expand Down Expand Up @@ -3164,7 +3164,7 @@ static driver_node_t* create_partition_node( const driver_node_t* parent, uint32
}

/**
* @brief dmdevfs_part_found_t collecting partition nodes
* @brief dmpart_found_t collecting partition nodes
*/
static bool on_partition_found( void* ctx, uint32_t number, uint64_t first_lba, uint64_t lba_count )
{
Expand Down Expand Up @@ -3208,8 +3208,12 @@ static dmlist_context_t* find_partitions( driver_node_t* node )
(found = dmlist_create()) != NULL)
{
partition_scan_t scan = { node, dmdrvi_read, handle, info.logical_block_size, found };
dmdevfs_partitions_scan(partition_read, &scan, info.logical_block_size, info.block_count,
on_partition_found, &scan);
dmpart_medium_t medium = { partition_read, &scan, info.logical_block_size, info.block_count };
dmpart_info_t table;
if (dmpart_scan(&medium, on_partition_found, &scan, &table) == -ENOMEM)
{
DMOD_LOG_ERROR("Out of memory reading the partition table of %s\n", node->path);
}
}
dmdrvi_close(node->driver_context, handle);
return found;
Expand Down
Loading
Loading