/*
 * $Id$
 *
 * Test program for mountlist management at restore time
 * Cn be used on host system with valgrind easier than with mondorestore
 */
#include <stdio.h>
#include "my-stuff.h"
#include "mr_mem.h"
#include "../common/mondostructures.h"
#include "../common/libmondo.h"
#include "../mondorestore/mondorestore.h"
#include "../mondorestore/mr-externs.h"

extern void twenty_seconds_til_yikes(void);

/* Reference to global bkpinfo */
struct s_bkpinfo *bkpinfo;

extern bool g_text_mode;
extern FILE *g_fprep;
extern double g_kernel_version;
extern int g_partition_table_locked_up;
extern int g_noof_rows;

bool g_ISO_restore_mode = FALSE;	/* are we in Iso Mode? */
bool g_I_have_just_nuked = FALSE;
char *g_isodir_device;
char *g_isodir_format;
char *g_biggielist_txt;
char *g_filelist_full;
char *g_filelist_imagedevs;
char *g_imagedevs_restthese;

char *g_mondo_cfg_file;

char *g_mountlist_fname;
char *g_mondo_home;

char *g_getfacl;
char *g_getfattr;

extern char *MONDO_LOGFILE;
extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction);
/* We don't have a cleanup function yet */
void (*mr_cleanup)(void) = NULL;

void main() {

struct mountlist_itself *mountlist = NULL;
struct raidlist_itself *raidlist;
char *tmpA = NULL;
char *tmpB = NULL;
char *tmpC = NULL;
bool ret = FALSE;

mr_asprintf(&MONDO_LOGFILE,"/tmp/mrtest-mountlist.log");

/* Globals */
g_loglevel = 99;
g_text_mode = FALSE;
g_main_pid = getpid();

if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
	fatal_error("Cannot malloc mountlist");
}
if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
	fatal_error("Cannot malloc raidlist");
}
malloc_libmondo_global_strings();

setup_newt_stuff();
mr_asprintf(&g_mountlist_fname, "/tmp/mountlist.txt");
log_it("before mountlist");
load_mountlist(mountlist, g_mountlist_fname);
log_it("after mountlist");
resize_mountlist_proportionately_to_suit_new_drives(mountlist);
log_it("after resize_mountlist_proportionately_to_suit_new_drives");
load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
log_it("after load_raidtab_into_raidlist");
edit_mountlist(g_mountlist_fname, mountlist, raidlist);
log_it("after edit_mountlist");

mr_asprintf(&tmpA, "%s", "         ");
mr_asprintf(&tmpB, "%s", "         ");
mr_asprintf(&tmpC, "%s", "         ");
ret = evaluate_mountlist(mountlist, tmpA, tmpB, tmpC);
log_it("after evaluate_mountlist");

mr_free(MONDO_LOGFILE);
exit(0);
}
