aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgermeier <germeier>2002-09-18 23:17:03 +0000
committergermeier <germeier>2002-09-18 23:17:03 +0000
commit2dd8def5573f6dbf9e8ab2752778b0bffce15637 (patch)
treeb4f18bc44c47680596b52aeb8c8dacc1a05efba4
parent71ab9acfd97cf1f71c1f66f5e1a8b879c0960e40 (diff)
downloadmpiosh-2dd8def5573f6dbf9e8ab2752778b0bffce15637.tar.gz
mpiosh-2dd8def5573f6dbf9e8ab2752778b0bffce15637.tar.bz2
mpiosh-2dd8def5573f6dbf9e8ab2752778b0bffce15637.zip
fixed check in mpiosh_cmd_mem
added code to check for internal memory before we use it (don't ask! :-)
-rw-r--r--ChangeLog10
-rw-r--r--libmpio/mpio.c54
-rw-r--r--mpiosh/callback.c4
3 files changed, 53 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index f62c9d0..a099610 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-09-19 Markus Germeier <mager@tzi.de>
+
+ * libmpio/mpio.c (mpio_init_internal):
+ added code to check if the internal memory is available
+ (don't ask! :-)
+ (mpio_sync): check if selected memory is available
+ * mpiosh/callback.c (mpiosh_cmd_mem):
+ fixed external mem check
+
+
2002-09-18 Markus Germeier <mager@tzi.de>
* mpiosh/callback.c (mpiosh_cmd_mem):
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index 778890f..e9ab24a 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.19 2002/09/18 22:18:29 germeier Exp $
+ * $Id: mpio.c,v 1.20 2002/09/18 23:17:03 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -63,8 +63,18 @@ mpio_init_internal(mpio_t *m)
/* init main memory parameters */
sm->manufacturer = m->version[i_offset];
sm->id = m->version[i_offset+1];
- sm->size = mpio_id2mem(sm->id);
sm->chips = 1;
+ if (mpio_id_valid(m->version[i_offset]))
+ {
+ sm->size = mpio_id2mem(sm->id);
+ } else {
+ sm->manufacturer = 0;
+ sm->id = 0;
+ sm->size = 0;
+ debug("WARNING: no internal memory found\n");
+ return;
+ }
+
/* look for a second installed memory chip */
if (mpio_id_valid(m->version[i_offset+2]))
@@ -202,7 +212,8 @@ mpio_init(BYTE (*progress_callback)(int, int))
mpio_init_external(new_mpio);
/* read FAT/spare area */
- mpio_fat_read(new_mpio, MPIO_INTERNAL_MEM, progress_callback);
+ if (new_mpio->internal.id)
+ mpio_fat_read(new_mpio, MPIO_INTERNAL_MEM, progress_callback);
return new_mpio;
}
@@ -217,6 +228,10 @@ int
mpio_memory_free(mpio_t *m, mpio_mem_t mem, int *free)
{
if (mem==MPIO_INTERNAL_MEM) {
+ if (!m->internal.size) {
+ *free=0;
+ return 0;
+ }
*free=mpio_fat_free_clusters(m, mem);
return (m->internal.geo.SumSector
* SECTOR_SIZE / 1000 * m->internal.chips);
@@ -259,16 +274,21 @@ mpio_get_info(mpio_t *m, mpio_info_t *info)
m->firmware.day, m->firmware.month, m->firmware.year);
snprintf(info->model, max, "%s", mpio_model_name[m->model]);
- if (m->internal.chips == 1)
- {
- snprintf(info->mem_internal, max, "%3dMB (%s)",
- mpio_id2mem(m->internal.id),
- mpio_id2manufacturer(m->internal.manufacturer));
- } else {
- snprintf(info->mem_internal, max, "%3dMB (%s) - %d chips",
- mpio_id2mem(m->internal.id)*m->internal.chips,
- mpio_id2manufacturer(m->internal.manufacturer),
- m->internal.chips);
+ if (!m->internal.id)
+ {
+ snprintf(info->mem_internal, max, "not available");
+ } else {
+ if (m->internal.chips == 1)
+ {
+ snprintf(info->mem_internal, max, "%3dMB (%s)",
+ mpio_id2mem(m->internal.id),
+ mpio_id2manufacturer(m->internal.manufacturer));
+ } else {
+ snprintf(info->mem_internal, max, "%3dMB (%s) - %d chips",
+ mpio_id2mem(m->internal.id)*m->internal.chips,
+ mpio_id2manufacturer(m->internal.manufacturer),
+ m->internal.chips);
+ }
}
if (m->external.id)
@@ -692,6 +712,14 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, BYTE *filename,
int
mpio_sync(mpio_t *m, mpio_mem_t mem)
{
+ mpio_smartmedia_t *sm;
+
+ if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
+ if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
+
+ if (!sm->size)
+ return 0;
+
/* this writes the FAT *and* the root directory */
return mpio_fat_write(m, mem);
}
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index bdcb345..798dab6 100644
--- a/mpiosh/callback.c
+++ b/mpiosh/callback.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: callback.c,v 1.10 2002/09/18 22:18:29 germeier Exp $
+ * $Id: callback.c,v 1.11 2002/09/18 23:17:03 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -166,7 +166,7 @@ mpiosh_cmd_mem(char *args[])
MPIOSH_CHECK_ARG;
if (!strcmp(args[0], "e")) {
- if (mpio_memory_free(mpiosh.dev, mpiosh.card, &free)) {
+ if (mpio_memory_free(mpiosh.dev, MPIO_EXTERNAL_MEM, &free)) {
mpiosh.card = MPIO_EXTERNAL_MEM;
mpiosh.prompt = PROMPT_EXT;
printf("external memory card is selected\n");