TFTP
Add virtText.txt
This commit is contained in:
@@ -13,7 +13,8 @@ extern struct llfs_data_file* llfs_root;
|
||||
static tftp_custom_file_t virt_file[] =
|
||||
{
|
||||
{.name = "index.txt",.data = NULL, .len = 0, .ofset = 0},
|
||||
{.name = "virtImage.raw",.data = NULL, .len = 0, .ofset = 0}
|
||||
{.name = "virtImage.raw",.data = NULL, .len = 0, .ofset = 0},
|
||||
{.name = "virtText.txt",.data = NULL, .len = 0, .ofset = 0}
|
||||
};
|
||||
|
||||
int str_cat_str(char* dest, size_t dest_size, const char* src) {
|
||||
@@ -103,6 +104,8 @@ void* tftp_open(const char* fname, const char* mode, uint8_t write) {
|
||||
return &virt_file[0];
|
||||
} else if (strcmp(fname, virt_file[1].name) == 0 && write != TFTP_READ) {
|
||||
return &virt_file[1];
|
||||
} else if (strcmp(fname, virt_file[2].name) == 0 && write != TFTP_READ) {
|
||||
return &virt_file[2];
|
||||
}
|
||||
|
||||
// TODO: waiting on Lorentz to finish creating f* functions for LLFS
|
||||
@@ -120,7 +123,9 @@ void tftp_close(void* handle) {
|
||||
LOG_CRIT(TAG, "handle is null");
|
||||
return;
|
||||
}
|
||||
if (handle == &virt_file[0] || handle == &virt_file[1]) {
|
||||
|
||||
if (handle == &virt_file[0] || handle == &virt_file[1] || handle == &virt_file[2]) {
|
||||
((tftp_custom_file_t*)handle)->ofset = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -153,6 +158,9 @@ int tftp_read(void* handle, void* buf, int bytes) {
|
||||
} else if ((tftp_custom_file_t*)file == &virt_file[1]) {
|
||||
LOG_CRIT(TAG, "Exception: Trying to read a write only file");
|
||||
return -1;
|
||||
} else if ((tftp_custom_file_t*)file == &virt_file[2]) {
|
||||
LOG_CRIT(TAG, "Exception: Trying to read a write only file");
|
||||
return -1;
|
||||
}
|
||||
// TODO: waiting on Lorentz to finish creating f* functions for LLFS
|
||||
ret = fread(buf, sizeof(uint8_t), bytes, file);
|
||||
@@ -206,6 +214,9 @@ void init_index(void)
|
||||
str_cat(virt_file[0].data, len, '\n');
|
||||
root = root->next;
|
||||
}
|
||||
|
||||
virt_file[2].data = malloc(100);
|
||||
virt_file[2].len = 100;
|
||||
}
|
||||
|
||||
struct tftp_context tftpContext_s = {
|
||||
@@ -239,4 +250,7 @@ void tftp_server_deinit(void) {
|
||||
virt_file[0].data = NULL;
|
||||
virt_file[0].len = 0;
|
||||
virt_file[0].ofset = 0;
|
||||
free(virt_file[2].data);
|
||||
virt_file[2].data = NULL;
|
||||
virt_file[2].len = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user