diff options
Diffstat (limited to 'libmpio')
-rw-r--r-- | libmpio/defs.h | 4 | ||||
-rw-r--r-- | libmpio/directory.c | 72 | ||||
-rw-r--r-- | libmpio/directory.h | 4 | ||||
-rw-r--r-- | libmpio/mpio.c | 28 |
4 files changed, 96 insertions, 12 deletions
diff --git a/libmpio/defs.h b/libmpio/defs.h index 0018591..1dcb1d4 100644 --- a/libmpio/defs.h +++ b/libmpio/defs.h @@ -1,7 +1,7 @@ /* -*- linux-c -*- */ /* - * $Id: defs.h,v 1.18 2003/04/06 23:09:20 germeier Exp $ + * $Id: defs.h,v 1.19 2003/04/11 21:42:57 germeier Exp $ * * Library for USB MPIO-* * @@ -80,6 +80,7 @@ typedef enum { FTYPE_CHAN = 0x00, /* fixed filenames */ #define MPIO_CONFIG_FILE "CONFIG.DAT" #define MPIO_CHANNEL_FILE "FMCONFIG.DAT" +#define MPIO_MPIO_RECORD "MPIO RECORD" /* type of callback functions */ typedef BYTE (*mpio_callback_t)(int, int) ; @@ -143,6 +144,7 @@ typedef struct { #define MPIO_ERR_DIR_NOT_FOUND -9 #define MPIO_ERR_DIR_NOT_A_DIR -10 #define MPIO_ERR_DIR_NAME_ERROR -11 +#define MPIO_ERR_DIR_NOT_EMPTY -12 /* internal errors, occur when UI has errors! */ #define MPIO_ERR_INT_STRING_INVALID -101 diff --git a/libmpio/directory.c b/libmpio/directory.c index 0dd8abd..aa62173 100644 --- a/libmpio/directory.c +++ b/libmpio/directory.c @@ -1,6 +1,6 @@ /* * - * $Id: directory.c,v 1.16 2003/04/06 23:09:20 germeier Exp $ + * $Id: directory.c,v 1.17 2003/04/11 21:42:57 germeier Exp $ * * Library for USB MPIO-* * @@ -155,6 +155,23 @@ mpio_directory_read(mpio_t *m, mpio_mem_t mem, mpio_directory_t *dir) return 0; } +BYTE +mpio_directory_is_empty(mpio_t *m, mpio_mem_t mem, mpio_directory_t *dir) +{ + mpio_dir_entry_t *dentry; + BYTE r; + + dentry = (mpio_dir_entry_t *)dir->dir; + dentry += 2; + + r = MPIO_OK; + if (dentry->name[0] != 0x00) + r = !r; + + return r; +} + + int mpio_directory_write(mpio_t *m, mpio_mem_t mem, mpio_directory_t *dir) { @@ -180,7 +197,7 @@ mpio_directory_write(mpio_t *m, mpio_mem_t mem, mpio_directory_t *dir) /* set type to directory */ f->i_fat[0x06] = FTYPE_ENTRY; - hexdumpn(0, f->i_fat, 16); + hexdumpn(2, f->i_fat, 16); } mpio_io_block_delete(m, mem, f); @@ -223,6 +240,7 @@ mpio_directory_make(mpio_t *m, mpio_mem_t mem, BYTE *dir) mpio_fatentry_t *f, *current; WORD self, parent; struct tm tt; + time_t curr; if (mem == MPIO_INTERNAL_MEM) sm = &m->internal; if (mem == MPIO_EXTERNAL_MEM) sm = &m->external; @@ -257,7 +275,7 @@ mpio_directory_make(mpio_t *m, mpio_mem_t mem, BYTE *dir) /* only one block needed for directory */ f->i_fat[0x02]=0; f->i_fat[0x03]=1; - hexdumpn(0, f->i_fat, 16); + hexdumpn(2, f->i_fat, 16); } if (sm->cdir == sm->root) @@ -279,6 +297,8 @@ mpio_directory_make(mpio_t *m, mpio_mem_t mem, BYTE *dir) mpio_fatentry_set_eof(m ,mem, f); mpio_io_block_write(m, mem, f, new->dir); + time(&curr); + tt = * localtime(&curr); mpio_dentry_put(m, mem, dir, strlen(dir), mktime(&tt), @@ -668,6 +688,32 @@ mpio_rootdir_clear (mpio_t *m, mpio_mem_t mem) return 0; } +BYTE +mpio_dentry_is_dir(mpio_t *m, mpio_mem_t mem, BYTE *p) +{ + int s; + mpio_dir_entry_t *dentry; + BYTE r; + + s = mpio_dentry_get_size(m, mem, p); + s -= DIR_ENTRY_SIZE ; + + dentry = (mpio_dir_entry_t *)p; + + while (s != 0) { + dentry++; + s -= DIR_ENTRY_SIZE ; + } + + if (dentry->attr & 0x10) { + r = MPIO_OK; + } else { + r= !MPIO_OK; + } + + return r; +} + int mpio_dentry_get_filesize(mpio_t *m, mpio_mem_t mem, BYTE *p) { @@ -869,15 +915,22 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem, i++; } + /* if we do not find any points we set the value ridiculously high, + then everything falls into place */ + if (!points) + points=1024*1024; + i=j=0; while ((j<8) && (points) && (i<(strlen(filename)))) { if (filename[i] == '.') { points--; - } else { - f_8_3[j] = toupper(filename[i]); - j++; + } else { + if (filename[i]!=' ') { + f_8_3[j] = toupper(filename[i]); + j++; + } } i++; } @@ -898,6 +951,13 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem, j++; } + /* This seems like a special case to me! */ + if (strcmp(MPIO_MPIO_RECORD, filename)==0) + { + f_8_3[6]='~'; + f_8_3[7]='0'; + } + if (mpio_dentry_find_name_8_3(m, mem, f_8_3)) { f_8_3[6]='~'; diff --git a/libmpio/directory.h b/libmpio/directory.h index 8281bfa..0129669 100644 --- a/libmpio/directory.h +++ b/libmpio/directory.h @@ -1,6 +1,6 @@ /* * - * $Id: directory.h,v 1.8 2003/04/06 23:09:20 germeier Exp $ + * $Id: directory.h,v 1.9 2003/04/11 21:42:57 germeier Exp $ * * Library for USB MPIO-* * @@ -43,6 +43,7 @@ int mpio_directory_init(mpio_t *, mpio_mem_t, mpio_directory_t *, WORD, WORD); int mpio_directory_read(mpio_t *, mpio_mem_t, mpio_directory_t *); int mpio_directory_write(mpio_t *, mpio_mem_t, mpio_directory_t *); +BYTE mpio_directory_is_empty(mpio_t *, mpio_mem_t, mpio_directory_t *); /* operations on a single directory entry */ int mpio_dentry_get_size(mpio_t *, mpio_mem_t, BYTE *); @@ -55,6 +56,7 @@ int mpio_dentry_delete(mpio_t *, BYTE, BYTE *); int mpio_dentry_get_filesize(mpio_t *, mpio_mem_t, BYTE *); long mpio_dentry_get_time(mpio_t *, mpio_mem_t, BYTE *); mpio_fatentry_t *mpio_dentry_get_startcluster(mpio_t *, mpio_mem_t, BYTE *); +BYTE mpio_dentry_is_dir(mpio_t *, mpio_mem_t, BYTE *); /* switch two directory entries */ void mpio_dentry_switch(mpio_t *, mpio_mem_t, BYTE *, BYTE *); diff --git a/libmpio/mpio.c b/libmpio/mpio.c index 0c6a7e8..8665396 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.48 2003/04/06 23:09:20 germeier Exp $ + * $Id: mpio.c,v 1.49 2003/04/11 21:42:57 germeier Exp $ * * Library for USB MPIO-* * @@ -89,6 +89,8 @@ static mpio_error_t mpio_errors[] = { "The selected directory is not a directory." }, { MPIO_ERR_DIR_NAME_ERROR, "The selected directory name is not allowed." }, + { MPIO_ERR_DIR_NOT_EMPTY, + "The selected directory is not empty." }, { MPIO_ERR_INT_STRING_INVALID, "Internal Error: Supported is invalid!" } }; @@ -648,6 +650,7 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t i_filename, int fd, toread; struct stat file_stat; struct tm tt; + time_t curr; BYTE *p = NULL; DWORD filesize, fsize, free, blocks; @@ -665,7 +668,6 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t i_filename, if (memory) { fsize=filesize=memory_size; - tt = (struct tm){ 0, 0, 0, 0, 0, 0, 0, 0, 0}; } else { if (stat((const char *)i_filename, &file_stat)!=0) { debug("could not find file: %s\n", i_filename); @@ -840,6 +842,11 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t i_filename, (*progress_callback)((fsize-filesize), fsize); } else { + if (memory) + { + time(&curr); + tt = * localtime(&curr); + } mpio_dentry_put(m, mem, o_filename, strlen(o_filename), ((memory)?mktime(&tt):file_stat.st_ctime), @@ -1058,6 +1065,19 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, f = mpio_dentry_get_startcluster(m, mem, p); if (f && p) { + if (mpio_dentry_is_dir(m, mem, p) == MPIO_OK) + { + /* ugly */ + mpio_directory_cd(m, mem, filename); + if (mpio_directory_is_empty(m, mem, sm->cdir) != MPIO_OK) + { + mpio_directory_cd(m, mem, ".."); + return MPIO_ERR_DIR_NOT_EMPTY; + } else { + mpio_directory_cd(m, mem, ".."); + } + } + filesize=fsize=mpio_dentry_get_filesize(m, mem, p); do { @@ -1099,8 +1119,8 @@ mpio_file_del(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, } mpio_dentry_delete(m, mem, filename); - - return (fsize-filesize); + + return MPIO_OK; } int |