forked from rasendubi/akernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarfs.c
39 lines (33 loc) · 817 Bytes
/
tarfs.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
#include <tarfs.h>
#include <utils.h>
typedef struct tar_header {
char filename[100];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char chksum[8];
char typeflag[1];
} tar_header;
static unsigned from_8_base(const char *in, int len) {
unsigned res = 0;
for (int i = 0; i < len; ++i) {
res = 8*res + in[i] - '0';
}
return res;
}
static unsigned round_up_to(unsigned a, unsigned round) {
return ((a - 1)/round + 1)*round;
}
void *tar_get_file(void *base, const char *filename) {
tar_header *head = (tar_header *)base;
while (head->filename[0]) {
if (strcmp(head->filename, filename) == 0) {
return (void *)((unsigned)head + 512);
}
unsigned file_size = from_8_base(head->size, 11);
head = (tar_header *)((unsigned)head + 512 +
round_up_to(file_size, 512));
}
return 0;
}