aboutsummaryrefslogtreecommitdiff
path: root/libmpio
diff options
context:
space:
mode:
authorgermeier <germeier>2002-09-18 22:18:29 +0000
committergermeier <germeier>2002-09-18 22:18:29 +0000
commit71ab9acfd97cf1f71c1f66f5e1a8b879c0960e40 (patch)
treeffeaaddfa7cfd37d66d790427b6ecd10baa51664 /libmpio
parent4a49120603daab9f9ad280f0ef44e36b0218a302 (diff)
downloadmpiosh-71ab9acfd97cf1f71c1f66f5e1a8b879c0960e40.tar.gz
mpiosh-71ab9acfd97cf1f71c1f66f5e1a8b879c0960e40.tar.bz2
mpiosh-71ab9acfd97cf1f71c1f66f5e1a8b879c0960e40.zip
removed wrong block mapping
added progress_callback for mpio_init mpiosh: external memory is only selectable if it is available
Diffstat (limited to 'libmpio')
-rw-r--r--libmpio/fat.c6
-rw-r--r--libmpio/fat.h4
-rw-r--r--libmpio/io.c105
-rw-r--r--libmpio/io.h5
-rw-r--r--libmpio/mpio.c12
-rw-r--r--libmpio/mpio.h4
6 files changed, 75 insertions, 61 deletions
diff --git a/libmpio/fat.c b/libmpio/fat.c
index aead3a7..6279599 100644
--- a/libmpio/fat.c
+++ b/libmpio/fat.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: fat.c,v 1.10 2002/09/11 13:44:30 germeier Exp $
+ * $Id: fat.c,v 1.11 2002/09/18 22:18:29 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -259,7 +259,7 @@ mpio_fatentry_plus_plus(mpio_fatentry_t *f)
/* read "fat_size" sectors of fat into the provided buffer */
int
-mpio_fat_read (mpio_t *m, mpio_mem_t mem)
+mpio_fat_read (mpio_t *m, mpio_mem_t mem, BYTE (*progress_callback)(int, int))
{
mpio_smartmedia_t *sm;
BYTE recvbuff[SECTOR_SIZE];
@@ -269,7 +269,7 @@ mpio_fat_read (mpio_t *m, mpio_mem_t mem)
{
sm = &m->internal;
if (mpio_io_spare_read(m, mem, 0, (sm->size / sm->chips), 0, sm->fat,
- (sm->fat_size * SECTOR_SIZE)))
+ (sm->fat_size * SECTOR_SIZE), progress_callback))
return 1;
return 0;
}
diff --git a/libmpio/fat.h b/libmpio/fat.h
index da7612b..af92d35 100644
--- a/libmpio/fat.h
+++ b/libmpio/fat.h
@@ -1,6 +1,6 @@
/*
*
- * $Id: fat.h,v 1.5 2002/09/11 00:18:34 germeier Exp $
+ * $Id: fat.h,v 1.6 2002/09/18 22:18:29 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -30,7 +30,7 @@
int mpio_bootblocks_read(mpio_t *, mpio_mem_t);
-int mpio_fat_read(mpio_t *, mpio_mem_t);
+int mpio_fat_read(mpio_t *, mpio_mem_t, BYTE (*)(int, int));
int mpio_fat_write(mpio_t *, mpio_mem_t);
int mpio_fat_clear(mpio_t *, mpio_mem_t);
int mpio_fat_free_clusters(mpio_t *, mpio_mem_t);
diff --git a/libmpio/io.c b/libmpio/io.c
index 778b044..ca2c033 100644
--- a/libmpio/io.c
+++ b/libmpio/io.c
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.c,v 1.13 2002/09/15 23:05:25 salmoon Exp $
+ * $Id: io.c,v 1.14 2002/09/18 22:18:29 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -109,32 +109,35 @@ cluster2block(int mem, int sector)
/* No Zone-based block management for SmartMedia below 32MB !!*/
- if (mem == 32)
- {
- /* I'm so large in *not* knowing! */
- if (sector >= 830)
- a++;
- if (a >= 1001)
- a += 21;
- }
-
- if (mem == 64)
- {
- /* I'm so large in *not* knowing! */
- if (sector >= 89)
- a++;
- if (a >= 1000)
- a += 21;
- if (a >= 2021)
- a += 24;
- if (a >= 3045)
- a += 24;
- /* WHAT? */
- if (a >= 3755)
- a++;
- }
-
- if (mem == 128)
+ /* The jumps are defect sectors on a specific SM medium and have to
+ be handled with a proper logic block -> physical block which
+ include a bad block management */
+
+/* if (mem == 32) */
+/* { */
+/* if (sector >= 830) */
+/* a++; */
+/* if (a >= 1001) */
+/* a += 21; */
+/* } */
+
+/* if (mem == 64) */
+/* { */
+/* /\* I'm so large in *not* knowing! *\/ */
+/* if (sector >= 89) */
+/* a++; */
+/* if (a >= 1000) */
+/* a += 21; */
+/* if (a >= 2021) */
+/* a += 24; */
+/* if (a >= 3045) */
+/* a += 24; */
+/* /\* WHAT? *\/ */
+/* if (a >= 3755) */
+/* a++; */
+/* } */
+
+ if (mem > 16)
{
/* two blocks are already spent elsewhere */
/* question is: where (CIS and ??) */
@@ -142,7 +145,7 @@ cluster2block(int mem, int sector)
a += 22;
/* ... and then add 24 empty blocks every 1000 sectors */
a += ((sector - 998) / 1000 * 24);
- }
+ }
return a;
}
@@ -183,6 +186,10 @@ cluster2blockaddress(DWORD index, BYTE size)
{
DWORD ba;
WORD block_address;
+
+ /* The jumps are defect sectors on a specific SM medium and have to
+ be handled with a proper logic block -> physical block which
+ include a bad block management */
if (index<0x40)
{
@@ -191,27 +198,23 @@ cluster2blockaddress(DWORD index, BYTE size)
if (index >= 0x8000)
{
ba = ((index % 0x8000) / 0x20);
- /* I'm so large in *not* knowing! */
- /* these are the same jumps as found in cluster2block */
- if (size == 64)
- {
- if (index >= 0x1d5e0)
- ba--;
- }
+/* if (size == 64) */
+/* { */
+/* if (index >= 0x1d5e0) */
+/* ba--; */
+/* } */
} else {
ba = (index / 0x20) - 2;
- /* I'm so large in *not* knowing! */
- /* these are the same jumps as found in cluster2block */
- if (size == 32)
- {
- if (ba >= 0x33f)
- ba--;
- }
- if (size == 64)
- {
- if (ba >= 0x05b)
- ba--;
- }
+/* if (size == 32) */
+/* { */
+/* if (ba >= 0x33f) */
+/* ba--; */
+/* } */
+/* if (size == 64) */
+/* { */
+/* if (ba >= 0x05b) */
+/* ba--; */
+/* } */
}
block_address= index2blockaddress(ba);
debugn(2, "block-foo: %06x %04x %04x\n", index, ba, block_address);
@@ -660,7 +663,8 @@ mpio_io_block_read(mpio_t *m, BYTE mem, mpio_fatentry_t *f, BYTE *output)
int
mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE size,
- BYTE wsize, BYTE *output, int toread)
+ BYTE wsize, BYTE *output, int toread,
+ BYTE (*progress_callback)(int, int))
{
int i;
int nwrite, nread;
@@ -697,6 +701,9 @@ mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE size,
output + (i * CMD_SIZE) +
(toread / chips * (chip - 1)),
CMD_SIZE);
+
+ if ((progress_callback) && (i % 256))
+ (*progress_callback)((i*CMD_SIZE), toread);
if(nread != CMD_SIZE)
{
@@ -709,6 +716,8 @@ mpio_io_spare_read(mpio_t *m, BYTE area, DWORD index, BYTE size,
CMD_SIZE);
}
}
+ if (progress_callback)
+ (*progress_callback)(toread, toread);
return 0;
}
diff --git a/libmpio/io.h b/libmpio/io.h
index 330a494..9eb6217 100644
--- a/libmpio/io.h
+++ b/libmpio/io.h
@@ -2,7 +2,7 @@
/*
*
- * $Id: io.h,v 1.6 2002/09/15 12:03:23 germeier Exp $
+ * $Id: io.h,v 1.7 2002/09/18 22:18:29 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -53,6 +53,7 @@ int mpio_io_block_write (mpio_t *, BYTE, mpio_fatentry_t *, 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);
+int mpio_io_spare_read (mpio_t *, BYTE, DWORD, BYTE, BYTE, BYTE *, int,
+ BYTE (*)(int, int));
#endif /* _MPIO_IO_H_ */
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index 35570e7..778890f 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.18 2002/09/18 20:32:22 crunchy Exp $
+ * $Id: mpio.c,v 1.19 2002/09/18 22:18:29 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -90,7 +90,8 @@ mpio_init_internal(mpio_t *m)
sm->fat_size = sm->max_cluster*16/SECTOR_SIZE;
debugn(2,"fat_size: %04x\n", sm->fat_size*SECTOR_SIZE);
sm->fat = malloc(sm->fat_size*SECTOR_SIZE);
- mpio_fat_read(m, MPIO_INTERNAL_MEM);
+ /* fat will be read in mpio_init, so we can more easily handle
+ a callback function */
/* Read directory from internal memory */
sm->dir_offset=0;
@@ -135,13 +136,13 @@ mpio_init_external(mpio_t *m)
mpio_bootblocks_read(m, MPIO_EXTERNAL_MEM);
sm->fat = malloc(SECTOR_SIZE*sm->fat_size);
- mpio_fat_read(m, MPIO_EXTERNAL_MEM);
+ mpio_fat_read(m, MPIO_EXTERNAL_MEM, NULL);
mpio_rootdir_read(m, MPIO_EXTERNAL_MEM);
}
}
mpio_t *
-mpio_init(void)
+mpio_init(BYTE (*progress_callback)(int, int))
{
mpio_t *new_mpio;
@@ -200,6 +201,9 @@ mpio_init(void)
/* external init */
mpio_init_external(new_mpio);
+ /* read FAT/spare area */
+ mpio_fat_read(new_mpio, MPIO_INTERNAL_MEM, progress_callback);
+
return new_mpio;
}
diff --git a/libmpio/mpio.h b/libmpio/mpio.h
index 6ace073..b4c381c 100644
--- a/libmpio/mpio.h
+++ b/libmpio/mpio.h
@@ -1,7 +1,7 @@
/* -*- linux-c -*- */
/*
- * $Id: mpio.h,v 1.4 2002/09/15 12:03:23 germeier Exp $
+ * $Id: mpio.h,v 1.5 2002/09/18 22:18:29 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -45,7 +45,7 @@
*init and shutdown
*/
-mpio_t *mpio_init(void);
+mpio_t *mpio_init(BYTE (*)(int, int));
void mpio_close(mpio_t *);
/*