root/trunk/client/revimage/image_raw.c

Revision 197, 2.3 kB (checked in by ludo, 2 years ago)

new client/server protocol for the UI (from r3948)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
Line 
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 #include <linux/fs.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include <sys/ioctl.h>
34 #include <unistd.h>
35
36 #include "compress.h"
37 #include "client.h"
38
39 char info1[32], info2[32];
40
41 void
42 allocated_sectors (PARAMS * p, char *dev)
43 {
44   int i, fd, bytes;
45   unsigned int size;
46
47   if ((fd = open (dev, O_RDONLY)) == -1) exit(1);
48  
49   if (ioctl(fd, BLKGETSIZE, &size) < 0) {
50     /* it's a file not a block dev */
51     struct stat st;
52    
53     fstat(fd, &st);
54     size = (st.st_size/512);
55     debug("Regular file: %d sectors\n",size);
56   } else {
57     debug("Block device: %d sectors\n",size);
58   }
59   close(fd);
60   if (size == 0) exit(1);
61
62   bytes = (size+7)/8;
63   p->bitmap = (unsigned char *) calloc (1, bytes);
64   p->bitmaplg = bytes;
65
66   p->nb_sect = size;
67
68   for (i = 0; i < bytes-1; i++)
69     p->bitmap[i] = 0xFF;
70   /* mark remaining sectors */
71   if (size & 7) {
72     p->bitmap[i] = (0xFF >> (8-(size & 7))) & 0xFF;
73   }
74  
75   sprintf(info1, "%u", size);
76   sprintf(info2, "%u", size);
77   print_sect_info(size, size);
78 }
79
80 int
81 main (int argc, char *argv[])
82 {
83   int fd;
84   PARAMS params;
85
86   if (argc != 3)
87     {
88       fprintf (stderr, "Usage : image_raw [device] [image prefix name]\n");
89       exit (1);
90     }
91
92   if (argv[2][0] == '?')
93     exit (0);
94
95   allocated_sectors(&params, argv[1]);
96
97   ui_send("init_backup", 5, argv[1], argv[2], info1, info2, argv[0]);
98   fd = open (argv[1], O_RDONLY); // |O_DIRECT);
99   compress_volume (fd, argv[2], &params, "");
100   close (fd);
101  
102   return 0;
103 }
Note: See TracBrowser for help on using the browser.