Compare commits

..

No commits in common. "6ab4de1ddbaf5a1813d19fe23488bc89f98626f7" and "be27cccf45940bdb369a500ca8db49b3421c0741" have entirely different histories.

3 changed files with 16 additions and 30 deletions

4
TODO
View file

@ -1 +1,5 @@
Implement randomness (xorshift? https://www.jstatsoft.org/article/view/v008i14)
Config parser (config.c)
Do the actual corrupty things
Use fopen(3) and friends instead of open(2)

View file

@ -62,11 +62,6 @@ parse_config(char *path)
continue;
}
/* Assume there's some extra whitespace at the start and ignore it */
if (state == ST_FILENAME && i == 0) {
break;
}
/* only run on the first whitespace */
if (!ws) {
DPRINTF(("i = %d\n", i));

View file

@ -126,7 +126,7 @@ dos_listdir(dosfs_t *fsd, unsigned int offset)
}
if (i > 0) {
cur->next = calloc(1, sizeof(dosfile_t));
cur->next = malloc(sizeof(dosfile_t));
if (cur->next == NULL) {
DPRINTF(("inner malloc failed!?\n"));
res = -1;
@ -147,14 +147,9 @@ dos_listdir(dosfs_t *fsd, unsigned int offset)
cur->fname[8] = 0;
for (j = 0; j < 3; j++) {
if (dirs[i].filename[j+8] == ' ') {
cur->fext[j] = 0;
break;
} else {
cur->fext[j] = dirs[i].filename[j+8];
}
cur->fext[j] = dirs[i].filename[j+8];
}
cur->fext[3] = 0;
cur->fext[4] = 0;
(void)memcpy(&cur->ent, &dirs[i], sizeof(struct dos_dirent));
@ -195,9 +190,8 @@ dos_freedir(dosfile_t *dirs)
static unsigned int *
read_fat_chain(dosfs_t *fsd, unsigned int first, int *length)
{
unsigned int foff, byte_off, *chain = NULL;
uint16_t next, cur;
uint8_t nbuf[3];
unsigned int cur, foff, byte_off, *chain = NULL;
uint16_t next;
int len = 0, res;
cur = first;
@ -210,12 +204,12 @@ read_fat_chain(dosfs_t *fsd, unsigned int first, int *length)
return NULL;
}
/* get byte offset of FAT entry */
foff = (fsd->fs_ver == 12) ? ((cur / 2)*3) : /* fat12 */
foff = (fsd->fs_ver == 12) ? (cur + (cur / 2)) : /* fat12 */
(cur * 2); /* fat16 */
byte_off = (fsd->ib.resv_sect * fsd->ib.sect_size) + foff;
res = pread(fsd->ifd, &nbuf, 3, byte_off);
/* XXX: endianness */
res = pread(fsd->ifd, &next, 2, byte_off);
if (res == -1) {
DPRINTF(("pread failed\n"));
free(chain);
@ -223,27 +217,21 @@ read_fat_chain(dosfs_t *fsd, unsigned int first, int *length)
}
if (fsd->fs_ver == 12) {
if (cur % 2) {
next = (nbuf[1] >> 4) | (uint16_t)(nbuf[2] << 4);
if (cur & 0x0001) {
next = next >> 4;
} else {
next = (uint16_t)(nbuf[1] & 0x0f) << 8 | nbuf[0];
next = next & 0x0FFF;
}
if (next == 0x0FFF) {
break;
} else if (next < 2 || next > 0xFF7) {
DPRINTF(("got weird sector %x from %x, bailing...\n", next, cur));
free(chain);
return NULL;
}
} else {
next = nbuf[0] | (uint16_t)nbuf[1] << 8;
if (next == 0xFFFF) {
break;
}
}
chain[len-1] = next;
cur = next;
}
*length = len;
@ -261,7 +249,7 @@ get_byte_offset(dosfs_t *fsd, dosfile_t *file, unsigned int f_offset)
if (f_offset > file->ent.size) {
DPRINTF(("offset requested is out of bounds!\n"));
return -ERANGE;
return -EINVAL;
}
/* size in bytes of a cluster */
@ -277,4 +265,3 @@ get_byte_offset(dosfs_t *fsd, dosfile_t *file, unsigned int f_offset)
return (file->fat_chain[coff] * csz) + (f_offset % csz);
}