| 1 |
/* |
|---|
| 2 |
* $Id$ |
|---|
| 3 |
*/ |
|---|
| 4 |
|
|---|
| 5 |
#include "config.h" |
|---|
| 6 |
|
|---|
| 7 |
#include <stdio.h> |
|---|
| 8 |
#include <stdlib.h> |
|---|
| 9 |
#include <string.h> |
|---|
| 10 |
#include <assert.h> |
|---|
| 11 |
|
|---|
| 12 |
#include <sys/mount.h> |
|---|
| 13 |
#include <sys/types.h> |
|---|
| 14 |
#include <sys/stat.h> |
|---|
| 15 |
#include <asm/types.h> |
|---|
| 16 |
#include <errno.h> |
|---|
| 17 |
#include <stdio.h> |
|---|
| 18 |
#include <mntent.h> |
|---|
| 19 |
#include <string.h> |
|---|
| 20 |
#include <unistd.h> |
|---|
| 21 |
#include <fcntl.h> |
|---|
| 22 |
#include <stdlib.h> |
|---|
| 23 |
#include <stdint.h> |
|---|
| 24 |
#include <sys/vfs.h> |
|---|
| 25 |
|
|---|
| 26 |
//#include <linux/lvm.h> |
|---|
| 27 |
|
|---|
| 28 |
#include "compress.h" |
|---|
| 29 |
#include "client.h" |
|---|
| 30 |
#include "lvm.h" |
|---|
| 31 |
|
|---|
| 32 |
char info1[32], info2[32]; |
|---|
| 33 |
unsigned long lvm_sect; |
|---|
| 34 |
|
|---|
| 35 |
void allocated_sectors(PARAMS * p) |
|---|
| 36 |
{ |
|---|
| 37 |
unsigned long i; |
|---|
| 38 |
unsigned long bitmap_lg; |
|---|
| 39 |
int off = 0; |
|---|
| 40 |
|
|---|
| 41 |
void setbit(unsigned char *base, unsigned long bit) { |
|---|
| 42 |
unsigned char mask[8] = |
|---|
| 43 |
{ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; |
|---|
| 44 |
|
|---|
| 45 |
base[bit >> 3] |= mask[bit & 7]; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
off = p->nb_sect; |
|---|
| 49 |
|
|---|
| 50 |
p->bitmap = (unsigned char *) calloc(bitmap_lg = (off + 7) / 8, 1); |
|---|
| 51 |
p->bitmaplg = bitmap_lg; |
|---|
| 52 |
|
|---|
| 53 |
// backup LVM: everything |
|---|
| 54 |
for (i = 0; i < off; i++) |
|---|
| 55 |
setbit(p->bitmap, i); |
|---|
| 56 |
|
|---|
| 57 |
sprintf(info1, "%u", off); |
|---|
| 58 |
sprintf(info2, "%u", off); |
|---|
| 59 |
print_sect_info(off, off); |
|---|
| 60 |
|
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
/* main */ |
|---|
| 64 |
int main(int argc, char *argv[]) |
|---|
| 65 |
{ |
|---|
| 66 |
PARAMS params; |
|---|
| 67 |
long long offset; |
|---|
| 68 |
int fd; |
|---|
| 69 |
|
|---|
| 70 |
if (argc != 3) { |
|---|
| 71 |
fprintf(stderr, |
|---|
| 72 |
"Usage : image_lvm [device] [image prefix name]\n"); |
|---|
| 73 |
exit(1); |
|---|
| 74 |
} |
|---|
| 75 |
// check for LVM |
|---|
| 76 |
lvm_check(argv[1], &offset); |
|---|
| 77 |
if (offset == 0) exit(1); |
|---|
| 78 |
|
|---|
| 79 |
params.nb_sect = offset/512; |
|---|
| 80 |
allocated_sectors(¶ms); |
|---|
| 81 |
|
|---|
| 82 |
if (argv[2][0] == '?') |
|---|
| 83 |
exit(0); |
|---|
| 84 |
|
|---|
| 85 |
// Compress now |
|---|
| 86 |
|
|---|
| 87 |
ui_send("init_backup", 5, argv[1], argv[2], info1, info2, argv[0]); |
|---|
| 88 |
fd = open(argv[1], O_RDONLY); |
|---|
| 89 |
|
|---|
| 90 |
compress_volume(fd, argv[2], ¶ms, "LVM"); |
|---|
| 91 |
close(fd); |
|---|
| 92 |
|
|---|
| 93 |
return 0; |
|---|
| 94 |
} |
|---|