file: Fix several bugs to do with handling of path field
This commit is contained in:
parent
2091aa9c21
commit
28dd8a1062
|
@ -19,6 +19,7 @@ struct file_handle {
|
||||||
bool readall;
|
bool readall;
|
||||||
struct volume *vol;
|
struct volume *vol;
|
||||||
char *path;
|
char *path;
|
||||||
|
size_t path_len;
|
||||||
void *fd;
|
void *fd;
|
||||||
void (*read)(void *fd, void *buf, uint64_t loc, uint64_t count);
|
void (*read)(void *fd, void *buf, uint64_t loc, uint64_t count);
|
||||||
void (*close)(void *fd);
|
void (*close)(void *fd);
|
||||||
|
|
|
@ -53,7 +53,7 @@ struct file_handle *fopen(struct volume *part, const char *filename) {
|
||||||
if ((ret = tftp_open(part, "", filename)) == NULL) {
|
if ((ret = tftp_open(part, "", filename)) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
goto success;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = ext2_open(part, filename)) != NULL) {
|
if ((ret = ext2_open(part, filename)) != NULL) {
|
||||||
|
@ -70,6 +70,7 @@ struct file_handle *fopen(struct volume *part, const char *filename) {
|
||||||
|
|
||||||
success:
|
success:
|
||||||
ret->path = (char *)filename;
|
ret->path = (char *)filename;
|
||||||
|
ret->path_len = filename_new_len;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +83,7 @@ void fclose(struct file_handle *fd) {
|
||||||
} else {
|
} else {
|
||||||
fd->close(fd);
|
fd->close(fd);
|
||||||
}
|
}
|
||||||
|
pmm_free(fd->path, fd->path_len);
|
||||||
pmm_free(fd, sizeof(struct file_handle));
|
pmm_free(fd, sizeof(struct file_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,9 @@ struct file_handle *uri_open(char *uri) {
|
||||||
panic(true, "tinf error");
|
panic(true, "tinf error");
|
||||||
}
|
}
|
||||||
compressed_fd->vol = ret->vol;
|
compressed_fd->vol = ret->vol;
|
||||||
|
compressed_fd->path = ext_mem_alloc(ret->path_len);
|
||||||
|
memcpy(compressed_fd->path, ret->path, ret->path_len);
|
||||||
|
compressed_fd->path_len = ret->path_len;
|
||||||
fclose(ret);
|
fclose(ret);
|
||||||
compressed_fd->is_memfile = true;
|
compressed_fd->is_memfile = true;
|
||||||
ret = compressed_fd;
|
ret = compressed_fd;
|
||||||
|
|
|
@ -227,7 +227,10 @@ static struct limine_file get_file(struct file_handle *file, char *cmdline) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.path = reported_addr(file->path);
|
char *path = ext_mem_alloc(file->path_len);
|
||||||
|
memcpy(path, file->path, file->path_len);
|
||||||
|
|
||||||
|
ret.path = reported_addr(path);
|
||||||
|
|
||||||
ret.address = reported_addr(freadall(file, MEMMAP_KERNEL_AND_MODULES));
|
ret.address = reported_addr(freadall(file, MEMMAP_KERNEL_AND_MODULES));
|
||||||
ret.size = file->size;
|
ret.size = file->size;
|
||||||
|
|
|
@ -69,6 +69,12 @@ struct file_handle *tftp_open(struct volume *part, const char *server_addr, cons
|
||||||
handle->pxe_ip = server_ip;
|
handle->pxe_ip = server_ip;
|
||||||
handle->pxe_port = server_port;
|
handle->pxe_port = server_port;
|
||||||
|
|
||||||
|
size_t name_len = strlen(name);
|
||||||
|
handle->path = ext_mem_alloc(1 + name_len + 1);
|
||||||
|
handle->path[0] = '/';
|
||||||
|
memcpy(&handle->path[1], name, name_len);
|
||||||
|
handle->path_len = 1 + name_len + 1;
|
||||||
|
|
||||||
struct pxenv_open open = {
|
struct pxenv_open open = {
|
||||||
.status = 0,
|
.status = 0,
|
||||||
.sip = server_ip,
|
.sip = server_ip,
|
||||||
|
@ -179,6 +185,12 @@ struct file_handle *tftp_open(struct volume *part, const char *server_addr, cons
|
||||||
handle->pxe_ip = *(uint32_t *)&ip;
|
handle->pxe_ip = *(uint32_t *)&ip;
|
||||||
handle->pxe_port = 69;
|
handle->pxe_port = 69;
|
||||||
|
|
||||||
|
size_t name_len = strlen(name);
|
||||||
|
handle->path = ext_mem_alloc(1 + name_len + 1);
|
||||||
|
handle->path[0] = '/';
|
||||||
|
memcpy(&handle->path[1], name, name_len);
|
||||||
|
handle->path_len = 1 + name_len + 1;
|
||||||
|
|
||||||
handle->fd = ext_mem_alloc(handle->size);
|
handle->fd = ext_mem_alloc(handle->size);
|
||||||
|
|
||||||
status = part->pxe_base_code->Mtftp(
|
status = part->pxe_base_code->Mtftp(
|
||||||
|
|
Loading…
Reference in New Issue