// File: hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::FileSystem()
FileSystem::FileSystem() : D(), BLKsize(1024) {
	cout << "Welcome to use our system!" << endl;
	cout << "If you need help, just type \"help\", and hit [enter]." << endl;
	cout << "Input \"exit\" to exit the ststem." << endl;
	cout << "Hope you enjoy yourself~ (´▽｀)" << endl;

    // set BLK_No. of root directory to 0 
    // (the implementation of diskdata has done this work)

    // get super block
    char buf[BLKsize];
    D.Getblk(buf, 0);

    // get root path inodeNum and cur dir inodeNum
    root_dir_inodeNum = cur_dir_inodeNum = buf[2];

    // get inode bitmap
    for(int i = 3; i <= 12; ++i) {
        inode_bitmap[i - 3] = buf[i];
    }

    // get data block bitmap
    for(int i = 13; i <= 92; ++i) {
        data_block_bitmap[i - 13] = buf[i];
    }

    cur_path.push_back("/");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movl $0x400, (%rdi)          # imm = 0x400
addq $0x8, %rdi
movq %rdi, -0x78(%rbp)
callq 0x3700
movq -0x70(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x68(%rbp)
callq 0x9260
movq 0x108ee(%rip), %rdi     # 0x14fd0
leaq 0xa9e1(%rip), %rsi      # 0xf0ca
callq 0x3250
movq %rax, -0x60(%rbp)
jmp 0x46f4
movq -0x60(%rbp), %rdi
movq 0x108c1(%rip), %rsi     # 0x14fc0
callq 0x32a0
jmp 0x4706
movq 0x108c3(%rip), %rdi     # 0x14fd0
leaq 0xa9d1(%rip), %rsi      # 0xf0e5
callq 0x3250
movq %rax, -0x80(%rbp)
jmp 0x471f
movq -0x80(%rbp), %rdi
movq 0x10896(%rip), %rsi     # 0x14fc0
callq 0x32a0
jmp 0x4731
movq 0x10898(%rip), %rdi     # 0x14fd0
leaq 0xa9db(%rip), %rsi      # 0xf11a
callq 0x3250
movq %rax, -0x88(%rbp)
jmp 0x474d
movq -0x88(%rbp), %rdi
movq 0x10865(%rip), %rsi     # 0x14fc0
callq 0x32a0
jmp 0x4762
movq 0x10867(%rip), %rdi     # 0x14fd0
leaq 0xa9cb(%rip), %rsi      # 0xf13b
callq 0x3250
movq %rax, -0x90(%rbp)
jmp 0x477e
movq -0x90(%rbp), %rdi
movq 0x10834(%rip), %rsi     # 0x14fc0
callq 0x32a0
jmp 0x4793
movq -0x70(%rbp), %rdi
movl (%rdi), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rsi
subq %rcx, %rsi
movq %rsi, -0x98(%rbp)
movq %rsi, %rsp
movq %rax, -0x28(%rbp)
addq $0x8, %rdi
xorl %edx, %edx
callq 0x3900
jmp 0x47cc
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
movsbl 0x2(%rcx), %ecx
movl %ecx, 0x34(%rax)
movl %ecx, 0x30(%rax)
movl $0x3, -0x2c(%rbp)
cmpl $0xc, -0x2c(%rbp)
jg 0x4829
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x2c(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, 0x50(%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x47e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x48f4
movl $0xd, -0x30(%rbp)
cmpl $0x5c, -0x30(%rbp)
jg 0x4860
movq -0x70(%rbp), %rax
movq -0x98(%rbp), %rcx
movslq -0x30(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x30(%rbp), %ecx
subl $0xd, %ecx
movslq %ecx, %rcx
movb %dl, 0x5a(%rax,%rcx)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x4830
movq -0x70(%rbp), %rax
addq $0x38, %rax
movq %rax, -0xa8(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x34a0
movq -0xa0(%rbp), %rdx
leaq 0xa821(%rip), %rsi      # 0xf0ae
leaq -0x50(%rbp), %rdi
callq 0x3c50
jmp 0x4898
movq -0xa8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x91a0
jmp 0x48aa
leaq -0x50(%rbp), %rdi
callq 0x3160
leaq -0x51(%rbp), %rdi
callq 0x32d0
movq -0x20(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x48eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3160
leaq -0x51(%rbp), %rdi
callq 0x32d0
movq -0x68(%rbp), %rdi
callq 0x9280
movq -0x78(%rbp), %rdi
callq 0x38e0
movq -0x10(%rbp), %rdi
callq 0x3490
nop