// File: /workspace/github_c_makefile_star2_O3/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 $0x5f8, %rsp            # imm = 0x5F8
cmpl $0x2, %edi
jne 0x3f46
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
callq 0x129c
testl %eax, %eax
js 0x3f56
leaq 0x178(%rsp), %rsi
xorl %edi, %edi
callq 0x133d
testl %eax, %eax
js 0x3f6a
xorl %eax, %eax
callq 0x1635
movl 0x17c(%rsp), %esi
movl 0x184(%rsp), %edx
subl 0x178(%rsp), %esi
subl 0x180(%rsp), %edx
leaq 0x807(%rip), %rdi       # 0x4592
xorl %eax, %eax
callq 0x1090
leaq 0x81a(%rip), %rdi       # 0x45b3
movl $0x80, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x82c(%rip), %rdi       # 0x45d8
xorl %eax, %eax
callq 0x1090
callq 0x1110
movl 0x1a4(%rsp), %eax
testl %eax, %eax
je 0x3f1f
leaq 0x578(%rsp), %rbx
xorl %r15d, %r15d
xorl %r13d, %r13d
subl 0x19c(%rsp), %eax
cmpl %eax, %r15d
jae 0x3f1f
movq %rbx, %rdi
movl %r13d, %esi
callq 0x19b5
movl $0x10, %ecx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
cmpb $0x6c, (%rsp)
je 0x3f0c
incl %r15d
leaq 0x7fe(%rip), %rdi       # 0x4610
movl %r13d, %esi
xorl %eax, %eax
callq 0x1090
movzbl (%rsp), %esi
leaq 0x801(%rip), %rdi       # 0x4628
xorl %eax, %eax
callq 0x1090
movzbl 0x1(%rsp), %esi
leaq 0x802(%rip), %rdi       # 0x463c
xorl %eax, %eax
callq 0x1090
movl 0x20(%rsp), %esi
leaq 0x7ff(%rip), %rdi       # 0x464b
xorl %eax, %eax
callq 0x1090
movl 0x24(%rsp), %esi
leaq 0x803(%rip), %rdi       # 0x4661
xorl %eax, %eax
callq 0x1090
movl 0x28(%rsp), %esi
leaq 0x810(%rip), %rdi       # 0x4680
xorl %eax, %eax
callq 0x1090
leaq 0x8(%rsp), %rdi
callq 0x1030
movl $0x50, %esi
leaq 0x80(%rsp), %rdi
leaq 0x80d(%rip), %r12       # 0x46a2
movq %r12, %rdx
movq %rax, %rcx
callq 0x1150
leaq 0x10(%rsp), %rdi
callq 0x1030
movl $0x50, %esi
movq %rbx, %rbp
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x1150
leaq 0x18(%rsp), %rdi
callq 0x1030
movl $0x50, %esi
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x1150
leaq 0x7c3(%rip), %rdi       # 0x46b7
leaq 0x80(%rsp), %rsi
movq %rbx, %rdx
movq %rbp, %rbx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1090
incl %r13d
movl 0x1a4(%rsp), %eax
cmpl %eax, %r13d
jb 0x3dd5
movl 0x1a0(%rsp), %esi
subl 0x198(%rsp), %esi
leaq 0x7a5(%rip), %rdi       # 0x46d9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1090
xorl %eax, %eax
callq 0x12da
jmp 0x3f84
leaq 0x5db(%rip), %rdi       # 0x4528
xorl %eax, %eax
callq 0x1090
jmp 0x3f7f
movq 0x8(%rbx), %rsi
leaq 0x5e8(%rip), %rdi       # 0x4549
xorl %eax, %eax
callq 0x1090
jmp 0x3f7f
leaq 0x5fd(%rip), %rdi       # 0x456e
xorl %eax, %eax
callq 0x1090
xorl %eax, %eax
callq 0x12da
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x5f8, %rsp            # imm = 0x5F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq