aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--libmpio/directory.c339
-rw-r--r--libmpio/directory.h5
-rw-r--r--libmpio/mpio.c21
-rw-r--r--libmpio/mpio.h11
-rw-r--r--mpiosh/callback.c21
-rw-r--r--mpiosh/callback.h3
-rw-r--r--mpiosh/global.c7
8 files changed, 265 insertions, 150 deletions
diff --git a/ChangeLog b/ChangeLog
index 9456f2c..1117487 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-04-20 Markus Germeier <mager@tzi.de>
+
+ * libmpio/directory.c (mpio_dentry_filename_write):
+ split this function from mpio_dentry_put to make a rename easier
+ * libmpio/mpio.c (mpio_file_rename):
+ libmpio/directory.c (mpio_dentry_rename):
+ new functions
+
2003-04-19 Markus Germeier <mager@tzi.de>
* libmpio/id3.h:
diff --git a/libmpio/directory.c b/libmpio/directory.c
index aa62173..6f0e82d 100644
--- a/libmpio/directory.c
+++ b/libmpio/directory.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: directory.c,v 1.17 2003/04/11 21:42:57 germeier Exp $
+ * $Id: directory.c,v 1.18 2003/04/19 23:58:02 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -421,6 +421,155 @@ mpio_directory_pwd(mpio_t *m, mpio_mem_t mem, BYTE pwd[INFO_LINE])
return;
}
+mpio_dir_entry_t *
+mpio_dentry_filename_write(mpio_t *m, mpio_mem_t mem, BYTE *p,
+ BYTE *filename, int filename_size)
+{
+ BYTE *unicode = 0;
+ BYTE *back, *fback;
+ BYTE *fname = 0;
+ iconv_t ic;
+ int in = 0, out = 0;
+ int fin = 0, fout = 0;
+ int count = 0;
+ BYTE index;
+ BYTE f_8_3[13];
+ mpio_dir_slot_t *slot;
+ mpio_dir_entry_t *dentry;
+ int i, j, points;
+
+ /* generate vfat filename in UNICODE */
+ ic = iconv_open(UNICODE, m->charset);
+ fin = in = filename_size + 1;
+ fout = out = filename_size * 2 + 2 + 26;
+ fname = malloc(in);
+ fback = fname;
+ unicode = malloc(out);
+ back = unicode;
+
+ memset(fname, 0, in);
+ snprintf(fname, in, "%s", filename);
+ memset(unicode, 0xff, out);
+ iconv(ic, (char **)&fback, &fin, (char **)&back, &fout);
+ iconv_close(ic);
+ hexdump(fname, in);
+ hexdump(unicode, out);
+
+ back = unicode;
+
+ count = filename_size / 13;
+ if (filename_size % 13)
+ count++;
+
+ slot = (mpio_dir_slot_t *)p;
+
+ index = 0x40 + count;
+ while (count > 0) {
+ mpio_dentry_copy_to_slot(back + ((count - 1) * 26), slot);
+ hexdump((char *)back + ((count - 1) * 26), 0x20);
+ slot->id = index;
+ slot->attr = 0x0f;
+ slot->reserved = 0x00;
+ slot->start[0] = 0x00;
+ slot->start[1] = 0x00;
+ /* FIXME: */
+ slot->alias_checksum = 0x00; // checksum for 8.3 alias
+
+ hexdump((char *)slot, 0x20);
+
+ slot++;
+ count--;
+ index = count;
+ }
+
+/* memcpy(p, m->internal.dir+0x220, 0x20); */
+
+/* p+=0x20; */
+ dentry = (mpio_dir_entry_t *)slot;
+
+ /* find uniq 8.3 filename */
+ memset(f_8_3, 0x20, 12);
+ f_8_3[8]='.';
+ f_8_3[12]=0x00;
+
+ i=0;
+ points=0;
+ /* count points to later find the correct file extension */
+ while (i<(strlen(filename)))
+ {
+ if (filename[i] == '.')
+ points++;
+ 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 {
+ if (filename[i]!=' ') {
+ f_8_3[j] = toupper(filename[i]);
+ j++;
+ }
+ }
+ i++;
+ }
+
+ j=i;
+ while((points) && (j<(strlen(filename))))
+ {
+ if (filename[j] == '.')
+ points--;
+ j++;
+ }
+
+ i=9;
+ while ((i<12) && (j<(strlen(filename))))
+ {
+ f_8_3[i] = toupper(filename[j]);
+ i++;
+ 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]='~';
+ f_8_3[7]='1';
+ }
+
+ while(mpio_dentry_find_name_8_3(m, mem, f_8_3))
+ f_8_3[7]++;
+
+
+/* memcpy(dentry->name,"AAAAAAAA",8); */
+/* memcpy(dentry->ext,"MP3",3); */
+
+/* hexdumpn(0, f_8_3, 13); */
+
+ memcpy(dentry->name, f_8_3, 8);
+ memcpy(dentry->ext, f_8_3+9, 3);
+
+ free(unicode);
+ free(fname);
+
+ return dentry;
+}
+
+
int
mpio_dentry_get_size(mpio_t *m, mpio_mem_t mem, BYTE *buffer)
{
@@ -817,19 +966,8 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem,
BYTE *filename, int filename_size,
time_t date, DWORD fsize, WORD ssector, BYTE attr)
{
- BYTE *unicode = 0;
- BYTE *back, *fback;
- BYTE *fname = 0;
- iconv_t ic;
- int in = 0, out = 0;
- int fin = 0, fout = 0;
- int count = 0;
- BYTE index;
- BYTE f_8_3[13];
- int i, j, points;
BYTE *p;
mpio_dir_entry_t *dentry;
- mpio_dir_slot_t *slot;
/* read and copied code from mtools-3.9.8/directory.c
* to make this one right
@@ -851,136 +989,11 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem,
p = m->internal.cdir->dir;
}
- /* generate vfat filename in UNICODE */
- ic = iconv_open(UNICODE, m->charset);
- fin = in = filename_size + 1;
- fout = out = filename_size * 2 + 2 + 26;
- fname = malloc(in);
- fback = fname;
- unicode = malloc(out);
- back = unicode;
-
- memset(fname, 0, in);
- snprintf(fname, in, "%s", filename);
- memset(unicode, 0xff, out);
- iconv(ic, (char **)&fback, &fin, (char **)&back, &fout);
- iconv_close(ic);
- hexdump(fname, in);
- hexdump(unicode, out);
-
- back = unicode;
-
- count = filename_size / 13;
- if (filename_size % 13)
- count++;
-
- slot = (mpio_dir_slot_t *)p;
-
- index = 0x40 + count;
- while (count > 0) {
- mpio_dentry_copy_to_slot(back + ((count - 1) * 26), slot);
- hexdump((char *)back + ((count - 1) * 26), 0x20);
- slot->id = index;
- slot->attr = 0x0f;
- slot->reserved = 0x00;
- slot->start[0] = 0x00;
- slot->start[1] = 0x00;
- /* FIXME: */
- slot->alias_checksum = 0x00; // checksum for 8.3 alias
-
- hexdump((char *)slot, 0x20);
-
- slot++;
- count--;
- index = count;
- }
-
-/* memcpy(p, m->internal.dir+0x220, 0x20); */
-
-/* p+=0x20; */
- dentry = (mpio_dir_entry_t *)slot;
-
- /* find uniq 8.3 filename */
- memset(f_8_3, 0x20, 12);
- f_8_3[8]='.';
- f_8_3[12]=0x00;
-
- i=0;
- points=0;
- /* count points to later find the correct file extension */
- while (i<(strlen(filename)))
- {
- if (filename[i] == '.')
- points++;
- 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 {
- if (filename[i]!=' ') {
- f_8_3[j] = toupper(filename[i]);
- j++;
- }
- }
- i++;
- }
-
- j=i;
- while((points) && (j<(strlen(filename))))
- {
- if (filename[j] == '.')
- points--;
- j++;
- }
-
- i=9;
- while ((i<12) && (j<(strlen(filename))))
- {
- f_8_3[i] = toupper(filename[j]);
- i++;
- 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]='~';
- f_8_3[7]='1';
- }
-
- while(mpio_dentry_find_name_8_3(m, mem, f_8_3))
- f_8_3[7]++;
-
-
-/* memcpy(dentry->name,"AAAAAAAA",8); */
-/* memcpy(dentry->ext,"MP3",3); */
-
-/* hexdumpn(0, f_8_3, 13); */
-
- memcpy(dentry->name, f_8_3, 8);
- memcpy(dentry->ext, f_8_3+9, 3);
+ dentry = mpio_dentry_filename_write(m, mem, p, filename, filename_size);
dentry->attr = attr;
dentry->lcase = 0x00;
-
-
/* read and copied code from mtools-3.9.8/directory.c
* to make this one right
*/
@@ -1006,9 +1019,6 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem,
dentry->start[0] = ssector & 0xff;
dentry->start[1] = ssector / 0x100;
- free(unicode);
- free(fname);
-
/* what do we want to return? */
return 0;
}
@@ -1259,3 +1269,50 @@ mpio_dentry_switch(mpio_t *m, mpio_mem_t mem, BYTE *file1, BYTE *file2)
return;
}
+
+void
+mpio_dentry_rename(mpio_t *m, mpio_mem_t mem, BYTE *p, BYTE *newfilename)
+{
+ mpio_smartmedia_t *sm;
+ BYTE *current;
+ int size1 , size2, offset, offset_d1, offset_d2;
+ BYTE tmp[DIR_SIZE];
+
+ if (mem == MPIO_INTERNAL_MEM) sm = &m->internal;
+ if (mem == MPIO_EXTERNAL_MEM) sm = &m->external;
+
+ current = sm->cdir->dir;
+
+ size1 = mpio_dentry_get_size(m, mem, p) / 0x20;
+ size2 = (strlen(newfilename) / 13) + 1;
+ if ((strlen(newfilename) % 13))
+ size2++;
+
+ debugn(2, "size1: %d size2: %d\n", size1, size2);
+
+ /* we want to copy the last dentry to the right location
+ * so we avoid reading and writing the same information
+ */
+ size1--; /* kludge so we can do compares without worry */
+ size2--;
+
+ memcpy(tmp, current, DIR_SIZE);
+ offset = p - current;
+ offset_d1 = offset + (size1 * 0x20);
+ offset_d2 = offset + (size2 * 0x20);
+
+ if (size2>size1) {
+ /* new filename needs at least one slot more than the old one */
+ memcpy(current+offset_d2, tmp+offset_d1, (DIR_SIZE-offset_d1));
+ }
+
+ if (size2<size1) {
+ /* new filename needs at least one slot less than the old one */
+ memset(p+offset, 0, (DIR_SIZE-offset)); /* clear to avoid bogus dentries */
+ memcpy(current+offset_d2, tmp+offset_d1, (DIR_SIZE-offset_d2));
+ }
+
+ mpio_dentry_filename_write(m, mem, p, newfilename, strlen(newfilename));
+
+ return ;
+}
diff --git a/libmpio/directory.h b/libmpio/directory.h
index 0129669..521b557 100644
--- a/libmpio/directory.h
+++ b/libmpio/directory.h
@@ -1,6 +1,6 @@
/*
*
- * $Id: directory.h,v 1.9 2003/04/11 21:42:57 germeier Exp $
+ * $Id: directory.h,v 1.10 2003/04/19 23:58:02 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -61,6 +61,9 @@ 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 *);
+/* rename a dentry */
+void mpio_dentry_rename(mpio_t *, mpio_mem_t, BYTE *, BYTE *);
+
/* Move a given file to a new position in the file
list relative to another file.
*/
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index 4bf1082..04c3b58 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.52 2003/04/19 09:32:48 germeier Exp $
+ * $Id: mpio.c,v 1.53 2003/04/19 23:58:02 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -896,6 +896,25 @@ mpio_file_switch(mpio_t *m, mpio_mem_t mem,
return 0;
}
+int
+mpio_file_rename(mpio_t *m, mpio_mem_t mem,
+ mpio_filename_t old, mpio_filename_t new)
+{
+ BYTE *p;
+
+ /* find files */
+ p = mpio_dentry_find_name(m, mem, old);
+ if (!p)
+ p = mpio_dentry_find_name_8_3(m, mem, old);
+
+ if (!p)
+ MPIO_ERR_RETURN(MPIO_ERR_FILE_NOT_FOUND);
+
+ mpio_dentry_rename(m, mem, p, new);
+
+ return 0;
+}
+
int mpio_file_move(mpio_t *m,mpio_mem_t mem, mpio_filename_t file,
mpio_filename_t after)
{
diff --git a/libmpio/mpio.h b/libmpio/mpio.h
index 64cd113..5684b3d 100644
--- a/libmpio/mpio.h
+++ b/libmpio/mpio.h
@@ -1,7 +1,7 @@
#/* -*- linux-c -*- */
/*
- * $Id: mpio.h,v 1.17 2003/04/19 09:32:48 germeier Exp $
+ * $Id: mpio.h,v 1.18 2003/04/19 23:58:02 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -127,13 +127,18 @@ int mpio_file_put_from_memory(mpio_t *, mpio_mem_t, mpio_filename_t,
BYTE *, int);
/*
+ * rename a file on the MPIO
+ */
+/* context, memory bank, filename, filename */
+int mpio_file_rename(mpio_t *, mpio_mem_t,
+ mpio_filename_t, mpio_filename_t);
+
+/*
* 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);
-
-
/* Move a named file after a given file. If after==NULL move it
to the top of the list,
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index 337d1d2..768222a 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.40 2003/04/19 11:41:26 germeier Exp $
+ * $Id: callback.c,v 1.41 2003/04/19 23:58:02 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -737,6 +737,25 @@ mpiosh_cmd_switch(char *args[])
}
void
+mpiosh_cmd_rename(char *args[])
+{
+ MPIOSH_CHECK_CONNECTION_CLOSED;
+
+ if(args[0] && args[1] && !args[2]) {
+ if ((mpio_file_rename(mpiosh.dev, mpiosh.card,
+ args[0], args[1])) == -1) {
+ mpio_perror("error");
+ } else {
+ mpio_sync(mpiosh.dev, mpiosh.card);
+ }
+
+ } else {
+ fprintf(stderr, "error: wrong number of arguments given\n");
+ printf("rename <oldfilename> <newfilename>\n");
+ }
+}
+
+void
mpiosh_cmd_dump_mem(char *args[])
{
diff --git a/mpiosh/callback.h b/mpiosh/callback.h
index 8d6be74..3d1c8f8 100644
--- a/mpiosh/callback.h
+++ b/mpiosh/callback.h
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: callback.h,v 1.10 2003/04/19 09:32:48 germeier Exp $
+ * $Id: callback.h,v 1.11 2003/04/19 23:58:02 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -49,6 +49,7 @@ void mpiosh_cmd_dump(char *args[]);
void mpiosh_cmd_free(char *args[]);
void mpiosh_cmd_format(char *args[]);
void mpiosh_cmd_switch(char *args[]);
+void mpiosh_cmd_rename(char *args[]);
void mpiosh_cmd_dump_mem(char *args[]);
void mpiosh_cmd_health(char *args[]);
void mpiosh_cmd_config(char *args[]);
diff --git a/mpiosh/global.c b/mpiosh/global.c
index 2f10870..0047627 100644
--- a/mpiosh/global.c
+++ b/mpiosh/global.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: global.c,v 1.10 2003/04/19 09:32:48 germeier Exp $
+ * $Id: global.c,v 1.11 2003/04/19 23:58:02 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -50,7 +50,7 @@ struct mpiosh_cmd_t commands[] = {
{ "ver", NULL, NULL,
" version of mpio package",
mpiosh_cmd_version, NULL },
- { "help", NULL, "[<command>]",
+ { "help", (char *[]){ "?", NULL }, "[<command>]",
" show information about known commands or just about <command>",
mpiosh_cmd_help, mpiosh_readline_comp_cmd },
{ "dir", (char *[]){ "ls", "ll", NULL }, NULL,
@@ -105,6 +105,9 @@ struct mpiosh_cmd_t commands[] = {
{ "switch", NULL, "<file1> <file2>",
" switches the order of two files",
mpiosh_cmd_switch, mpiosh_readline_comp_mpio_file },
+ { "rename", (char *[]){ "ren", NULL }, "<oldfilename> <newfilename>",
+ " renames a file on the current memory card",
+ mpiosh_cmd_rename, mpiosh_readline_comp_mpio_file },
{ "ldir", (char *[]){ "lls", NULL }, NULL,
" list local directory",
mpiosh_cmd_ldir, NULL },