I am trying to parse these 30 bytes:
00000000: 4353 4333 3630 4653 0200 0000 1900 0000
00000010: 0002 0000 0032 0000 0035 0000
Into a struct (also 30 bytes):
struct superblock_t {
uint8_t fs_id [8];
uint16_t block_size;
uint32_t file_system_block_count;
uint32_t fat_start_block;
uint32_t fat_block_count;
uint32_t root_dir_start_block;
uint32_t root_dir_block_count;
} PACKED;
I am first reading the 30 bytes into a buffer then using memcpy()
to copy desired memory.
unsigned char buf[30]; //should this buffer be size_t 31?
read(file_descriptor, buf, 30);
struct superblock_t super_block; //initilize a super_block
memcpy(super_block.fs_id, buf, 8);
memcpy(super_block.block_size, buf + 8, 2);
memcpy(super_block.file_system_block_count, buf + 10, 4);
// and so on for additional attributes.
I am then getting a segfault error :(
Am I misusing the memcpy()
function? Sorry, I'm coming from c++ for reference.