-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmain.c
43 lines (34 loc) · 803 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <err.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include "undelete_jpg.h"
#include "status_bar.h"
int main(int argc, char *argv[])
{
int fd;
uint8_t *fptr;
ssize_t size;
int img_count;
if (argc != 2)
errx(1, "Usage: ./undelete_jpg /dev/device");
printf("Recovering from: %s\n", argv[1]);
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
warn("Error opening %s", argv[1]);
return 1;
}
size = get_file_size(fd);
if (size == -1)
return 1;
fptr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (fptr == MAP_FAILED) {
img_count = undelete_jpg_read(fd, size);
} else {
img_count = undelete_jpg_mmap(fptr, size);
}
printf("\n%i images recovered\n", img_count);
return 0;
}