aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgermeier <germeier>2003-04-11 21:42:57 +0000
committergermeier <germeier>2003-04-11 21:42:57 +0000
commit17225c6d8fe3c925c5863f736f6572720c95c5d7 (patch)
treeab43eddfdb58eb47ad05bff98ae3a7639eb07335
parent50c439ffa36fed9e1cce65b211ec05bf50925cc2 (diff)
downloadmpiosh-17225c6d8fe3c925c5863f736f6572720c95c5d7.tar.gz
mpiosh-17225c6d8fe3c925c5863f736f6572720c95c5d7.tar.bz2
mpiosh-17225c6d8fe3c925c5863f736f6572720c95c5d7.zip
timestamp generation fixes as suggested by Sebastian
8.3 generation fixes for "MPIO RECORD" directory
-rw-r--r--ChangeLog12
-rw-r--r--libmpio/defs.h4
-rw-r--r--libmpio/directory.c72
-rw-r--r--libmpio/directory.h4
-rw-r--r--libmpio/mpio.c28
-rw-r--r--mpiosh/callback.c34
6 files changed, 134 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 53ac3a5..2c0388f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2003-04-11 Markus Germeier <mager@tzi.de>
+
+ * libmpio/directory.c (mpio_directory_make):
+ libmpio/mpio.c (mpio_file_put_real):
+ fix timestamp generation as suggested by Sebastian. Thanks!
+ (mpio_directory_is_empty,mpio_dentry_is_dir):
+ added functions
+ (mpio_dentry_put): another 8.3 generation fix,
+ special treatment for "MPIO RECORD" dir.
+ * mpiosh/callback.c (mpiosh_cmd_format):
+ mkdir "MPIO RECORD" dir if it existed before the format
+
2003-04-07 Markus Germeier <mager@tzi.de>
* Mega-Update all over the place
initial support for directories
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
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index c3e82d4..8006e5f 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.35 2003/04/06 23:09:20 germeier Exp $
+ * $Id: callback.c,v 1.36 2003/04/11 21:42:58 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -518,9 +518,10 @@ void
mpiosh_cmd_mdel(char *args[])
{
BYTE * p;
- int size, i = 0;
+ int i = 0;
int error;
regex_t regex;
+ int r;
BYTE fname[100];
BYTE errortext[100];
BYTE month, day, hour, minute, type;
@@ -543,19 +544,27 @@ mpiosh_cmd_mdel(char *args[])
mpio_dentry_get(mpiosh.dev, mpiosh.card, p, fname, 100,
&year, &month, &day, &hour, &minute, &fsize, &type);
- if (!(error = regexec(&regex, fname, 0, NULL, 0))) {
+ if ((!(error = regexec(&regex, fname, 0, NULL, 0))) &&
+ (strcmp(fname, "..")) && (strcmp(fname, ".")))
+ {
/* this line has to be above the del, or we won't write
* the FAT and directory in case of an abort!!!
*/
deleted=1;
printf("deleting '%s' ... \n", fname);
- size = mpio_file_del(mpiosh.dev, mpiosh.card,
+ r = mpio_file_del(mpiosh.dev, mpiosh.card,
fname, mpiosh_callback_del);
printf("\n");
if (mpiosh_cancel) break;
/* if we delete a file, start again from the beginning,
because the directory has changed !! */
- p = mpio_directory_open(mpiosh.dev, mpiosh.card);
+ if (r != MPIO_OK)
+ {
+ printf("ERROR: %s\n", mpio_strerror(r));
+ p = mpio_dentry_next(mpiosh.dev, mpiosh.card, p);
+ break;
+ }
+ p = mpio_directory_open(mpiosh.dev, mpiosh.card);
} else {
regerror(error, &regex, errortext, 100);
debugn (2, "file does not match: %s (%s)\n", fname, errortext);
@@ -630,8 +639,8 @@ void
mpiosh_cmd_format(char *args[])
{
char answer[512];
- BYTE *config, *fmconfig;
- int csize, fmsize;
+ BYTE *config, *fmconfig, *rconfig;
+ int csize, fmsize, rsize;
MPIOSH_CHECK_CONNECTION_CLOSED;
@@ -647,11 +656,14 @@ mpiosh_cmd_format(char *args[])
/* save config files and write them back after formatting */
config = NULL;
fmconfig = NULL;
+ rconfig = NULL;
csize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM,
MPIO_CONFIG_FILE, NULL, &config);
fmsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM,
MPIO_CHANNEL_FILE, NULL, &fmconfig);
+ rsize = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_MPIO_RECORD, NULL, &rconfig);
}
if (mpio_memory_format(mpiosh.dev, mpiosh.card,
@@ -672,13 +684,19 @@ mpiosh_cmd_format(char *args[])
MPIO_CHANNEL_FILE, FTYPE_CHAN,
NULL, fmconfig, fmsize)==-1)
mpio_perror("error");
+ if (rconfig)
+ if (mpio_directory_make(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_MPIO_RECORD)!=MPIO_OK)
+ mpio_perror("error");
- if (config || fmconfig)
+ if (config || fmconfig || rconfig)
mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM);
if (config)
free(config);
if (fmconfig)
free(fmconfig);
+ if (rconfig)
+ free(rconfig);
}
}