aboutsummaryrefslogtreecommitdiff
path: root/mpiosh
diff options
context:
space:
mode:
Diffstat (limited to 'mpiosh')
-rw-r--r--mpiosh/callback.c93
-rw-r--r--mpiosh/callback.h6
-rw-r--r--mpiosh/config.c24
-rw-r--r--mpiosh/config.h5
-rw-r--r--mpiosh/global.c9
-rw-r--r--mpiosh/global.h5
6 files changed, 134 insertions, 8 deletions
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index 70c2e5a..daf99a0 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.42 2003/06/26 19:53:58 germeier Exp $
+ * $Id: callback.c,v 1.43 2003/06/27 12:21:21 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -834,6 +834,96 @@ mpiosh_cmd_health(char *args[])
}
void
+mpiosh_cmd_backup(char *args[])
+{
+ int size;
+ char filename[ 1024 ];
+
+ UNUSED(args);
+
+ MPIOSH_CHECK_CONNECTION_CLOSED;
+
+ if ( !mpiosh_config_check_backup_dir( mpiosh.config, TRUE ) ) {
+ fprintf( stderr, "error: could not create backup directory: %s\n",
+ CONFIG_BACKUP );
+ return;
+ }
+
+ snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CONFIG_FILE );
+ size = mpio_file_get_as( mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CONFIG_FILE,
+ filename,
+ mpiosh_callback_get );
+ if ( size == -1 ) return;
+ if ( !size )
+ debugn (1, "file does not exist: %s\n", MPIO_CONFIG_FILE );
+
+ snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CHANNEL_FILE );
+ size = mpio_file_get_as( mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CHANNEL_FILE,
+ filename,
+ mpiosh_callback_get );
+ if ( size == -1 ) return;
+ if ( !size )
+ debugn (2, "file does not exist: %s\n", MPIO_CHANNEL_FILE );
+
+ snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_FONT_FON );
+ size = mpio_file_get_as( mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_FONT_FON,
+ filename,
+ mpiosh_callback_get );
+ if ( size == -1 ) return;
+ if ( !size )
+ debugn (2, "file does not exist: %s\n", MPIO_FONT_FON );
+}
+
+void
+mpiosh_cmd_restore(char *args[])
+{
+ int size;
+ char filename[ 1024 ];
+
+ UNUSED(args);
+
+ MPIOSH_CHECK_CONNECTION_CLOSED;
+
+ if ( !mpiosh_config_check_backup_dir( mpiosh.config, FALSE ) ) {
+ fprintf( stderr, "error: there is no backup: %s\n",
+ CONFIG_BACKUP );
+ return;
+ }
+
+ snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CONFIG_FILE );
+ size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM,
+ filename,
+ MPIO_CONFIG_FILE,
+ FTYPE_CONF, mpiosh_callback_put );
+ if ( size == -1 ) return;
+ if ( !size )
+ debugn (1, "file does not exist: %s\n", MPIO_CONFIG_FILE );
+
+ snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_CHANNEL_FILE );
+ size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM,
+ filename,
+ MPIO_CHANNEL_FILE,
+ FTYPE_CHAN, mpiosh_callback_put );
+ if ( size == -1 ) return;
+ if ( !size )
+ debugn (2, "file does not exist: %s\n", MPIO_CHANNEL_FILE );
+
+ snprintf( filename, 1024, "%s%s", CONFIG_BACKUP, MPIO_FONT_FON );
+ size = mpio_file_put_as( mpiosh.dev, MPIO_INTERNAL_MEM,
+ filename,
+ MPIO_FONT_FON,
+ FTYPE_FONT, mpiosh_callback_put );
+ if ( size == -1 ) return;
+ if ( !size )
+ debugn (2, "file does not exist: %s\n", MPIO_FONT_FON );
+}
+
+
+#if 0
+void
mpiosh_cmd_config(char *args[])
{
BYTE *config_data;
@@ -906,6 +996,7 @@ mpiosh_cmd_config(char *args[])
printf("config [read|write|show] <\n");
}
}
+#endif
void
mpiosh_cmd_channel(char *args[])
diff --git a/mpiosh/callback.h b/mpiosh/callback.h
index f0e2b61..00ffb86 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.12 2003/06/26 19:53:59 germeier Exp $
+ * $Id: callback.h,v 1.13 2003/06/27 12:21:21 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -52,7 +52,11 @@ 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_backup(char *args[]);
+void mpiosh_cmd_restore(char *args[]);
+#if 0
void mpiosh_cmd_config(char *args[]);
+#endif
void mpiosh_cmd_channel(char *args[]);
void mpiosh_cmd_id3(char *args[]);
void mpiosh_cmd_id3_format(char *args[]);
diff --git a/mpiosh/config.c b/mpiosh/config.c
index bc2c7dd..e962266 100644
--- a/mpiosh/config.c
+++ b/mpiosh/config.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: config.c,v 1.5 2003/04/19 11:41:26 germeier Exp $
+ * $Id: config.c,v 1.6 2003/06/27 12:21:21 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -167,7 +167,27 @@ mpiosh_config_read(struct mpiosh_config_t *config)
}
int
-mpiosh_config_write(struct mpiosh_config_t *config)
+mpiosh_config_check_backup_dir( struct mpiosh_config_t *config, int create )
+{
+ DIR *dir;
+ char *path = cfg_resolve_path( CONFIG_BACKUP );
+ int ret = 1;
+
+ if ( ( dir = opendir( path ) ) == NULL )
+ if ( create )
+ ret = ( ! mkdir(path, 0777 ) );
+ else
+ ret = 0;
+ else
+ closedir(dir);
+
+ free(path);
+
+ return ret;
+}
+
+int
+mpiosh_config_write( struct mpiosh_config_t *config )
{
DIR *dir;
char *path = cfg_resolve_path(CONFIG_USER);
diff --git a/mpiosh/config.h b/mpiosh/config.h
index c7924d4..81c88e1 100644
--- a/mpiosh/config.h
+++ b/mpiosh/config.h
@@ -2,7 +2,7 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: config.h,v 1.3 2003/04/19 09:32:48 germeier Exp $
+ * $Id: config.h,v 1.4 2003/06/27 12:21:21 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -47,6 +47,9 @@ const char *mpiosh_config_read_key(struct mpiosh_config_t *config,
int mpiosh_config_read(struct mpiosh_config_t *config);
int mpiosh_config_write(struct mpiosh_config_t *config);
+int mpiosh_config_check_backup_dir( struct mpiosh_config_t *config,
+ int create );
+
#endif
/* end of config.h */
diff --git a/mpiosh/global.c b/mpiosh/global.c
index dc4ad45..f589114 100644
--- a/mpiosh/global.c
+++ b/mpiosh/global.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: global.c,v 1.13 2003/06/26 19:53:59 germeier Exp $
+ * $Id: global.c,v 1.14 2003/06/27 12:21:21 crunchy Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -36,6 +36,7 @@ int mpiosh_cancel_ack = 0;
/* configuration filenames */
const char *CONFIG_GLOBAL = SYSCONFDIR "/mpio/";
const char *CONFIG_USER = "~/.mpio/";
+const char *CONFIG_BACKUP = "~/.mpio/backup/";
const char *CONFIG_FILE = "mpioshrc";
const char *CONFIG_HISTORY = "history";
@@ -136,6 +137,12 @@ struct mpiosh_cmd_t commands[] = {
" dump FAT, directory, spare area and the first 0x100 of the\n"
" selected memory card",
mpiosh_cmd_dump_mem, NULL },
+ { "backup", NULL, NULL,
+ " create a backup of all known configuration files.",
+ mpiosh_cmd_backup, NULL },
+ { "restore", NULL, NULL,
+ " restore an existing backup of all known configuration files.",
+ mpiosh_cmd_restore, NULL },
#if 0
/* deactivated for the 0.6.0 release because the code is incomplete! -mager */
{ "config", (char *[]) { "conf", NULL }, "[read|write|show]",
diff --git a/mpiosh/global.h b/mpiosh/global.h
index a807c4a..1e52491 100644
--- a/mpiosh/global.h
+++ b/mpiosh/global.h
@@ -2,9 +2,9 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: global.h,v 1.2 2002/10/29 20:03:35 crunchy Exp $
+ * $Id: global.h,v 1.3 2003/06/27 12:21:22 crunchy Exp $
*
- * Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
+ * Copyright (C) 2001-2003 Andreas Büsching <crunchy@tzi.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,6 +56,7 @@ extern int mpiosh_cancel_ack;
extern const char *CONFIG_GLOBAL;
extern const char *CONFIG_USER;
+extern const char *CONFIG_BACKUP;
extern const char *CONFIG_FILE;
extern const char *CONFIG_HISTORY;