// File: /workspace/github_cpp_makefile_star2_O1/ljl0222[P]SecondFileSystem/INode.cpp
// Function: Inode::ReadI()
void Inode::ReadI()
{
	int lbn;	/* �ļ��߼����� */
	int bn;		/* lbn��Ӧ�������̿��� */
	int offset;	/* ��ǰ�ַ�������ʼ����λ�� */
	int nbytes;	/* �������û�Ŀ�����ֽ����� */

	Buf* pBuf;

	User& u = globalUser;
	BufferManager& bufMgr = globalBufferManager;

	if (0 == u.u_IOParam.m_Count)
	{
		/* ��Ҫ���ֽ���Ϊ�㣬�򷵻� */
		return;
	}

	this->i_flag |= Inode::IACC;

	/* һ��һ���ַ����ض�������ȫ�����ݣ�ֱ�������ļ�β */
	while (User::myNOERROR == u.u_error && u.u_IOParam.m_Count != 0)
	{
		lbn = bn = u.u_IOParam.m_Offset / Inode::BLOCK_SIZE;
		offset = u.u_IOParam.m_Offset % Inode::BLOCK_SIZE;
		/* ���͵��û������ֽ�������ȡ��������ʣ���ֽ����뵱ǰ�ַ�������Ч�ֽ�����Сֵ */
		nbytes = min(Inode::BLOCK_SIZE - offset, u.u_IOParam.m_Count);

		if (1)
		{	/* ���������������豸�ļ� */

			int remain = this->i_size - u.u_IOParam.m_Offset;
			/* �����Ѷ��������ļ���β */
			if (remain <= 0)
			{
				return;
			}
			/* ���͵��ֽ�������ȡ����ʣ���ļ��ĳ��� */
			nbytes = min(nbytes, remain);

			/* ���߼�����lbnת���������̿���bn ��Bmap������Inode::rablock����UNIX��Ϊ��ȡԤ�����Ŀ���̫��ʱ��
			 * ������Ԥ������ʱ Inode::rablock ֵΪ 0��
			 * */
			if ((bn = this->Bmap(lbn)) == 0)
			{
				return;
			}
		}

		pBuf = bufMgr.Bread(bn);

		/* ��¼������ȡ�ַ������߼����� */
		this->i_lastr = lbn;

		/* ������������ʼ��λ�� */
		unsigned char* start = pBuf->b_addr + offset;

		/* ������: �ӻ������������û�Ŀ����
		 * i386оƬ��ͬһ��ҳ��ӳ���û��ռ����ں˿ռ䣬��һ��Ӳ���ϵĲ��� ʹ��i386��ʵ�� iomove����
		 * ��PDP-11Ҫ��������*/
		memcpy(u.u_IOParam.m_Base, start, nbytes);

		/* �ô����ֽ���nbytes���¶�дλ�� */
		u.u_IOParam.m_Base += nbytes;
		u.u_IOParam.m_Offset += nbytes;
		u.u_IOParam.m_Count -= nbytes;

		bufMgr.Brelse(pBuf);	/* ʹ���껺�棬�ͷŸ���Դ */
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, -0x30(%rbp)
leaq 0x18671(%rip), %r12     # 0x1dbd8
cmpl $0x0, 0x13fc(%r12)
je 0x5674
movq -0x30(%rbp), %rax
orb $0x4, (%rax)
cmpl $0x0, 0x10c8(%r12)
sete %cl
movl 0x13fc(%r12), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5674
movl 0x13f8(%r12), %ecx
leal 0x1ff(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movl %edx, %r15d
sarl $0x9, %r15d
andl $0xfffffe00, %edx       # imm = 0xFFFFFE00
movl %ecx, %ebx
subl %edx, %ebx
movl $0x200, %r14d           # imm = 0x200
subl %ebx, %r14d
cmpl %r14d, %eax
cmovll %eax, %r14d
movq -0x30(%rbp), %rdi
movl 0x1c(%rdi), %eax
subl %ecx, %eax
jle 0x55f8
cmpl %r14d, %eax
cmovll %eax, %r14d
movl %r15d, %esi
callq 0x5684
movl %eax, %esi
testl %eax, %eax
setne %al
jmp 0x55fd
xorl %eax, %eax
movl %r15d, %esi
testb %al, %al
je 0x5674
leaq 0x7c58(%rip), %rdi      # 0xd260
callq 0x3af0
movq %rax, %r13
movq -0x30(%rbp), %rax
movl %r15d, 0x48(%rax)
movslq %ebx, %rsi
addq 0x20(%r13), %rsi
movq 0x13f0(%r12), %rdi
movslq %r14d, %r15
movq %r15, %rdx
callq 0x31b0
addq %r15, 0x13f0(%r12)
addl %r15d, 0x13f8(%r12)
subl %r15d, 0x13fc(%r12)
leaq 0x7c0f(%rip), %rdi      # 0xd260
movq %r13, %rsi
callq 0x3a9c
cmpl $0x0, 0x10c8(%r12)
jne 0x5674
movl 0x13fc(%r12), %eax
testl %eax, %eax
jne 0x55a1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop