| 1 |
/* |
|---|
| 2 |
* $Id$ |
|---|
| 3 |
*/ |
|---|
| 4 |
/* |
|---|
| 5 |
* Linbox Rescue Server |
|---|
| 6 |
* Copyright (C) 2002-2005 Linbox FAS, Free & Alter Soft |
|---|
| 7 |
* |
|---|
| 8 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 9 |
* it under the terms of the GNU General Public License as published by |
|---|
| 10 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 |
* (at your option) any later version. |
|---|
| 12 |
* |
|---|
| 13 |
* This program is distributed in the hope that it will be useful, |
|---|
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 |
* GNU General Public License for more details. |
|---|
| 17 |
* |
|---|
| 18 |
* You should have received a copy of the GNU General Public License |
|---|
| 19 |
* along with this program; if not, write to the Free Software |
|---|
| 20 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 21 |
*/ |
|---|
| 22 |
|
|---|
| 23 |
#include "config.h" |
|---|
| 24 |
|
|---|
| 25 |
#include <stdio.h> |
|---|
| 26 |
#include <stdlib.h> |
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <assert.h> |
|---|
| 29 |
|
|---|
| 30 |
#include "compress.h" |
|---|
| 31 |
#include "client.h" |
|---|
| 32 |
|
|---|
| 33 |
char info1[32], info2[32]; |
|---|
| 34 |
|
|---|
| 35 |
void |
|---|
| 36 |
check_signature (FILE * f, PARAMS * p) |
|---|
| 37 |
{ |
|---|
| 38 |
char dum[4096]; |
|---|
| 39 |
|
|---|
| 40 |
fread (dum, 4096, 1, f); |
|---|
| 41 |
|
|---|
| 42 |
if (strncmp (dum + 4096 - 10, "SWAP-SPACE", 10) == 0) |
|---|
| 43 |
return; |
|---|
| 44 |
if (strncmp (dum + 4096 - 10, "SWAPSPACE2", 10) == 0) |
|---|
| 45 |
return; |
|---|
| 46 |
|
|---|
| 47 |
exit (1); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
void |
|---|
| 51 |
allocated_sectors (PARAMS * p) |
|---|
| 52 |
{ |
|---|
| 53 |
int i, used; |
|---|
| 54 |
|
|---|
| 55 |
p->bitmap = (unsigned char *) calloc (8, 1); |
|---|
| 56 |
p->bitmaplg = 8; |
|---|
| 57 |
|
|---|
| 58 |
p->nb_sect = 8; |
|---|
| 59 |
used = 8; |
|---|
| 60 |
|
|---|
| 61 |
for (i = 0; i < 8; i++) |
|---|
| 62 |
p->bitmap[i] = 0xFF; |
|---|
| 63 |
|
|---|
| 64 |
sprintf(info1, "%u", p->nb_sect); |
|---|
| 65 |
sprintf(info2, "%u", used); |
|---|
| 66 |
print_sect_info(p->nb_sect, used); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
/* */ |
|---|
| 70 |
int main (int argc, char *argv[]) |
|---|
| 71 |
{ |
|---|
| 72 |
FILE *fi; |
|---|
| 73 |
PARAMS params; |
|---|
| 74 |
int fd; |
|---|
| 75 |
|
|---|
| 76 |
if (argc != 3) |
|---|
| 77 |
{ |
|---|
| 78 |
fprintf (stderr, "Usage : image_swap [device] [image prefix name]\n"); |
|---|
| 79 |
exit (1); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
// Just check for SWAP-SPACE or SWAPSPACE2 |
|---|
| 83 |
|
|---|
| 84 |
fi = fopen (argv[1], "rb"); |
|---|
| 85 |
check_signature (fi, ¶ms); |
|---|
| 86 |
allocated_sectors (¶ms); |
|---|
| 87 |
fclose (fi); |
|---|
| 88 |
|
|---|
| 89 |
if (argv[2][0] == '?') |
|---|
| 90 |
exit (0); |
|---|
| 91 |
|
|---|
| 92 |
// Compress now |
|---|
| 93 |
// |
|---|
| 94 |
|
|---|
| 95 |
ui_send("init_backup", 5, argv[1], argv[2], info1, info2, argv[0]); |
|---|
| 96 |
fd = open (argv[1], O_RDONLY); |
|---|
| 97 |
compress_volume (fd, argv[2], ¶ms, "SWAP=1"); |
|---|
| 98 |
close (fd); |
|---|
| 99 |
|
|---|
| 100 |
return 0; |
|---|
| 101 |
} |
|---|