diff options
Diffstat (limited to 'libmpio')
-rw-r--r-- | libmpio/fat.c | 110 | ||||
-rw-r--r-- | libmpio/io.c | 11 | ||||
-rw-r--r-- | libmpio/mpio.c | 25 |
3 files changed, 90 insertions, 56 deletions
diff --git a/libmpio/fat.c b/libmpio/fat.c index 170ab6c..3a5a087 100644 --- a/libmpio/fat.c +++ b/libmpio/fat.c @@ -1,6 +1,6 @@ /* * - * $Id: fat.c,v 1.7 2002/09/10 12:31:09 germeier Exp $ + * $Id: fat.c,v 1.8 2002/09/10 13:41:21 germeier Exp $ * * Library for USB MPIO-* * @@ -226,13 +226,21 @@ mpio_fatentry_plus_plus(mpio_fatentry_t *f) f->entry++; if (f->mem == MPIO_INTERNAL_MEM) { - if (f->entry > f->m->internal.max_cluster) - return 0; + if (f->entry >= f->m->internal.max_cluster) + { + f->entry--; + mpio_fatentry_entry2hw(f->m, f); + return 0; + } + mpio_fatentry_entry2hw(f->m, f); } if (f->mem == MPIO_EXTERNAL_MEM) { if (f->entry > f->m->external.max_cluster) - return 0; + { + f->entry--; + return 0; + } } return 1; @@ -414,7 +422,8 @@ mpio_fat_free_clusters(mpio_t *m, mpio_mem_t mem) do { - if (mpio_fatentry_free(m, mem, f)) e++; + if (mpio_fatentry_free(m, mem, f)) + e++; } while (mpio_fatentry_plus_plus(f)); free(f); @@ -503,11 +512,16 @@ int mpio_fat_clear(mpio_t *m, mpio_mem_t mem) { mpio_smartmedia_t *sm; + mpio_fatentry_t *f; - if (mem == MPIO_INTERNAL_MEM) { + if (mem == MPIO_INTERNAL_MEM) { sm = &m->internal; - debug("clearing of the internal FAT not yet supported , sorry\n"); - return 0; + + f = mpio_fatentry_new(m, mem, 1); + do { + mpio_fatentry_set_free(m, mem, f) ; + } while(mpio_fatentry_plus_plus(f)); + free(f); } if (mem == MPIO_EXTERNAL_MEM) { @@ -540,41 +554,59 @@ mpio_fat_write(mpio_t *m, mpio_mem_t mem) if (mem == MPIO_INTERNAL_MEM) { sm = &m->internal; - debug("ERROR: internal FAT is written during block or sector writes!\n"); - exit(-1); + + f=mpio_fatentry_new(m, mem, 0); + mpio_io_block_delete(m, mem, f); + free(f); + + memset(dummy, 0x00, BLOCK_SIZE); + + for (i= 0; i< 0x20; i++) + { + + if (i<DIR_NUM) + { + mpio_io_sector_write(m, mem, i, (sm->dir + SECTOR_SIZE * i)); + } else { + mpio_io_sector_write(m, mem, i, dummy); + } + } } - if (mem == MPIO_EXTERNAL_MEM) sm=&m->external; + if (mem == MPIO_EXTERNAL_MEM) + { + sm=&m->external; - memset(dummy, 0xff, BLOCK_SIZE); + memset(dummy, 0xff, BLOCK_SIZE); - for (i = 0x40; i < (sm->dir_offset + DIR_NUM) ; i++) { - if (((i / 0x20) * 0x20) == i) { - /* yuck */ - f=mpio_fatentry_new(m, mem, - ((i / 0x20) - - ((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2 ))); - mpio_io_block_delete(m, mem, f); - free(f); - } - - if (i == 0x40) - mpio_io_sector_write(m, mem, 0x40, sm->mbr); - if ((i > 0x40) && (i < sm->pbr_offset)) - mpio_io_sector_write(m, mem, i, dummy); - - if (i == sm->pbr_offset) - mpio_io_sector_write(m, mem, sm->pbr_offset, sm->pbr); - - if ((i >= sm->fat_offset) && (i < (sm->fat_offset + (2 * sm->fat_size)))) - mpio_io_sector_write(m, mem, i, - (sm->fat + SECTOR_SIZE * - ((i - sm->fat_offset) % sm->fat_size))); - - if (i>=sm->dir_offset) - mpio_io_sector_write(m, mem, i, - (sm->dir + (i - sm->dir_offset) * SECTOR_SIZE)); - } + for (i = 0x40; i < (sm->dir_offset + DIR_NUM) ; i++) { + if (((i / 0x20) * 0x20) == i) { + /* yuck */ + f=mpio_fatentry_new(m, mem, + ((i / 0x20) - + ((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2 ))); + mpio_io_block_delete(m, mem, f); + free(f); + } + + if (i == 0x40) + mpio_io_sector_write(m, mem, 0x40, sm->mbr); + if ((i > 0x40) && (i < sm->pbr_offset)) + mpio_io_sector_write(m, mem, i, dummy); + + if (i == sm->pbr_offset) + mpio_io_sector_write(m, mem, sm->pbr_offset, sm->pbr); + + if ((i >= sm->fat_offset) && (i < (sm->fat_offset + (2 * sm->fat_size)))) + mpio_io_sector_write(m, mem, i, + (sm->fat + SECTOR_SIZE * + ((i - sm->fat_offset) % sm->fat_size))); + + if (i>=sm->dir_offset) + mpio_io_sector_write(m, mem, i, + (sm->dir + (i - sm->dir_offset) * SECTOR_SIZE)); + } + } return 0; } diff --git a/libmpio/io.c b/libmpio/io.c index 95692fe..126e111 100644 --- a/libmpio/io.c +++ b/libmpio/io.c @@ -2,7 +2,7 @@ /* * - * $Id: io.c,v 1.7 2002/09/10 12:31:09 germeier Exp $ + * $Id: io.c,v 1.8 2002/09/10 13:41:21 germeier Exp $ * * Library for USB MPIO-* * @@ -488,11 +488,9 @@ mpio_io_sector_write(mpio_t *m, BYTE mem, DWORD index, BYTE *input) sendbuff[SECTOR_SIZE + 0x0c] = ba; } + /* easy but working, we write back the FAT info we read before */ if (mem==MPIO_INTERNAL_MEM) - { - debug("WARNING, code for internal FAT entry (in ECC area)" - " not yet in place!!\n"); - } + memcpy((sendbuff+SECTOR_SIZE), sm->fat, 0x10); debugn (5, "\n>>> MPIO\n"); hexdump(sendbuff, SECTOR_TRANS); @@ -688,7 +686,8 @@ mpio_io_block_delete(mpio_t *m, BYTE mem, mpio_fatentry_t *f) if (status[0] != 0xc0) { - debug ("error formatting Block %04x\n", index); + debug ("error formatting Block (%04x) %02x:%06x\n", + f->entry, chip, address); return 0; } diff --git a/libmpio/mpio.c b/libmpio/mpio.c index 552c126..67d2ddb 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.7 2002/09/10 12:31:09 germeier Exp $ + * $Id: mpio.c,v 1.8 2002/09/10 13:41:21 germeier Exp $ * * Library for USB MPIO-* * @@ -442,6 +442,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename, 2002, 8, 13, 2, 12, fsize, startsector); + /* this writes the FAT *and* the root directory */ mpio_fat_write(m, mem); return fsize-filesize; @@ -460,9 +461,7 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem, if (mem == MPIO_INTERNAL_MEM) { sm=&m->internal; - data_offset=0x00; - debug("formatting of internal memory is not yet supported, sorry\n"); - return 0; + data_offset = 0x01; } if (mem == MPIO_EXTERNAL_MEM) @@ -489,15 +488,18 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem, } while (mpio_fatentry_plus_plus(f)); free(f); - /* format CIS area */ - f = mpio_fatentry_new(m, mem, /* yuck */ - (1 - ((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2 ))); - mpio_io_block_delete(m, mem, f); - free(f); - mpio_io_sector_write(m, mem, 0x20, sm->cis); - mpio_io_sector_write(m, mem, 0x21, sm->cis); + if (mem == MPIO_EXTERNAL_MEM) { + /* format CIS area */ + f = mpio_fatentry_new(m, mem, /* yuck */ + (1-((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2))); + mpio_io_block_delete(m, mem, f); + free(f); + mpio_io_sector_write(m, mem, 0x20, sm->cis); + mpio_io_sector_write(m, mem, 0x21, sm->cis); + } mpio_rootdir_clear(m, mem); + /* this writes the FAT *and* the root directory */ mpio_fat_write(m, mem); if (progress_callback) @@ -563,6 +565,7 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, BYTE *filename, } mpio_dentry_delete(m, mem, filename); + /* this writes the FAT *and* the root directory */ mpio_fat_write(m, mem); return (fsize-filesize); |