vfs: add follow_path function
This commit is contained in:
@@ -221,4 +221,70 @@ int vsf_read_file_by_path(const char* path, uint8_t** buffer, l9660_dir* dir)
|
||||
debug_log("bytes read: 0x%X\n", read);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void follow_path(const char* path, l9660_file* file, l9660_dir* dir)
|
||||
{
|
||||
int pos = 0;
|
||||
int start_from_root = 0;
|
||||
char buf[32];
|
||||
int bufpos = 0;
|
||||
|
||||
int isdir = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (path[pos] == '/')
|
||||
{
|
||||
start_from_root = 1;
|
||||
pos++;
|
||||
l9660_fs_open_root(dir, global_fs);
|
||||
debug_log("start_from_root\n");
|
||||
debug_log("/");
|
||||
}
|
||||
|
||||
//printf("start_from_root: %X\n\n", start_from_root);
|
||||
l9660_status status;
|
||||
|
||||
while(path[pos] != '\0')
|
||||
{
|
||||
while (path[pos] != '/' && path[pos] != '\0')
|
||||
{
|
||||
buf[bufpos] = path[pos];
|
||||
pos++;
|
||||
bufpos++;
|
||||
}
|
||||
buf[bufpos] = '\0'; // Null-terminate the string
|
||||
bufpos = 0;
|
||||
|
||||
if(path[pos] != '\0')
|
||||
{
|
||||
isdir = 1;
|
||||
debug_log("%s->", buf);//this is a directory
|
||||
l9660_dir dir2;
|
||||
status = l9660_opendirat(&dir2, dir, buf);
|
||||
if(status != L9660_OK)
|
||||
{
|
||||
debug_log("FUCKFUCKFUCKFUCK BLYAAAT!!!!!\n");
|
||||
return;
|
||||
}
|
||||
*dir = dir2;
|
||||
}
|
||||
else
|
||||
{
|
||||
isdir = 0;
|
||||
debug_log("%s", buf);//this is a file
|
||||
status = l9660_openat(file, dir, buf);
|
||||
if(status != L9660_OK)
|
||||
{
|
||||
debug_log("PIZDAPIZDA BLYAAAT!!!!!\n");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
debug_log("\n");
|
||||
//printf("buf: %s\n", buf);
|
||||
debug_log("isdir: %X\n", isdir);
|
||||
}
|
||||
@@ -131,6 +131,20 @@ void kmain(unsigned int magic, unsigned int info)
|
||||
|
||||
mount_fs();
|
||||
|
||||
l9660_dir* dir = (l9660_dir*)malloc(sizeof(l9660_dir));
|
||||
l9660_file* file = (l9660_file*)malloc(sizeof(l9660_file));
|
||||
|
||||
follow_path("/bin/bash.", file, dir);
|
||||
|
||||
//////////////
|
||||
l9660_seek(file, L9660_SEEK_END, 0);
|
||||
uint32_t file_size = l9660_tell(file);
|
||||
debug_log("file_size: %X\n", file_size);
|
||||
l9660_seek(file, L9660_SEEK_SET, 0);
|
||||
free(file);
|
||||
free(dir);
|
||||
//////////////
|
||||
|
||||
exec_from_file("caller.", ".");
|
||||
|
||||
while(1)
|
||||
|
||||
Reference in New Issue
Block a user