aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgermeier <germeier>2002-09-09 15:48:55 +0000
committergermeier <germeier>2002-09-09 15:48:55 +0000
commitda1281c5d1f7cac1e88805ae63542540f113accf (patch)
tree571073ad7b8eea45fe2b6502612b391f6c5bd821
parent3a5afefa2a788b242bfeb4dce330202e24a1ca77 (diff)
downloadmpiosh-da1281c5d1f7cac1e88805ae63542540f113accf.tar.gz
mpiosh-da1281c5d1f7cac1e88805ae63542540f113accf.tar.bz2
mpiosh-da1281c5d1f7cac1e88805ae63542540f113accf.zip
updated code to format external SmartMedia cards
fixed max_cluster issues
-rw-r--r--ChangeLog7
-rw-r--r--TODO5
-rw-r--r--libmpio/fat.c37
-rw-r--r--libmpio/io.c29
-rw-r--r--libmpio/io.h4
-rw-r--r--libmpio/mpio.c60
6 files changed, 98 insertions, 44 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e03bab..769c072 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2002-09-09 Markus Germeier <mager@tzi.de>
+ * libmpio/mpio.c (mpio_memory_format):
+ updated code to format external SmartMedia cards
+ * libmpio/fat.c (mpio_fatentry_plus_plus, mpio_bootblocks_read):
+ fixed max_cluster issues
+
+2002-09-09 Markus Germeier <mager@tzi.de>
+
* libmpio/io.c (cluster2block):
fixed cluster to block mapping for 32MB SmartMedia cards
* libmpio/io.c (mpio_io_block_read, mpio_io_sector_read):
diff --git a/TODO b/TODO
index 245ca4f..9bad0b7 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-$Id: TODO,v 1.5 2002/09/08 17:03:50 germeier Exp $
+$Id: TODO,v 1.6 2002/09/09 15:48:56 germeier Exp $
* Kernel Module
- the MPIO can no multitasking, so:
@@ -16,7 +16,8 @@ $Id: TODO,v 1.5 2002/09/08 17:03:50 germeier Exp $
- implement writing of files
If everything is done:
- - implement formating of external memory
+ - implement formating of external memory [partially done]
+ * write code to fix defective CIS (??), MBR, PBR
- implement formating of internal memory (BEWARE !!!!)
* mpio_tool [is deprecated, use mpiosh]
diff --git a/libmpio/fat.c b/libmpio/fat.c
index 554a620..1a723ab 100644
--- a/libmpio/fat.c
+++ b/libmpio/fat.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: fat.c,v 1.4 2002/09/08 23:22:48 germeier Exp $
+ * $Id: fat.c,v 1.5 2002/09/09 15:48:58 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -180,13 +180,22 @@ mpio_bootblocks_read (mpio_t *m, mpio_mem_t mem)
temp = ((total_sector / 0x20 * 0x02 / 0x200) + 0x01);
}
- sm->max_cluster = (total_sector / BLOCK_SECTORS);
- debugn(2,"max_cluster: %d\n", sm->max_cluster);
sm->fat_offset = sm->pbr_offset + 0x01;
sm->fat_size = temp;
sm->fat_nums = *(sm->pbr + 0x10);
sm->dir_offset = sm->pbr_offset + 0x01 + temp * 2;
-
+ sm->max_cluster = (total_sector / BLOCK_SECTORS);
+ /* fix max clusters */
+ temp*=2;
+ while (temp>=0x10)
+ {
+ sm->max_cluster--;
+ temp-=BLOCK_SECTORS;
+ }
+
+ debug("max_cluster: %d\n", sm->max_cluster);
+ debug("temp: %04x\n", temp);
+
return 0;
}
@@ -204,8 +213,11 @@ mpio_fatentry_new(mpio_t *m, mpio_mem_t mem, DWORD sector)
new->mem = mem;
new->entry = sector;
}
+
+ if (mem == MPIO_INTERNAL_MEM)
+ mpio_fatentry_entry2hw(m, new);
- return new;
+ return new;
}
int
@@ -219,7 +231,7 @@ mpio_fatentry_plus_plus(mpio_fatentry_t *f)
}
if (f->mem == MPIO_EXTERNAL_MEM) {
- if (f->entry > (f->m->external.max_cluster - 2))
+ if (f->entry > f->m->external.max_cluster)
return 0;
}
@@ -522,13 +534,14 @@ int
mpio_fat_write(mpio_t *m, mpio_mem_t mem)
{
mpio_smartmedia_t *sm;
+ mpio_fatentry_t *f;
BYTE dummy[BLOCK_SIZE];
WORD i;
if (mem == MPIO_INTERNAL_MEM) {
sm = &m->internal;
- debug("writing of the internal FAT is not yet supported, sorry\n");
- return 0;
+ debug("ERROR: internal FAT is written during block or sector writes!\n");
+ exit(-1);
}
if (mem == MPIO_EXTERNAL_MEM) sm=&m->external;
@@ -537,8 +550,12 @@ mpio_fat_write(mpio_t *m, mpio_mem_t mem)
for (i = 0x40; i < (sm->dir_offset + DIR_NUM) ; i++) {
if (((i / 0x20) * 0x20) == i) {
-/* debug("formatting: %2x\n", i); */
- mpio_io_block_delete(m, mem, i, sm->size);
+ /* 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)
diff --git a/libmpio/io.c b/libmpio/io.c
index 6a4c0f1..d325053 100644
--- a/libmpio/io.c
+++ b/libmpio/io.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.c,v 1.4 2002/09/09 13:29:52 germeier Exp $
+ * $Id: io.c,v 1.5 2002/09/09 15:49:01 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -626,14 +626,37 @@ mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE size,
}
int
-mpio_io_block_delete(mpio_t *m, BYTE mem, DWORD index, BYTE size)
+mpio_io_block_delete(mpio_t *m, BYTE mem, mpio_fatentry_t *f)
{
+ mpio_smartmedia_t *sm;
int nwrite, nread;
BYTE cmdpacket[CMD_SIZE], status[CMD_SIZE];
+ BYTE chip=0;
+ DWORD address;
+
+ if (mem == MPIO_INTERNAL_MEM)
+ {
+ sm = &m->internal;
+ hexdump((char *)&f->entry, 4);
+ hexdump((char *)&f->hw_address, 4);
+ chip = f->hw_address / 0x1000000;
+ address = f->hw_address & 0x0ffffff;
+ }
+ if (mem == MPIO_EXTERNAL_MEM)
+ {
+ sm = &m->external;
+ chip = MPIO_EXTERNAL_MEM;
+ address = cluster2block(sm->size, f->entry);
+ address *= BLOCK_SECTORS;
+
+ /* add offset to start of "data" area! */
+ address += (sm->dir_offset + DIR_NUM - (2 * BLOCK_SECTORS));
+
+ }
/* Send command packet to MPIO */
- mpio_io_set_cmdpacket(DEL_BLOCK, mem, index, size, 0, cmdpacket);
+ mpio_io_set_cmdpacket(DEL_BLOCK, chip, address, sm->size, 0, cmdpacket);
debugn (5, ">>> MPIO\n");
hexdump (cmdpacket, sizeof(cmdpacket));
diff --git a/libmpio/io.h b/libmpio/io.h
index 0436cd1..79c74a9 100644
--- a/libmpio/io.h
+++ b/libmpio/io.h
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.h,v 1.3 2002/09/03 21:20:53 germeier Exp $
+ * $Id: io.h,v 1.4 2002/09/09 15:49:04 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -50,7 +50,7 @@ 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_delete(mpio_t *, BYTE, DWORD, BYTE);
+int mpio_io_block_delete(mpio_t *, BYTE, mpio_fatentry_t *);
/* */
int mpio_io_spare_read (mpio_t *, BYTE, DWORD, BYTE, BYTE, BYTE *, int);
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index f6cfd84..ca87c82 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.5 2002/09/09 13:29:52 germeier Exp $
+ * $Id: mpio.c,v 1.6 2002/09/09 15:49:06 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -424,10 +424,10 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
}
/* debug("mager: %04x : %3d\n", realsector*BLOCK_SECTORS, realsector); */
- mpio_io_block_delete(m, mem, ((realsector*BLOCK_SECTORS) + data_offset),
- sm->size);
- mpio_io_block_write(m, mem, realsector + (data_offset/BLOCK_SECTORS),
- sm->size, block);
+/* mpio_io_block_delete(m, mem, ((realsector*BLOCK_SECTORS) + data_offset), */
+/* sm->size); */
+/* mpio_io_block_write(m, mem, realsector + (data_offset/BLOCK_SECTORS), */
+/* sm->size, block); */
filesize -= toread;
@@ -454,34 +454,40 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem,
{
int data_offset;
mpio_smartmedia_t *sm;
+ mpio_fatentry_t *f;
DWORD clusters;
DWORD i;
- if (mem == MPIO_INTERNAL_MEM) {
- sm=&m->internal;
- data_offset=0x00;
- debug("formatting of internal memory is not yet supported, sorry\n");
- return 0;
- }
+ if (mem == MPIO_INTERNAL_MEM)
+ {
+ sm=&m->internal;
+ data_offset=0x00;
+ debug("formatting 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;
- }
-/* debug("mager: %2x\n", data_offset); */
+ if (mem == MPIO_EXTERNAL_MEM)
+ {
+ sm = &m->external;
+ data_offset = 0x02;
+ }
clusters = sm->size*128;
-/* debug("Clusters: %4x\n", sm->size*128); */
-
- for (i = data_offset; i < clusters; i += 0x20) {
- mpio_io_block_delete(m, mem, i, sm->size);
- if (progress_callback)
- (*progress_callback)(i, clusters + 1);
- }
+ f = mpio_fatentry_new(m, mem, data_offset);
+ do
+ {
+ mpio_io_block_delete(m, mem, f);
+ if (progress_callback)
+ (*progress_callback)(f->entry, sm->max_cluster + 1);
+ } while (mpio_fatentry_plus_plus(f));
+ free(f);
/* format CIS area */
- mpio_io_block_delete(m, mem, 0x20, sm->size);
+ 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);
@@ -490,7 +496,7 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem,
mpio_fat_write(m, mem);
if (progress_callback)
- (*progress_callback)(clusters+1, clusters+1);
+ (*progress_callback)(sm->max_cluster+1, sm->max_cluster+1);
return 0;
}
@@ -580,8 +586,8 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, BYTE *filename,
/* realsector = sector_hack(sm->size, sector); */
}
- mpio_io_block_delete(m, mem, (realsector * BLOCK_SECTORS) + data_offset,
- sm->size);
+/* mpio_io_block_delete(m, mem, (realsector * BLOCK_SECTORS) + data_offset, */
+/* sm->size); */
if (filesize > BLOCK_SIZE) {
towrite = BLOCK_SIZE;