// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x200, %ecx            # imm = 0x200
subl $0x1, %ecx
shrl $0x9, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x6c(%rax)
jge 0x138fa
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x9db5(%rip), %rdi      # 0x1d6a8
movb $0x0, %al
callq 0xd140
movq -0x8(%rbp), %rax
cmpl $0x10000, 0x6c(%rax)    # imm = 0x10000
jg 0x13909
jmp 0x13928
leaq 0x9de0(%rip), %rdi      # 0x1d6f0
leaq 0x9d21(%rip), %rsi      # 0x1d638
movl $0x143, %edx            # imm = 0x143
leaq 0x9df6(%rip), %rcx      # 0x1d719
callq 0x3200
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x13948
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3040
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x13870
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x1397b
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3040
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x13870
movl $0x0, -0xc(%rbp)
cmpl $0x3e8, -0xc(%rbp)      # imm = 0x3E8
jge 0x139cf
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq 0x90(%rax,%rcx,8), %rdi
callq 0x13ac0
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq $0x0, 0x90(%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x13992
movq -0x8(%rbp), %rax
movl $0x0, 0x8c(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x8(%rbp), %rax
movw $0x6, 0x34(%rax)
movq -0x8(%rbp), %rdi
addq $0x36, %rdi
leaq 0x9d47(%rip), %rsi      # 0x1d748
callq 0x30c0
movq -0x8(%rbp), %rdi
addq $0x3a, %rdi
leaq 0x9d37(%rip), %rsi      # 0x1d74c
callq 0x30c0
movq -0x8(%rbp), %rdi
addq $0x47, %rdi
leaq 0x9d30(%rip), %rsi      # 0x1d759
callq 0x30c0
movq -0x8(%rbp), %rdi
addq $0x54, %rdi
leaq 0x9d29(%rip), %rsi      # 0x1d766
callq 0x30c0
movq -0x8(%rbp), %rax
movw $0x0, 0x68(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x62(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x88(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)