CE fix strange characters appearing at the end of file
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m46s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m46s
This commit is contained in:
@@ -25,31 +25,39 @@ static struct tar_file* tar_get_file (struct tarfs* tarfs, const char* filename)
|
||||
|
||||
static size_t tar_get_size (uint8_t* in) {
|
||||
size_t size = 0;
|
||||
size_t j;
|
||||
size_t count = 1;
|
||||
for (size_t i = 0; i < 11; i++) {
|
||||
if (in[i] < '0' || in[i] > '7')
|
||||
break;
|
||||
|
||||
for (j = 11; j > 0; j--, count *= 8)
|
||||
size += ((in[j - 1] - '0') * count);
|
||||
size = (size * 8) + (in[i] - '0');
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr) {
|
||||
static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr, size_t max_size) {
|
||||
size_t i;
|
||||
uint8_t* ptr = addr;
|
||||
|
||||
for (i = 0; i < TARFS_FILES_MAX; i++) {
|
||||
struct tar_header* hdr = (struct tar_header*)addr;
|
||||
struct tar_header* hdr = (struct tar_header*)ptr;
|
||||
|
||||
if (hdr->filename[0] == '\0')
|
||||
break;
|
||||
|
||||
if ((size_t)(ptr - addr) + 512 > max_size)
|
||||
break;
|
||||
|
||||
size_t size = tar_get_size (hdr->size);
|
||||
|
||||
tarfs->tarfs_files[i].header = hdr;
|
||||
tarfs->tarfs_files[i].content = (uint8_t*)((uintptr_t)hdr + 512);
|
||||
tarfs->tarfs_files[i].size = tar_get_size ((uint8_t*)hdr->size);
|
||||
tarfs->tarfs_files[i].content = ptr + 512;
|
||||
tarfs->tarfs_files[i].size = size;
|
||||
|
||||
addr += 512 + ((size + 511) & ~511);
|
||||
ptr += 512 + ((size + 511) & ~511);
|
||||
|
||||
if ((size_t)(ptr - addr) > max_size)
|
||||
break;
|
||||
}
|
||||
|
||||
return i;
|
||||
@@ -92,6 +100,7 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
|
||||
if (buffer == NULL) {
|
||||
spin_unlock (&back_device->lock);
|
||||
free (volume->udata);
|
||||
volume->udata = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -105,12 +114,14 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
|
||||
|
||||
if (ret < 0) {
|
||||
free (buffer);
|
||||
free (volume->udata);
|
||||
volume->udata = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
tarfs->buffer = buffer;
|
||||
|
||||
tar_parse (tarfs, tarfs->buffer);
|
||||
tar_parse (tarfs, tarfs->buffer, total_size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -166,6 +177,9 @@ int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
|
||||
if (file == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (off >= file->size)
|
||||
return -ST_OOB_ERROR;
|
||||
|
||||
memcpy (buffer, (void*)((uintptr_t)file->content + off), min (size, file->size));
|
||||
|
||||
return ST_OK;
|
||||
@@ -183,19 +197,21 @@ int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
|
||||
|
||||
size_t entry_counter = 0;
|
||||
for (size_t i = 0; i < TARFS_FILES_MAX; i++) {
|
||||
if ((tarfs->tarfs_files[i].header != NULL) && (entry_num == entry_counter)) {
|
||||
tar_file = &tarfs->tarfs_files[i];
|
||||
break;
|
||||
if (tarfs->tarfs_files[i].header != NULL) {
|
||||
if (entry_num == entry_counter) {
|
||||
tar_file = &tarfs->tarfs_files[i];
|
||||
break;
|
||||
}
|
||||
entry_counter++;
|
||||
}
|
||||
entry_counter++;
|
||||
}
|
||||
|
||||
if (tar_file != NULL) {
|
||||
sprintf (entry->path, "/%s", tar_file->header->filename);
|
||||
return ST_NOT_DIR;
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
return ST_DIR_NO_ENTRIES;
|
||||
return -ST_DIR_NO_ENTRIES;
|
||||
}
|
||||
|
||||
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
|
||||
|
||||
Reference in New Issue
Block a user