// File: ljl0222[P]SecondFileSystem/FileManager.cpp
// Function: FileManager::Ls()
void FileManager::Ls() 
{
    User& u = globalUser;
    BufferManager& bufferManager = globalBufferManager;

    Inode* pINode = u.u_cdir;
    Buf* pBuffer = NULL;
    u.u_IOParam.m_Offset = 0;
    u.u_IOParam.m_Count = pINode->i_size / sizeof(DirectoryEntry);

    int lsCnt = 0;

    while (u.u_IOParam.m_Count) 
    {
        if (0 == u.u_IOParam.m_Offset % Inode::BLOCK_SIZE) 
        {
            if (pBuffer) 
            {
                bufferManager.Brelse(pBuffer);
            }
            int phyBlkno = pINode->Bmap(u.u_IOParam.m_Offset / Inode::BLOCK_SIZE);
            pBuffer = bufferManager.Bread(phyBlkno);
        }
        memcpy(&u.u_dent, pBuffer->b_addr + (u.u_IOParam.m_Offset % Inode::BLOCK_SIZE), sizeof(u.u_dent));
        u.u_IOParam.m_Offset += sizeof(DirectoryEntry);
        u.u_IOParam.m_Count--;

        if (0 == u.u_dent.m_ino)
            continue;
        u.ls += u.u_dent.name;
        u.ls += " ";
        lsCnt++;
        if (lsCnt % 7 == 0)
            u.ls += "\n";
    }

    if (pBuffer) 
    {
        bufferManager.Brelse(pBuffer);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x1dc55(%rip), %rax     # 0x24cc8
movq %rax, -0x10(%rbp)
leaq 0xd2d2(%rip), %rax      # 0x14350
movq %rax, -0x18(%rbp)
leaq 0x1dc3f(%rip), %rax     # 0x24cc8
movq 0x1058(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
leaq 0x1dc25(%rip), %rax     # 0x24cc8
movl $0x0, 0x13f8(%rax)
movq -0x20(%rbp), %rax
movslq 0x1c(%rax), %rax
shrq $0x5, %rax
movl %eax, %ecx
leaq 0x1dc06(%rip), %rax     # 0x24cc8
movl %ecx, 0x13fc(%rax)
movl $0x0, -0x2c(%rbp)
leaq 0x1dbf2(%rip), %rax     # 0x24cc8
cmpl $0x0, 0x13fc(%rax)
je 0x7268
leaq 0x1dbde(%rip), %rax     # 0x24cc8
movl 0x13f8(%rax), %eax
movl $0x200, %ecx            # imm = 0x200
cltd
idivl %ecx
xorl %eax, %eax
cmpl %edx, %eax
jne 0x714b
cmpq $0x0, -0x28(%rbp)
je 0x7115
movq -0x28(%rbp), %rsi
leaq 0xd240(%rip), %rdi      # 0x14350
callq 0x3e80
movq -0x20(%rbp), %rdi
leaq 0x1dba8(%rip), %rax     # 0x24cc8
movl 0x13f8(%rax), %eax
movl $0x200, %ecx            # imm = 0x200
cltd
idivl %ecx
movl %eax, %esi
callq 0x8020
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %esi
leaq 0xd20e(%rip), %rdi      # 0x14350
callq 0x3f10
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
leaq 0x1db6e(%rip), %rax     # 0x24cc8
movl 0x13f8(%rax), %eax
movl $0x200, %esi            # imm = 0x200
cltd
idivl %esi
movslq %edx, %rdx
leaq 0x1db56(%rip), %rax     # 0x24cc8
movq (%rcx,%rdx), %rsi
movq %rsi, 0x1068(%rax)
movq 0x8(%rcx,%rdx), %rsi
movq %rsi, 0x1070(%rax)
movq 0x10(%rcx,%rdx), %rsi
movq %rsi, 0x1078(%rax)
movq 0x18(%rcx,%rdx), %rcx
movq %rcx, 0x1080(%rax)
leaq 0x1db20(%rip), %rax     # 0x24cc8
movslq 0x13f8(%rax), %rax
addq $0x20, %rax
movl %eax, %ecx
leaq 0x1db0c(%rip), %rax     # 0x24cc8
movl %ecx, 0x13f8(%rax)
leaq 0x1daff(%rip), %rax     # 0x24cc8
movl 0x13fc(%rax), %ecx
addl $-0x1, %ecx
leaq 0x1daef(%rip), %rax     # 0x24cc8
movl %ecx, 0x13fc(%rax)
xorl %eax, %eax
leaq 0x1dae0(%rip), %rcx     # 0x24cc8
cmpl 0x1068(%rcx), %eax
jne 0x71f5
jmp 0x70cf
leaq 0x1dacc(%rip), %rsi     # 0x24cc8
movq %rsi, %rdi
addq $0x1408, %rdi           # imm = 0x1408
addq $0x1068, %rsi           # imm = 0x1068
addq $0x4, %rsi
callq 0x32d0
leaq 0x1daab(%rip), %rdi     # 0x24cc8
addq $0x1408, %rdi           # imm = 0x1408
leaq 0x6f45(%rip), %rsi      # 0xe170
callq 0x32d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl $0x7, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x7263
leaq 0x1da78(%rip), %rdi     # 0x24cc8
addq $0x1408, %rdi           # imm = 0x1408
leaq 0x6ea2(%rip), %rsi      # 0xe100
callq 0x32d0
jmp 0x70cf
cmpq $0x0, -0x28(%rbp)
je 0x727f
movq -0x28(%rbp), %rsi
leaq 0xd0d6(%rip), %rdi      # 0x14350
callq 0x3e80
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)