// File: /workspace/github_c_makefile_star2_O2/j-hoppe[P]tu58fs/rt11.c
// Function: rt11_filesystem_init
void rt11_filesystem_init(rt11_filesystem_t *_this) {
	int i;
	// set device params

	// image may be variable sized !
	_this->blockcount = NEEDED_BLOCKS(RT11_BLOCKSIZE, _this->image_size);

	/*
	 _this->blockcount = _this->radi->block_count;
	 */

	if (_this->blockcount < 0)
		fatal("rt11_filesystem_init(): RT-11 blockcount for device %s not yet defined!",
				_this->device_info->device_name);

	// trunc large devices, only 64K blocks addressable = 32MB
	// no support for partitioned disks at the moment
	assert(_this->blockcount <= RT11_MAX_BLOCKCOUNT);

#ifdef DEFAULTBOOTLOADER
	// link default bootblock to const byte array
	_this->nobootblock->blocknr = 0;
	_this->nobootblock->byte_offset = 0;
	_this->nobootblock->data = rt11_nobootblock;
	_this->nobootblock->data_size = 512;
#endif

	if (_this->bootblock->data)
		free(_this->bootblock->data);
	stream_init(_this->bootblock);

	if (_this->monitor->data)
		free(_this->monitor->data);
	stream_init(_this->monitor);

	for (i = 0; i < RT11_MAX_FILES_PER_IMAGE; i++) {
		rt11_file_destroy(_this->file[i]);
		_this->file[i] = NULL;
	}
	_this->file_count = 0;

	// defaults for home block, according to [VFFM91], page 1-3
	_this->pack_cluster_size = 1;
	_this->first_dir_blocknr = 6;
	strcpy(_this->system_version, "V3A");
	strcpy(_this->volume_id, "RT11A       ");
	strcpy(_this->owner_name, "            ");
	strcpy(_this->system_id, "DECRT11A    ");
	_this->dir_entry_extra_bytes = 0;
	_this->homeblock_chksum = 0;
	_this->struct_changed = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl $0x1ff, %eax            # imm = 0x1FF
addl 0x8(%rdi), %eax
movl %eax, %ecx
shrl $0x9, %ecx
movl %ecx, 0x6c(%rdi)
cmpl $0x2000200, %eax        # imm = 0x2000200
jae 0xdb89
movq %rdi, %rbx
movq 0x78(%rdi), %rax
movq 0x8(%rax), %rdi
callq 0x3050
movq 0x78(%rbx), %rax
andw $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax)
xorl %ebp, %ebp
movb %bpl, 0x14(%rax)
movq 0x80(%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x3050
movq 0x80(%rbx), %rax
andw $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax)
movb %bpl, 0x14(%rax)
pushq $0x12
popq %r15
cmpq $0x3fa, %r15            # imm = 0x3FA
je 0xdb0e
movq (%rbx,%r15,8), %r14
testq %r14, %r14
je 0xdb04
movq 0x80(%r14), %rdi
callq 0xf6c6
movq 0x90(%r14), %rdi
callq 0xf6c6
movq 0x88(%r14), %rdi
callq 0xf6c6
movq %r14, %rdi
callq 0x3050
andq $0x0, (%rbx,%r15,8)
incq %r15
jmp 0xdac6
movl $0x1, 0x30(%rbx)
movw $0x6, 0x34(%rbx)
movl $0x413356, 0x36(%rbx)   # imm = 0x413356
movabsq $0x2020204131315452, %rax # imm = 0x2020204131315452
movq %rax, 0x3a(%rbx)
movabsq $0x20202020202020, %rax # imm = 0x20202020202020
movq %rax, 0x3f(%rbx)
movabsq $0x2020202020202020, %rcx # imm = 0x2020202020202020
movq %rcx, 0x47(%rbx)
movq %rax, 0x4c(%rbx)
movabsq $0x4131315452434544, %rax # imm = 0x4131315452434544
movq %rax, 0x54(%rbx)
movabsq $0x20202020413131, %rax # imm = 0x20202020413131
movq %rax, 0x59(%rbx)
andw $0x0, 0x68(%rbx)
andw $0x0, 0x62(%rbx)
andq $0x0, 0x88(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7c14(%rip), %rdi      # 0x157a4
leaq 0x7b9d(%rip), %rsi      # 0x15734
leaq 0x7c2f(%rip), %rcx      # 0x157cd
movl $0x143, %edx            # imm = 0x143
callq 0x3200