10 struct multiboot_module
*mod
;
15 extern struct multiboot_module
*mboot_modules
;
16 extern int mboot_module_count
;
19 FILE *fopen(const char *path
, const char *mode
)
21 for (int i
= 0; i
< mboot_module_count
; i
++) {
22 if (!strcmp(path
, mboot_modules
[i
].cmdline
)) {
23 FILE *fp
= malloc(sizeof(*fp
));
24 fp
->mod
= &mboot_modules
[i
];
34 int fclose(FILE *stream
)
41 size_t fread(void *ptr
, size_t size
, size_t nmemb
, FILE *stream
)
43 size_t byte_size
= size
* nmemb
;
44 size_t mod_len
= stream
->mod
->mod_end
- stream
->mod
->mod_start
;
46 if (stream
->loc
> mod_len
) {
50 if (byte_size
> mod_len
- stream
->loc
) {
51 byte_size
= mod_len
- stream
->loc
;
53 nmemb
= byte_size
/ size
;
54 byte_size
= nmemb
* size
;
56 memcpy(ptr
, (uint8_t *)stream
->mod
->mod_start
+ stream
->loc
, byte_size
);
57 stream
->loc
+= byte_size
;
69 int fseek(FILE *stream
, long offset
, int whence
)
77 stream
->loc
+= offset
;
81 stream
->loc
= stream
->mod
->mod_end
- stream
->mod
->mod_start
;
82 stream
->loc
+= offset
;
86 if (stream
->loc
< 0) {