From 71ab9acfd97cf1f71c1f66f5e1a8b879c0960e40 Mon Sep 17 00:00:00 2001 From: germeier Date: Wed, 18 Sep 2002 22:18:29 +0000 Subject: removed wrong block mapping added progress_callback for mpio_init mpiosh: external memory is only selectable if it is available --- ChangeLog | 14 ++++++++ libmpio/fat.c | 6 ++-- libmpio/fat.h | 4 +-- libmpio/io.c | 105 +++++++++++++++++++++++++++++------------------------- libmpio/io.h | 5 +-- libmpio/mpio.c | 12 ++++--- libmpio/mpio.h | 4 +-- mpiosh/callback.c | 27 +++++++++++--- mpiosh/callback.h | 3 +- mpiosh/mpiosh.c | 5 +-- 10 files changed, 116 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0df39c7..f62c9d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-09-18 Markus Germeier + + * mpiosh/callback.c (mpiosh_cmd_mem): + external memory is only selectable if it is available + * libmpio/mpio.c (mpio_init): added progress callback + for init + * mpiosh/callback.c (mpiosh_callback_init): + added function + * libmpio/io.c (cluster2block, cluster2blockaddress): + removed wrong block mapping + (current mapping should work with complete error + free SM cards _only_) + + 2002-09-18 Andreas Buesching * libmpio/mpio.c (mpio_file_get, mpio_file_put, mpio_file_del): 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 *); /* diff --git a/mpiosh/callback.c b/mpiosh/callback.c index df4a3ab..bdcb345 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.c,v 1.9 2002/09/18 20:32:22 crunchy Exp $ + * $Id: callback.c,v 1.10 2002/09/18 22:18:29 germeier Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -160,13 +160,20 @@ mpiosh_cmd_info(char *args[]) void mpiosh_cmd_mem(char *args[]) { + int free; + MPIOSH_CHECK_CONNECTION_CLOSED; MPIOSH_CHECK_ARG; if (!strcmp(args[0], "e")) { - mpiosh.card = MPIO_EXTERNAL_MEM; - mpiosh.prompt = PROMPT_EXT; - printf("external memory card is selected\n"); + if (mpio_memory_free(mpiosh.dev, mpiosh.card, &free)) { + mpiosh.card = MPIO_EXTERNAL_MEM; + mpiosh.prompt = PROMPT_EXT; + printf("external memory card is selected\n"); + } else { + printf("no external memory card is available\n"); + } + } else if (!strcmp(args[0], "i")) { mpiosh.card = MPIO_INTERNAL_MEM; mpiosh.prompt = PROMPT_INT; @@ -183,7 +190,8 @@ mpiosh_cmd_open(char *args[]) UNUSED(args); - mpiosh.dev = mpio_init(); + mpiosh.dev = mpio_init(mpiosh_callback_init); + printf("\n"); if (mpiosh.dev == NULL) printf("error: could not open connection MPIO player\n"); @@ -217,6 +225,15 @@ mpiosh_cmd_quit(char *args[]) exit(0); } +BYTE +mpiosh_callback_init(int read, int total) +{ + printf("\rinitialized %.2f %%", ((double) read / total) * 100.0 ); + fflush(stdout); + + return mpiosh_cancel; // continue +} + BYTE mpiosh_callback_get(int read, int total) { diff --git a/mpiosh/callback.h b/mpiosh/callback.h index 92642fa..08a756c 100644 --- a/mpiosh/callback.h +++ b/mpiosh/callback.h @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.h,v 1.3 2002/09/15 12:03:23 germeier Exp $ + * $Id: callback.h,v 1.4 2002/09/18 22:18:29 germeier Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -55,6 +55,7 @@ void mpiosh_cmd_lcd(char *args[]); void mpiosh_cmd_lmkdir(char *args[]); /* progress callbacks */ +BYTE mpiosh_callback_init(int read, int total); BYTE mpiosh_callback_get(int read, int total); BYTE mpiosh_callback_put(int read, int total); BYTE mpiosh_callback_del(int read, int total); diff --git a/mpiosh/mpiosh.c b/mpiosh/mpiosh.c index 10e518e..aa4ff2d 100644 --- a/mpiosh/mpiosh.c +++ b/mpiosh/mpiosh.c @@ -2,7 +2,7 @@ /* * - * $Id: mpiosh.c,v 1.13 2002/09/18 20:32:22 crunchy Exp $ + * $Id: mpiosh.c,v 1.14 2002/09/18 22:18:29 germeier Exp $ * * Author: Andreas Büsching * @@ -418,7 +418,8 @@ main(int argc, char *argv[]) { debug_init(); mpiosh_init(); - mpiosh.dev = mpio_init(); + mpiosh.dev = mpio_init(mpiosh_callback_init); + printf("\n"); if (mpiosh.card == MPIO_INTERNAL_MEM) mpiosh.prompt = PROMPT_INT; -- cgit v1.2.3