// File: /workspace/github_c_makefile_star2_O1/miniupnp[P]hfsplustools/src/hfscommon.c
// Function: read_partition_map
void read_partition_map(FILE * f)
{
	unsigned char buffer[SECTOR_SIZE];
	unsigned int i = 0;
	unsigned int count = 0;
	uint16_t block_size = 0;
	uint32_t number_of_blocks = 0;

#if 0
	fseek(f, PARTITION_MAP_OFFSET, SEEK_SET);
#else
	/* read the Driver Descriptor */
	fseek(f, 0, SEEK_SET);
	fread(buffer, 1, sizeof(buffer), f);
	hexdump(buffer, 32, 0);
	if(readu16(buffer) != 0x4552) {	// signature
		printf("bad signature for Driver Descriptor block\n");
	} else {
		unsigned int i, desc_count;
		printf("=== Driver Descriptor Block ===\n");
		block_size = readu16(buffer + 2);
		number_of_blocks = readu32(buffer + 4);
		printf("%lu blocks of %hu bytes. %lu bytes total.\n",
		       (unsigned long)number_of_blocks, block_size, (unsigned long)number_of_blocks * block_size);
		printf("Type %04hx Identifier %04hx Data %08x\n",
		       readu16(buffer+8), readu16(buffer+10), readu32(buffer+12));
		desc_count = readu16(buffer+16);
		printf("%u descriptors%s\n", desc_count, (desc_count == 0) ? "." : " :");
		for (i = 0; i < desc_count; i++) {
			printf(" #%02u : start block %u, block count %u, OS=%04x\n",
			       i, readu32(buffer+18+i*8), readu16(buffer+20+i*8),
			       readu32(buffer+22+i*8));
		}
	}
#endif

	do {
		unsigned int start, size;
		unsigned int start_l, size_l;
		fread(buffer, 1, sizeof(buffer), f);
		hexdump(buffer, 136, 0);
		printf("=== partition %u ===\n", i);
		if(readu16(buffer) != 0x504D) {	// signature
			printf("bad signature\n");
			break;
		}
		count = readu32(buffer + 4);
		printf("total number of partitions = %u\n", count);
		start = readu32(buffer + 8);
		size = readu32(buffer + 12);
		printf("starting sector=%u (offset %08x) size %u (%u bytes)\n",
			start, start * SECTOR_SIZE, size, size * SECTOR_SIZE);
		start_l = readu32(buffer + 80);
		size_l = readu32(buffer + 84);
		printf("logical starting sector=%u (offset %08x) size %u (%u bytes)\n",
			start_l, start_l * SECTOR_SIZE, size_l, size_l * SECTOR_SIZE);
		printf(" name = '%s' type = '%s'\n", buffer + 16, buffer + 48);
		if(strcmp((char *)buffer + 48, "Apple_HFS") == 0) {
			printf("---\n");
			hfs_part_sector = start;
			hfs_part_sector_count = size;
		}
		i++;
	} while(i < count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %r13
xorl %esi, %esi
xorl %edx, %edx
callq 0x1100
movq %rsp, %r14
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %r13, %rcx
callq 0x1070
movq %r14, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x19e8
movzwl (%r14), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl $0x4552, %eax           # imm = 0x4552
jne 0x2d86
leaq 0xed7(%rip), %rdi       # 0x3b7f
callq 0x1060
movzwl 0x2(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %edx
movl 0x4(%rsp), %esi
bswapl %esi
movq %rdx, %rcx
imulq %rsi, %rcx
leaq 0xb4f(%rip), %rdi       # 0x381c
xorl %eax, %eax
callq 0x1090
movzwl 0x8(%rsp), %eax
movzwl 0xa(%rsp), %ecx
rolw $0x8, %ax
rolw $0x8, %cx
movzwl %ax, %esi
movzwl %cx, %edx
movl 0xc(%rsp), %ecx
bswapl %ecx
leaq 0xb4e(%rip), %rdi       # 0x3847
xorl %eax, %eax
callq 0x1090
movzwl 0x10(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
testw %r14w, %r14w
leaq 0xb68(%rip), %rax       # 0x3880
leaq 0xdfe(%rip), %rdx       # 0x3b1d
cmoveq %rax, %rdx
leaq 0xb44(%rip), %rdi       # 0x386e
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
testw %r14w, %r14w
je 0x2d92
leaq 0xb41(%rip), %r15       # 0x3882
xorl %r12d, %r12d
movzbl 0x12(%rsp,%r12,8), %eax
shll $0x18, %eax
movzbl 0x13(%rsp,%r12,8), %edx
shll $0x10, %edx
orl %eax, %edx
movzwl 0x14(%rsp,%r12,8), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
orl %ecx, %edx
movl 0x16(%rsp,%r12,8), %r8d
bswapl %r8d
movq %r15, %rdi
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
incq %r12
cmpq %r12, %r14
jne 0x2d44
jmp 0x2d92
leaq 0xe12(%rip), %rdi       # 0x3b9f
callq 0x1060
movq %rsp, %r14
leaq 0xb18(%rip), %r12       # 0x38b4
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %r13, %rcx
callq 0x1070
movq %r14, %rdi
movl $0x88, %esi
xorl %edx, %edx
callq 0x19e8
movq %r12, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
movzwl (%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %ebx
cmpl $0x504d, %ebx           # imm = 0x504D
jne 0x2ebd
movq %r13, %r12
movl 0x4(%rsp), %ebp
bswapl %ebp
leaq 0xad1(%rip), %rdi       # 0x38ca
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
movl 0x8(%rsp), %r14d
movl 0xc(%rsp), %r13d
bswapl %r14d
bswapl %r13d
movl %r14d, %edx
shll $0x9, %edx
movl %r13d, %r8d
shll $0x9, %r8d
leaq 0xacd(%rip), %rdi       # 0x38f3
movl %r14d, %esi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1090
movl 0x50(%rsp), %esi
movl 0x54(%rsp), %ecx
bswapl %esi
bswapl %ecx
movl %esi, %edx
shll $0x9, %edx
movl %ecx, %r8d
shll $0x9, %r8d
leaq 0xa99(%rip), %rdi       # 0x38eb
xorl %eax, %eax
callq 0x1090
leaq 0xac8(%rip), %rdi       # 0x3928
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x1090
movq 0x30(%rsp), %rax
movabsq $0x46485f656c707041, %rcx # imm = 0x46485F656C707041
xorq %rcx, %rax
movzwl 0x38(%rsp), %ecx
xorq $0x53, %rcx
orq %rax, %rcx
jne 0x2eab
leaq 0xd31(%rip), %rdi       # 0x3bc9
callq 0x1060
movl %r14d, 0x3220(%rip)     # 0x60c4
movl %r13d, 0x321d(%rip)     # 0x60c8
incl %r15d
movq %r12, %r13
movq %rsp, %r14
leaq 0x9f9(%rip), %r12       # 0x38b4
jmp 0x2ec9
leaq 0xd09(%rip), %rdi       # 0x3bcd
callq 0x1060
cmpl $0x504d, %ebx           # imm = 0x504D
jne 0x2eda
cmpl %ebp, %r15d
jb 0x2da1
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq