// File: /workspace/github_c_makefile_star2_O2/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 $0x218, %rsp            # imm = 0x218
movq %rdi, %r14
xorl %esi, %esi
xorl %edx, %edx
callq 0x1100
leaq 0x10(%rsp), %rbx
pushq $0x1
popq %rsi
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rcx
callq 0x1070
pushq $0x20
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x179c
movzwl (%rbx), %eax
rolw $0x8, %ax
cmpw $0x4552, %ax            # imm = 0x4552
jne 0x2c45
leaq 0x1015(%rip), %rdi      # 0x3b7f
callq 0x1060
leaq 0x26(%rsp), %r14
movzwl -0x14(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %edx
movl -0x12(%r14), %esi
bswapl %esi
movq %rdx, %rcx
imulq %rsi, %rcx
leaq 0xc88(%rip), %rdi       # 0x381c
xorl %eax, %eax
callq 0x1090
movzwl -0xe(%r14), %eax
movzwl -0xc(%r14), %ecx
rolw $0x8, %ax
rolw $0x8, %cx
movzwl %ax, %esi
movzwl %cx, %edx
movl -0xa(%r14), %ecx
bswapl %ecx
leaq 0xc87(%rip), %rdi       # 0x3847
xorl %eax, %eax
callq 0x1090
movzwl -0x6(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %ebx
testw %bx, %bx
leaq 0xca3(%rip), %rax       # 0x3880
leaq 0xf39(%rip), %rdx       # 0x3b1d
cmoveq %rax, %rdx
leaq 0xc7f(%rip), %rdi       # 0x386e
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0xc83(%rip), %r15       # 0x3882
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x2c51
leaq -0x4(%r14), %rdi
callq 0x188f
movl %eax, %ebp
movzwl -0x2(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %r13d
movq %r14, %rdi
callq 0x188f
movq %r15, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r13d, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x1090
incq %r12
addq $0x8, %r14
jmp 0x2c02
leaq 0xf53(%rip), %rdi       # 0x3b9f
callq 0x1060
leaq 0x40(%rsp), %r15
leaq 0x10(%rsp), %r12
xorl %r13d, %r13d
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
pushq $0x1
popq %rsi
movq 0x8(%rsp), %rcx
callq 0x1070
movq %r12, %rdi
movl $0x88, %esi
xorl %edx, %edx
callq 0x179c
leaq 0xc2b(%rip), %rdi       # 0x38b4
movl %r13d, %esi
xorl %eax, %eax
callq 0x1090
movzwl 0x10(%rsp), %eax
rolw $0x8, %ax
cmpw $0x504d, %ax            # imm = 0x504D
jne 0x2d61
movl 0x14(%rsp), %r14d
bswapl %r14d
leaq 0xc15(%rip), %rdi       # 0x38ca
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
movl 0x18(%rsp), %ebp
movl 0x1c(%rsp), %ebx
bswapl %ebp
bswapl %ebx
movl %ebp, %edx
shll $0x9, %edx
movl %ebx, %r8d
shll $0x9, %r8d
leaq 0xc15(%rip), %rdi       # 0x38f3
movl %ebp, %esi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1090
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %ecx
bswapl %esi
bswapl %ecx
movl %esi, %edx
shll $0x9, %edx
movl %ecx, %r8d
shll $0x9, %r8d
leaq 0xbe3(%rip), %rdi       # 0x38eb
xorl %eax, %eax
callq 0x1090
leaq 0xc12(%rip), %rdi       # 0x3928
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1090
movq %r15, %rdi
leaq 0xc13(%rip), %rsi       # 0x3942
pushq $0xa
popq %rdx
callq 0x10f0
testl %eax, %eax
jne 0x2d53
leaq 0xe87(%rip), %rdi       # 0x3bc9
callq 0x1060
movl %ebp, 0x3377(%rip)      # 0x60c4
movl %ebx, 0x3375(%rip)      # 0x60c8
incl %r13d
cmpl %r14d, %r13d
jb 0x2c5e
jmp 0x2d6d
leaq 0xe65(%rip), %rdi       # 0x3bcd
callq 0x1060
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq