-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
132 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include "initramfs.h" | ||
#include "SLAB_allocator.h" | ||
#include "file_system.h" | ||
|
||
void* current_addr; | ||
|
||
uint32_t str_to_int(char* s, size_t len) { | ||
uint32_t x = 0; | ||
for (size_t i = 0; i < len; ++i) { | ||
x = x * 16 ; | ||
if (s[i] >= '0' && s[i] <= '9') { | ||
x += s[i] - '0'; | ||
} else if (s[i] >= 'a' && s[i] <= 'z'){ | ||
x += s[i] - 'a' + 10; | ||
} else { | ||
x += s[i] - 'A' + 10; | ||
} | ||
} | ||
|
||
return x; | ||
} | ||
|
||
int add_one_file() { | ||
printf("start: %p; current: %p, end: %p\n", init_ref, current_addr, init_ref_end); | ||
current_addr += 4 - ((uint64_t)current_addr)%4; | ||
if ((uint64_t)current_addr % 4 == 0) current_addr -= 4; | ||
|
||
if (current_addr >= init_ref_end) { | ||
return 0; | ||
} | ||
|
||
printf("ok\n"); | ||
struct cpio_header* header = (struct cpio_header*)current_addr; | ||
printf("ok\n"); | ||
current_addr += sizeof(struct cpio_header); | ||
|
||
printf("current: %p\n", current_addr); | ||
|
||
printf("%c\n", *((char*)header)); | ||
printf("%s\n", header->namesize); | ||
|
||
uint32_t name_len = str_to_int(header->namesize, 8); | ||
|
||
printf("name_len: %d\n", name_len); | ||
|
||
char* name = malloc_small(name_len + 1); | ||
for (uint32_t i = 0; i < name_len; ++i) { | ||
name[i] = ((char*)current_addr)[i]; | ||
} | ||
|
||
name[name_len] = 0; | ||
|
||
printf("%s\n", name); | ||
|
||
if (name_len == 10 && strncmp(name, END_OF_ARCHIVE, name_len)) { | ||
return 0; | ||
} | ||
|
||
current_addr += name_len; | ||
|
||
uint32_t mode = str_to_int(header->mode, 8); | ||
|
||
if (S_ISDIR(mode)) { | ||
mkdir(name); | ||
} else if (S_ISREG(mode)) { | ||
int file = open(name, O_WRONLY|O_CREAT|O_EXCL); | ||
|
||
uint32_t filesize = str_to_int(header->filesize, 8); | ||
|
||
current_addr += 4 - ((uint64_t)current_addr)%4; | ||
if ((uint64_t)current_addr % 4 == 0) current_addr -= 4; | ||
|
||
write(file, current_addr, filesize); | ||
|
||
current_addr += filesize; | ||
} | ||
return 1; | ||
} | ||
|
||
void initramfs_to_fs() { | ||
printf("START add to initranfs\n"); | ||
current_addr = init_ref; | ||
while (add_one_file()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters