void mi_ls2() { char *buffer2; int t_size, i = 0; struct i_stat e; t_size = mi_dir("/", &buffer2); printf("Hi ha %i arxius. \n", t_size/64); if (t_size > 0) { for (i = 0; i < t_size; i += 64) { mi_stat(&buffer2[i], &e); printf("%s [%i bytes]\t \t ", &buffer2[i], e.i_size); if (((i/64) % 4) == 3) printf("\n"); } } printf("\n"); }
int proceso (int n) { char nombre[N_LINEA]; memset(nombre, '\0', N_LINEA); char linea[N_LINEA]; memset(linea, '\0', N_LINEA); sprintf(nombre,"/proceso-%d.dat",n); printf("%s\n", nombre); if (mi_creat(nombre) < 0) { printf("ERROR (simulacion.c): Error al ejecutar mi_creat(%s).\n", nombre); return (-1); } else { sprintf(linea, "Inicio log proceso PID %d\n", getpid()); printf("Fichero <<%s>> creado! // %d // %s ", nombre, strlen(linea), linea); if (mi_write(nombre, linea, 0, strlen(linea)) < 0) { char buffer[10000]; memset(buffer, '\0', 10000); mi_dir("/", buffer); printf("%s", buffer); printf("ERROR (simulacion.c): Error al ejecutar mi_write(%s, &s, 0, %d).\n", nombre, linea, strlen(linea)); return (-1); } /* Para imprir la hora */ struct tm *p_tiempo; time_t tiempo; struct STAT estado; int i; for (i = 0; i < N_LOGS; i++) { tiempo = time(NULL); p_tiempo = localtime(&tiempo); sprintf(linea, " %d:%d:%d Línea número %d\n", p_tiempo->tm_hour, p_tiempo->tm_min, p_tiempo->tm_sec, i); if (mi_stat(nombre, &estado) < 0) { printf("ERROR (simulacion.c): Error al ejecutar mi_stat(%s, &estado) 1.\n", nombre); return (-1); } else { if (mi_write(nombre, linea, estado.t_bytes, strlen(linea)) < 0) { printf("ERROR (simulacion.c): Error al ejecutar mi_write(%s, linea, %d, %d) 1.\n", nombre, estado.t_bytes, strlen(linea)); return (-1); } } usleep(100000); /* Cada línea debe esperar 0,1 segundos */ } sprintf(linea, "Fin log proceso PID %d\n", getpid()); printf("%s\n", linea); if (mi_stat(nombre, &estado) < 0) { printf("ERROR (simulacion.c): Error al ejecutar mi_stat(%s, &estado) 2.\n", nombre); return (-1); } else { if (mi_write(nombre, linea, estado.t_bytes, strlen(linea)) < 0) { printf("ERROR (simulacion.c): Error al ejecutar mi_write(%s, %s, %d, %d) 2.\n", nombre, linea, estado.t_bytes, strlen(linea)); return (-1); } } } return (1); }