diff options
author | germeier <germeier> | 2002-10-27 17:37:24 +0000 |
---|---|---|
committer | germeier <germeier> | 2002-10-27 17:37:24 +0000 |
commit | 037e02905b802686be908d4f8cd989f0c5002b99 (patch) | |
tree | 2491218ec9c05b4fd54d12dfe21bf5c0674584e2 /libmpio | |
parent | 13b7579bd45e89304b8697a6fb471bf0524f49d4 (diff) | |
download | mpiosh-037e02905b802686be908d4f8cd989f0c5002b99.tar.gz mpiosh-037e02905b802686be908d4f8cd989f0c5002b99.tar.bz2 mpiosh-037e02905b802686be908d4f8cd989f0c5002b99.zip |
implemented the switch command
finished support for writing files directly from memory (for config files)
Diffstat (limited to 'libmpio')
-rw-r--r-- | libmpio/directory.c | 75 | ||||
-rw-r--r-- | libmpio/directory.h | 5 | ||||
-rw-r--r-- | libmpio/mpio.c | 112 | ||||
-rw-r--r-- | libmpio/mpio.h | 13 |
4 files changed, 155 insertions, 50 deletions
diff --git a/libmpio/directory.c b/libmpio/directory.c index 4795b3d..c5bdc8e 100644 --- a/libmpio/directory.c +++ b/libmpio/directory.c @@ -1,6 +1,6 @@ /* * - * $Id: directory.c,v 1.9 2002/10/27 02:45:28 germeier Exp $ + * $Id: directory.c,v 1.10 2002/10/27 17:37:25 germeier Exp $ * * Library for USB MPIO-* * @@ -607,26 +607,10 @@ 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 <len)) - { - if (filename[j] == '.') - i=8; - filename_8_3[i] = filename[j]; - - i++; - j++; - } - p = mpio_directory_open(m, mem); while ((p) && (!found)) { mpio_dentry_get_real (m, mem, p, @@ -634,9 +618,8 @@ mpio_dentry_find_name_8_3(mpio_t *m, BYTE mem, BYTE *filename) fname_8_3, &wdummy, &bdummy, &bdummy, &bdummy, &bdummy, &ddummy); - - if ((strcmp(fname_8_3, filename_8_3) == 0) && - (strcmp(filename_8_3,fname_8_3) == 0)) { + if ((strcmp(fname_8_3, filename) == 0) && + (strcmp(filename,fname_8_3) == 0)) { found = p; p = NULL; } @@ -719,3 +702,55 @@ mpio_dentry_delete(mpio_t *m, BYTE mem, BYTE *filename) return 0; } + +void +mpio_dentry_switch(mpio_t *m, mpio_mem_t mem, BYTE *file1, BYTE *file2) +{ + mpio_smartmedia_t *sm; + BYTE *p1, *p2; + BYTE *current; + int size1 , size2; + BYTE tmp[DIR_SIZE]; + + if (mem == MPIO_INTERNAL_MEM) sm = &m->internal; + if (mem == MPIO_EXTERNAL_MEM) sm = &m->external; + + if (file1 == file2) + return; + + if (file1<file2) + { + p1 = file1; + p2 = file2; + } else { + p1 = file2; + p2 = file1; + } + size1 = mpio_dentry_get_size(m, mem, p1); + size2 = mpio_dentry_get_size(m, mem, p2); + + current = tmp; + memset(tmp, 0xff, DIR_SIZE); + /* before the first file */ + if (p1 != sm->dir) + { + memcpy(current, sm->dir, p1 - sm->dir); + current += (p1 - sm->dir); + } + /* the second file*/ + memcpy(current, p2, size2); + current += size2; + /* between the files */ + memcpy(current, p1+size1, (p2-p1-size1)); + current += (p2-p1-size1); + /* the first file */ + memcpy(current, p1, size1); + current += size1; + /* and the rest */ + memcpy(current, p2+size2, (sm->dir+DIR_SIZE-p2-size2)); + + /* really update the directory */ + memcpy(sm->dir, tmp, DIR_SIZE); + + return; +} diff --git a/libmpio/directory.h b/libmpio/directory.h index e3fe54d..b30b305 100644 --- a/libmpio/directory.h +++ b/libmpio/directory.h @@ -1,6 +1,6 @@ /* * - * $Id: directory.h,v 1.5 2002/10/26 13:07:43 germeier Exp $ + * $Id: directory.h,v 1.6 2002/10/27 17:37:26 germeier Exp $ * * Library for USB MPIO-* * @@ -50,6 +50,9 @@ 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 *); +/* switch two directory entries */ +void mpio_dentry_switch(mpio_t *, mpio_mem_t, BYTE *, 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 *); diff --git a/libmpio/mpio.c b/libmpio/mpio.c index e2a6ec5..2bcdd5c 100644 --- a/libmpio/mpio.c +++ b/libmpio/mpio.c @@ -1,6 +1,6 @@ /* * - * $Id: mpio.c,v 1.35 2002/10/27 02:45:28 germeier Exp $ + * $Id: mpio.c,v 1.36 2002/10/27 17:37:27 germeier Exp $ * * Library for USB MPIO-* * @@ -353,6 +353,21 @@ mpio_close(mpio_t *m) } } +mpio_model_t +mpio_get_model(mpio_t *m) +{ + mpio_model_t r; + + if (m) + { + r = m->model; + } else { + r = MPIO_MODEL_UNKNOWN; + } + + return r; +} + void mpio_get_info(mpio_t *m, mpio_info_t *info) { @@ -532,6 +547,7 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, BYTE block[BLOCK_SIZE]; int fd, toread; struct stat file_stat; + struct tm tt; BYTE *p=NULL; DWORD filesize, fsize, free, blocks; @@ -542,13 +558,19 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, if (mem==MPIO_INTERNAL_MEM) sm=&m->internal; if (mem==MPIO_EXTERNAL_MEM) sm=&m->external; - if (stat((const char *)filename, &file_stat)!=0) { - debug("could not find file: %s\n", filename); - MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND); - } - fsize=filesize=file_stat.st_size; - debugn(2, "filesize: %d\n", fsize); - + if (memory) + { + fsize=filesize=memory_size; + tt = (struct tm){ 0, 0, 0, 0, 0, 0, 0, 0, 0}; + } else { + if (stat((const char *)filename, &file_stat)!=0) { + debug("could not find file: %s\n", filename); + MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND); + } + fsize=filesize=file_stat.st_size; + debugn(2, "filesize: %d\n", fsize); + } + /* check if there is enough space left */ mpio_memory_free(m, mem, &free); if (free*1024<fsize) { @@ -594,12 +616,15 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, f->i_fat[0x03]= blocks & 0xff; } - /* open file for writing */ - fd = open(filename, O_RDONLY); - if (fd==-1) - { - debug("could not open file: %s\n", filename); - MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND); + if (!memory) + { + /* open file for writing */ + fd = open(filename, O_RDONLY); + if (fd==-1) + { + debug("could not open file: %s\n", filename); + MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND); + } } while ((filesize>BLOCK_SIZE) && (!abort)) { @@ -610,11 +635,16 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, toread=filesize; } - if (read(fd, block, toread)!=toread) { - debug("error reading file data\n"); - close(fd); - MPIO_ERR_RETURN(MPIO_ERR_READING_FILE); - } + if (memory) + { + memcpy(block, memory+(fsize-filesize), toread); + } else { + if (read(fd, block, toread)!=toread) { + debug("error reading file data\n"); + close(fd); + MPIO_ERR_RETURN(MPIO_ERR_READING_FILE); + } + } filesize -= toread; /* get new free block from FAT and write current block out */ @@ -640,18 +670,24 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, toread=filesize; } - if (read(fd, block, toread)!=toread) { - debug("error reading file data\n"); - close(fd); - MPIO_ERR_RETURN(MPIO_ERR_READING_FILE); - } + if (memory) + { + memcpy(block, memory+(fsize-filesize), toread); + } else { + if (read(fd, block, toread)!=toread) { + debug("error reading file data\n"); + close(fd); + MPIO_ERR_RETURN(MPIO_ERR_READING_FILE); + } + } filesize -= toread; /* mark end of FAT chain and write last block */ mpio_fatentry_set_eof(m ,mem, f); mpio_io_block_write(m, mem, f, block); - close(fd); + if (!memory) + close(fd); if (progress_callback) (*progress_callback)((fsize-filesize), fsize); @@ -700,12 +736,36 @@ mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename, } else { mpio_dentry_put(m, mem, filename, strlen(filename), - file_stat.st_ctime, fsize, start); + ((memory)?mktime(&tt):file_stat.st_ctime), + fsize, start); } return fsize-filesize; } +int +mpio_file_switch(mpio_t *m, mpio_mem_t mem, + mpio_filename_t file1, mpio_filename_t file2) +{ + BYTE *p1, *p2; + + /* find files */ + p1 = mpio_dentry_find_name(m, mem, file1); + if (!p1) + p1 = mpio_dentry_find_name_8_3(m, mem, file1); + + p2 = mpio_dentry_find_name(m, mem, file2); + if (!p2) + p2 = mpio_dentry_find_name_8_3(m, mem, file2); + + if ((!p1) || (!p2)) + MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND); + + mpio_dentry_switch(m, mem, p1, p2); + + return 0; +} + int mpio_memory_format(mpio_t *m, mpio_mem_t mem, mpio_callback_t progress_callback) { diff --git a/libmpio/mpio.h b/libmpio/mpio.h index 51decef..3f0205c 100644 --- a/libmpio/mpio.h +++ b/libmpio/mpio.h @@ -1,7 +1,7 @@ #/* -*- linux-c -*- */ /* - * $Id: mpio.h,v 1.11 2002/10/27 02:45:28 germeier Exp $ + * $Id: mpio.h,v 1.12 2002/10/27 17:37:27 germeier Exp $ * * Library for USB MPIO-* * @@ -58,8 +58,8 @@ void mpio_close(mpio_t *); /* get version */ void mpio_get_info(mpio_t *, mpio_info_t *); -/* print version: deprecated */ -//void mpio_print_version(mpio_t *); +/* get model */ +mpio_model_t mpio_get_model(mpio_t *); /* retrieves free memory in bytes */ int mpio_memory_free(mpio_t *, mpio_mem_t, int *free); @@ -107,6 +107,13 @@ int mpio_file_put_from_memory(mpio_t *, mpio_mem_t, mpio_filename_t, BYTE *, int); /* + * switch position of two files + */ +/* context, memory bank, filename, filename */ +int mpio_file_switch(mpio_t *, mpio_mem_t, + mpio_filename_t, mpio_filename_t); + +/* * formating a memory (internal mem or external SmartMedia card) */ |