aboutsummaryrefslogtreecommitdiff
path: root/libmpio
diff options
context:
space:
mode:
authorgermeier <germeier>2002-09-10 12:31:09 +0000
committergermeier <germeier>2002-09-10 12:31:09 +0000
commitaead174ddcfc61eafa706c7fdff0c8b84dbd2128 (patch)
treebe673848fc1b690c70ae126e23ad5f91701b8d70 /libmpio
parentf076913d50fda1192456e6a9b804f91bb7b15039 (diff)
downloadmpiosh-aead174ddcfc61eafa706c7fdff0c8b84dbd2128.tar.gz
mpiosh-aead174ddcfc61eafa706c7fdff0c8b84dbd2128.tar.bz2
mpiosh-aead174ddcfc61eafa706c7fdff0c8b84dbd2128.zip
reactivated deleting of files (external mem only)
added error handling for memory formatting 2 fatentry function add minor bug fixes
Diffstat (limited to 'libmpio')
-rw-r--r--libmpio/fat.c45
-rw-r--r--libmpio/fat.h9
-rw-r--r--libmpio/io.c91
-rw-r--r--libmpio/io.h10
-rw-r--r--libmpio/mpio.c156
5 files changed, 145 insertions, 166 deletions
diff --git a/libmpio/fat.c b/libmpio/fat.c
index 79d7a0d..170ab6c 100644
--- a/libmpio/fat.c
+++ b/libmpio/fat.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: fat.c,v 1.6 2002/09/09 15:51:37 germeier Exp $
+ * $Id: fat.c,v 1.7 2002/09/10 12:31:09 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -578,3 +578,46 @@ mpio_fat_write(mpio_t *m, mpio_mem_t mem)
return 0;
}
+
+int
+mpio_fatentry_set_free (mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f)
+{
+ int e;
+ mpio_smartmedia_t *sm;
+
+ if (mem == MPIO_INTERNAL_MEM) {
+ sm = &m->internal;
+ e = f->entry * 0x10;
+ memset((sm->fat+e), 0xff, 0x10);
+ }
+
+ if (mem == MPIO_EXTERNAL_MEM) {
+ sm = &m->internal;
+ mpio_fatentry_write(m, mem, f, 0);
+ }
+
+ return 0;
+}
+
+int
+mpio_fatentry_set_defect(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f)
+{
+ int e;
+ mpio_smartmedia_t *sm;
+
+ if (mem == MPIO_INTERNAL_MEM) {
+ sm = &m->internal;
+ e = f->entry * 0x10;
+ debug("Sorry, I don't now how to mark an internal block as"
+ " defective yet.\n");
+/* memset((sm->fat+e), 0xff, 0x10); */
+ }
+
+ if (mem == MPIO_EXTERNAL_MEM) {
+ sm = &m->internal;
+ mpio_fatentry_write(m, mem, f, 0xfff7);
+ }
+
+ return 0;
+}
+
diff --git a/libmpio/fat.h b/libmpio/fat.h
index d392050..b8667f4 100644
--- a/libmpio/fat.h
+++ b/libmpio/fat.h
@@ -1,6 +1,6 @@
/*
*
- * $Id: fat.h,v 1.3 2002/09/08 23:22:48 germeier Exp $
+ * $Id: fat.h,v 1.4 2002/09/10 12:31:09 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -45,9 +45,14 @@ int mpio_fatentry_next_free(mpio_t *, mpio_mem_t,
int mpio_fatentry_next_entry(mpio_t *, mpio_mem_t,
mpio_fatentry_t *);
DWORD mpio_fatentry_read(mpio_t *, mpio_mem_t, mpio_fatentry_t *);
-int mpio_fatentry_write(mpio_t *, mpio_mem_t, mpio_fatentry_t *,
+int mpio_fatentry_write(mpio_t *, mpio_mem_t, mpio_fatentry_t *,
WORD);
+int mpio_fatentry_set_free (mpio_t *, mpio_mem_t,
+ mpio_fatentry_t *);
+int mpio_fatentry_set_defect(mpio_t *, mpio_mem_t,
+ mpio_fatentry_t *);
+
int mpio_fat_internal_find_startsector(mpio_t *, BYTE);
void mpio_fatentry_hw2entry(mpio_t *, mpio_fatentry_t *);
diff --git a/libmpio/io.c b/libmpio/io.c
index 02b3774..95692fe 100644
--- a/libmpio/io.c
+++ b/libmpio/io.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.c,v 1.6 2002/09/09 17:31:25 germeier Exp $
+ * $Id: io.c,v 1.7 2002/09/10 12:31:09 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -346,7 +346,7 @@ mpio_io_version_read(mpio_t *m, BYTE *buffer)
int
mpio_io_sector_read(mpio_t *m, BYTE mem, DWORD index, BYTE *output)
{
- mpio_smartmedia_t *sm;
+ mpio_smartmedia_t *sm=0;
int nwrite, nread;
BYTE cmdpacket[CMD_SIZE], recvbuff[SECTOR_TRANS];
@@ -393,11 +393,15 @@ mpio_io_sector_read(mpio_t *m, BYTE mem, DWORD index, BYTE *output)
debug ("ECC error @ (%02x : %06x)\n", mem, index);
}
- if (mem==MPIO_INTERNAL_MEM)
- {
- debugn(2, "WARNING, code for internal FAT entry (in ECC area)"
- " not yet in place!!\n");
- }
+ /* This should not be needed:
+ * we don't have ECC information for the internal memory
+ * we only read the directory through this function
+ */
+ /* if (mem==MPIO_INTERNAL_MEM) */
+ /* { */
+ /* debugn(2, "WARNING, code for internal FAT entry (in ECC area)" */
+ /* " not yet in place!!\n"); */
+ /* } */
debugn (5, "\n<<< MPIO\n");
hexdump (recvbuff, SECTOR_TRANS);
@@ -679,33 +683,33 @@ mpio_io_block_delete(mpio_t *m, BYTE mem, mpio_fatentry_t *f)
return 0;
}
- if (status[0] != 0xc0) debug ("error formatting Block %04x\n", index);
debugn(5, "<<< MPIO\n");
hexdump(status, CMD_SIZE);
+
+ if (status[0] != 0xc0)
+ {
+ debug ("error formatting Block %04x\n", index);
+ return 0;
+ }
return CMD_SIZE;
}
int
-mpio_io_block_write(mpio_t *m, BYTE area, DWORD index, BYTE size, BYTE *data)
+mpio_io_block_write(mpio_t *m, BYTE mem, mpio_fatentry_t *f, BYTE *data)
{
- int i = 0;
+ mpio_smartmedia_t *sm;
int nwrite;
+ int i;
DWORD block_address, ba;
- DWORD rarea = 0;
BYTE cmdpacket[CMD_SIZE], sendbuff[BLOCK_TRANS];
+ BYTE chip=0;
+ DWORD address;
- if (area == MPIO_INTERNAL_MEM)
- {
- rarea = index / 0x1000000;
- index &= 0xffffff;
- }
- if (area == MPIO_EXTERNAL_MEM)
- {
- rarea = area;
- }
-
- index *= BLOCK_SECTORS;
+ if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
+ if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
+
+ fatentry2hw(f, &chip, &address);
/* build block for transfer to MPIO */
for (i = 0; i < BLOCK_SECTORS; i++)
@@ -715,28 +719,29 @@ mpio_io_block_write(mpio_t *m, BYTE area, DWORD index, BYTE size, BYTE *data)
SECTOR_SIZE);
memset(sendbuff + (i * SECTOR_TRANS) + SECTOR_SIZE,
0xff, CMD_SIZE);
+
/* fill in block information */
- if (index < 0x40)
- {
- block_address = 0;
- } else {
- ba = (index / 0x20) - 2;
- /* debugn(2, "foobar: %4x\n", ba); */
- block_address = index2blockaddress(ba);
- /* debugn(2, "foobar: %4x\n", block_address); */
- }
-
- ba = (block_address / 0x100) & 0xff;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x06] = ba;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0b] = ba;
-
- ba = block_address & 0xff;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x07] = ba;
- sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0c] = ba;
-
- /* generate ECC Area information */
- if (area == MPIO_EXTERNAL_MEM)
+ if (mem == MPIO_EXTERNAL_MEM)
{
+ if (address < 0x40)
+ {
+ block_address = 0;
+ } else {
+ ba = (address / 0x20) - 2;
+ /* debugn(2, "foobar: %4x\n", ba); */
+ block_address = index2blockaddress(ba);
+ /* debugn(2, "foobar: %4x\n", block_address); */
+ }
+
+ ba = (block_address / 0x100) & 0xff;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x06] = ba;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0b] = ba;
+
+ ba = block_address & 0xff;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x07] = ba;
+ sendbuff[(i * SECTOR_TRANS) + SECTOR_SIZE + 0x0c] = ba;
+
+ /* generate ECC Area information */
mpio_ecc_256_gen ((sendbuff + (i * SECTOR_TRANS)),
((sendbuff + (i * SECTOR_TRANS)
+ SECTOR_SIZE + 13)));
@@ -747,7 +752,7 @@ mpio_io_block_write(mpio_t *m, BYTE area, DWORD index, BYTE size, BYTE *data)
}
}
- mpio_io_set_cmdpacket(PUT_BLOCK, rarea, index, size, 0x48 , cmdpacket);
+ mpio_io_set_cmdpacket(PUT_BLOCK, chip, address, sm->size, 0x48 , cmdpacket);
debugn(5, "\n>>> MPIO\n");
hexdump(cmdpacket, sizeof(cmdpacket));
diff --git a/libmpio/io.h b/libmpio/io.h
index 79c74a9..0f97eed 100644
--- a/libmpio/io.h
+++ b/libmpio/io.h
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.h,v 1.4 2002/09/09 15:49:04 germeier Exp $
+ * $Id: io.h,v 1.5 2002/09/10 12:31:09 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -37,19 +37,19 @@
int mpio_io_set_cmdpacket(mpio_cmd_t, mpio_mem_t,
DWORD, BYTE, BYTE, BYTE *);
-int mpio_io_bulk_read(int, BYTE *, int);
+int mpio_io_bulk_read (int, BYTE *, int);
int mpio_io_bulk_write(int, BYTE *, int);
/* read version block into memory */
int mpio_io_version_read(mpio_t *, BYTE *);
/* */
-int mpio_io_sector_read(mpio_t *, BYTE, DWORD, BYTE *);
+int mpio_io_sector_read (mpio_t *, BYTE, DWORD, BYTE *);
int mpio_io_sector_write(mpio_t *, BYTE, DWORD, BYTE *);
/* */
-int mpio_io_block_read(mpio_t *, BYTE, mpio_fatentry_t *, BYTE *);
-int mpio_io_block_write(mpio_t *, BYTE, DWORD, BYTE, BYTE *);
+int mpio_io_block_read (mpio_t *, BYTE, mpio_fatentry_t *, BYTE *);
+int mpio_io_block_write (mpio_t *, BYTE, mpio_fatentry_t *, BYTE *);
int mpio_io_block_delete(mpio_t *, BYTE, mpio_fatentry_t *);
/* */
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index ca87c82..552c126 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.6 2002/09/09 15:49:06 germeier Exp $
+ * $Id: mpio.c,v 1.7 2002/09/10 12:31:09 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -266,8 +266,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (strncmp("sysdum", filename, 6) == 0)
return 0;
- if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
-
+ if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
/* find file */
@@ -278,7 +277,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (p)
f = mpio_dentry_get_startcluster(m, mem, p);
- if (f) {
+ if (f && p) {
filesize=fsize=mpio_dentry_get_filesize(m, mem, p);
unlink(filename);
@@ -473,11 +472,18 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem,
}
clusters = sm->size*128;
+
+ /* clear the fat before anything else, so we can mark clusters defective
+ * if we found a bad block
+ */
+ mpio_fat_clear(m, mem);
f = mpio_fatentry_new(m, mem, data_offset);
do
{
- mpio_io_block_delete(m, mem, f);
+ if (!mpio_io_block_delete(m, mem, f))
+ mpio_fatentry_set_defect(m, mem, f);
+
if (progress_callback)
(*progress_callback)(f->entry, sm->max_cluster + 1);
} while (mpio_fatentry_plus_plus(f));
@@ -491,7 +497,6 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem,
mpio_io_sector_write(m, mem, 0x20, sm->cis);
mpio_io_sector_write(m, mem, 0x21, sm->cis);
- mpio_fat_clear(m, mem);
mpio_rootdir_clear(m, mem);
mpio_fat_write(m, mem);
@@ -502,141 +507,62 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem,
}
-/* can we share code with mpio_file_get ??? */
int
mpio_file_del(mpio_t *m, mpio_mem_t mem, BYTE *filename,
BYTE (*progress_callback)(int, int))
{
BYTE *p;
- BYTE bdummy;
- WORD wdummy;
-
mpio_smartmedia_t *sm;
- int data_offset;
- BYTE fname[129];
- DWORD startsector=0, sector;
- DWORD realsector=0, oldsector=0;
- int towrite;
-
+ mpio_fatentry_t *f, backup;
DWORD filesize, fsize;
- DWORD fat_and;
- DWORD fat_end;
BYTE abort=0;
- debug("Support for deleting files is deactivated!");
- return 0;
-
/* please fix me sometime */
/* the system entry are kind of special ! */
if (strncmp("sysdum", filename, 6)==0)
return 0;
- if (mem==MPIO_INTERNAL_MEM) {
- sm=&m->internal;
- data_offset=0x00;
- fat_and=0xffffffff;
- fat_end=0xffffffff;
- debug("deleting from files of internal memory"
- " is not yet supported, sorry\n");
- return 0;
- }
-
- if (mem==MPIO_EXTERNAL_MEM) {
- sm=&m->external;
- data_offset=sm->dir_offset+DIR_NUM-(2*BLOCK_SECTORS);
- /* FAT 16 vs. FAT 12 */
- if (sm->size==128) {
- fat_and=0xffff;
- fat_end=0xfff8;
- } else {
- fat_and=0xfff;
- fat_end=0xff8;
- }
- }
-
+ if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
+ if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
- p=mpio_directory_open(m, mem);
- while (p) {
+ /* find file */
+ p = mpio_dentry_find_name(m, mem, filename);
+ if (!p)
+ p = mpio_dentry_find_name_8_3(m, mem, filename);
- mpio_dentry_get (m, p,
- fname, 128,
- &wdummy, &bdummy, &bdummy,
- &bdummy, &bdummy, &filesize);
- fsize=filesize;
- if ((strcmp(fname,filename)==0) && (strcmp(filename,fname)==0)) {
- startsector=mpio_dentry_get_startcluster(m, mem, p);
- p=NULL;
- }
-
- p=mpio_dentry_next(m, p);
- }
+ if (p)
+ f = mpio_dentry_get_startcluster(m, mem, p);
- /* grr, of curse these are clusters not sectors */
- /* must code while awake, must ... */
- if (startsector) {
- debugn(2, "startsector: %4x\n", startsector);
- sector = startsector;
- if (mem == MPIO_INTERNAL_MEM) {
- realsector = mpio_fat_internal_find_startsector(m, sector);
- realsector = realsector+ /* chose the right bank */
- (0x01000000*((realsector / (sm->size / 16 * 1000 / sm->chips)) + 1));
- sector = realsector;
- debugn(2, "startsector (real): %4x\n", sector);
- } else {
-/* realsector = sector_hack(sm->size, sector); */
- }
-
-/* mpio_io_block_delete(m, mem, (realsector * BLOCK_SECTORS) + data_offset, */
-/* sm->size); */
-
- if (filesize > BLOCK_SIZE) {
- towrite = BLOCK_SIZE;
- } else {
- towrite = filesize;
- }
+ if (f && p) {
+ filesize=fsize=mpio_dentry_get_filesize(m, mem, p);
+ do
+ {
+ debugn(2, "sector: %4x\n", f->entry);
- filesize -= towrite;
-
-/* debugn(5, "sector: (%6x) %4x\n", */
-/* (sector&0xffffff), mpio_fatentry_read(m, mem, sector&0xffffff)); */
-
-/* while((((mpio_fatentry_read(m, mem, (sector & 0xffffff)) & fat_and) */
-/* < fat_end)) && (filesize>0) && (!abort)) { */
-/* oldsector = sector; */
-/* sector = mpio_fatentry_read(m, mem, sector & 0xffffff); */
-/* mpio_fatentry_write(m, mem, oldsector, 0); */
-/* debugn(2,"next sector: %4x\n", sector); */
-/* if (mem == MPIO_INTERNAL_MEM) { */
-/* realsector = sector; */
-/* } else { */
-/* realsector = sector_hack(sm->size, sector); */
-/* } */
-
-/* debugn(2," realsector: %4x\n", realsector); */
+ mpio_io_block_delete(m, mem, f);
-/* mpio_io_block_delete(m, mem, */
-/* ((realsector * BLOCK_SECTORS) + data_offset), */
-/* sm->size); */
-/* if (filesize > BLOCK_SIZE) { */
-/* towrite = BLOCK_SIZE; */
-/* } else { */
-/* towrite = filesize; */
-/* } */
-
-/* filesize -= towrite; */
+ if (filesize != fsize)
+ mpio_fatentry_set_free(m, mem, &backup);
+
+ memcpy(&backup, f, sizeof(mpio_fatentry_t));
+
+ if (filesize > BLOCK_SIZE) {
+ filesize -= BLOCK_SIZE;
+ } else {
+ filesize -= filesize;
+ }
-/* if (progress_callback) */
-/* abort=(*progress_callback)((fsize-filesize), fsize); */
-/* } */
-/* mpio_fatentry_write(m, mem, sector, 0); */
+ if (progress_callback)
+ abort=(*progress_callback)((fsize-filesize), fsize);
+ } while (mpio_fatentry_next_entry(m, mem, f));
+ mpio_fatentry_set_free(m, mem, &backup);
+
} else {
debug("unable to locate the file: %s\n", filename);
}
- /* TODO: delete directory entry */
mpio_dentry_delete(m, mem, filename);
-
mpio_fat_write(m, mem);
return (fsize-filesize);