// File: /workspace/github_c_makefile_star2_O2/carlitosmarin[P]Sistema-Ficheros-SOII/leer_sf.c
// Function: main
int main (int argc, char **argv) {
	if (argc != 2) {
		printf("Numero de parametros incorrectos");
		return -1;
	}
	//Montamos el disco
	if(bmount(argv[1]) < 0){
		printf("No se ha podido abrir el fichero: %s", argv[1]);
		return -1;
	}

	int tamMB, tamAI;

	struct superbloque sb;
	if(bread(posSB,&sb) < 0) {
		printf("Error en la lectura del superbloque");
		bumount();
		return -1;
	}

	leerSB(); //Mostrar todos los campos del superbloque

	tamMB = sb.posUltimoBloqueMB - sb.posPrimerBloqueMB;
	tamAI = sb.posUltimoBloqueAI - sb.posPrimerBloqueAI;
	printf("Tamanyo MB: %d \nTamanyo AI: %d \n", tamMB, tamAI);

	printf("Tamanyo de la estructura inodo: %lu\n", sizeof(struct inodo));

	unsigned int i = 0,y = 1;

	printf("\nPulsa ENTER para mostrar la lista de inodos no libres."); getchar();
	struct tm *ts;
	char atime[80];
	char mtime[80];
	char ctime[80];
	unsigned int x = 0;
	struct inodo in;

	for(i = 0; i < sb.totInodos && x < (sb.totInodos - sb.cantInodosLibres); i++){ // Muestra todos lo ins
		in = leer_inodo(i);
		if(in.tipo != 'l'){
			x++;
			printf("----> Numero inodo: %d\n",i);
			printf("\tTipo de inodo: %c\n",in.tipo);
			printf("\tPermisos: %d\n",in.permisos);
			printf("\tNumero de links: %d\n",in.cantLinks);
			printf("\tTamanyo en bytes logicos: %d\n",in.tamBytesLogicos);
			printf("\tNumero de bloques que ocupa: %d\n",in.cantBloquesOcupados);
			ts = localtime(&in.atime);
			strftime(atime, sizeof(atime), "%a %Y-%m-%d %H:%M:%S", ts);
			ts = localtime(&in.mtime);
			strftime(mtime, sizeof(mtime), "%a %Y-%m-%d %H:%M:%S", ts);
			ts = localtime(&in.ctime);
			strftime(ctime, sizeof(ctime), "%a %Y-%m-%d %H:%M:%S", ts);
			printf("\tATIME: %s\n\tMTIME: %s\n\tCTIME: %s\n",atime,mtime,ctime);
		}
	}

	printf("\nBLOQUES OCUPADOS (%d bloques ocupados)\n", sb.totBloques-sb.cantBloquesLibres);

	bumount();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x608, %rsp            # imm = 0x608
cmpl $0x2, %edi
jne 0x3dda
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
callq 0x129c
testl %eax, %eax
js 0x3e11
leaq 0x188(%rsp), %rsi
xorl %edi, %edi
callq 0x1339
testl %eax, %eax
js 0x3e25
xorl %eax, %eax
callq 0x160f
movl 0x18c(%rsp), %esi
movl 0x194(%rsp), %edx
subl 0x188(%rsp), %esi
subl 0x190(%rsp), %edx
leaq 0x947(%rip), %rdi       # 0x4592
xorl %eax, %eax
callq 0x1090
leaq 0x95a(%rip), %rdi       # 0x45b3
movl $0x80, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x96c(%rip), %rdi       # 0x45d8
xorl %eax, %eax
callq 0x1090
callq 0x1110
leaq 0x588(%rsp), %rbx
xorl %r14d, %r14d
xorl %ebp, %ebp
pushq $0x50
popq %r12
movl 0x1b4(%rsp), %eax
cmpl %eax, %r14d
jae 0x3dea
subl 0x1ac(%rsp), %eax
cmpl %eax, %ebp
jae 0x3dea
movq %rbx, %rdi
movl %r14d, %esi
callq 0x196e
pushq $0x10
popq %rcx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
cmpb $0x6c, 0x10(%rsp)
je 0x3dd2
incl %ebp
movl %ebp, 0xc(%rsp)
leaq 0x937(%rip), %rdi       # 0x4610
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
movzbl 0x10(%rsp), %esi
leaq 0x939(%rip), %rdi       # 0x4628
xorl %eax, %eax
callq 0x1090
movzbl 0x11(%rsp), %esi
leaq 0x93a(%rip), %rdi       # 0x463c
xorl %eax, %eax
callq 0x1090
movl 0x30(%rsp), %esi
leaq 0x937(%rip), %rdi       # 0x464b
xorl %eax, %eax
callq 0x1090
movl 0x34(%rsp), %esi
leaq 0x93b(%rip), %rdi       # 0x4661
xorl %eax, %eax
callq 0x1090
movl 0x38(%rsp), %esi
leaq 0x948(%rip), %rdi       # 0x4680
xorl %eax, %eax
callq 0x1090
leaq 0x18(%rsp), %rdi
callq 0x1030
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
leaq 0x947(%rip), %r15       # 0x46a2
movq %r15, %rdx
movq %rax, %rcx
callq 0x1150
leaq 0x20(%rsp), %rdi
callq 0x1030
movq %rbx, %rbp
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x1150
leaq 0x28(%rsp), %rdi
callq 0x1030
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x1150
leaq 0x901(%rip), %rdi       # 0x46b7
leaq 0x90(%rsp), %rsi
movq %rbx, %rdx
movq %rbp, %rbx
movl 0xc(%rsp), %ebp
movq %r13, %rcx
xorl %eax, %eax
callq 0x1090
incl %r14d
jmp 0x3c89
leaq 0x747(%rip), %rdi       # 0x4528
xorl %eax, %eax
callq 0x1090
jmp 0x3e3a
movl 0x1b0(%rsp), %esi
subl 0x1a8(%rsp), %esi
leaq 0x8da(%rip), %rdi       # 0x46d9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1090
xorl %eax, %eax
callq 0x12d8
jmp 0x3e3d
movq 0x8(%rbx), %rsi
leaq 0x72d(%rip), %rdi       # 0x4549
xorl %eax, %eax
callq 0x1090
jmp 0x3e3a
leaq 0x742(%rip), %rdi       # 0x456e
xorl %eax, %eax
callq 0x1090
xorl %eax, %eax
callq 0x12d8
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x608, %rsp            # imm = 0x608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq