root/trunk/client/revimage/image_jfs.c

Revision 197, 2.8 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/types.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 checkit(char *dev)
42 {
43   int fd, bs;
44   __u8 buf[512];
45
46   fd = open (dev, O_RDONLY);
47   if (fd == -1) exit(1);
48   lseek(fd, 0x8000, SEEK_SET);
49   if (read(fd, buf, 256) != 256) exit(1);
50  
51   if (strncmp (buf, "JFS1", 4) == 0)
52     {
53       debug("JFS1 magic found\n");
54       bs = (buf[7]<<24) + (buf[6]<<16) + (buf[5]<<8) + (buf[4]);
55       debug("version: %d\n", bs);
56     }
57   else
58     {
59       debug("magic not found\n");
60       exit(1);
61     }
62  
63   close (fd);
64 }
65
66 void
67 allocated_sectors (PARAMS * p, char *dev)
68 {
69   int i, fd, bytes;
70   int size;
71
72   if ((fd = open (dev, O_RDONLY)) == -1) exit(1);
73  
74   if (ioctl(fd, BLKGETSIZE, &size) < 0) {
75     /* it's a file not a block dev */
76     struct stat st;
77    
78     fstat(fd, &st);
79     size = (st.st_size/512);
80     debug("Regular file: %d sectors\n",size);
81   } else {
82     debug("Block device: %d sectors\n",size);
83   }
84   close(fd);
85   if (size == 0) exit(1);
86
87   bytes = (size+7)/8;
88   p->bitmap = (unsigned char *) calloc (1, bytes);
89   p->bitmaplg = bytes;
90
91   p->nb_sect = size;
92
93   for (i = 0; i < bytes-1; i++)
94     p->bitmap[i] = 0xFF;
95   /* mark remaining sectors */
96   if (size & 7) {
97     p->bitmap[i] = (0xFF >> (8-(size & 7))) & 0xFF;
98   }
99  
100   sprintf(info1, "%u", size);
101   sprintf(info2, "%u", size);
102   print_sect_info(size, size);
103 }
104
105 /*  */
106 int
107 main (int argc, char *argv[])
108 {
109   int fd;
110   PARAMS params;
111
112   if (argc != 3)
113     {
114       fprintf (stderr, "Usage : image_jfs [device] [image prefix name]\n");
115       exit (1);
116     }
117
118   checkit(argv[1]);
119
120   if (argv[2][0] == '?')
121       exit (0);
122
123   allocated_sectors(&params, argv[1]);
124
125   ui_send("init_backup", 5, argv[1], argv[2], info1, info2, argv[0]);
126   fd = open (argv[1], O_RDONLY);
127   compress_volume (fd, argv[2], &params, "");
128   close (fd);
129  
130   return 0;
131 }
Note: See TracBrowser for help on using the browser.