diff options
author | crunchy <crunchy> | 2002-09-18 20:32:21 +0000 |
---|---|---|
committer | crunchy <crunchy> | 2002-09-18 20:32:21 +0000 |
commit | 4a49120603daab9f9ad280f0ef44e36b0218a302 (patch) | |
tree | b52ecd086c0ffdb03018c7f1cbdfba5634ab923e /libmpio | |
parent | 4b5697d9e49aa865058acf71b9a464ff939e8b1e (diff) | |
download | mpiosh-4a49120603daab9f9ad280f0ef44e36b0218a302.tar.gz mpiosh-4a49120603daab9f9ad280f0ef44e36b0218a302.tar.bz2 mpiosh-4a49120603daab9f9ad280f0ef44e36b0218a302.zip |
bug fix for mput; removed compiler warnings; better return values on error
Diffstat (limited to 'libmpio')
-rw-r--r-- | libmpio/defs.h | 19 | ||||
-rw-r--r-- | libmpio/mpio.c | 35 |
2 files changed, 30 insertions, 24 deletions
diff --git a/libmpio/defs.h b/libmpio/defs.h index 7f247aa..7e06524 100644 --- a/libmpio/defs.h +++ b/libmpio/defs.h @@ -1,7 +1,7 @@ /* -*- linux-c -*- */ /* - * $Id: defs.h,v 1.5 2002/09/15 23:05:25 salmoon Exp $ + * $Id: defs.h,v 1.6 2002/09/18 20:32:21 crunchy Exp $ * * Library for USB MPIO-* * @@ -46,14 +46,6 @@ typedef enum { MPIO_MODEL_DME = 0x00, MPIO_MODEL_DMK = 0x04, MPIO_MODEL_UNKNOWN = 0x05 } mpio_model_t; -static BYTE *mpio_model_name[] = { - "MPIO-DME", - "MPIO-DMG", - "MPIO-DMB", - "MPIO-DMB+", - "MPIO-DMK", - "unknown" }; - /* USB commands */ typedef enum { GET_VERSION = 0x01, GET_BLOCK = 0x02, @@ -100,6 +92,15 @@ typedef enum { FTYPE_CONF = 'C', #define INFO_LINE 81 +/* error codes */ +#define MPIO_ERR_FILE_NOT_FOUND -1 +#define MPIO_ERR_NOT_ENOUGH_SPACE -2 +#define MPIO_ERR_FILE_EXISTS -3 +#define MPIO_ERR_FAT_ERROR -4 +#define MPIO_ERR_READING_FILE -5 +#define MPIO_ERR_PERMISSION_DENIED -6 +#define MPIO_ERR_WRITING_FILE -7 + /* get formatted information, about the MPIO player */ typedef struct { diff --git a/libmpio/mpio.c b/libmpio/mpio.c index 51a2894..35570e7 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.17 2002/09/15 12:03:23 germeier Exp $ + * $Id: mpio.c,v 1.18 2002/09/18 20:32:22 crunchy Exp $ * * Library for USB MPIO-* * @@ -43,6 +43,14 @@ #define DSTRING 100 +static BYTE *mpio_model_name[] = { + "MPIO-DME", + "MPIO-DMG", + "MPIO-DMB", + "MPIO-DMB+", + "MPIO-DMK", + "unknown" }; + void mpio_init_internal(mpio_t *); void mpio_init_external(mpio_t *); @@ -275,7 +283,6 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename, BYTE (*progress_callback)(int, int)) { mpio_smartmedia_t *sm; - BYTE fname[129]; BYTE block[BLOCK_SIZE]; int fd, towrite; BYTE *p; @@ -288,7 +295,7 @@ 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 0; + return MPIO_ERR_PERMISSION_DENIED; if (mem == MPIO_INTERNAL_MEM) sm = &m->internal; if (mem == MPIO_EXTERNAL_MEM) sm = &m->external; @@ -323,7 +330,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, BYTE *filename, debug("error writing file data\n"); close(fd); free (f); - return -1; + return MPIO_ERR_WRITING_FILE; } filesize -= towrite; @@ -360,7 +367,6 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename, mpio_smartmedia_t *sm; mpio_fatentry_t *f, current, firstblock, backup; WORD start; - int data_offset; BYTE block[BLOCK_SIZE]; int fd, toread; struct stat file_stat; @@ -374,7 +380,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 0; + return MPIO_ERR_FILE_NOT_FOUND; } fsize=filesize=file_stat.st_size; debugn(2, "filesize: %d\n", fsize); @@ -383,7 +389,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 0; + return MPIO_ERR_NOT_ENOUGH_SPACE; } /* check if filename already exists */ @@ -393,7 +399,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename, if (p) { debug("filename already exists\n"); - return 0; + return MPIO_ERR_FILE_EXISTS; } /* find first free sector */ @@ -401,7 +407,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, BYTE *filename, if (!f) { debug("could not free cluster for file!\n"); - return 0; + return MPIO_ERR_FAT_ERROR; } else { memcpy(&firstblock, f, sizeof(mpio_fatentry_t)); start=f->entry; @@ -429,7 +435,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 0; + return MPIO_ERR_FILE_NOT_FOUND; } while ((filesize>BLOCK_SIZE) && (!abort)) { @@ -443,7 +449,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 -1; + return MPIO_ERR_READING_FILE; } filesize -= toread; @@ -473,7 +479,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 -1; + return MPIO_ERR_READING_FILE; } filesize -= toread; @@ -544,7 +550,6 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem, mpio_smartmedia_t *sm; mpio_fatentry_t *f; DWORD clusters; - DWORD i; BYTE abort = 0; if (mem == MPIO_INTERNAL_MEM) @@ -621,7 +626,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 0; + return MPIO_ERR_PERMISSION_DENIED; if (mem == MPIO_INTERNAL_MEM) sm = &m->internal; if (mem == MPIO_EXTERNAL_MEM) sm = &m->external; @@ -684,7 +689,7 @@ int mpio_sync(mpio_t *m, mpio_mem_t mem) { /* this writes the FAT *and* the root directory */ - mpio_fat_write(m, mem); + return mpio_fat_write(m, mem); } int |