// File: /workspace/github_c_makefile_star2_O2/carlitosmarin[P]Sistema-Ficheros-SOII/./src/directorios.c
// Function: mi_dir
int mi_dir (const char *camino, char *buf) {
	int pid = 0, pi = 0, pe = 0;
	int BE = buscar_entrada(camino, &pid, &pi, &pe, 0, 0);
	if(BE < 0) { //Tratamiento de errores
		switch(BE){
		case -1: printf("\"%s\" Camino no valido\n", camino); break;
		case -2: printf("No tienes permisos de lectura\n"); break;
		case -3: printf("Error en la lectura de la entrada \"%s\"\n", camino); break;
		case -4: printf("No existe la entrada \"%s\"\n", camino); break;
		case -5: printf("Error a la hora de reservar un inodo"); break;
		case -6: printf("No existe directorio intermedio a \"%s\"", camino); break;
		case -7: printf("Error a la hora de liberar un inodo"); break;
		case -8: printf("Error en la escritura de la entrada \"%s\"\n", camino); break;
		case -9: printf("Ya existe la entrada \"%s\"\n", camino); break;
		}
		puts("Falla MI_DIR");
		return -1; //Error BE
	}
	struct inodo in;
	in = leer_inodo(pi);
	struct entrada entr;
	if(in.tipo != 'd' && in.permisos & 4) return -1;
	int numEntradas = in.tamBytesLogicos/sizeof(struct entrada);
	int nentrada = 0;
	while(nentrada < numEntradas){ //Mientras haya entradas
			if(mi_read_f(pi,&entr,nentrada*sizeof(struct entrada),sizeof(struct entrada)) < 0) return -2; //Leemos una entrada Error LECTURA
			in = leer_inodo(entr.inodo);

			if(in.tipo == 'd') strcat(buf,"D"); //Tipo de inodo
			else strcat(buf,"F");
			strcat(buf,"\t");
			//Para incorporar informacion acerca de los permisos
			if(in.permisos & 4) strcat(buf,"r");
			else strcat(buf,"-");

			if(in.permisos & 2) strcat(buf,"w");
			else strcat(buf,"-");

			if(in.permisos & 1) strcat(buf,"x");
			else strcat(buf,"-");

			strcat(buf, "\t");

			//Para incorporar informacion acerca del tiempo
			struct tm *tm;
			char tmp[100];
			tm = localtime(&in.mtime);
			sprintf(tmp, "%d-%02d-%02d %02d:%02d:%02d\t", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
			strcat(buf,tmp);

			strcat(buf,entr.nombre);
			strcat(buf,"\n");
			nentrada++;
		}
	return numEntradas;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1c(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0x14(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x18(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2d09
testl %eax, %eax
js 0x32cc
movl 0x14(%rsp), %esi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movl %esi, 0xc(%rsp)
callq 0x194e
cmpb $0x64, (%r15)
je 0x3153
testb $0x4, 0x21(%rsp)
jne 0x335a
leaq 0x30(%rsp), %rax
movl 0x14(%rax), %r15d
shrl $0x6, %r15d
leaq 0xa0(%rsp), %r14
xorl %ebp, %ebp
movl %r15d, 0x8(%rsp)
subl $0x1, %r15d
jb 0x32e8
movl 0xc(%rsp), %edi
movq %r14, %rsi
movl %ebp, %edx
pushq $0x40
popq %rcx
callq 0x27ed
testl %eax, %eax
js 0x32ee
movl 0xdc(%rsp), %esi
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
callq 0x194e
pushq $0x10
popq %rcx
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl %ebp, 0x10(%rsp)
movq %r14, %rbp
xorl %r14d, %r14d
cmpb $0x64, 0x20(%rsp)
setne %r14b
movq %rbx, %rdi
callq 0x1080
leal 0x44(,%r14,2), %ecx
movw %cx, (%rbx,%rax)
movq %rbx, %rdi
callq 0x1080
movw $0x9, %cx
movw %cx, (%rbx,%rax)
movb 0x21(%rsp), %r14b
testb $0x4, %r14b
pushq $0x72
popq %r12
pushq $0x2d
popq %r13
cmovel %r13d, %r12d
movq %rbx, %rdi
callq 0x1080
movw %r12w, (%rbx,%rax)
testb $0x2, %r14b
pushq $0x77
popq %r12
cmovel %r13d, %r12d
movq %rbx, %rdi
callq 0x1080
movw %r12w, (%rbx,%rax)
testb $0x1, %r14b
pushq $0x78
popq %r14
cmovel %r13d, %r14d
movq %rbx, %rdi
callq 0x1080
movw %r14w, (%rbx,%rax)
movq %rbp, %r14
movl 0x10(%rsp), %ebp
movq %rbx, %rdi
callq 0x1080
movw $0x9, %cx
movw %cx, (%rbx,%rax)
leaq 0x30(%rsp), %rdi
callq 0x1030
movl 0x14(%rax), %edx
movl $0x76c, %ecx            # imm = 0x76C
addl %ecx, %edx
movl 0x10(%rax), %ecx
incl %ecx
movl 0xc(%rax), %r8d
movl 0x8(%rax), %r9d
movl (%rax), %r10d
movl 0x4(%rax), %r11d
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
leaq 0x1214(%rip), %rsi      # 0x44a7
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0x1160
popq %rcx
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1150
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1150
movq %rbx, %rdi
callq 0x1080
movw $0xa, (%rbx,%rax)
addl $0x40, %ebp
jmp 0x316f
addl $0x9, %eax
leaq 0xf86(%rip), %rcx       # 0x425c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x118a(%rip), %rdi      # 0x4470
jmp 0x3344
movl 0x8(%rsp), %eax
jmp 0x335d
pushq $-0x2
jmp 0x335c
leaq 0x10dd(%rip), %rdi      # 0x43d6
jmp 0x3302
leaq 0x1120(%rip), %rdi      # 0x4422
xorl %eax, %eax
callq 0x1090
jmp 0x334e
leaq 0x10e9(%rip), %rdi      # 0x43fb
jmp 0x3344
leaq 0x11e6(%rip), %rdi      # 0x4501
callq 0x1060
jmp 0x334e
leaq 0x111d(%rip), %rdi      # 0x4446
jmp 0x3344
leaq 0x1089(%rip), %rdi      # 0x43bb
jmp 0x3344
leaq 0x1058(%rip), %rdi      # 0x4393
jmp 0x3344
leaq 0x1038(%rip), %rdi      # 0x437c
movq %r14, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x1145(%rip), %rdi      # 0x449a
callq 0x1060
pushq $-0x1
popq %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq