leer el nombre de un archivo por línea de comandos verificar si el archivo existe y tiene exactamente 512 bytes verificar la "firma": los ultimos 2 bytes leer el contenido del archivo
#include <stdlib.h> #include <stdio.h> #include <stdint.h> #define BLOCK_SIZE 512 int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: ./recover image"); return 1; } char *file = argv[1]; FILE *f = fopen(file, "r"); if (f == NULL) { fprintf(stderr, "No such file %s.\n", file); return 2; } fseek(f, 0L, SEEK_END); int sz = ftell(f); if (sz == BLOCK_SIZE) { fseek(f, 0L, SEEK_SET); uint8_t buffer[BLOCK_SIZE]; fread(buffer, BLOCK_SIZE, 1, f); if (buffer[0] == 0xff && buffer[1] == 0xd8