aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--README9
-rw-r--r--libmpio/defs.h7
-rw-r--r--libmpio/mpio.c85
-rw-r--r--libmpio/mpio.h15
-rw-r--r--mpiosh/callback.c9
6 files changed, 110 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index a099610..e075efa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-09-19 Andreas Buesching <crunchy@tzi.de>
+
+ * mpiosh/callback.c (mpiosh_cmd_mput): using new error handling
+ functions
+
+ * libmpio/mpio.c (mpio_errno, mpio_strerror, mpio_perror):
+ add functions for error handling
+ (mpio_file_get, mpio_file_put, mpio_file_del): using error
+ handling functions
+
2002-09-19 Markus Germeier <mager@tzi.de>
* libmpio/mpio.c (mpio_init_internal):
diff --git a/README b/README
index e054e83..0149144 100644
--- a/README
+++ b/README
@@ -17,10 +17,11 @@ When you want to stop playing, disconnect MPIO and type:
- Is there any risk to use this software with my MPIO mp3 player?
-We do not really know that, but we do not garantee for anything. If you
-use this software and your MPIO mp3 player turns into a useless brick it
-is your own fault. If you use any other device with this library it would
-be a wonder if does _not_ turn into a brick. So if you use do not like your mp3 player just use this software ;-)
+We do not really know that, but we do not garantee for anything. If
+you use this software and your MPIO mp3 player turns into a useless
+brick it is your own fault. If you use any other device with this
+library it would be a wonder if does _not_ turn it into a brick. So if
+you do not like your mp3 player just use this software ;-)
- I downloaded a current CVS snapshot but there is no configure script, only
a configure.in ! What do I have to do??
diff --git a/libmpio/defs.h b/libmpio/defs.h
index 7e06524..70f789f 100644
--- a/libmpio/defs.h
+++ b/libmpio/defs.h
@@ -1,7 +1,7 @@
/* -*- linux-c -*- */
/*
- * $Id: defs.h,v 1.6 2002/09/18 20:32:21 crunchy Exp $
+ * $Id: defs.h,v 1.7 2002/09/19 20:46:02 crunchy Exp $
*
* Library for USB MPIO-*
*
@@ -93,6 +93,11 @@ typedef enum { FTYPE_CONF = 'C',
#define INFO_LINE 81
/* error codes */
+typedef struct {
+ int id;
+ char *msg;
+} mpio_error_t;
+
#define MPIO_ERR_FILE_NOT_FOUND -1
#define MPIO_ERR_NOT_ENOUGH_SPACE -2
#define MPIO_ERR_FILE_EXISTS -3
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index e9ab24a..ea0f23c 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.20 2002/09/18 23:17:03 germeier Exp $
+ * $Id: mpio.c,v 1.21 2002/09/19 20:46:02 crunchy Exp $
*
* Library for USB MPIO-*
*
@@ -49,7 +49,31 @@ static BYTE *mpio_model_name[] = {
"MPIO-DMB",
"MPIO-DMB+",
"MPIO-DMK",
- "unknown" };
+ "unknown"
+};
+
+static mpio_error_t mpio_errors[] = {
+ { MPIO_ERR_FILE_NOT_FOUND,
+ "The selected file can not be found." },
+ { MPIO_ERR_NOT_ENOUGH_SPACE,
+ "There is not enough space left on the selected memory card." },
+ { MPIO_ERR_FILE_EXISTS,
+ "The selected file already exists and can not be overwritten. Remove it first." },
+ { MPIO_ERR_FAT_ERROR,
+ "Internal error while reading the FAT." },
+ { MPIO_ERR_READING_FILE,
+ "The selected file can not be read." },
+ { MPIO_ERR_PERMISSION_DENIED,
+ "There are not enough rights to access the file/directory." },
+ { MPIO_ERR_WRITING_FILE,
+ "There are no permisson to write to the selected file." }
+};
+
+static const int mpio_error_num = sizeof mpio_errors / sizeof(mpio_error_t);
+
+static int _mpio_errno = 0;
+
+#define MPIO_ERR_RETURN(err) _mpio_errno = err; return -1
void mpio_init_internal(mpio_t *);
void mpio_init_external(mpio_t *);
@@ -318,8 +342,8 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename,
/* please fix me sometime */
/* the system entries are kind of special ! */
- if (strncmp("sysdum", filename, 6) == 0)
- return MPIO_ERR_PERMISSION_DENIED;
+ if (strncmp("sysdum", filename, 6) == 0)
+ MPIO_ERR_RETURN(MPIO_ERR_PERMISSION_DENIED);
if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
@@ -354,7 +378,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename,
debug("error writing file data\n");
close(fd);
free (f);
- return MPIO_ERR_WRITING_FILE;
+ MPIO_ERR_RETURN(MPIO_ERR_WRITING_FILE);
}
filesize -= towrite;
@@ -404,7 +428,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (stat((const char *)filename, &file_stat)!=0) {
debug("could not find file: %s\n", filename);
- return MPIO_ERR_FILE_NOT_FOUND;
+ MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND);
}
fsize=filesize=file_stat.st_size;
debugn(2, "filesize: %d\n", fsize);
@@ -413,7 +437,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
mpio_memory_free(m, mem, &free);
if (free*1024<fsize) {
debug("not enough space left (only %d KB)\n", free);
- return MPIO_ERR_NOT_ENOUGH_SPACE;
+ MPIO_ERR_RETURN(MPIO_ERR_NOT_ENOUGH_SPACE);
}
/* check if filename already exists */
@@ -423,7 +447,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (p)
{
debug("filename already exists\n");
- return MPIO_ERR_FILE_EXISTS;
+ MPIO_ERR_RETURN(MPIO_ERR_FILE_EXISTS);
}
/* find first free sector */
@@ -431,7 +455,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (!f)
{
debug("could not free cluster for file!\n");
- return MPIO_ERR_FAT_ERROR;
+ MPIO_ERR_RETURN(MPIO_ERR_FAT_ERROR);
} else {
memcpy(&firstblock, f, sizeof(mpio_fatentry_t));
start=f->entry;
@@ -459,7 +483,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (fd==-1)
{
debug("could not open file: %s\n", filename);
- return MPIO_ERR_FILE_NOT_FOUND;
+ MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND);
}
while ((filesize>BLOCK_SIZE) && (!abort)) {
@@ -473,7 +497,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (read(fd, block, toread)!=toread) {
debug("error reading file data\n");
close(fd);
- return MPIO_ERR_READING_FILE;
+ MPIO_ERR_RETURN(MPIO_ERR_READING_FILE);
}
filesize -= toread;
@@ -503,7 +527,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename,
if (read(fd, block, toread)!=toread) {
debug("error reading file data\n");
close(fd);
- return MPIO_ERR_READING_FILE;
+ MPIO_ERR_RETURN(MPIO_ERR_READING_FILE);
}
filesize -= toread;
@@ -650,7 +674,7 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, BYTE *filename,
/* please fix me sometime */
/* the system entry are kind of special ! */
if (strncmp("sysdum", filename, 6)==0)
- return MPIO_ERR_PERMISSION_DENIED;
+ MPIO_ERR_RETURN(MPIO_ERR_PERMISSION_DENIED);
if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
@@ -736,8 +760,41 @@ mpio_memory_debug(mpio_t *m, mpio_mem_t mem)
return 0;
}
+int
+mpio_errno(void)
+{
+ int no = _mpio_errno;
+ _mpio_errno = 0;
+
+ return no;
+}
-
+char *
+mpio_strerror(int errno)
+{
+ int i;
+
+ printf("mpio_strerror %d\n", errno);
+
+ if (errno >= 0) return NULL;
+
+ for (i = 0; i < mpio_error_num; i++) {
+ if (mpio_errors[i].id == errno)
+ return mpio_errors[i].msg;
+ }
+ return NULL;
+}
+void
+mpio_perror(char *prefix)
+{
+ char *msg = mpio_strerror(_mpio_errno);
+ if (msg == NULL) return;
+
+ if (prefix)
+ fprintf(stderr, "%s: %s\n", prefix, msg);
+ else
+ fprintf(stderr, "%s\n", msg);
+}
diff --git a/libmpio/mpio.h b/libmpio/mpio.h
index b4c381c..7df2349 100644
--- a/libmpio/mpio.h
+++ b/libmpio/mpio.h
@@ -1,7 +1,7 @@
/* -*- linux-c -*- */
/*
- * $Id: mpio.h,v 1.5 2002/09/18 22:18:29 germeier Exp $
+ * $Id: mpio.h,v 1.6 2002/09/19 20:46:02 crunchy Exp $
*
* Library for USB MPIO-*
*
@@ -95,6 +95,19 @@ int mpio_sync(mpio_t *, mpio_mem_t);
int mpio_memory_debug(mpio_t *, mpio_mem_t);
/*
+ * error handling
+ */
+
+/* returns error code of last error */
+int mpio_errno(void);
+
+/* returns the description of the error <errno> */
+char * mpio_strerror(int errno);
+
+/* prints the error message of the last error*/
+void mpio_perror(char *prefix);
+
+/*
* timeline:
* ---------
* 2004: some functions to change the order of files
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index 798dab6..1a02b04 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.11 2002/09/18 23:17:03 germeier Exp $
+ * $Id: callback.c,v 1.12 2002/09/19 20:46:02 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -355,10 +355,9 @@ mpiosh_cmd_mput(char *args[])
for (j = 0; j < size; j++, run++) {
if (!(error = regexec(&regex, (*run)->d_name, 0, NULL, 0))) {
printf("putting '%s' ... \n", (*run)->d_name);
- fsize = mpio_file_put(mpiosh.dev, mpiosh.card,
- (*run)->d_name, mpiosh_callback_put);
- if ((fsize < 0) && (fsize == MPIO_ERR_NOT_ENOUGH_SPACE)) {
- fprintf(stderr, "error: not enough space left on memory card\n");
+ if (mpio_file_put(mpiosh.dev, mpiosh.card,
+ (*run)->d_name, mpiosh_callback_put) == -1) {
+ mpio_perror("error");
break;
}