From 13b7579bd45e89304b8697a6fb471bf0524f49d4 Mon Sep 17 00:00:00 2001 From: germeier Date: Sun, 27 Oct 2002 02:45:28 +0000 Subject: added code to read/write and display config files (CONFIG.DAT and FMCONFIG.DAT) another 8.3 fix :-( --- libmpio/defs.h | 9 +++++-- libmpio/directory.c | 4 +-- libmpio/fat.c | 18 ++++++++++--- libmpio/mpio.c | 76 ++++++++++++++++++++++++++++++++++++++++++++--------- libmpio/mpio.h | 29 ++++++++++++++++++-- 5 files changed, 114 insertions(+), 22 deletions(-) (limited to 'libmpio') diff --git a/libmpio/defs.h b/libmpio/defs.h index 89195f0..49d8311 100644 --- a/libmpio/defs.h +++ b/libmpio/defs.h @@ -1,7 +1,7 @@ /* -*- linux-c -*- */ /* - * $Id: defs.h,v 1.12 2002/10/26 13:07:43 germeier Exp $ + * $Id: defs.h,v 1.13 2002/10/27 02:45:28 germeier Exp $ * * Library for USB MPIO-* * @@ -63,7 +63,8 @@ typedef enum { GET_VERSION = 0x01, /* file types on internal memory */ /* found in the code of salmoon, are these needed? -mager */ -typedef enum { FTYPE_MUSIC = 0x01, +typedef enum { FTYPE_CHAN = 0x00, + FTYPE_MUSIC = 0x01, FTYPE_CONF = 'C', FTYPE_FONT = 'F', FTYPE_OTHER = 'H', @@ -71,6 +72,10 @@ typedef enum { FTYPE_MUSIC = 0x01, FTYPE_WAV = 'V', FTYPE_ENTRY = 'R' } mpio_filetype_t; +/* fixed filenames */ +#define MPIO_CONFIG_FILE "CONFIG.DAT" +#define MPIO_CHANNEL_FILE "FMCONFIG.DAT" + /* type of callback functions */ typedef BYTE (*mpio_callback_t)(int, int) ; typedef BYTE (*mpio_callback_init_t)(mpio_mem_t, int, int) ; diff --git a/libmpio/directory.c b/libmpio/directory.c index d3cd677..4795b3d 100644 --- a/libmpio/directory.c +++ b/libmpio/directory.c @@ -1,6 +1,6 @@ /* * - * $Id: directory.c,v 1.8 2002/10/17 22:49:27 germeier Exp $ + * $Id: directory.c,v 1.9 2002/10/27 02:45:28 germeier Exp $ * * Library for USB MPIO-* * @@ -525,7 +525,7 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem, f_8_3[12]=0x00; i=0; - while ((i<6) && (filename[i] != '.') && (i<(strlen(filename)))) + while ((i<8) && (filename[i] != '.') && (i<(strlen(filename)))) { f_8_3[i] = toupper(filename[i]); i++; diff --git a/libmpio/fat.c b/libmpio/fat.c index ad9f9dd..8582aa9 100644 --- a/libmpio/fat.c +++ b/libmpio/fat.c @@ -1,6 +1,6 @@ -/* + /* * - * $Id: fat.c,v 1.18 2002/10/13 12:03:51 germeier Exp $ + * $Id: fat.c,v 1.19 2002/10/27 02:45:28 germeier Exp $ * * Library for USB MPIO-* * @@ -498,7 +498,8 @@ mpio_fatentry_read(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f ) (sm->fat[e+0x00] != 0xee))) { debug("defective block encountered, abort reading!\n"); - return 0xaaaaaaaa; +/* return 0xaaaaaaaa; */ + return 0xffffffff; } /* this is a special system file! */ if((sm->fat[e+6] != FTYPE_MUSIC) && @@ -507,7 +508,16 @@ mpio_fatentry_read(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f ) (sm->fat[e+9] == 0xff) && (sm->fat[e+10] == 0xff)) return 0xffffffff; - + /* this is a special system file! */ + if (sm->fat[e+6] == FTYPE_CONF) + return 0xffffffff; + /* this is a special system file! */ + if((sm->fat[e+6] != FTYPE_MUSIC) && + (sm->fat[e+0x0b] == 0xff) && + (sm->fat[e+0x0c] == 0xff) && + (sm->fat[e+0x0d] == 0xff)) + return 0xffffffff; + if((sm->fat[e+7] == 0xff) && (sm->fat[e+8] == 0xff) && (sm->fat[e+9] == 0xff) && diff --git a/libmpio/mpio.c b/libmpio/mpio.c index 871bd98..e2a6ec5 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.34 2002/10/26 13:07:43 germeier Exp $ + * $Id: mpio.c,v 1.35 2002/10/27 02:45:28 germeier Exp $ * * Library for USB MPIO-* * @@ -46,6 +46,10 @@ void mpio_init_internal(mpio_t *); void mpio_init_external(mpio_t *); int mpio_check_filename(mpio_filename_t); +int mpio_file_get_real(mpio_t *, mpio_mem_t, mpio_filename_t, + mpio_callback_t, BYTE **); +int mpio_file_put_real(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_filetype_t, + mpio_callback_t, BYTE *, int); static BYTE *mpio_model_name[] = { "MPIO-DME", @@ -391,6 +395,20 @@ mpio_get_info(mpio_t *m, mpio_info_t *info) int mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, mpio_callback_t progress_callback) +{ + return mpio_file_get_real(m, mem, filename, progress_callback, NULL); +} + +int +mpio_file_get_to_memory(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, + mpio_callback_t progress_callback, BYTE **memory) +{ + return mpio_file_get_real(m, mem, filename, progress_callback, memory); +} + +int +mpio_file_get_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, + mpio_callback_t progress_callback, BYTE **memory) { mpio_smartmedia_t *sm; BYTE block[BLOCK_SIZE]; @@ -418,9 +436,14 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, if (f && p) { filesize=fsize=mpio_dentry_get_filesize(m, mem, p); - - unlink(filename); - fd = open(filename, (O_RDWR | O_CREAT), (S_IRWXU | S_IRGRP | S_IROTH)); + + if (memory) + { + *memory = malloc(filesize); + } else { + unlink(filename); + fd = open(filename, (O_RDWR | O_CREAT), (S_IRWXU | S_IRGRP | S_IROTH)); + } do { @@ -431,13 +454,19 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, } else { towrite = filesize; } + + if (memory) + { + memcpy((*memory)+(fsize-filesize) , block, towrite); + } else { + if (write(fd, block, towrite) != towrite) { + debug("error writing file data\n"); + close(fd); + free (f); + MPIO_ERR_RETURN(MPIO_ERR_WRITING_FILE); + } + } - if (write(fd, block, towrite) != towrite) { - debug("error writing file data\n"); - close(fd); - free (f); - MPIO_ERR_RETURN(MPIO_ERR_WRITING_FILE); - } filesize -= towrite; if (progress_callback) @@ -451,8 +480,11 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, if (merror<0) debug("defective block encountered!\n"); - close (fd); - free (f); + if(!memory) + { + close (fd); + free (f); + } /* read and copied code from mtools-3.9.8/mcopy.c * to make this one right @@ -473,6 +505,26 @@ int mpio_file_put(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, mpio_filetype_t filetype, mpio_callback_t progress_callback) +{ + return mpio_file_put_real(m, mem, filename, filetype, + progress_callback, NULL,0); +} + +int +mpio_file_put_from_memory(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, + mpio_filetype_t filetype, + mpio_callback_t progress_callback, + BYTE *memory, int memory_size) +{ + return mpio_file_put_real(m, mem, filename, filetype, + progress_callback, memory, memory_size); +} + +int +mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, + mpio_filetype_t filetype, + mpio_callback_t progress_callback, + BYTE *memory, int memory_size) { mpio_smartmedia_t *sm; mpio_fatentry_t *f, current, firstblock, backup; diff --git a/libmpio/mpio.h b/libmpio/mpio.h index a36cc49..51decef 100644 --- a/libmpio/mpio.h +++ b/libmpio/mpio.h @@ -1,7 +1,7 @@ #/* -*- linux-c -*- */ /* - * $Id: mpio.h,v 1.10 2002/10/26 13:07:43 germeier Exp $ + * $Id: mpio.h,v 1.11 2002/10/27 02:45:28 germeier Exp $ * * Library for USB MPIO-* * @@ -75,16 +75,41 @@ BYTE* mpio_dentry_next(mpio_t *, mpio_mem_t, BYTE *); int mpio_dentry_get(mpio_t *, mpio_mem_t, BYTE *, BYTE *, int,WORD *, BYTE *, BYTE *, BYTE *, BYTE *, DWORD *); +/* + * reading/writing/deleting of files + */ + /* context, memory bank, filename, callback */ int mpio_file_get(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_callback_t); -/* context, memory bank, filename, callback */ +/* context, memory bank, filename, filetype, callback */ int mpio_file_put(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_filetype_t, mpio_callback_t); /* context, memory bank, filename, callback */ int mpio_file_del(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_callback_t); +/* + * reading/writing files into memory (used for config+font files) + */ + +/* context, memory bank, filename, callback, pointer to memory */ +/* the needed memory is allocated and the memory pointer is return */ +/* via the "BYTE **" */ + +int mpio_file_get_to_memory(mpio_t *, mpio_mem_t, mpio_filename_t, + mpio_callback_t, BYTE **); + +/* context, memory bank, filename, filetype, callback ... */ +/* ... memory pointer, size of file */ +int mpio_file_put_from_memory(mpio_t *, mpio_mem_t, mpio_filename_t, + mpio_filetype_t, mpio_callback_t, + BYTE *, int); + +/* + * formating a memory (internal mem or external SmartMedia card) + */ + /* context, memory bank, callback */ int mpio_memory_format(mpio_t *, mpio_mem_t, mpio_callback_t); -- cgit v1.2.3