From d9ec7993f9705a100043fc890eaa050bcba05349 Mon Sep 17 00:00:00 2001 From: germeier Date: Tue, 24 Sep 2002 15:38:03 +0000 Subject: fixed issues with 8.3 names in directory.c actually use mpio_filetype_t to tag files during writing of internal memory writing of Config.dat does work now (though it needs some code in mpiosh) --- ChangeLog | 10 ++++++++++ libmpio/defs.h | 7 ++++--- libmpio/directory.c | 35 ++++++++++++++++++++++++++++------- libmpio/fat.c | 48 ++++++++++++++++++++++++++++-------------------- libmpio/fat.h | 6 +++--- libmpio/mpio.c | 23 +++++++---------------- libmpio/mpio.h | 5 +++-- mpiosh/callback.c | 8 ++++---- 8 files changed, 87 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index f16b419..f059c90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-09-24 Markus Germeier + * libmpio/directory.c (mpio_dentry_put): fixed 8.3 handling + to allow correct writing of CONFIG.DAT + (mpio_dentry_find_name_8_3): fixed handling of given filename + * libmpio/mpio.c (mpio_file_del, mpio_file_get): + system files (like sysdum?.du?) can now be read and deleted + (mpio_file_put): use mpio_filetype_t to tag files which are + written to the internal memory (it is now possible to write + config files back to the player) + 2002-09-24 Markus Germeier * a lot of little changes and updates * mpiosh/callback.c (mpiosh_cmd_dump_mem): diff --git a/libmpio/defs.h b/libmpio/defs.h index a6422cd..68a87ca 100644 --- a/libmpio/defs.h +++ b/libmpio/defs.h @@ -1,7 +1,7 @@ /* -*- linux-c -*- */ /* - * $Id: defs.h,v 1.9 2002/09/23 22:38:03 germeier Exp $ + * $Id: defs.h,v 1.10 2002/09/24 15:38:03 germeier Exp $ * * Library for USB MPIO-* * @@ -59,12 +59,13 @@ typedef enum { GET_VERSION = 0x01, /* file types on internal memory */ /* found in the code of salmoon, are these needed? -mager */ -typedef enum { FTYPE_CONF = 'C', +typedef enum { FTYPE_MUSIC = 0x01, + FTYPE_CONF = 'C', FTYPE_FONT = 'F', FTYPE_OTHER = 'H', FTYPE_MEMO = 'M', FTYPE_WAV = 'V', - FTYPE_ENTRY = 'R' } mpio_file_t; + FTYPE_ENTRY = 'R' } mpio_filetype_t; /* type of callback functions */ typedef BYTE (*mpio_callback_t)(int, int) ; diff --git a/libmpio/directory.c b/libmpio/directory.c index 0991cc1..ea51ac3 100644 --- a/libmpio/directory.c +++ b/libmpio/directory.c @@ -1,6 +1,6 @@ /* * - * $Id: directory.c,v 1.6 2002/09/14 22:54:41 germeier Exp $ + * $Id: directory.c,v 1.7 2002/09/24 15:38:03 germeier Exp $ * * Library for USB MPIO-* * @@ -414,7 +414,7 @@ mpio_dentry_get_startcluster(mpio_t *m, mpio_mem_t mem, BYTE *p) if (cluster < 0) return NULL; - new = mpio_fatentry_new(m, mem, cluster); + new = mpio_fatentry_new(m, mem, cluster, FTYPE_MUSIC); if (mem == MPIO_INTERNAL_MEM) { @@ -515,8 +515,6 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem, /* find uniq 8.3 filename */ memset(f_8_3, 0x20, 12); - f_8_3[6]='~'; - f_8_3[7]='1'; f_8_3[8]='.'; f_8_3[12]=0x00; @@ -540,6 +538,12 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem, j++; } + if (mpio_dentry_find_name_8_3(m, mem, f_8_3)) + { + f_8_3[6]='~'; + f_8_3[7]='1'; + } + while(mpio_dentry_find_name_8_3(m, mem, f_8_3)) f_8_3[7]++; @@ -597,8 +601,25 @@ mpio_dentry_find_name_8_3(mpio_t *m, BYTE mem, BYTE *filename) WORD wdummy; BYTE fname[129]; BYTE fname_8_3[13]; + BYTE filename_8_3[13]; DWORD ddummy; BYTE *found = 0; + int i, j, len; + + /* format given filename to a "standard" 8.3 filename */ + memset(filename_8_3, 0x20, 13); + filename_8_3[12]=0; + len=strlen(filename); + i=j=0; + while ((i<13) && (j i_fat, 0xff, 0x10); new->i_fat[0x00] = 0xaa; /* start of file */ - new->i_fat[0x06] = 0x01; /* filetype, hmm ... */ + new->i_fat[0x06] = ftype; new->i_fat[0x0b] = 0x00; new->i_fat[0x0c] = 0x00; new->i_fat[0x0d] = 0x00; @@ -341,17 +341,24 @@ mpio_fatentry_read(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f ) debug("defective block encountered, abort reading!\n"); return 0xaaaaaaaa; } - e += 7; - if((sm->fat[e+0] == 0xff) && - (sm->fat[e+1] == 0xff) && - (sm->fat[e+2] == 0xff) && - (sm->fat[e+3] == 0xff)) + /* this is a special system file! */ + if((sm->fat[e+6] != FTYPE_MUSIC) && + (sm->fat[e+7] == 0xff) && + (sm->fat[e+8] == 0x00) && + (sm->fat[e+9] == 0xff) && + (sm->fat[e+10] == 0xff)) + return 0xffffffff; + + if((sm->fat[e+7] == 0xff) && + (sm->fat[e+8] == 0xff) && + (sm->fat[e+9] == 0xff) && + (sm->fat[e+10] == 0xff)) return 0xffffffff; - v = sm->fat[e+0] * 0x1000000 + - sm->fat[e+1] * 0x10000 + - sm->fat[e+2] * 0x100 + - sm->fat[e+3]; + v = sm->fat[e+7] * 0x1000000 + + sm->fat[e+8] * 0x10000 + + sm->fat[e+9] * 0x100 + + sm->fat[e+10]; return v; } @@ -427,7 +434,7 @@ mpio_fat_internal_find_startsector(mpio_t *m, BYTE start) mpio_smartmedia_t *sm = &m->internal; int found=-1; - f = mpio_fatentry_new(m, MPIO_INTERNAL_MEM, 0); + f = mpio_fatentry_new(m, MPIO_INTERNAL_MEM, 0, FTYPE_MUSIC); while(mpio_fatentry_plus_plus(f)) { @@ -451,7 +458,7 @@ mpio_fat_internal_find_fileindex(mpio_t *m) memset(index, 1, 256); - f = mpio_fatentry_new(m, MPIO_INTERNAL_MEM, 0); + f = mpio_fatentry_new(m, MPIO_INTERNAL_MEM, 0, FTYPE_MUSIC); while(mpio_fatentry_plus_plus(f)) { if (sm->fat[f->entry * 0x10 + 1] != 0xff) @@ -483,7 +490,7 @@ mpio_fat_free_clusters(mpio_t *m, mpio_mem_t mem) int e = 0; int fsize; - f = mpio_fatentry_new(m, mem, 0); + f = mpio_fatentry_new(m, mem, 0, FTYPE_MUSIC); do { @@ -497,11 +504,11 @@ mpio_fat_free_clusters(mpio_t *m, mpio_mem_t mem) } mpio_fatentry_t * -mpio_fatentry_find_free(mpio_t *m, mpio_mem_t mem) +mpio_fatentry_find_free(mpio_t *m, mpio_mem_t mem, BYTE ftype) { mpio_fatentry_t *f; - f = mpio_fatentry_new(m, mem, 1); + f = mpio_fatentry_new(m, mem, 1, ftype); while(mpio_fatentry_plus_plus(f)) { @@ -589,7 +596,7 @@ mpio_fat_clear(mpio_t *m, mpio_mem_t mem) if (mem == MPIO_INTERNAL_MEM) { sm = &m->internal; - f = mpio_fatentry_new(m, mem, 1); + f = mpio_fatentry_new(m, mem, 1, FTYPE_MUSIC); do { mpio_fatentry_set_free(m, mem, f) ; } while(mpio_fatentry_plus_plus(f)); @@ -627,7 +634,7 @@ mpio_fat_write(mpio_t *m, mpio_mem_t mem) if (mem == MPIO_INTERNAL_MEM) { sm = &m->internal; - f=mpio_fatentry_new(m, mem, 0); + f=mpio_fatentry_new(m, mem, 0, FTYPE_MUSIC); mpio_io_block_delete(m, mem, f); free(f); @@ -656,7 +663,8 @@ mpio_fat_write(mpio_t *m, mpio_mem_t mem) /* yuck */ f=mpio_fatentry_new(m, mem, ((i / 0x20) - - ((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2 ))); + ((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2 )), + FTYPE_MUSIC); mpio_io_block_delete(m, mem, f); free(f); } diff --git a/libmpio/fat.h b/libmpio/fat.h index 84963b5..65e0857 100644 --- a/libmpio/fat.h +++ b/libmpio/fat.h @@ -1,6 +1,6 @@ /* * - * $Id: fat.h,v 1.7 2002/09/23 22:38:03 germeier Exp $ + * $Id: fat.h,v 1.8 2002/09/24 15:38:03 germeier Exp $ * * Library for USB MPIO-* * @@ -36,10 +36,10 @@ int mpio_fat_clear(mpio_t *, mpio_mem_t); int mpio_fat_free_clusters(mpio_t *, mpio_mem_t); int mpio_fat_free(mpio_t *, mpio_mem_t); -mpio_fatentry_t *mpio_fatentry_new(mpio_t *, mpio_mem_t, DWORD); +mpio_fatentry_t *mpio_fatentry_new(mpio_t *, mpio_mem_t, DWORD, BYTE); int mpio_fatentry_plus_plus(mpio_fatentry_t *); -mpio_fatentry_t *mpio_fatentry_find_free(mpio_t *, mpio_mem_t); +mpio_fatentry_t *mpio_fatentry_find_free(mpio_t *, mpio_mem_t, BYTE); int mpio_fatentry_next_free(mpio_t *, mpio_mem_t, mpio_fatentry_t *); int mpio_fatentry_next_entry(mpio_t *, mpio_mem_t, diff --git a/libmpio/mpio.c b/libmpio/mpio.c index 97c5884..6e2fd45 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.26 2002/09/23 22:38:03 germeier Exp $ + * $Id: mpio.c,v 1.27 2002/09/24 15:38:03 germeier Exp $ * * Library for USB MPIO-* * @@ -381,11 +381,6 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, MPIO_CHECK_FILENAME(filename); - /* please fix me sometime */ - /* the system entries are kind of special ! */ - 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; @@ -454,6 +449,7 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, int mpio_file_put(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, + mpio_filetype_t filetype, mpio_callback_t progress_callback) { mpio_smartmedia_t *sm; @@ -497,7 +493,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, } /* find first free sector */ - f = mpio_fatentry_find_free(m, mem); + f = mpio_fatentry_find_free(m, mem, filetype); if (!f) { debug("could not free cluster for file!\n"); @@ -637,8 +633,7 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, } int -mpio_memory_format(mpio_t *m, mpio_mem_t mem, - BYTE (*progress_callback)(int, int)) +mpio_memory_format(mpio_t *m, mpio_mem_t mem, mpio_callback_t progress_callback) { int data_offset; mpio_smartmedia_t *sm; @@ -665,7 +660,7 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem, */ mpio_fat_clear(m, mem); - f = mpio_fatentry_new(m, mem, data_offset); + f = mpio_fatentry_new(m, mem, data_offset, FTYPE_MUSIC); do { if (!mpio_io_block_delete(m, mem, f)) @@ -689,7 +684,8 @@ mpio_memory_format(mpio_t *m, mpio_mem_t mem, if (mem == MPIO_EXTERNAL_MEM) { /* format CIS area */ f = mpio_fatentry_new(m, mem, /* yuck */ - (1-((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2))); + (1-((sm->dir_offset + DIR_NUM)/BLOCK_SECTORS - 2)), + FTYPE_MUSIC); mpio_io_block_delete(m, mem, f); free(f); mpio_io_sector_write(m, mem, 0x20, sm->cis); @@ -719,11 +715,6 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, MPIO_CHECK_FILENAME(filename); - /* please fix me sometime */ - /* the system entry are kind of special ! */ - 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; diff --git a/libmpio/mpio.h b/libmpio/mpio.h index 10272c9..d90591f 100644 --- a/libmpio/mpio.h +++ b/libmpio/mpio.h @@ -1,7 +1,7 @@ #/* -*- linux-c -*- */ /* - * $Id: mpio.h,v 1.8 2002/09/23 22:38:03 germeier Exp $ + * $Id: mpio.h,v 1.9 2002/09/24 15:38:03 germeier Exp $ * * Library for USB MPIO-* * @@ -75,7 +75,8 @@ int mpio_dentry_get(mpio_t *, mpio_mem_t, BYTE *, BYTE *, int,WORD *, int mpio_file_get(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_callback_t); /* context, memory bank, filename, callback */ -int mpio_file_put(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_callback_t); +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); diff --git a/mpiosh/callback.c b/mpiosh/callback.c index 8fd1e5f..cc99d29 100644 --- a/mpiosh/callback.c +++ b/mpiosh/callback.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: callback.c,v 1.18 2002/09/23 22:38:03 germeier Exp $ + * $Id: callback.c,v 1.19 2002/09/24 15:38:03 germeier Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -352,7 +352,7 @@ mpiosh_cmd_put(char *args[]) MPIOSH_CHECK_CONNECTION_CLOSED; MPIOSH_CHECK_ARG; - if ((size = mpio_file_put(mpiosh.dev, mpiosh.card, args[0], + if ((size = mpio_file_put(mpiosh.dev, mpiosh.card, args[0], FTYPE_MUSIC, mpiosh_callback_put)) == -1) { mpio_perror("error"); } else { @@ -400,8 +400,8 @@ mpiosh_cmd_mput(char *args[]) if (!(error = regexec(®ex, (*run)->d_name, 0, NULL, 0))) { printf("putting '%s' ... \n", (*run)->d_name); - if (mpio_file_put(mpiosh.dev, mpiosh.card, - (*run)->d_name, mpiosh_callback_put) == -1) { + if (mpio_file_put(mpiosh.dev, mpiosh.card, (*run)->d_name, + FTYPE_MUSIC, mpiosh_callback_put) == -1) { mpio_perror("error"); /* an existing file is no reason for a complete abort!! */ if (mpio_errno()==MPIO_ERR_FILE_EXISTS) -- cgit v1.2.3