// File: ljl0222[P]SecondFileSystem/INode.cpp
// Function: Inode::IUpdate(int)
void Inode::IUpdate(int time)
{
	Buf* pBuf;
	DiskInode dInode;
	FileSystem& filesys = globalFileSystem;
	BufferManager& bufMgr = globalBufferManager;

	/* ��IUPD��IACC��־֮һ�����ã�����Ҫ������ӦDiskInode
	 * Ŀ¼����������������;����Ŀ¼�ļ���IACC��IUPD��־ */
	if ((this->i_flag & (Inode::IUPD | Inode::IACC)) != 0)
	{
		/* ���ص�ע�ͣ��ڻ��������ҵ�������i�ڵ㣨this->i_number���Ļ�����
		 * ����һ�������Ļ����飬���δ����е�Bwrite()�ڽ�������д�ش��̺����ͷŸû����顣
		 * ���ô��Ÿ�DiskInode���ַ������뻺���� */
		pBuf = bufMgr.Bread(FileSystem::INODE_ZONE_START_SECTOR + this->i_number / FileSystem::INODE_NUMBER_PER_SECTOR);

		/* ���ڴ�Inode�����е���Ϣ���Ƶ�dInode�У�Ȼ����dInode���ǻ����оɵ�����Inode */
		dInode.d_mode = this->i_mode;
		dInode.d_nlink = this->i_nlink;
		dInode.d_uid = this->i_uid;
		dInode.d_gid = this->i_gid;
		dInode.d_size = this->i_size;
		for (int i = 0; i < 10; i++)
		{
			dInode.d_addr[i] = this->i_addr[i];
		}

		if (this->i_flag & Inode::IACC)
		{
			/* ������������ʱ�� */
			dInode.d_atime = time;
		}
		if (this->i_flag & Inode::IUPD)
		{
			/* ������������ʱ�� */
			dInode.d_mtime = time;
		}

		/* ��pָ�򻺴����о�����Inode��ƫ��λ�� */
		unsigned char* p = pBuf->b_addr + (this->i_number % FileSystem::INODE_NUMBER_PER_SECTOR) * sizeof(DiskInode);
		DiskInode* pNode = &dInode;

		/* ��dInode�е������ݸ��ǻ����еľ�����Inode */
		memcpy(p, pNode, sizeof(DiskInode));

		/* ������д�������̣��ﵽ���¾�����Inode��Ŀ�� */
		bufMgr.Bwrite(pBuf);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x8a10
movq -0x90(%rbp), %rax
leaq 0x1a964(%rip), %rcx     # 0x22ed8
movq %rcx, -0x60(%rbp)
leaq 0xbdd1(%rip), %rcx      # 0x14350
movq %rcx, -0x68(%rbp)
movl (%rax), %eax
andl $0x6, %eax
cmpl $0x0, %eax
je 0x86e4
movq -0x90(%rbp), %rax
movl 0x14(%rax), %esi
movl %esi, %eax
addl $0x7, %eax
testl %esi, %esi
cmovsl %eax, %esi
sarl $0x3, %esi
addl $0x2, %esi
leaq 0xbd9e(%rip), %rdi      # 0x14350
callq 0x3f10
movq %rax, -0x98(%rbp)
jmp 0x85c0
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rcx, -0x18(%rbp)
movl 0x4(%rax), %ecx
movl %ecx, -0x58(%rbp)
movl 0xc(%rax), %ecx
movl %ecx, -0x54(%rbp)
movw 0x18(%rax), %cx
movw %cx, -0x50(%rbp)
movw 0x1a(%rax), %cx
movw %cx, -0x4e(%rbp)
movl 0x1c(%rax), %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x78(%rbp)
cmpl $0xa, -0x78(%rbp)
jge 0x863d
movq -0x90(%rbp), %rax
movslq -0x78(%rbp), %rcx
movl 0x20(%rax,%rcx,4), %ecx
movslq -0x78(%rbp), %rax
movl %ecx, -0x48(%rbp,%rax,4)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x85fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x8a80
jmp 0x86f6
movq -0x90(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x8654
movl -0xc(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x90(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x866b
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x90(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x14(%rcx), %ecx
movl %ecx, %esi
addl $0x7, %esi
testl %ecx, %ecx
movl %ecx, %edx
cmovsl %esi, %edx
andl $-0x8, %edx
subl %edx, %ecx
movslq %ecx, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rcx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups 0x30(%rcx), %xmm3
movups %xmm3, 0x30(%rax)
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movq -0x18(%rbp), %rsi
leaq 0xbc75(%rip), %rdi      # 0x14350
callq 0x3fa0
jmp 0x86e2
jmp 0x86e4
leaq -0x58(%rbp), %rdi
callq 0x8a80
addq $0xa0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x3580
nop