diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | libmpio/directory.c | 96 | ||||
-rw-r--r-- | libmpio/directory.h | 11 | ||||
-rw-r--r-- | libmpio/mpio.c | 3 | ||||
-rw-r--r-- | libmpio/mpio.h | 10 | ||||
-rw-r--r-- | mpiosh/callback.c | 18 |
6 files changed, 89 insertions, 57 deletions
@@ -1,3 +1,11 @@ +2002-09-15 Markus Germeier <mager@tzi.de> + + * libmpio/directory.c: add debug informations, + (mpio_dentry_get): fixed a off-by-one error + + * libmpio/mpio.h: add mpio_mem_t to dentry functions + to enable further debugging + 2002-09-14 Andreas Buesching <crunchy@tzi.de> * mpiosh/mpiosh.c: does not hang anymore after reading commands diff --git a/libmpio/directory.c b/libmpio/directory.c index 81447a0..0991cc1 100644 --- a/libmpio/directory.c +++ b/libmpio/directory.c @@ -1,6 +1,6 @@ /* * - * $Id: directory.c,v 1.5 2002/09/11 21:34:19 germeier Exp $ + * $Id: directory.c,v 1.6 2002/09/14 22:54:41 germeier Exp $ * * Library for USB MPIO-* * @@ -68,7 +68,7 @@ int date_dos2unix(unsigned short time,unsigned short date) /* directory operations */ BYTE * -mpio_directory_open(mpio_t *m, BYTE mem) +mpio_directory_open(mpio_t *m, mpio_mem_t mem) { BYTE *out; if (mem == MPIO_EXTERNAL_MEM) { @@ -81,14 +81,19 @@ mpio_directory_open(mpio_t *m, BYTE mem) out = m->internal.dir; } - if (out[0] == 0x00) - return NULL; + if (out[0] == 0x00) + { + debugn(3, "directory is empty\n"); + return NULL; + } + + debugn(3, "first dentry: %08x\n", out); return out; } int -mpio_dentry_get_size(mpio_t *m, BYTE *buffer) +mpio_dentry_get_size(mpio_t *m, mpio_mem_t mem, BYTE *buffer) { mpio_dir_entry_t *dentry; @@ -117,29 +122,37 @@ mpio_dentry_get_size(mpio_t *m, BYTE *buffer) } BYTE* -mpio_dentry_next(mpio_t *m, BYTE *buffer) +mpio_dentry_next(mpio_t *m, mpio_mem_t mem, BYTE *buffer) { int size; BYTE *out; - size = mpio_dentry_get_size(m, buffer); - if (size<0) + size = mpio_dentry_get_size(m, mem, buffer); + + if (size<=0) return NULL; out = buffer + size; - if (*out == 0x00) - return NULL; + if (*out == 0x00) + { + debugn(3, "no more entries\n"); + return NULL; + } + + debugn(3, "next dentry: %08x\n", out); return out; } int -mpio_dentry_get_raw(mpio_t *m, BYTE *dentry, BYTE *buffer, int bufsize) +mpio_dentry_get_raw(mpio_t *m, mpio_mem_t mem, BYTE *dentry, + BYTE *buffer, int bufsize) { int size; - size = mpio_dentry_get_size(m, buffer); + size = mpio_dentry_get_size(m, mem, buffer); + debugn(3, "dentry size is: 0x%02x\n", size); if (size < 0) return size; @@ -169,23 +182,23 @@ mpio_dentry_copy_to_slot(BYTE *buffer, mpio_dir_slot_t *slot) } int -mpio_dentry_get(mpio_t *m, BYTE *buffer, +mpio_dentry_get(mpio_t *m, mpio_mem_t mem, BYTE *buffer, BYTE *filename, int filename_size, WORD *year, BYTE *month, BYTE *day, BYTE *hour, BYTE *minute, DWORD *fsize) { - BYTE filename_8_3[12]; + BYTE filename_8_3[13]; - return mpio_dentry_get_real(m, buffer, filename, filename_size, + return mpio_dentry_get_real(m, mem, buffer, filename, filename_size, filename_8_3, year, month, day, hour, minute, fsize); } /* TODO: please clean me up !!! */ int -mpio_dentry_get_real(mpio_t *m, BYTE *buffer, +mpio_dentry_get_real(mpio_t *m, mpio_mem_t mem, BYTE *buffer, BYTE *filename, int filename_size, - BYTE filename_8_3[12], + BYTE *filename_8_3, WORD *year, BYTE *month, BYTE *day, BYTE *hour, BYTE *minute, DWORD *fsize) { @@ -193,13 +206,14 @@ mpio_dentry_get_real(mpio_t *m, BYTE *buffer, int vfat = 0; int num_slots = 0; int slots = 0; - int in = 0, out = 0; + int in = 0, out = 0, iconv_return; mpio_dir_entry_t *dentry; mpio_dir_slot_t *slot; BYTE *unicode = 0; BYTE *uc; BYTE *fname = 0; iconv_t ic; + int dsize; if (buffer == NULL) return -1; @@ -211,11 +225,17 @@ mpio_dentry_get_real(mpio_t *m, BYTE *buffer, (dentry->start[0] == 0x00) && (dentry->start[1] == 0x00)) { - num_slots = (mpio_dentry_get_size(m, buffer) / 0x20) - 1; + dsize = mpio_dentry_get_size(m, mem, buffer); + debugn(3, "dentry size is: 0x%02x\n", dsize); + hexdump(buffer, dsize); + num_slots = (dsize / 0x20) - 1; slots = num_slots - 1; dentry++; vfat++; - unicode = malloc(256); + in = num_slots * 26; + out = num_slots * 13; + unicode = malloc(in + 2); + memset(unicode, 0x00, (in+2)); uc = unicode; fname = filename; slot = (mpio_dir_slot_t *)buffer; @@ -237,31 +257,33 @@ mpio_dentry_get_real(mpio_t *m, BYTE *buffer, if (vfat) { ic = iconv_open("ASCII", "UNICODE"); - in = num_slots * 26; - out = num_slots * 13; memset(fname, 0, filename_size); - iconv(ic, (char **)&uc, &in, (char **)&fname, &out); + hexdumpn(4, unicode, in+2); + debugn(4, "before iconv: in: %2d - out: %2d\n", in, out); + iconv_return = iconv(ic, (char **)&uc, &in, (char **)&fname, &out); + debugn(4, "after iconv: in: %2d - out: %2d (return: %d)\n", in, out, + iconv_return); + hexdumpn(4, filename, (num_slots*13)-out); iconv_close(ic); - free(unicode); } + free(unicode); memcpy(filename_8_3, dentry->name, 8); filename_8_3[0x08] = '.'; memcpy(filename_8_3 + 0x09, dentry->ext, 3); filename_8_3[0x0c] = 0; - + hexdumpn(4, filename_8_3, 13); + if (!vfat) { if (filename_size >= 12) { snprintf(filename, 13, "%s", filename_8_3); } else { - snprintf(filename, 12, "%s", "ERROR"); + snprintf(filename, filename_size, "%s", "ERROR"); } } -/* hexdumpn(0, filename_8_3, 13); */ - date = (dentry->date[1] * 0x100) + dentry->date[0]; *year = date / 512 + 1980; *month = (date / 32) & 0xf; @@ -323,7 +345,7 @@ mpio_dentry_get_filesize(mpio_t *m, mpio_mem_t mem, BYTE *p) int fsize; mpio_dir_entry_t *dentry; - s = mpio_dentry_get_size(m, p); + s = mpio_dentry_get_size(m, mem, p); s -= DIR_ENTRY_SIZE ; dentry = (mpio_dir_entry_t *)p; @@ -350,7 +372,7 @@ mpio_dentry_get_time(mpio_t *m, mpio_mem_t mem, BYTE *p) int s; mpio_dir_entry_t *dentry; - s = mpio_dentry_get_size(m, p); + s = mpio_dentry_get_size(m, mem, p); s -= DIR_ENTRY_SIZE ; dentry = (mpio_dir_entry_t *)p; @@ -375,7 +397,7 @@ mpio_dentry_get_startcluster(mpio_t *m, mpio_mem_t mem, BYTE *p) mpio_dir_slot_t *dentry; mpio_fatentry_t *new; - s = mpio_dentry_get_size(m, p); + s = mpio_dentry_get_size(m, mem, p); s -= DIR_ENTRY_SIZE ; dentry = (mpio_dir_slot_t *)p; @@ -404,7 +426,7 @@ mpio_dentry_get_startcluster(mpio_t *m, mpio_mem_t mem, BYTE *p) } int -mpio_dentry_put(mpio_t *m, BYTE mem, +mpio_dentry_put(mpio_t *m, mpio_mem_t mem, BYTE *filename, int filename_size, time_t date, DWORD fsize, WORD ssector) { @@ -580,7 +602,7 @@ mpio_dentry_find_name_8_3(mpio_t *m, BYTE mem, BYTE *filename) p = mpio_directory_open(m, mem); while ((p) && (!found)) { - mpio_dentry_get_real (m, p, + mpio_dentry_get_real (m, mem, p, fname, 128, fname_8_3, &wdummy, &bdummy, &bdummy, @@ -592,7 +614,7 @@ mpio_dentry_find_name_8_3(mpio_t *m, BYTE mem, BYTE *filename) p = NULL; } - p = mpio_dentry_next(m, p); + p = mpio_dentry_next(m, mem, p); } return found; @@ -610,7 +632,7 @@ mpio_dentry_find_name(mpio_t *m, BYTE mem, BYTE *filename) p = mpio_directory_open(m, mem); while ((p) && (!found)) { - mpio_dentry_get (m, p, + mpio_dentry_get (m, mem, p, fname, 128, &wdummy, &bdummy, &bdummy, &bdummy, &bdummy, &ddummy); @@ -619,7 +641,7 @@ mpio_dentry_find_name(mpio_t *m, BYTE mem, BYTE *filename) p = NULL; } - p = mpio_dentry_next(m, p); + p = mpio_dentry_next(m, mem, p); } return found; @@ -648,7 +670,7 @@ mpio_dentry_delete(mpio_t *m, BYTE mem, BYTE *filename) return 0; } - size = mpio_dentry_get_size(m, start); + size = mpio_dentry_get_size(m, mem, start); if (size <= 0) { debug("fatal error in mpio_dentry_delete\n"); diff --git a/libmpio/directory.h b/libmpio/directory.h index 6982e8b..2bd1b89 100644 --- a/libmpio/directory.h +++ b/libmpio/directory.h @@ -1,6 +1,6 @@ /* * - * $Id: directory.h,v 1.3 2002/09/11 21:34:19 germeier Exp $ + * $Id: directory.h,v 1.4 2002/09/14 22:54:41 germeier Exp $ * * Library for USB MPIO-* * @@ -35,9 +35,9 @@ int mpio_rootdir_clear (mpio_t *, mpio_mem_t); int mpio_rootdir_format(mpio_t *, mpio_mem_t); /* operations on a single directory entry */ -int mpio_dentry_get_size(mpio_t *, BYTE *); -int mpio_dentry_get_raw(mpio_t *, BYTE *, BYTE *, int); -int mpio_dentry_put(mpio_t *, BYTE, BYTE *, int, +int mpio_dentry_get_size(mpio_t *, mpio_mem_t, BYTE *); +int mpio_dentry_get_raw(mpio_t *, mpio_mem_t, BYTE *, BYTE *, int); +int mpio_dentry_put(mpio_t *, mpio_mem_t, BYTE *, int, time_t, DWORD, WORD); BYTE * mpio_dentry_find_name_8_3(mpio_t *, BYTE, BYTE *); BYTE * mpio_dentry_find_name(mpio_t *, BYTE, BYTE *); @@ -49,7 +49,8 @@ mpio_fatentry_t *mpio_dentry_get_startcluster(mpio_t *, mpio_mem_t, BYTE *); /* helper functions */ void mpio_dentry_copy_from_slot(BYTE *, mpio_dir_slot_t *); void mpio_dentry_copy_to_slot(BYTE *, mpio_dir_slot_t *); -int mpio_dentry_get_real(mpio_t *, BYTE *, BYTE *, int, BYTE[12], +int mpio_dentry_get_real(mpio_t *, mpio_mem_t, BYTE *, BYTE *, + int, BYTE[12], WORD *, BYTE *, BYTE *, BYTE *, BYTE *, DWORD *); #endif /* _MPIO_DIRECTORY_H_ */ diff --git a/libmpio/mpio.c b/libmpio/mpio.c index 8f3b87c..f65b47e 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.15 2002/09/14 16:14:46 germeier Exp $ + * $Id: mpio.c,v 1.16 2002/09/14 22:54:41 germeier Exp $ * * Library for USB MPIO-* * @@ -80,6 +80,7 @@ mpio_init_internal(mpio_t *m) debugn(2,"max_cluster: %d\n", sm->max_cluster); /* 16 bytes per cluster */ sm->fat_size = sm->max_cluster*16/SECTOR_SIZE; + debugn(2,"fat_size: %04x\n", sm->fat_size*SECTOR_SIZE); sm->fat = malloc(sm->fat_size*SECTOR_SIZE); mpio_fat_read(m, MPIO_INTERNAL_MEM); diff --git a/libmpio/mpio.h b/libmpio/mpio.h index 8e52527..0acf8c9 100644 --- a/libmpio/mpio.h +++ b/libmpio/mpio.h @@ -1,7 +1,7 @@ /* -*- linux-c -*- */ /* - * $Id: mpio.h,v 1.2 2002/09/13 13:07:05 germeier Exp $ + * $Id: mpio.h,v 1.3 2002/09/14 22:54:41 germeier Exp $ * * Library for USB MPIO-* * @@ -64,12 +64,12 @@ int mpio_memory_free(mpio_t *, mpio_mem_t, int *free); */ /* context, memory bank */ -BYTE* mpio_directory_open(mpio_t *, BYTE); +BYTE* mpio_directory_open(mpio_t *, mpio_mem_t); /* context, dir context */ -BYTE* mpio_dentry_next(mpio_t *, BYTE *); +BYTE* mpio_dentry_next(mpio_t *, mpio_mem_t, BYTE *); /* context, dir context */ -int mpio_dentry_get(mpio_t *, BYTE *, BYTE *, int,WORD *, BYTE *, BYTE *, - BYTE *, BYTE *, DWORD *); +int mpio_dentry_get(mpio_t *, mpio_mem_t, BYTE *, BYTE *, int,WORD *, + BYTE *, BYTE *, BYTE *, BYTE *, DWORD *); /* context, memory bank, filename, callback */ int mpio_file_get(mpio_t *, mpio_mem_t, BYTE *, BYTE (*)(int, int)); diff --git a/mpiosh/callback.c b/mpiosh/callback.c index 00163e4..cc520d5 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.5 2002/09/14 11:19:30 crunchy Exp $ + * $Id: callback.c,v 1.6 2002/09/14 22:54:41 germeier Exp $ * * Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de> * @@ -125,7 +125,7 @@ mpiosh_cmd_dir(char *args[]) while (p != NULL) { memset(fname, '\0', 100); - mpio_dentry_get(mpiosh.dev, p, + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, &year, &month, &day, &hour, &minute, &fsize); @@ -133,7 +133,7 @@ mpiosh_cmd_dir(char *args[]) printf ("%02d.%02d.%04d %02d:%02d %9d - %s\n", day, month, year, hour, minute, fsize, fname); - p = mpio_dentry_next(mpiosh.dev, p); + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); } } @@ -264,7 +264,7 @@ mpiosh_cmd_mget(char *args[]) p = mpio_directory_open(mpiosh.dev, mpiosh.card); while (p != NULL) { memset(fname, '\0', 100); - mpio_dentry_get(mpiosh.dev, p, fname, 100, + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, &year, &month, &day, &hour, &minute, &fsize); if (!(error = regexec(®ex, fname, 0, NULL, 0))) { @@ -278,7 +278,7 @@ mpiosh_cmd_mget(char *args[]) debugn (2, "file does not match: %s (%s)\n", fname, errortext); } - p = mpio_dentry_next(mpiosh.dev, p); + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); } } i++; @@ -408,7 +408,7 @@ mpiosh_cmd_mdel(char *args[]) p = mpio_directory_open(mpiosh.dev, mpiosh.card); while (p != NULL) { memset(fname, '\0', 100); - mpio_dentry_get(mpiosh.dev, p, fname, 100, + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100, &year, &month, &day, &hour, &minute, &fsize); if (!(error = regexec(®ex, fname, 0, NULL, 0))) { @@ -424,7 +424,7 @@ mpiosh_cmd_mdel(char *args[]) } else { regerror(error, ®ex, errortext, 100); debugn (2, "file does not match: %s (%s)\n", fname, errortext); - p = mpio_dentry_next(mpiosh.dev, p); + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); } } @@ -458,7 +458,7 @@ mpiosh_cmd_dump(char *args[]) while (p != NULL) { memset(fname, '\0', 256); - mpio_dentry_get(mpiosh.dev, p, + mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 256, &year, &month, &day, &hour, &minute, &fsize); @@ -467,7 +467,7 @@ mpiosh_cmd_dump(char *args[]) printf("getting '%s' ... \n", arg[0]); mpiosh_cmd_get(arg); - p = mpio_dentry_next(mpiosh.dev, p); + p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p); } } |