// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
leaq 0x1867a(%rip), %r12     # 0x1dbd8
cmpl $0x0, 0x13fc(%r12)
je 0x5675
orb $0x4, (%rdi)
cmpl $0x0, 0x10c8(%r12)
sete %al
movl 0x13fc(%r12), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5675
movq %rdi, -0x30(%rbp)
movl 0x13f8(%r12), %r14d
leal 0x1ff(%r14), %r15d
testl %r14d, %r14d
cmovnsl %r14d, %r15d
movl 0x1c(%rdi), %ebx
subl %r14d, %ebx
jle 0x5675
movl %r15d, %r13d
sarl $0x9, %r13d
movq -0x30(%rbp), %rdi
movl %esi, -0x34(%rbp)
movl %r13d, %esi
callq 0x5684
movl -0x34(%rbp), %ecx
testl %eax, %eax
je 0x5675
andl $0xfffffe00, %r15d      # imm = 0xFFFFFE00
subl %r15d, %r14d
movl $0x200, %r15d           # imm = 0x200
subl %r14d, %r15d
cmpl %r15d, %ecx
cmovll %ecx, %r15d
cmpl %r15d, %ebx
cmovll %ebx, %r15d
leaq 0x7c5d(%rip), %rdi      # 0xd260
movl %eax, %esi
callq 0x3aa4
movq %rax, %rbx
movq -0x30(%rbp), %rax
movl %r13d, 0x48(%rax)
movslq %r14d, %rsi
addq 0x20(%rbx), %rsi
movq 0x13f0(%r12), %rdi
movslq %r15d, %r15
movq %r15, %rdx
callq 0x31b0
addq %r15, 0x13f0(%r12)
addl %r15d, 0x13f8(%r12)
subl %r15d, 0x13fc(%r12)
leaq 0x7c12(%rip), %rdi      # 0xd260
movq %rbx, %rsi
callq 0x3a58
movq -0x30(%rbp), %rdi
cmpl $0x0, 0x10c8(%r12)
jne 0x5675
movl 0x13fc(%r12), %esi
testl %esi, %esi
jne 0x5598
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq