| [1] | 1 | /* libmondo-devices.c Subroutines for handling devices
|
|---|
| [85] | 2 | $Id: libmondo-devices.c 3883 2024-03-09 23:58:41Z bruno $
|
|---|
| [1] | 3 | */
|
|---|
| 4 |
|
|---|
| 5 | /**
|
|---|
| 6 | * @file
|
|---|
| 7 | * Functions to handle interactions with backup devices.
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| [3378] | 10 | #include <sys/types.h>
|
|---|
| 11 | #include <dirent.h>
|
|---|
| 12 |
|
|---|
| [1] | 13 | #include "my-stuff.h"
|
|---|
| [2211] | 14 | #include "mr_mem.h"
|
|---|
| [2434] | 15 | #include "mr_str.h"
|
|---|
| [1] | 16 | #include "mondostructures.h"
|
|---|
| [3870] | 17 |
|
|---|
| [1] | 18 | #include "libmondo-files-EXT.h"
|
|---|
| 19 | #include "libmondo-string-EXT.h"
|
|---|
| 20 | #include "libmondo-tools-EXT.h"
|
|---|
| [541] | 21 | #include "libmondo-gui-EXT.h"
|
|---|
| [1] | 22 | #include "libmondo-fork-EXT.h"
|
|---|
| 23 | #include "libmondo-stream-EXT.h"
|
|---|
| [3872] | 24 | #include "newt-specific-EXT.h"
|
|---|
| [1] | 25 |
|
|---|
| 26 | #ifdef __FreeBSD__
|
|---|
| 27 | #define DKTYPENAMES
|
|---|
| 28 | #define FSTYPENAMES
|
|---|
| 29 | #include <sys/disklabel.h>
|
|---|
| 30 | #include <sys/disk.h>
|
|---|
| 31 | #elif linux
|
|---|
| 32 | #define u64 unsigned long long
|
|---|
| [128] | 33 | #include <linux/fs.h> /* for BLKGETSIZE64 */
|
|---|
| [1] | 34 | #include <linux/hdreg.h>
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 | /*@unused@*/
|
|---|
| [85] | 38 | //static char cvsid[] = "$Id: libmondo-devices.c 3883 2024-03-09 23:58:41Z bruno $";
|
|---|
| [2771] | 39 | //
|
|---|
| [1] | 40 |
|
|---|
| [2771] | 41 | extern char *which_compression_type();
|
|---|
| [2772] | 42 | /* Do we use extended attributes and acl ? */
|
|---|
| 43 | extern char *g_getfacl;
|
|---|
| 44 | extern char *g_getfattr;
|
|---|
| [2771] | 45 |
|
|---|
| [1] | 46 | extern int g_current_media_number;
|
|---|
| 47 | extern double g_kernel_version;
|
|---|
| 48 |
|
|---|
| 49 | extern bool g_ISO_restore_mode;
|
|---|
| [99] | 50 | extern char *g_selfmounted_isodir;
|
|---|
| [1316] | 51 | extern char *MONDO_LOGFILE;
|
|---|
| [1] | 52 |
|
|---|
| [1656] | 53 | extern void setup_tmpdir(char *path);
|
|---|
| [3154] | 54 | extern void setup_scratchdir(char *path);
|
|---|
| [3838] | 55 | extern char *call_program_and_get_last_line_of_output(const char *);
|
|---|
| [1656] | 56 |
|
|---|
| [1] | 57 | /**
|
|---|
| 58 | * ????? @bug ?????
|
|---|
| 59 | * @ingroup globalGroup
|
|---|
| 60 | */
|
|---|
| [128] | 61 | bool g_restoring_live_from_cd = FALSE;
|
|---|
| [2380] | 62 | bool g_restoring_live_from_netfs = FALSE;
|
|---|
| [1] | 63 |
|
|---|
| [128] | 64 | extern t_bkptype g_backup_media_type; // set by main()
|
|---|
| [1] | 65 |
|
|---|
| [1645] | 66 | /* Reference to global bkpinfo */
|
|---|
| 67 | extern struct s_bkpinfo *bkpinfo;
|
|---|
| [1] | 68 |
|
|---|
| [2424] | 69 | /* Stuff that handles the -I and -E option when a whole disk DSF is used */
|
|---|
| 70 | typedef struct mounted_fs_struct {
|
|---|
| 71 | char device[MAX_STR_LEN]; /* The name of the device */
|
|---|
| 72 | char mount_point[MAX_STR_LEN]; /* The devices mount point */
|
|---|
| 73 | unsigned char check; /* 1 == included on DSF */
|
|---|
| 74 | struct mounted_fs_struct *next;
|
|---|
| 75 | } MOUNTED_FS_STRUCT;
|
|---|
| [1] | 76 |
|
|---|
| [2424] | 77 | static MOUNTED_FS_STRUCT *DSF_Head = NULL; /* Points to the first entry of mounted_fs_struct list */
|
|---|
| 78 | static MOUNTED_FS_STRUCT *DSF_Tail = NULL; /* Points to the last entry of mounted_fs_struct list */
|
|---|
| [1] | 79 |
|
|---|
| [1645] | 80 |
|
|---|
| [1] | 81 | /**
|
|---|
| [3879] | 82 | * Frees the memory for all of the structures on the linked list of
|
|---|
| 83 | * all of the non-NETFS mounted file systems.
|
|---|
| 84 | */
|
|---|
| 85 | static void free_mounted_fs_list (void) {
|
|---|
| 86 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
|---|
| 87 | MOUNTED_FS_STRUCT *DSFnext = NULL;
|
|---|
| 88 |
|
|---|
| 89 | DSFptr = DSF_Head;
|
|---|
| 90 | while (DSFptr != NULL) {
|
|---|
| 91 | DSFnext = DSFptr->next;
|
|---|
| 92 | paranoid_free(DSFptr);
|
|---|
| 93 | DSFptr = DSFnext;
|
|---|
| 94 | }
|
|---|
| 95 | DSF_Head = NULL;
|
|---|
| 96 | DSF_Tail = NULL;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * Creates a singly linked list of all of the non-NETFS mounted file systems.
|
|---|
| 102 | * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold
|
|---|
| 103 | * the list of mounted file systems.
|
|---|
| 104 | * @return None.
|
|---|
| 105 | */
|
|---|
| 106 | static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
|
|---|
| 107 | {
|
|---|
| 108 | assert (DSFptr);
|
|---|
| 109 | if (DSF_Head == NULL) {
|
|---|
| 110 | DSF_Head = DSFptr;
|
|---|
| 111 | } else {
|
|---|
| 112 | DSF_Tail->next = DSFptr;
|
|---|
| 113 | }
|
|---|
| 114 | DSFptr->next = NULL;
|
|---|
| 115 | DSF_Tail = DSFptr;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | /**
|
|---|
| 121 | * Creates a linked list of all of the non-NETFS mounted file systems.
|
|---|
| 122 | * We use a linked list because we don't know how many mounted file
|
|---|
| 123 | * there are (and there can be a lot).
|
|---|
| 124 | * @return 0 on success and greated than 0 on failure.
|
|---|
| 125 | */
|
|---|
| 126 | static int create_list_of_non_NETFS_mounted_file_systems (void)
|
|---|
| 127 | {
|
|---|
| 128 | int i = 0;
|
|---|
| 129 | int mount_cnt = 0;
|
|---|
| 130 | int lastpos = 0;
|
|---|
| 131 | char *mounted_file_system = NULL;
|
|---|
| 132 | char *command = NULL;
|
|---|
| 133 | char *token = NULL;
|
|---|
| 134 | char token_chars[] =" :\t\r\f\a\0";
|
|---|
| 135 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
|---|
| 136 |
|
|---|
| 137 | free_mounted_fs_list();
|
|---|
| 138 | /********
|
|---|
| 139 | * Find the number of mounted file system entries and their respective mount points.
|
|---|
| 140 | * I can't return all of the entries as one string because it's length can be longer
|
|---|
| 141 | * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
|
|---|
| 142 | * So start looping and get the number of mounted file systems and query them one by one.
|
|---|
| 143 | ********/
|
|---|
| 144 | /* Get the number of mounted file systems ((those that start with "/dev/" */
|
|---|
| 145 | mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
|
|---|
| 146 | log_msg(5, "Running: %s", command);
|
|---|
| 147 | mounted_file_system = call_program_and_get_last_line_of_output(command);
|
|---|
| 148 | mr_free(command);
|
|---|
| 149 |
|
|---|
| 150 | mount_cnt = atoi(mounted_file_system);
|
|---|
| 151 | log_msg (5, "mount_cnt: %d", mount_cnt);
|
|---|
| 152 | mr_free(mounted_file_system);
|
|---|
| 153 |
|
|---|
| 154 | for (i=mount_cnt; i > 0; i--) {
|
|---|
| 155 | mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
|
|---|
| 156 | log_msg(5, "Running: %s", command);
|
|---|
| 157 | mounted_file_system = call_program_and_get_last_line_of_output(command);
|
|---|
| 158 | mr_free(command);
|
|---|
| 159 |
|
|---|
| 160 | log_msg (5, "mounted_file_system: %s", mounted_file_system);
|
|---|
| 161 | if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
|
|---|
| 162 | log_msg (4, "Could not get the list of mounted file systems");
|
|---|
| 163 | mr_free(mounted_file_system);
|
|---|
| 164 | mr_free(token);
|
|---|
| 165 | return (1);
|
|---|
| 166 | }
|
|---|
| 167 | if (token) {
|
|---|
| 168 | log_msg (5, "token: %s", token);
|
|---|
| 169 | }
|
|---|
| 170 | while (token != NULL) {
|
|---|
| 171 | log_msg (5, "token: %s", token);
|
|---|
| 172 | if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
|
|---|
| 173 | fatal_error ("Cannot allocate memory");
|
|---|
| 174 | }
|
|---|
| 175 | add_mounted_fs_struct(DSFptr);
|
|---|
| 176 | strcpy(DSFptr->device, token);
|
|---|
| 177 | mr_free(token);
|
|---|
| 178 | if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
|
|---|
| 179 | log_msg (5, "Ran out of entries on the mounted file systems list");
|
|---|
| 180 | mr_free(mounted_file_system);
|
|---|
| 181 | mr_free(token);
|
|---|
| 182 | return (1);
|
|---|
| 183 | }
|
|---|
| 184 | log_msg (5, "token: %s", token);
|
|---|
| 185 | strcpy(DSFptr->mount_point, token);
|
|---|
| 186 | mr_free(token);
|
|---|
| 187 | token = mr_strtok(mounted_file_system, token_chars, &lastpos);
|
|---|
| 188 | }
|
|---|
| 189 | mr_free(mounted_file_system);
|
|---|
| 190 | }
|
|---|
| 191 | return (0);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /**
|
|---|
| 195 | * Find the structure, in the singly linked list of all of the non-NETFS
|
|---|
| 196 | * mounted file systems, that contains the specified mount point.
|
|---|
| 197 | * @param mount_point The mount point to find
|
|---|
| 198 | * @return NULL is it didn't find the mount point, a pointer to the
|
|---|
| 199 | * structure if it did.
|
|---|
| 200 | */
|
|---|
| 201 | static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
|
|---|
| 202 | {
|
|---|
| 203 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
|---|
| 204 |
|
|---|
| 205 | DSFptr = DSF_Head;
|
|---|
| 206 | while (DSFptr != NULL) {
|
|---|
| 207 | if (!strcmp(DSFptr->mount_point, mount_point)) {
|
|---|
| 208 | break;
|
|---|
| 209 | }
|
|---|
| 210 | DSFptr = DSFptr->next;
|
|---|
| 211 | }
|
|---|
| 212 | return (DSFptr);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 | /**
|
|---|
| 217 | * Find the structure, in the singly linked list of all of the non-NETFS
|
|---|
| 218 | * mounted file systems, that contains the specified device.
|
|---|
| 219 | * @param device The device to find
|
|---|
| 220 | * @return NULL if it didn't find the device, a pointer to the
|
|---|
| 221 | * structure if it did.
|
|---|
| 222 | */
|
|---|
| 223 | static MOUNTED_FS_STRUCT *find_device_in_list(char *device) {
|
|---|
| 224 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
|---|
| 225 |
|
|---|
| 226 | DSFptr = DSF_Head;
|
|---|
| 227 | while (DSFptr != NULL) {
|
|---|
| 228 | if (!strcmp(DSFptr->device, device)) {
|
|---|
| 229 | break;
|
|---|
| 230 | }
|
|---|
| 231 | DSFptr = DSFptr->next;
|
|---|
| 232 | }
|
|---|
| 233 | return (DSFptr);
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | /**
|
|---|
| 238 | * Given a whole disk device special file, determine which mounted file systems
|
|---|
| 239 | * are on the dsf's partitions and which mounted file systems are not.
|
|---|
| 240 | * @param dsf The whole disk device special file.
|
|---|
| 241 | * @param included_dsf_list A char pointer used to hold the list of mount points
|
|---|
| 242 | * that are on the dsf. Memory for the array will be allocated within the function.
|
|---|
| 243 | * @param excluded_dsf_list A char pointer used to hold the list of mount points
|
|---|
| 244 | * that are not on the dsf. Memory for the array will be allocated within the function.
|
|---|
| 245 | * @return 0 on success, -1 if no device special file was passed in, -2 if a device
|
|---|
| 246 | * special file was passed in but it has no partitions on it, or 1 on failure
|
|---|
| 247 | */
|
|---|
| 248 | static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
|
|---|
| 249 | int i = 0;
|
|---|
| 250 | int c = 0;
|
|---|
| 251 | int lastpos = 0;
|
|---|
| 252 | char *VG = NULL;
|
|---|
| 253 | char *tmp = NULL;
|
|---|
| 254 | char *command = NULL;
|
|---|
| 255 | char *partition_list = NULL;
|
|---|
| 256 | char partitions[64][MAX_STR_LEN];
|
|---|
| 257 | char *mount_list = NULL;
|
|---|
| 258 | char *token = NULL;
|
|---|
| 259 | char *ndsf = NULL;
|
|---|
| 260 | char token_chars[] =" \t\r\f\a\0";
|
|---|
| 261 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
|---|
| 262 |
|
|---|
| 263 | memset((char *)partitions, 0, sizeof(partitions));
|
|---|
| 264 |
|
|---|
| 265 | log_msg(5, "dsf: %s", dsf);
|
|---|
| 266 |
|
|---|
| 267 | /********
|
|---|
| 268 | * See if a device special file was passed in (i.e. it must start with /dev/
|
|---|
| 269 | ********/
|
|---|
| 270 | if (strncmp(dsf, "/dev/", 5)) {
|
|---|
| 271 | log_msg (4, "%s does not start with /dev/ and (probably) is not a device special file", dsf);
|
|---|
| 272 | return (-1);
|
|---|
| 273 | }
|
|---|
| 274 | log_msg(4, " %s looks like a device special file", dsf);
|
|---|
| 275 | /* Verify that the dsf exists */
|
|---|
| 276 | mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);
|
|---|
| 277 | log_msg(5, " Executing: %s", command);
|
|---|
| 278 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 279 | mr_free(command);
|
|---|
| 280 |
|
|---|
| 281 | log_msg(5, " Return value: %s", tmp);
|
|---|
| 282 | c = atoi(tmp);
|
|---|
| 283 | mr_free(tmp);
|
|---|
| 284 |
|
|---|
| 285 | if (!c) {
|
|---|
| 286 | log_to_screen("Cannot find device special file %s", dsf);
|
|---|
| 287 | return (1);
|
|---|
| 288 | }
|
|---|
| 289 | log_msg(4, " %s device special file exists", dsf);
|
|---|
| 290 |
|
|---|
| 291 | /* Get a list of the mounted file systems */
|
|---|
| 292 | if (create_list_of_non_NETFS_mounted_file_systems()) {
|
|---|
| 293 | log_to_screen ("Could not get the list of mounted file systems");
|
|---|
| 294 | return (1);
|
|---|
| 295 | }
|
|---|
| 296 | log_msg (5, "Processing dsf: %s", dsf);
|
|---|
| 297 | /********
|
|---|
| 298 | * Get a list of the dsf's partitions. There could be no partitions on the disk
|
|---|
| 299 | * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
|
|---|
| 300 | * Either way, it's an error.
|
|---|
| 301 | ********/
|
|---|
| 302 | mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
|
|---|
| 303 | log_msg(5, "Executing: %s", command);
|
|---|
| 304 | partition_list = call_program_and_get_last_line_of_output(command);
|
|---|
| 305 | mr_free(command);
|
|---|
| 306 | log_msg(4, "Partition list for %s: %s", dsf, partition_list);
|
|---|
| 307 | if (!strlen(partition_list)) {
|
|---|
| 308 | /* There were no partitions on the disk */
|
|---|
| 309 | log_msg(4, "No partitions on device special file %s", dsf);
|
|---|
| 310 | log_msg(4, "I guess it's a partition itself");
|
|---|
| 311 | strcpy(partitions[0], dsf);
|
|---|
| 312 | ndsf = truncate_to_drive_name(dsf);
|
|---|
| 313 | } else {
|
|---|
| 314 | /* Fill the partition list */
|
|---|
| 315 | i = 0;
|
|---|
| 316 | lastpos = 0;
|
|---|
| 317 | while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
|
|---|
| 318 | log_msg (4, "Found partition: %s", token);
|
|---|
| 319 | strcpy(partitions[i++], token);
|
|---|
| 320 | mr_free(token);
|
|---|
| 321 | }
|
|---|
| 322 | mr_asprintf(ndsf, "%s", dsf);
|
|---|
| 323 | }
|
|---|
| 324 | mr_free(partition_list);
|
|---|
| 325 |
|
|---|
| 326 | /* In any case we want to exclude the dsf itself from all MondRescue activities
|
|---|
| 327 | * at restore time (LVM, fdisk, ...) so we want it in our exclude_dev list */
|
|---|
| 328 | if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
|
|---|
| 329 | fatal_error ("Cannot allocate memory");
|
|---|
| 330 | }
|
|---|
| 331 | add_mounted_fs_struct(DSFptr);
|
|---|
| 332 | strcpy(DSFptr->device, dsf);
|
|---|
| 333 | DSFptr->check = 1;
|
|---|
| 334 |
|
|---|
| 335 | /* For the rest ndsf is the new dsf to deal with */
|
|---|
| 336 | /********
|
|---|
| 337 | * At this point, we have a list of all of the partitions on the dsf. Now try to
|
|---|
| 338 | * see which partitions have a file system on them.
|
|---|
| 339 | *
|
|---|
| 340 | * Loop through each partition on the disk and:
|
|---|
| 341 | *
|
|---|
| 342 | * - If the partition is swap, it ignores it.
|
|---|
| 343 | *
|
|---|
| 344 | * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
|
|---|
| 345 | * to the linked list, copies to it the device name and mount point, and sets check == 1.
|
|---|
| 346 | *
|
|---|
| 347 | * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
|
|---|
| 348 | * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
|
|---|
| 349 | * to it the device name and mount point, and sets check == 1. Note that if the Volume Group
|
|---|
| 350 | * contains more than one disk, it will still add the entry even if the Logical Volume's
|
|---|
| 351 | * extents are not on the dsf that was passed in to the function. For example, Volume Group
|
|---|
| 352 | * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
|
|---|
| 353 | * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
|
|---|
| 354 | * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
|
|---|
| 355 | * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
|
|---|
| 356 | *
|
|---|
| 357 | * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
|
|---|
| 358 | * software raid device, it adds an entry to the linked list, copies to it the software raid
|
|---|
| 359 | * device name and mount point, and sets check == 1.
|
|---|
| 360 | *
|
|---|
| 361 | * - If the partition is part of a mounted software raid device, it adds an entry to the linked
|
|---|
| 362 | * list, copies to it the software raid device name and mount point, and sets check == 1.
|
|---|
| 363 | *
|
|---|
| 364 | ********/
|
|---|
| 365 | for (i=0; strlen(partitions[i]); i++) {
|
|---|
| 366 | log_msg(4, "Processing partition: %s", partitions[i]);
|
|---|
| 367 | /* See if it's swap. If it is, ignore it. */
|
|---|
| 368 | mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
|
|---|
| 369 | log_msg(5, " Running: %s", command);
|
|---|
| 370 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 371 | mr_free(command);
|
|---|
| 372 |
|
|---|
| 373 | log_msg(5, " Return value: %s", tmp);
|
|---|
| 374 | c = strlen(tmp);
|
|---|
| 375 | mr_free(tmp);
|
|---|
| 376 |
|
|---|
| 377 | if (c) {
|
|---|
| 378 | log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
|
|---|
| 379 | continue;
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | /* It's not swap. See if we can find the mount point from the mount command. */
|
|---|
| 383 | mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
|
|---|
| 384 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 385 | mr_free(command);
|
|---|
| 386 |
|
|---|
| 387 | if (strlen(tmp)) {
|
|---|
| 388 | log_msg(4, " %s is mounted: %s", partitions[i], tmp);
|
|---|
| 389 | if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
|
|---|
| 390 | log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
|
|---|
| 391 | mr_free(tmp);
|
|---|
| 392 | return (1);
|
|---|
| 393 | }
|
|---|
| 394 | DSFptr->check = 1;
|
|---|
| 395 | mr_free(tmp);
|
|---|
| 396 | continue;
|
|---|
| 397 | }
|
|---|
| 398 | mr_free(tmp);
|
|---|
| 399 |
|
|---|
| 400 | /* It's not swap and it's not mounted. See if it's LVM */
|
|---|
| 401 | log_msg(4, " It's not mounted. Checking to see if it's LVM...");
|
|---|
| 402 |
|
|---|
| 403 | /* Check for LVM */
|
|---|
| 404 | mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]);
|
|---|
| 405 | log_msg(5, " Running: %s", command);
|
|---|
| 406 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 407 | mr_free(command);
|
|---|
| 408 |
|
|---|
| 409 | if (strlen(tmp)) {
|
|---|
| 410 | log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]);
|
|---|
| 411 | /* It's LVM: Find the VG it's in */
|
|---|
| 412 | mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
|
|---|
| 413 | log_msg(5, " Running: %s", command);
|
|---|
| 414 | VG = call_program_and_get_last_line_of_output(command);
|
|---|
| 415 | mr_free(command);
|
|---|
| 416 |
|
|---|
| 417 | log_msg(4, " Volume Group: %s", VG);
|
|---|
| 418 | if (strlen(VG)) {
|
|---|
| 419 | /* Found the Volume Group. Now find all of the VG's mount points */
|
|---|
| 420 | log_msg(4, " Found the Volume Group. Now find all of the VG's mount points");
|
|---|
| 421 | mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
|
|---|
| 422 | log_msg(5, " Running: %s", command);
|
|---|
| 423 | mount_list = call_program_and_get_last_line_of_output(command);
|
|---|
| 424 | mr_free(command);
|
|---|
| 425 |
|
|---|
| 426 | log_msg(4, " VG %s mount_list: %s", VG, mount_list);
|
|---|
| 427 | lastpos = 0;
|
|---|
| 428 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
|---|
| 429 | log_msg (5, "mount point token: %s", token);
|
|---|
| 430 | if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
|
|---|
| 431 | log_msg (4, "Can't find mount point %s in mounted file systems list", token);
|
|---|
| 432 | mr_free(tmp);
|
|---|
| 433 | mr_free(token);
|
|---|
| 434 | return (1);
|
|---|
| 435 | }
|
|---|
| 436 | DSFptr->check = 1;
|
|---|
| 437 | mr_free(token);
|
|---|
| 438 | }
|
|---|
| 439 | /********
|
|---|
| 440 | * Now we want to see if there are any software raid devices using
|
|---|
| 441 | * any of the Logical Volumes on the Volume Group.
|
|---|
| 442 | *******/
|
|---|
| 443 | mr_free(mount_list);
|
|---|
| 444 |
|
|---|
| 445 | mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
|
|---|
| 446 | log_msg (5, "Running: %s", command);
|
|---|
| 447 | mount_list = call_program_and_get_last_line_of_output(command);
|
|---|
| 448 | mr_free(command);
|
|---|
| 449 | log_msg(4, " Software raid device list: %s", mount_list);
|
|---|
| 450 | lastpos = 0;
|
|---|
| 451 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
|---|
| 452 | mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
|
|---|
| 453 | log_msg (5, "Running: %s", command);
|
|---|
| 454 | mr_free(tmp);
|
|---|
| 455 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 456 | mr_free(command);
|
|---|
| 457 | log_msg(4, "Number of Software raid device: %s", tmp);
|
|---|
| 458 | if (atoi(tmp)) {
|
|---|
| 459 | /* This device is on our disk */
|
|---|
| 460 | if ((DSFptr = find_device_in_list(token)) == NULL) {
|
|---|
| 461 | log_msg (4, "Can't find device %s in mounted file systems list", token);
|
|---|
| 462 | mr_free(tmp);
|
|---|
| 463 | mr_free(token);
|
|---|
| 464 | return (1);
|
|---|
| 465 | }
|
|---|
| 466 | DSFptr->check = 1;
|
|---|
| 467 | }
|
|---|
| 468 | }
|
|---|
| 469 | mr_free(token);
|
|---|
| 470 | paranoid_free(mount_list);
|
|---|
| 471 | } else {
|
|---|
| 472 | log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
|
|---|
| 473 | mr_free(tmp);
|
|---|
| 474 | return (1);
|
|---|
| 475 | }
|
|---|
| 476 | mr_free(tmp);
|
|---|
| 477 | mr_free(VG);
|
|---|
| 478 | continue;
|
|---|
| 479 | } else {
|
|---|
| 480 | log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
|
|---|
| 481 | }
|
|---|
| 482 | mr_free(tmp);
|
|---|
| 483 |
|
|---|
| 484 | /********
|
|---|
| 485 | * It's not swap, mounted, or LVM. See if it's used in a software raid device.
|
|---|
| 486 | ********/
|
|---|
| 487 | log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
|
|---|
| 488 | mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
|
|---|
| 489 | log_msg(4, " Running: %s", command);
|
|---|
| 490 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 491 | mr_free(command);
|
|---|
| 492 |
|
|---|
| 493 | if (!strlen(tmp)) {
|
|---|
| 494 | log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]);
|
|---|
| 495 | mr_free(tmp);
|
|---|
| 496 | continue;
|
|---|
| 497 | }
|
|---|
| 498 | log_msg (5, " UUID: %s", tmp);
|
|---|
| 499 |
|
|---|
| 500 | /* Get the Software raid device list */
|
|---|
| 501 | mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
|
|---|
| 502 | log_msg (5, " Running: %s", command);
|
|---|
| 503 | mount_list = call_program_and_get_last_line_of_output(command);
|
|---|
| 504 | mr_free(command);
|
|---|
| 505 |
|
|---|
| 506 | log_msg(4, " Software raid device list: %s", mount_list);
|
|---|
| 507 | /* Loop through the software raid device list to see if we can find the partition */
|
|---|
| 508 | lastpos = 0;
|
|---|
| 509 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
|---|
| 510 | mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
|
|---|
| 511 | log_msg(4, " Running: %s", command);
|
|---|
| 512 | mr_free(tmp);
|
|---|
| 513 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| 514 | mr_free(command);
|
|---|
| 515 |
|
|---|
| 516 | if (!atoi(tmp)) {
|
|---|
| 517 | log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token);
|
|---|
| 518 | } else {
|
|---|
| 519 | if ((DSFptr = find_device_in_list(token)) == NULL) {
|
|---|
| 520 | log_msg (4, "Can't find device %s in mounted file systems list", token);
|
|---|
| 521 | mr_free(tmp);
|
|---|
| 522 | mr_free(token);
|
|---|
| 523 | return (1);
|
|---|
| 524 | }
|
|---|
| 525 | DSFptr->check = 1;
|
|---|
| 526 | break;
|
|---|
| 527 | }
|
|---|
| 528 | mr_free(token);
|
|---|
| 529 | }
|
|---|
| 530 | mr_free(tmp);
|
|---|
| 531 | mr_free(mount_list);
|
|---|
| 532 | }
|
|---|
| 533 |
|
|---|
| 534 | /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
|
|---|
| 535 | i = 0;
|
|---|
| 536 | DSFptr= DSF_Head;
|
|---|
| 537 | while (DSFptr != NULL) {
|
|---|
| 538 | i += strlen(DSFptr->mount_point) + 1;
|
|---|
| 539 | DSFptr = DSFptr->next;
|
|---|
| 540 | }
|
|---|
| 541 | log_msg (5, "i: %d", i);
|
|---|
| 542 | if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
|
|---|
| 543 | fatal_error ("Cannot allocate memory");
|
|---|
| 544 | }
|
|---|
| 545 | if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
|
|---|
| 546 | fatal_error ("Cannot allocate memory");
|
|---|
| 547 | }
|
|---|
| 548 | DSFptr= DSF_Head;
|
|---|
| 549 | while (DSFptr != NULL) {
|
|---|
| 550 | if (DSFptr->check) {
|
|---|
| 551 | log_msg (4, "%s is mounted on %s and is on disk %s", DSFptr->device, DSFptr->mount_point, ndsf);
|
|---|
| 552 | strcat(*included_dsf_list, DSFptr->mount_point);
|
|---|
| 553 | strcat(*included_dsf_list, "|");
|
|---|
| 554 | } else {
|
|---|
| 555 | log_msg (4, "%s is mounted on %s and is NOT on disk %s", DSFptr->device, DSFptr->mount_point, ndsf);
|
|---|
| 556 | strcat(*excluded_dsf_list, DSFptr->mount_point);
|
|---|
| 557 | strcat(*excluded_dsf_list, "|");
|
|---|
| 558 | }
|
|---|
| 559 | DSFptr = DSFptr->next;
|
|---|
| 560 | }
|
|---|
| 561 | mr_free(ndsf);
|
|---|
| 562 |
|
|---|
| 563 | log_msg (5, "included_dsf_list: %s", *included_dsf_list);
|
|---|
| 564 | log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
|
|---|
| 565 | return (0);
|
|---|
| 566 | }
|
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 | /**
|
|---|
| 570 | * Load (inject) the tray of the specified CD device.
|
|---|
| 571 | * @param dev The device to load/inject.
|
|---|
| 572 | * @return 0 for success, nonzero for failure.
|
|---|
| 573 | */
|
|---|
| 574 | int inject_device(char *dev)
|
|---|
| 575 | {
|
|---|
| 576 | char *command = NULL;
|
|---|
| 577 | int i;
|
|---|
| 578 |
|
|---|
| 579 | if (dev == NULL) {
|
|---|
| 580 | return (1);
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | #ifdef __FreeBSD__
|
|---|
| 584 | if (strstr(dev, "acd")) {
|
|---|
| 585 | mr_asprintf(command, "cdcontrol -f %s close", dev);
|
|---|
| 586 | } else {
|
|---|
| 587 | mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev);
|
|---|
| 588 | }
|
|---|
| 589 | #else
|
|---|
| 590 | mr_asprintf(command, "eject -t %s", dev);
|
|---|
| 591 | #endif
|
|---|
| 592 | i = run_program_and_log_output(command, FALSE);
|
|---|
| 593 | mr_free(command);
|
|---|
| 594 | return (i);
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 | /**
|
|---|
| [1] | 599 | * Retract all CD trays and wait for autorun to complete.
|
|---|
| 600 | * @ingroup deviceGroup
|
|---|
| 601 | */
|
|---|
| 602 | void retract_CD_tray_and_defeat_autorun(void)
|
|---|
| 603 | {
|
|---|
| [3878] | 604 | // log_it("rctada: Retracting optical tray", __LINE__);
|
|---|
| [2931] | 605 | if (!bkpinfo->please_dont_eject) {
|
|---|
| [3878] | 606 | if (bkpinfo->media_device != NULL) {
|
|---|
| 607 | inject_device(bkpinfo->media_device);
|
|---|
| [3879] | 608 | }
|
|---|
| [128] | 609 | }
|
|---|
| 610 | if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) {
|
|---|
| 611 | log_it("autorun detected; sleeping for 2 seconds");
|
|---|
| 612 | sleep(2);
|
|---|
| 613 | }
|
|---|
| [1] | 614 | }
|
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 | /**
|
|---|
| [3878] | 619 | * Find out what device is mounted as root (/).
|
|---|
| 620 | * @return Root device.
|
|---|
| 621 | * @note The returned string points to storage that needs to be freed by
|
|---|
| 622 | * caller
|
|---|
| 623 | * @bug A bit of a misnomer; it's actually finding out the root device.
|
|---|
| 624 | * The mountpoint (where it's mounted) will obviously be '/'.
|
|---|
| 625 | */
|
|---|
| 626 | char *where_is_root_mounted(void) {
|
|---|
| 627 |
|
|---|
| 628 | /*@ buffers **************** */
|
|---|
| 629 | char *tmp = NULL;
|
|---|
| 630 |
|
|---|
| 631 | #ifdef __FreeBSD__
|
|---|
| 632 | tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
|
|---|
| 633 | #else
|
|---|
| 634 | tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
|
|---|
| 635 | if (strstr(tmp, "/dev/cciss/")) {
|
|---|
| 636 | mr_free(tmp);
|
|---|
| 637 | tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
|
|---|
| 638 | }
|
|---|
| 639 | if (strstr(tmp, "/dev/md")) {
|
|---|
| 640 | mr_free(tmp);
|
|---|
| 641 | tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
|
|---|
| 642 | }
|
|---|
| 643 | #endif
|
|---|
| 644 |
|
|---|
| 645 | return (tmp);
|
|---|
| 646 | }
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 | /**
|
|---|
| [1] | 651 | * Determine whether we're booted off a ramdisk.
|
|---|
| 652 | * @return @c TRUE (we are) or @c FALSE (we aren't).
|
|---|
| 653 | * @ingroup utilityGroup
|
|---|
| 654 | */
|
|---|
| [128] | 655 | bool am_I_in_disaster_recovery_mode(void)
|
|---|
| [1] | 656 | {
|
|---|
| [2214] | 657 | char *tmp = NULL;
|
|---|
| [128] | 658 | bool is_this_a_ramdisk = FALSE;
|
|---|
| [1] | 659 |
|
|---|
| [3610] | 660 | tmp = where_is_root_mounted();
|
|---|
| [3380] | 661 | log_msg(0, "root is mounted at %s", tmp);
|
|---|
| [3191] | 662 | log_msg(0, "That doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp);
|
|---|
| [1] | 663 |
|
|---|
| 664 | #ifdef __FreeBSD__
|
|---|
| [128] | 665 | if (strstr(tmp, "/dev/md")) {
|
|---|
| 666 | is_this_a_ramdisk = TRUE;
|
|---|
| 667 | }
|
|---|
| [1] | 668 | #else
|
|---|
| [128] | 669 | if (!strncmp(tmp, "/dev/ram", 8)
|
|---|
| 670 | || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/")
|
|---|
| 671 | && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
|
|---|
| 672 | || !strcmp(tmp, "/dev/root")) {
|
|---|
| 673 | is_this_a_ramdisk = TRUE;
|
|---|
| 674 | } else {
|
|---|
| 675 | is_this_a_ramdisk = FALSE;
|
|---|
| 676 | }
|
|---|
| [1] | 677 | #endif
|
|---|
| [2214] | 678 | mr_free(tmp);
|
|---|
| [1] | 679 |
|
|---|
| [128] | 680 | if (is_this_a_ramdisk) {
|
|---|
| [1983] | 681 | if (!does_file_exist("/THIS-IS-A-RAMDISK")) {
|
|---|
| [3191] | 682 | log_to_screen("Using /dev/root is stupid of you but I'll forgive you.");
|
|---|
| [128] | 683 | is_this_a_ramdisk = FALSE;
|
|---|
| 684 | }
|
|---|
| 685 | }
|
|---|
| 686 | if (does_file_exist("/THIS-IS-A-RAMDISK")) {
|
|---|
| 687 | is_this_a_ramdisk = TRUE;
|
|---|
| 688 | }
|
|---|
| [3191] | 689 |
|
|---|
| 690 | log_msg(1, "Is this a ramdisk? result = %s", (is_this_a_ramdisk) ? "TRUE" : "FALSE");
|
|---|
| [128] | 691 | return (is_this_a_ramdisk);
|
|---|
| [1] | 692 | }
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
|
|---|
| 698 | /**
|
|---|
| 699 | * Turn @c bkpinfo->backup_media_type into a human-readable string.
|
|---|
| [3881] | 700 | * @return The human readable string (e.g. @c optical becomes <tt>"optical"</tt>).
|
|---|
| [1] | 701 | * @note The returned string points to static storage that will be overwritten with each call.
|
|---|
| 702 | * @ingroup stringGroup
|
|---|
| 703 | */
|
|---|
| 704 | static char *bkptype_to_string(t_bkptype bt)
|
|---|
| 705 | {
|
|---|
| [3879] | 706 | char *output = NULL;
|
|---|
| [128] | 707 | switch (bt) {
|
|---|
| 708 | case none:
|
|---|
| [3879] | 709 | mr_asprintf(output, "%s", "none");
|
|---|
| [1] | 710 | break;
|
|---|
| [128] | 711 | case iso:
|
|---|
| [3879] | 712 | mr_asprintf(output, "%s", "iso");
|
|---|
| [1] | 713 | break;
|
|---|
| [3881] | 714 | case optical:
|
|---|
| 715 | mr_asprintf(output, "%s", "optical");
|
|---|
| [1] | 716 | break;
|
|---|
| [2380] | 717 | case netfs:
|
|---|
| [3879] | 718 | mr_asprintf(output, "%s", "netfs");
|
|---|
| [1] | 719 | break;
|
|---|
| [128] | 720 | case tape:
|
|---|
| [3879] | 721 | mr_asprintf(output, "%s", "tape");
|
|---|
| [1] | 722 | break;
|
|---|
| [128] | 723 | case udev:
|
|---|
| [3879] | 724 | mr_asprintf(output, "%s", "udev");
|
|---|
| [1] | 725 | break;
|
|---|
| [1687] | 726 | case usb:
|
|---|
| [3879] | 727 | mr_asprintf(output, "%s", "usb");
|
|---|
| [1687] | 728 | break;
|
|---|
| [128] | 729 | default:
|
|---|
| [3879] | 730 | mr_asprintf(output, "%s", "default");
|
|---|
| [128] | 731 | }
|
|---|
| 732 | return (output);
|
|---|
| [1] | 733 | }
|
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 | /**
|
|---|
| 738 | * @addtogroup deviceGroup
|
|---|
| 739 | * @{
|
|---|
| 740 | */
|
|---|
| 741 | /**
|
|---|
| 742 | * Eject the tray of the specified CD device.
|
|---|
| 743 | * @param dev The device to eject.
|
|---|
| 744 | * @return the return value of the @c eject command. (0=success, nonzero=failure)
|
|---|
| 745 | */
|
|---|
| [128] | 746 | int eject_device(char *dev)
|
|---|
| [1] | 747 | {
|
|---|
| [3191] | 748 | char *command = NULL;
|
|---|
| [128] | 749 | int res1 = 0, res2 = 0;
|
|---|
| [1] | 750 |
|
|---|
| [3191] | 751 | if (dev == NULL) {
|
|---|
| 752 | return (1);
|
|---|
| 753 | }
|
|---|
| [1] | 754 |
|
|---|
| [128] | 755 | if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
|
|---|
| 756 | && g_backup_media_type != udev) {
|
|---|
| [3191] | 757 | mr_asprintf(command, "mt -f %s offline", dev);
|
|---|
| [128] | 758 | res1 = run_program_and_log_output(command, 1);
|
|---|
| [3191] | 759 | mr_free(command);
|
|---|
| [128] | 760 | } else {
|
|---|
| 761 | res1 = 0;
|
|---|
| 762 | }
|
|---|
| [1] | 763 |
|
|---|
| 764 | #ifdef __FreeBSD__
|
|---|
| [128] | 765 | if (strstr(dev, "acd")) {
|
|---|
| [3191] | 766 | mr_asprintf(command, "cdcontrol -f %s eject", dev);
|
|---|
| [128] | 767 | } else {
|
|---|
| [3191] | 768 | mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev);
|
|---|
| [128] | 769 | }
|
|---|
| [1] | 770 | #else
|
|---|
| [3191] | 771 | mr_asprintf(command, "eject %s", dev);
|
|---|
| [1] | 772 | #endif
|
|---|
| 773 |
|
|---|
| [128] | 774 | log_msg(3, "Ejecting %s", dev);
|
|---|
| 775 | res2 = run_program_and_log_output(command, 1);
|
|---|
| [3191] | 776 | mr_free(command);
|
|---|
| [128] | 777 | if (res1 && res2) {
|
|---|
| 778 | return (1);
|
|---|
| 779 | } else {
|
|---|
| 780 | return (0);
|
|---|
| 781 | }
|
|---|
| [1] | 782 | }
|
|---|
| 783 |
|
|---|
| 784 | /**
|
|---|
| 785 | * Determine whether a non-Microsoft partition exists on any connected hard drive.
|
|---|
| [3653] | 786 | * @return TRUE (there's a Linux/FreeBSD partition) or FALSE (Microsoft has taken over yet another innocent machine).
|
|---|
| [1] | 787 | */
|
|---|
| [128] | 788 | bool does_nonMS_partition_exist(void)
|
|---|
| [1] | 789 | {
|
|---|
| 790 | #if __FreeBSD__
|
|---|
| [128] | 791 | return
|
|---|
| [3371] | 792 | !system("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
|
|---|
| [1] | 793 | #else
|
|---|
| [128] | 794 | return
|
|---|
| [3377] | 795 | !system("mr-parted2fdisk -l 2>/dev/null | grep '^/dev/' | grep -Eqv '(MS|DOS|EFI|FAT|NTFS)'");
|
|---|
| [1] | 796 | #endif
|
|---|
| 797 | }
|
|---|
| 798 |
|
|---|
| 799 | /**
|
|---|
| 800 | * Determine whether the specified @p partno exists on the specified @p drive.
|
|---|
| 801 | * @param drive The drive to search for the partition in.
|
|---|
| 802 | * @param partno The partition number to look for.
|
|---|
| 803 | * @return 0 if it exists, nonzero otherwise.
|
|---|
| 804 | */
|
|---|
| [128] | 805 | int does_partition_exist(const char *drive, int partno)
|
|---|
| [1] | 806 | {
|
|---|
| [128] | 807 | /*@ buffers **************************************************** */
|
|---|
| [3191] | 808 | char *program = NULL;
|
|---|
| 809 | char *incoming = NULL;
|
|---|
| [2211] | 810 | char *searchstr = NULL;
|
|---|
| [1] | 811 |
|
|---|
| [128] | 812 | /*@ ints ******************************************************* */
|
|---|
| 813 | int res = 0;
|
|---|
| [1] | 814 |
|
|---|
| [128] | 815 | /*@ pointers *************************************************** */
|
|---|
| 816 | FILE *fin;
|
|---|
| [1] | 817 |
|
|---|
| [128] | 818 | /*@ end vars *************************************************** */
|
|---|
| 819 | assert_string_is_neither_NULL_nor_zerolength(drive);
|
|---|
| 820 | assert(partno >= 0 && partno < 999);
|
|---|
| [1] | 821 |
|
|---|
| 822 | #ifdef __FreeBSD__
|
|---|
| [128] | 823 | // We assume here that this is running from mondorestore. (It is.)
|
|---|
| [3859] | 824 | tmp = build_partition_name(drive, partno);
|
|---|
| 825 | mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, tmp);
|
|---|
| 826 | mr_free(tmp);
|
|---|
| [3191] | 827 | res = system(program);
|
|---|
| 828 | mr_free(program);
|
|---|
| 829 | return(res);
|
|---|
| [1] | 830 | #endif
|
|---|
| 831 |
|
|---|
| [3377] | 832 | mr_asprintf(program, "mr-parted2fdisk -l %s 2> /dev/null", drive);
|
|---|
| [128] | 833 | fin = popen(program, "r");
|
|---|
| 834 | if (!fin) {
|
|---|
| 835 | log_it("program=%s", program);
|
|---|
| 836 | log_OS_error("Cannot popen-in program");
|
|---|
| [3191] | 837 | mr_free(program);
|
|---|
| [128] | 838 | return (0);
|
|---|
| [1] | 839 | }
|
|---|
| [3191] | 840 | mr_free(program);
|
|---|
| 841 |
|
|---|
| [3859] | 842 | searchstr = build_partition_name(drive, partno);
|
|---|
| 843 | mr_strcat(searchstr, " ");
|
|---|
| [3191] | 844 | for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
|
|---|
| [128] | 845 | if (strstr(incoming, searchstr)) {
|
|---|
| 846 | res = 1;
|
|---|
| 847 | }
|
|---|
| [3191] | 848 | mr_free(incoming);
|
|---|
| [128] | 849 | }
|
|---|
| [3859] | 850 | mr_free(searchstr);
|
|---|
| [3191] | 851 | mr_free(incoming);
|
|---|
| 852 |
|
|---|
| [128] | 853 | if (pclose(fin)) {
|
|---|
| 854 | log_OS_error("Cannot pclose fin");
|
|---|
| 855 | }
|
|---|
| 856 | return (res);
|
|---|
| [1] | 857 | }
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 | /**
|
|---|
| [3429] | 864 | * Determine whether given NULL-terminated @p str exists in the begining of @p dev.
|
|---|
| [1] | 865 | * @param dev The device to look in.
|
|---|
| 866 | * @param str The string to look for.
|
|---|
| 867 | * @return TRUE if it exists, FALSE if it doesn't.
|
|---|
| 868 | */
|
|---|
| [128] | 869 | bool does_string_exist_in_boot_block(char *dev, char *str)
|
|---|
| [1] | 870 | {
|
|---|
| [128] | 871 | /*@ buffers **************************************************** */
|
|---|
| [3191] | 872 | char *command = NULL;
|
|---|
| [1] | 873 |
|
|---|
| [128] | 874 | /*@ end vars *************************************************** */
|
|---|
| 875 | int i;
|
|---|
| [1] | 876 |
|
|---|
| [128] | 877 | assert_string_is_neither_NULL_nor_zerolength(dev);
|
|---|
| 878 | assert_string_is_neither_NULL_nor_zerolength(str);
|
|---|
| [1] | 879 |
|
|---|
| [3379] | 880 | /* For UEFI detection, this should be extended to count=1000 ! */
|
|---|
| 881 | if (bkpinfo->boot_type == UEFI) {
|
|---|
| 882 | mr_asprintf(command, "dd if=%s bs=446 count=1000 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str);
|
|---|
| 883 | } else {
|
|---|
| 884 | mr_asprintf(command, "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str);
|
|---|
| 885 | }
|
|---|
| [128] | 886 | i = system(command);
|
|---|
| [3191] | 887 | mr_free(command);
|
|---|
| [128] | 888 | if (i) {
|
|---|
| 889 | return (FALSE);
|
|---|
| 890 | } else {
|
|---|
| 891 | return (TRUE);
|
|---|
| 892 | }
|
|---|
| [1] | 893 | }
|
|---|
| 894 |
|
|---|
| 895 | /**
|
|---|
| 896 | * Determine whether specified @p str exists in the first @p n sectors of
|
|---|
| 897 | * @p dev.
|
|---|
| 898 | * @param dev The device to look in.
|
|---|
| 899 | * @param str The string to look for.
|
|---|
| 900 | * @param n The number of 512-byte sectors to search.
|
|---|
| 901 | */
|
|---|
| [128] | 902 | bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n)
|
|---|
| [1] | 903 | {
|
|---|
| [128] | 904 | /*@ buffers **************************************************** */
|
|---|
| [3191] | 905 | char *command = NULL;
|
|---|
| [128] | 906 | /*@ end vars *************************************************** */
|
|---|
| 907 | int i;
|
|---|
| [1] | 908 |
|
|---|
| [3191] | 909 | mr_asprintf(command, "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, n, str);
|
|---|
| [128] | 910 | i = system(command);
|
|---|
| [3191] | 911 | mr_free(command);
|
|---|
| [128] | 912 | if (i) {
|
|---|
| 913 | return (FALSE);
|
|---|
| 914 | } else {
|
|---|
| 915 | return (TRUE);
|
|---|
| 916 | }
|
|---|
| [1] | 917 | }
|
|---|
| 918 |
|
|---|
| 919 |
|
|---|
| [3878] | 920 | /*
|
|---|
| 921 | * This function tries to find an optical media device
|
|---|
| 922 | * and return it's device file to the caller that needs to free it
|
|---|
| 923 | */
|
|---|
| 924 | char *find_optical_device(void) {
|
|---|
| 925 | char *dev = NULL;
|
|---|
| 926 | char *tmp1 = NULL;
|
|---|
| 927 | char *command = NULL;
|
|---|
| 928 |
|
|---|
| 929 | log_to_screen("I am looking for your optical burner. Please wait.");
|
|---|
| 930 |
|
|---|
| 931 | if (bkpinfo->media_device != NULL) {
|
|---|
| 932 | log_msg(3, "Been there, done that. Returning %s", bkpinfo->media_device);
|
|---|
| 933 | return (bkpinfo->media_device);
|
|---|
| 934 | }
|
|---|
| 935 |
|
|---|
| 936 | mr_asprintf(tmp1, "cdrecord -inq 2> /dev/null | grep -E '^Detected ' | cut -d':' -f2");
|
|---|
| 937 | dev = call_program_and_get_last_line_of_output(tmp1);
|
|---|
| 938 | mr_free(tmp1);
|
|---|
| 939 |
|
|---|
| 940 | if ((dev != NULL) && does_file_exist(dev)) {
|
|---|
| 941 | log_msg(2, "find_optical_device found %s automatically", dev);
|
|---|
| 942 | } else {
|
|---|
| 943 | mr_free(dev);
|
|---|
| 944 | tmp1 = find_home_of_exe("lsscsi");
|
|---|
| 945 | if (tmp1 != NULL) {
|
|---|
| 946 | mr_asprintf(command, "%s | grep ' cd' | awk '{print $NF}' | head -1", tmp1);
|
|---|
| 947 | dev = call_program_and_get_last_line_of_output(command);
|
|---|
| 948 | mr_free(command);
|
|---|
| 949 | }
|
|---|
| 950 | mr_free(tmp1);
|
|---|
| 951 |
|
|---|
| 952 | if ((dev == NULL) || !does_file_exist(dev)) {
|
|---|
| 953 | /* trying something else then */
|
|---|
| 954 | mr_asprintf(dev, "%s", VANILLA_SCSI_CDROM);
|
|---|
| 955 | if (!does_file_exist(dev)) {
|
|---|
| 956 | mr_asprintf(dev, "%s", ALT_CDROM);
|
|---|
| 957 | if (!does_file_exist(dev)) {
|
|---|
| 958 | mr_asprintf(dev, "%s", "/dev/cdrom");
|
|---|
| 959 | if (!does_file_exist(dev)) {
|
|---|
| 960 | mr_asprintf(dev, "%s", "/dev/dvd");
|
|---|
| 961 | if (!does_file_exist(dev)) {
|
|---|
| 962 | log_it("Unable to find a tape device on this system");
|
|---|
| 963 | }
|
|---|
| 964 | }
|
|---|
| 965 | }
|
|---|
| 966 | }
|
|---|
| 967 | }
|
|---|
| 968 | if (dev != NULL) {
|
|---|
| 969 | log_it("find_optical_device found %s manually", dev);
|
|---|
| 970 | }
|
|---|
| 971 | }
|
|---|
| 972 |
|
|---|
| 973 | if ((dev != NULL) && does_file_exist(dev)) {
|
|---|
| 974 | log_it("find_optical_device returns %s", dev);
|
|---|
| 975 | } else {
|
|---|
| 976 | mr_free(dev);
|
|---|
| 977 | log_it("find_optical_device found no optical burner on your system returning NULL");
|
|---|
| 978 | }
|
|---|
| 979 | return(dev);
|
|---|
| 980 | }
|
|---|
| [1] | 981 | /**
|
|---|
| [3878] | 982 | * Mount the CD-ROM or USB device at /mnt/cdrom.
|
|---|
| 983 | * @param bkpinfo The backup information structure. Fields used:
|
|---|
| 984 | * - @c bkpinfo->backup_media_type
|
|---|
| 985 | * - @c bkpinfo->disaster_recovery
|
|---|
| 986 | * - @c bkpinfo->isodir
|
|---|
| 987 | * - @c bkpinfo->media_device
|
|---|
| 988 | * @return TRUE for success, FALSE for failure.
|
|---|
| 989 | */
|
|---|
| 990 | bool mount_media(const char *mountpoint) {
|
|---|
| 991 |
|
|---|
| 992 | char *mount_cmd = NULL;
|
|---|
| 993 | char *mountdir = NULL;
|
|---|
| 994 | char *tmp = NULL;
|
|---|
| 995 | int i = 0, res = 0;
|
|---|
| 996 | #ifdef __FreeBSD__
|
|---|
| 997 | char mdd[32];
|
|---|
| 998 | char *mddev = mdd;
|
|---|
| 999 | char *dev;
|
|---|
| 1000 | #endif
|
|---|
| 1001 |
|
|---|
| 1002 | if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
|
|---|
| 1003 | log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
|
|---|
| 1004 | return(TRUE);
|
|---|
| 1005 | }
|
|---|
| 1006 |
|
|---|
| 1007 | assert_string_is_neither_NULL_nor_zerolength(mountpoint);
|
|---|
| 1008 |
|
|---|
| 1009 | mr_asprintf(tmp, "mount | grep -F %s", mountpoint);
|
|---|
| 1010 | if (!run_program_and_log_output(tmp, FALSE)) {
|
|---|
| 1011 | log_msg(2, "mount_media() - media already mounted. Fair enough.");
|
|---|
| 1012 | mr_free(tmp);
|
|---|
| 1013 | return (TRUE);
|
|---|
| 1014 | }
|
|---|
| 1015 | mr_free(tmp);
|
|---|
| 1016 |
|
|---|
| 1017 | make_hole_for_dir(mountpoint);
|
|---|
| 1018 |
|
|---|
| 1019 | if (bkpinfo->backup_media_type == netfs) {
|
|---|
| 1020 | log_msg(2, "Mounting for Network thingy");
|
|---|
| 1021 | log_msg(2, "isodir = %s", bkpinfo->isodir);
|
|---|
| 1022 | if (((bkpinfo->isodir == NULL) || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) {
|
|---|
| 1023 | mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
|
|---|
| 1024 | log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
|
|---|
| 1025 | }
|
|---|
| 1026 | #ifdef __FreeBSD__
|
|---|
| 1027 | if (bkpinfo->netfs_remote_dir != NULL) {
|
|---|
| 1028 | // NETFS
|
|---|
| 1029 | mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
|
|---|
| 1030 | } else {
|
|---|
| 1031 | // ISO
|
|---|
| 1032 | mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
|
|---|
| 1033 | }
|
|---|
| 1034 | mddev = make_vn(mount_cmd);
|
|---|
| 1035 | mr_free(mount_cmd);
|
|---|
| 1036 |
|
|---|
| 1037 | mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint);
|
|---|
| 1038 | #else
|
|---|
| 1039 | if (bkpinfo->netfs_remote_dir != NULL) {
|
|---|
| 1040 | // NETFS
|
|---|
| 1041 | mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, mountpoint);
|
|---|
| 1042 | } else {
|
|---|
| 1043 | // ISO
|
|---|
| 1044 | mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, mountpoint);
|
|---|
| 1045 | }
|
|---|
| 1046 | #endif
|
|---|
| 1047 |
|
|---|
| 1048 | } else if (bkpinfo->backup_media_type == iso) {
|
|---|
| 1049 | if (bkpinfo->subdir) {
|
|---|
| 1050 | mr_asprintf(mountdir, "%s/%s", bkpinfo->isodir, bkpinfo->subdir);
|
|---|
| 1051 | } else {
|
|---|
| 1052 | mr_asprintf(mountdir, "%s", bkpinfo->isodir);
|
|---|
| 1053 | }
|
|---|
| 1054 | #ifdef __FreeBSD__
|
|---|
| 1055 | mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number);
|
|---|
| 1056 | mddev = make_vn(mount_cmd);
|
|---|
| 1057 | mr_free(mount_cmd);
|
|---|
| 1058 |
|
|---|
| 1059 | mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint);
|
|---|
| 1060 | #else
|
|---|
| 1061 | mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, mountpoint);
|
|---|
| 1062 | #endif
|
|---|
| 1063 | mr_free(mountdir);
|
|---|
| 1064 | } else if (bkpinfo->backup_media_type == usb) {
|
|---|
| 1065 | mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, mountpoint);
|
|---|
| 1066 | } else { // optical
|
|---|
| 1067 | if (bkpinfo->disaster_recovery
|
|---|
| 1068 | && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
|
|---|
| 1069 | mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
|
|---|
| 1070 | } else {
|
|---|
| 1071 | if (bkpinfo->media_device == NULL) {
|
|---|
| 1072 | bkpinfo->media_device = find_optical_device();
|
|---|
| 1073 | }
|
|---|
| 1074 | }
|
|---|
| 1075 |
|
|---|
| 1076 | #ifdef __FreeBSD__
|
|---|
| 1077 | if (g_ISO_restore_mode) {
|
|---|
| 1078 | mr_asprintf(dev, "%s", make_vn(bkpinfo->media_device));
|
|---|
| 1079 | if (!dev) {
|
|---|
| 1080 | mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", bkpinfo->media_device);
|
|---|
| 1081 | fatal_error(command);
|
|---|
| 1082 | }
|
|---|
| 1083 | mr_free(bkpinfo->media_device);
|
|---|
| 1084 | bkpinfo->media_device = dev
|
|---|
| 1085 | }
|
|---|
| 1086 |
|
|---|
| 1087 | mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE);
|
|---|
| 1088 | #else
|
|---|
| 1089 | mr_asprintf(mount_cmd, "mount %s -o loop,ro -t iso9660 %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE);
|
|---|
| 1090 | #endif
|
|---|
| 1091 | log_msg(2, "(mount_media) --- command = %s", mount_cmd);
|
|---|
| 1092 | // usefull ??
|
|---|
| 1093 | if (strncmp(bkpinfo->media_device, "/dev/", 5) == 0) {
|
|---|
| 1094 | retract_CD_tray_and_defeat_autorun();
|
|---|
| 1095 | }
|
|---|
| 1096 | }
|
|---|
| 1097 |
|
|---|
| 1098 | for (i = 0; i < 2; i++) {
|
|---|
| 1099 | res = run_program_and_log_output(mount_cmd, FALSE);
|
|---|
| 1100 | if (!res) {
|
|---|
| 1101 | break;
|
|---|
| 1102 | } else {
|
|---|
| 1103 | log_msg(2, "Failed to mount device.");
|
|---|
| 1104 | sleep(5);
|
|---|
| 1105 | sync();
|
|---|
| 1106 | }
|
|---|
| 1107 | }
|
|---|
| 1108 | mr_free(mount_cmd);
|
|---|
| 1109 |
|
|---|
| 1110 | if (res) {
|
|---|
| 1111 | log_msg(2, "Failed, despite %d attempts", i);
|
|---|
| 1112 | return(FALSE);
|
|---|
| 1113 | } else {
|
|---|
| 1114 | log_msg(2, "Mounted media drive OK");
|
|---|
| 1115 | return(TRUE);
|
|---|
| 1116 | }
|
|---|
| 1117 | }
|
|---|
| 1118 | /**************************************************************************
|
|---|
| 1119 | *END_MOUNT_MEDIA *
|
|---|
| 1120 | **************************************************************************/
|
|---|
| 1121 |
|
|---|
| 1122 |
|
|---|
| 1123 |
|
|---|
| 1124 |
|
|---|
| 1125 | /**
|
|---|
| [3875] | 1126 | * Try to mount CD/DVD at @p mountpoint. If the CD/DVD is not found or has
|
|---|
| 1127 | * not been specified, call find_optical_device() to find it.
|
|---|
| [1] | 1128 | * @param mountpoint Where to mount the CD-ROM.
|
|---|
| [3875] | 1129 | * @return TRUE for success, FALSE for failure.
|
|---|
| 1130 | * @see mount_media
|
|---|
| [1] | 1131 | */
|
|---|
| [3875] | 1132 | bool find_and_mount_actual_cd(char *mountpoint) {
|
|---|
| [3191] | 1133 |
|
|---|
| [128] | 1134 | /*@ buffers ***************************************************** */
|
|---|
| [1] | 1135 |
|
|---|
| [128] | 1136 | /*@ int's ****************************************************** */
|
|---|
| [3875] | 1137 | bool res;
|
|---|
| [1] | 1138 |
|
|---|
| [128] | 1139 | /*@ end vars **************************************************** */
|
|---|
| [1] | 1140 |
|
|---|
| [128] | 1141 | assert(bkpinfo != NULL);
|
|---|
| 1142 | assert_string_is_neither_NULL_nor_zerolength(mountpoint);
|
|---|
| [1] | 1143 |
|
|---|
| [3875] | 1144 | if (bkpinfo->media_device == NULL) {
|
|---|
| 1145 | bkpinfo->media_device = find_optical_device();
|
|---|
| [128] | 1146 | }
|
|---|
| [1] | 1147 |
|
|---|
| [128] | 1148 | if (bkpinfo->backup_media_type != iso) {
|
|---|
| 1149 | retract_CD_tray_and_defeat_autorun();
|
|---|
| 1150 | }
|
|---|
| [1] | 1151 |
|
|---|
| [3875] | 1152 | if ((bkpinfo->media_device == NULL) || (res = mount_media(mountpoint))) {
|
|---|
| [3870] | 1153 | mr_free(bkpinfo->media_device);
|
|---|
| 1154 | if ((bkpinfo->media_device = mr_popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", "/dev/cdrom")) == NULL) {
|
|---|
| [3875] | 1155 | res = TRUE;
|
|---|
| [128] | 1156 | } else {
|
|---|
| [3875] | 1157 | res = mount_media(mountpoint);
|
|---|
| [128] | 1158 | }
|
|---|
| 1159 | }
|
|---|
| 1160 | if (res) {
|
|---|
| [541] | 1161 | log_msg(1, "mount failed");
|
|---|
| [128] | 1162 | } else {
|
|---|
| [3870] | 1163 | log_msg(1, "mount succeeded with %s", bkpinfo->media_device);
|
|---|
| [128] | 1164 | }
|
|---|
| 1165 | return (res);
|
|---|
| [1] | 1166 | }
|
|---|
| [3875] | 1167 | /*
|
|---|
| 1168 | * This function tries to find a USB media device
|
|---|
| 1169 | * and return it's device file to the caller that needs to free it
|
|---|
| [1] | 1170 | */
|
|---|
| [3875] | 1171 | char *find_usb_device(void)
|
|---|
| [1] | 1172 | {
|
|---|
| [3875] | 1173 | char *dev = NULL;
|
|---|
| [2214] | 1174 | char *tmp1 = NULL;
|
|---|
| [3191] | 1175 | char *command = NULL;
|
|---|
| [1] | 1176 |
|
|---|
| [3875] | 1177 | log_to_screen("I am looking for your USB key. Please wait.");
|
|---|
| [1] | 1178 |
|
|---|
| [3875] | 1179 | if (bkpinfo->media_device != NULL) {
|
|---|
| 1180 | log_msg(3, "Been there, done that. Returning %s", bkpinfo->media_device);
|
|---|
| 1181 | return (bkpinfo->media_device);
|
|---|
| [128] | 1182 | }
|
|---|
| [1] | 1183 |
|
|---|
| [3875] | 1184 | tmp1 = find_home_of_exe("lsscsi");
|
|---|
| 1185 | if (tmp1 != NULL) {
|
|---|
| 1186 | mr_asprintf(command, "%s | grep ' disk' | grep USB | awk '{print $NF}' | head -1", tmp1);
|
|---|
| 1187 | dev = call_program_and_get_last_line_of_output(command);
|
|---|
| [3191] | 1188 | mr_free(command);
|
|---|
| [128] | 1189 | }
|
|---|
| [3875] | 1190 | mr_free(tmp1);
|
|---|
| [3191] | 1191 |
|
|---|
| [3875] | 1192 | if ((dev == NULL) || !does_file_exist(dev)) {
|
|---|
| 1193 | tmp1 = find_home_of_exe("lsblk");
|
|---|
| 1194 | if (tmp1 != NULL) {
|
|---|
| 1195 | mr_asprintf(command, "%s --noheadings --raw --output rm,tran,type,path --sort path | awk '/^1 usb disk/ {d=$4} END {print d}'", tmp1);
|
|---|
| 1196 | dev = call_program_and_get_last_line_of_output(command);
|
|---|
| 1197 | mr_free(command);
|
|---|
| [1] | 1198 | }
|
|---|
| [3875] | 1199 | mr_free(tmp1);
|
|---|
| 1200 | log_it("Unable to find a tape device on this system");
|
|---|
| [1] | 1201 | }
|
|---|
| [3875] | 1202 | if (dev != NULL) {
|
|---|
| 1203 | log_it("find_usb_device found %s manually", dev);
|
|---|
| [128] | 1204 | }
|
|---|
| [1] | 1205 |
|
|---|
| [3875] | 1206 | if ((dev != NULL) && does_file_exist(dev)) {
|
|---|
| 1207 | log_it("find_usb_device returns %s", dev);
|
|---|
| [128] | 1208 | } else {
|
|---|
| [3875] | 1209 | mr_free(dev);
|
|---|
| 1210 | log_it("find_usb_device found no USB key on your system returning NULL");
|
|---|
| [128] | 1211 | }
|
|---|
| [3875] | 1212 | return(dev);
|
|---|
| 1213 | }
|
|---|
| [2214] | 1214 |
|
|---|
| [3191] | 1215 |
|
|---|
| [1] | 1216 |
|
|---|
| [3875] | 1217 | /* Generic fund to find a media
|
|---|
| 1218 | * Return a dynamically allocted string that caller needs to free
|
|---|
| 1219 | * @media_type is the type of media to look for
|
|---|
| 1220 | */
|
|---|
| [1] | 1221 |
|
|---|
| [3875] | 1222 | char *find_device(t_bkptype media_type) {
|
|---|
| 1223 |
|
|---|
| 1224 | if (media_type == usb) {
|
|---|
| 1225 | return(find_usb_device());
|
|---|
| 1226 | } else if (media_type == tape) {
|
|---|
| 1227 | return(find_tape_device());
|
|---|
| [3881] | 1228 | } else if (media_type == optical) {
|
|---|
| [3875] | 1229 | return(find_optical_device());
|
|---|
| 1230 | } else {
|
|---|
| 1231 | return(NULL);
|
|---|
| 1232 | }
|
|---|
| 1233 | }
|
|---|
| 1234 |
|
|---|
| 1235 |
|
|---|
| 1236 |
|
|---|
| 1237 |
|
|---|
| [1] | 1238 | #include <sys/ioctl.h>
|
|---|
| 1239 |
|
|---|
| 1240 | /**
|
|---|
| 1241 | * Find the size of the specified @p drive, in megabytes. Uses @c ioctl calls
|
|---|
| 1242 | * and @c dmesg.
|
|---|
| 1243 | * @param drive The device to find the size of.
|
|---|
| 1244 | * @return size in megabytes.
|
|---|
| 1245 | */
|
|---|
| [128] | 1246 | long get_phys_size_of_drive(char *drive)
|
|---|
| [1] | 1247 | {
|
|---|
| [128] | 1248 | int fd;
|
|---|
| [1] | 1249 | #if linux
|
|---|
| [128] | 1250 | unsigned long long s = 0;
|
|---|
| [3060] | 1251 | int fileid, cylinders = 0;
|
|---|
| [128] | 1252 | int cylindersize = 0;
|
|---|
| [1] | 1253 | int gotgeo = 0;
|
|---|
| 1254 |
|
|---|
| [128] | 1255 |
|
|---|
| 1256 | struct hd_geometry hdgeo;
|
|---|
| [1] | 1257 | #elif __FreeBSD__
|
|---|
| [128] | 1258 | off_t s;
|
|---|
| [1] | 1259 | #endif
|
|---|
| 1260 |
|
|---|
| [128] | 1261 | long outvalA = -1;
|
|---|
| 1262 | long outvalB = -1;
|
|---|
| 1263 | long outvalC = -1;
|
|---|
| [1] | 1264 |
|
|---|
| [128] | 1265 | if ((fd = open(drive, O_RDONLY)) != -1) {
|
|---|
| 1266 | if (ioctl(fd,
|
|---|
| [1] | 1267 | #if linux
|
|---|
| [128] | 1268 | #ifdef BLKGETSIZE64
|
|---|
| 1269 | BLKGETSIZE64,
|
|---|
| 1270 | #else
|
|---|
| 1271 | BLKGETSIZE,
|
|---|
| 1272 | #endif
|
|---|
| [1] | 1273 | #elif __FreeBSD__
|
|---|
| [128] | 1274 | DIOCGMEDIASIZE,
|
|---|
| [1] | 1275 | #endif
|
|---|
| [128] | 1276 | &s) != -1) {
|
|---|
| 1277 | close(fd);
|
|---|
| 1278 | // s>>11 works for older disks but not for newer ones
|
|---|
| 1279 | outvalB =
|
|---|
| [1] | 1280 | #if linux
|
|---|
| [128] | 1281 | #ifdef BLKGETSIZE64
|
|---|
| 1282 | s >> 20
|
|---|
| [1] | 1283 | #else
|
|---|
| [128] | 1284 | s >> 11
|
|---|
| [1] | 1285 | #endif
|
|---|
| [128] | 1286 | #else
|
|---|
| 1287 | s >> 20
|
|---|
| 1288 | #endif
|
|---|
| 1289 | ;
|
|---|
| 1290 | }
|
|---|
| [1] | 1291 | }
|
|---|
| 1292 |
|
|---|
| [128] | 1293 | if (outvalB <= 0) {
|
|---|
| 1294 | log_msg(1, "Error getting size of %s: %s", drive, strerror(errno));
|
|---|
| [1] | 1295 | #if linux
|
|---|
| [161] | 1296 | fileid = open(drive, O_RDONLY);
|
|---|
| [2205] | 1297 | if (fileid != -1) {
|
|---|
| [161] | 1298 | if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
|
|---|
| 1299 | if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
|
|---|
| 1300 | cylindersize = hdgeo.heads * hdgeo.sectors / 2;
|
|---|
| 1301 | outvalA = cylindersize * cylinders / 1024;
|
|---|
| 1302 | log_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
|
|---|
| 1303 | hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
|
|---|
| 1304 | gotgeo = 1;
|
|---|
| 1305 | } else {
|
|---|
| 1306 | log_msg(1, "Harddisk geometry wrong");
|
|---|
| 1307 | }
|
|---|
| [1] | 1308 | } else {
|
|---|
| [161] | 1309 | log_msg(1,
|
|---|
| 1310 | "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode",
|
|---|
| 1311 | strerror(errno));
|
|---|
| [1] | 1312 | }
|
|---|
| [161] | 1313 | close(fileid);
|
|---|
| [1] | 1314 | } else {
|
|---|
| [161] | 1315 | log_msg(1, "Failed to open %s for reading: %s", drive,
|
|---|
| [128] | 1316 | strerror(errno));
|
|---|
| [1] | 1317 | }
|
|---|
| [161] | 1318 | if (!gotgeo) {
|
|---|
| 1319 | log_msg(1, "Failed to get harddisk geometry, using old mode");
|
|---|
| 1320 | }
|
|---|
| [1] | 1321 | #endif
|
|---|
| [161] | 1322 | }
|
|---|
| [1] | 1323 | // OLDER DISKS will give ridiculously low value for outvalB (so outvalA is returned) :)
|
|---|
| 1324 | // NEWER DISKS will give sane value for outvalB (close to outvalA, in other words) :)
|
|---|
| 1325 |
|
|---|
| [128] | 1326 | outvalC = (outvalA > outvalB) ? outvalA : outvalB;
|
|---|
| 1327 |
|
|---|
| [1] | 1328 | // log_msg (5, "drive = %s, error = %s", drive, strerror (errno));
|
|---|
| 1329 | // fatal_error ("GPSOD: Unable to get size of drive");
|
|---|
| [128] | 1330 | log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB,
|
|---|
| 1331 | outvalC);
|
|---|
| 1332 |
|
|---|
| 1333 | return (outvalC);
|
|---|
| [1] | 1334 | }
|
|---|
| [128] | 1335 |
|
|---|
| [1] | 1336 | /**
|
|---|
| 1337 | * Determine whether @p format is supported by the kernel. Uses /proc/filesystems
|
|---|
| 1338 | * under Linux and @c lsvfs under FreeBSD.
|
|---|
| 1339 | * @param format The format to test.
|
|---|
| 1340 | * @return TRUE if the format is supported, FALSE if not.
|
|---|
| 1341 | */
|
|---|
| [128] | 1342 | bool is_this_a_valid_disk_format(char *format)
|
|---|
| [1] | 1343 | {
|
|---|
| [2211] | 1344 | char *good_formats = NULL;
|
|---|
| [3191] | 1345 | char *command = NULL;
|
|---|
| 1346 | char *format_sz = NULL;
|
|---|
| [3291] | 1347 | char *p = NULL;
|
|---|
| [1] | 1348 |
|
|---|
| [128] | 1349 | FILE *pin;
|
|---|
| 1350 | int retval;
|
|---|
| [1] | 1351 |
|
|---|
| [128] | 1352 | assert_string_is_neither_NULL_nor_zerolength(format);
|
|---|
| [1] | 1353 |
|
|---|
| [3191] | 1354 | mr_asprintf(format_sz, "%s ", format);
|
|---|
| [1] | 1355 |
|
|---|
| 1356 | #ifdef __FreeBSD__
|
|---|
| [3191] | 1357 | mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
|
|---|
| [1] | 1358 | #else
|
|---|
| [3191] | 1359 | mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
|
|---|
| [1] | 1360 | #endif
|
|---|
| 1361 |
|
|---|
| [128] | 1362 | pin = popen(command, "r");
|
|---|
| [3191] | 1363 | mr_free(command);
|
|---|
| 1364 |
|
|---|
| [128] | 1365 | if (!pin) {
|
|---|
| 1366 | log_OS_error("Unable to read good formats");
|
|---|
| 1367 | retval = 0;
|
|---|
| 1368 | } else {
|
|---|
| [3291] | 1369 | mr_getline(p, pin);
|
|---|
| [3614] | 1370 | good_formats = mr_strip_spaces(p);
|
|---|
| [3337] | 1371 | mr_free(p);
|
|---|
| [3291] | 1372 | (void)pclose(pin);
|
|---|
| 1373 | mr_strcat(good_formats, " swap lvm raid ntfs-3g ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
|
|---|
| [128] | 1374 | if (strstr(good_formats, format_sz)) {
|
|---|
| 1375 | retval = 1;
|
|---|
| 1376 | } else {
|
|---|
| 1377 | retval = 0;
|
|---|
| 1378 | }
|
|---|
| 1379 | }
|
|---|
| [3291] | 1380 | mr_free(good_formats);
|
|---|
| [3191] | 1381 | mr_free(format_sz);
|
|---|
| 1382 |
|
|---|
| [128] | 1383 | return (retval);
|
|---|
| [1] | 1384 | }
|
|---|
| 1385 |
|
|---|
| 1386 |
|
|---|
| 1387 | /** @def SWAPLIST_COMMAND The command to list the swap files/partitions in use. */
|
|---|
| 1388 |
|
|---|
| 1389 | /**
|
|---|
| 1390 | * Determine whether @p device_raw is currently mounted.
|
|---|
| 1391 | * @param device_raw The device to check.
|
|---|
| 1392 | * @return TRUE if it's mounted, FALSE if not.
|
|---|
| 1393 | */
|
|---|
| [128] | 1394 | bool is_this_device_mounted(char *device_raw)
|
|---|
| [1] | 1395 | {
|
|---|
| 1396 |
|
|---|
| [3448] | 1397 | char *tmp = NULL;
|
|---|
| 1398 | bool retval = FALSE;
|
|---|
| 1399 |
|
|---|
| [3453] | 1400 | mr_asprintf(tmp, "mr-device-mounted %s > /dev/null", device_raw);
|
|---|
| [3448] | 1401 | if (system(tmp) == 0) {
|
|---|
| 1402 | retval = TRUE;
|
|---|
| 1403 | }
|
|---|
| 1404 | mr_free(tmp);
|
|---|
| [3450] | 1405 | return(retval);
|
|---|
| [3449] | 1406 | }
|
|---|
| [3448] | 1407 |
|
|---|
| [1] | 1408 | #ifdef __FreeBSD__
|
|---|
| 1409 | // CODE IS FREEBSD-SPECIFIC
|
|---|
| 1410 | /**
|
|---|
| 1411 | * Create a loopback device for specified @p fname.
|
|---|
| 1412 | * @param fname The file to associate with a device.
|
|---|
| 1413 | * @return /dev entry for the device, or NULL if it couldn't be allocated.
|
|---|
| 1414 | */
|
|---|
| [128] | 1415 | char *make_vn(char *fname)
|
|---|
| [1] | 1416 | {
|
|---|
| [128] | 1417 | char *device = (char *) malloc(MAX_STR_LEN);
|
|---|
| [3610] | 1418 | char *mddevice = NULL;
|
|---|
| 1419 | char *command = NULL;
|
|---|
| 1420 | char *tmp = NULL;
|
|---|
| [128] | 1421 | int vndev = 2;
|
|---|
| [3610] | 1422 |
|
|---|
| 1423 | tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate");
|
|---|
| 1424 | if (atoi(tmp) < 500000) {
|
|---|
| [128] | 1425 | do {
|
|---|
| [3610] | 1426 | mr_asprintf(mddevice, "vn%ic", vndev++);
|
|---|
| 1427 | mr_free(command);
|
|---|
| 1428 | mr_asprintf(command, "vnconfig %s %s", mddevice, fname);
|
|---|
| [128] | 1429 | if (vndev > 10) {
|
|---|
| [3610] | 1430 | mr_free(tmp);
|
|---|
| 1431 | mr_free(mddevice);
|
|---|
| 1432 | mr_free(command);
|
|---|
| [128] | 1433 | return NULL;
|
|---|
| 1434 | }
|
|---|
| 1435 | }
|
|---|
| 1436 | while (system(command));
|
|---|
| 1437 | } else {
|
|---|
| [3610] | 1438 | mr_asprintf(command, "mdconfig -a -t vnode -f %s", fname);
|
|---|
| [128] | 1439 | mddevice = call_program_and_get_last_line_of_output(command);
|
|---|
| 1440 | if (!strstr(mddevice, "md")) {
|
|---|
| [3610] | 1441 | mr_free(tmp);
|
|---|
| 1442 | mr_free(command);
|
|---|
| 1443 | mr_free(mddevice);
|
|---|
| [128] | 1444 | return NULL;
|
|---|
| 1445 | }
|
|---|
| 1446 | }
|
|---|
| [3610] | 1447 | mr_free(tmp);
|
|---|
| 1448 | mr_free(command);
|
|---|
| [128] | 1449 | sprintf(device, "/dev/%s", mddevice);
|
|---|
| [3610] | 1450 | mr_free(mddevice);
|
|---|
| [128] | 1451 | return device;
|
|---|
| [1] | 1452 | }
|
|---|
| 1453 |
|
|---|
| 1454 |
|
|---|
| 1455 |
|
|---|
| 1456 | // CODE IS FREEBSD-SPECIFIC
|
|---|
| 1457 | /**
|
|---|
| 1458 | * Deallocate specified @p dname.
|
|---|
| 1459 | * This should be called when you are done with the device created by make_vn(),
|
|---|
| 1460 | * so the system does not run out of @c vn devices.
|
|---|
| 1461 | * @param dname The device to deallocate.
|
|---|
| 1462 | * @return 0 for success, nonzero for failure.
|
|---|
| 1463 | */
|
|---|
| [128] | 1464 | int kick_vn(char *dname)
|
|---|
| [1] | 1465 | {
|
|---|
| [3191] | 1466 | char *command = NULL;
|
|---|
| [3610] | 1467 | char *tmp = NULL;
|
|---|
| [3191] | 1468 | int res = 0;
|
|---|
| [1] | 1469 |
|
|---|
| [128] | 1470 | if (strncmp(dname, "/dev/", 5) == 0) {
|
|---|
| 1471 | dname += 5;
|
|---|
| 1472 | }
|
|---|
| [1] | 1473 |
|
|---|
| [3610] | 1474 | tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate");
|
|---|
| 1475 | if (atoi(tmp) < 500000) {
|
|---|
| [3191] | 1476 | mr_asprintf(command, "vnconfig -d %s", dname);
|
|---|
| [128] | 1477 | } else {
|
|---|
| [3191] | 1478 | mr_asprintf(command, "mdconfig -d -u %s", dname);
|
|---|
| [128] | 1479 | }
|
|---|
| [3610] | 1480 | mr_free(tmp);
|
|---|
| [3191] | 1481 | res = system(command);
|
|---|
| 1482 | mr_free(command);
|
|---|
| 1483 | return(res);
|
|---|
| [1] | 1484 | }
|
|---|
| 1485 | #endif
|
|---|
| 1486 |
|
|---|
| 1487 |
|
|---|
| 1488 | /**
|
|---|
| 1489 | * Mount the CD-ROM at @p mountpoint.
|
|---|
| 1490 | * @param device The device (or file if g_ISO_restore_mode) to mount.
|
|---|
| 1491 | * @param mountpoint The place to mount it.
|
|---|
| 1492 | * @return 0 for success, nonzero for failure.
|
|---|
| 1493 | */
|
|---|
| [1741] | 1494 | int mount_USB_here(char *device, char *mountpoint)
|
|---|
| 1495 | {
|
|---|
| 1496 | /*@ buffer ****************************************************** */
|
|---|
| [3191] | 1497 | char *command = NULL;
|
|---|
| [1741] | 1498 | int retval;
|
|---|
| 1499 |
|
|---|
| 1500 | assert_string_is_neither_NULL_nor_zerolength(device);
|
|---|
| 1501 | assert_string_is_neither_NULL_nor_zerolength(mountpoint);
|
|---|
| 1502 |
|
|---|
| 1503 | make_hole_for_dir(mountpoint);
|
|---|
| 1504 | if (isdigit(device[0])) {
|
|---|
| 1505 | return(1);
|
|---|
| 1506 | }
|
|---|
| [3191] | 1507 | log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint);
|
|---|
| [1741] | 1508 |
|
|---|
| 1509 | #ifdef __FreeBSD__
|
|---|
| [3191] | 1510 | mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
|
|---|
| [1741] | 1511 |
|
|---|
| 1512 | #else
|
|---|
| [3191] | 1513 | mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
|
|---|
| [1741] | 1514 | #endif
|
|---|
| 1515 |
|
|---|
| 1516 | log_msg(4, command);
|
|---|
| 1517 | retval = system(command);
|
|---|
| 1518 | log_msg(1, "system(%s) returned %d", command, retval);
|
|---|
| [3191] | 1519 | mr_free(command);
|
|---|
| [1741] | 1520 |
|
|---|
| 1521 | return (retval);
|
|---|
| 1522 | }
|
|---|
| 1523 |
|
|---|
| 1524 | /**
|
|---|
| [3878] | 1525 | * Find out what number CD is in the drive.
|
|---|
| 1526 | * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used.
|
|---|
| 1527 | * @return The current CD number, or -1 if it could not be found.
|
|---|
| 1528 | * @note If the CD is not mounted, it will be mounted
|
|---|
| 1529 | * (and remain mounted after this function returns).
|
|---|
| 1530 | */
|
|---|
| 1531 | int what_number_cd_is_this(void) {
|
|---|
| [3875] | 1532 |
|
|---|
| [3878] | 1533 | int cd_number = -1;
|
|---|
| 1534 | char *mountdev = NULL;
|
|---|
| [3875] | 1535 | char *tmp = NULL;
|
|---|
| [1] | 1536 |
|
|---|
| [3878] | 1537 | assert(bkpinfo != NULL);
|
|---|
| 1538 | // log_it("Asking what_number_cd_is_this");
|
|---|
| 1539 | if ((g_ISO_restore_mode) || (g_restoring_live_from_cd)) {
|
|---|
| 1540 | tmp = call_program_and_get_last_line_of_output("mount | grep iso9660 | awk '{print $3;}'");
|
|---|
| 1541 | mr_asprintf(mountdev, "%s%s", tmp, "/archives/THIS-CD-NUMBER");
|
|---|
| [3875] | 1542 | mr_free(tmp);
|
|---|
| [3878] | 1543 | cd_number = atoi(last_line_of_file(mountdev));
|
|---|
| 1544 | mr_free(mountdev);
|
|---|
| 1545 | return (cd_number);
|
|---|
| [2682] | 1546 | }
|
|---|
| [1] | 1547 |
|
|---|
| [3878] | 1548 | if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) {
|
|---|
| 1549 | log_it("ERROR: bkpinfo->media_device shoulnd't be unaccessible here\n");
|
|---|
| 1550 | /* trying again ! */
|
|---|
| 1551 | bkpinfo->media_device = find_optical_device();
|
|---|
| [2682] | 1552 | }
|
|---|
| [3878] | 1553 | if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) {
|
|---|
| 1554 | fatal_error("ERROR: bkpinfo->media_device shoulnd't really be unaccessible here\n");
|
|---|
| [2682] | 1555 | }
|
|---|
| [3878] | 1556 | if (!is_this_device_mounted(MNT_CDROM)) {
|
|---|
| 1557 | mount_media(MNT_CDROM);
|
|---|
| 1558 | }
|
|---|
| [2682] | 1559 |
|
|---|
| [3878] | 1560 | cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
|
|---|
| 1561 | return(cd_number);
|
|---|
| [2682] | 1562 | }
|
|---|
| 1563 |
|
|---|
| 1564 |
|
|---|
| 1565 |
|
|---|
| 1566 |
|
|---|
| [1] | 1567 | /**
|
|---|
| 1568 | * Ask the user for CD number @p cd_number_i_want.
|
|---|
| 1569 | * Sets g_current_media_number once the correct CD is inserted.
|
|---|
| 1570 | * @param bkpinfo The backup information structure. Fields used:
|
|---|
| 1571 | * - @c bkpinfo->backup_media_type
|
|---|
| [20] | 1572 | * - @c bkpinfo->prefix
|
|---|
| [1] | 1573 | * - @c bkpinfo->isodir
|
|---|
| 1574 | * - @c bkpinfo->media_device
|
|---|
| 1575 | * - @c bkpinfo->please_dont_eject_when_restoring
|
|---|
| 1576 | * @param cd_number_i_want The CD number to ask for.
|
|---|
| 1577 | */
|
|---|
| 1578 | void
|
|---|
| [1645] | 1579 | insist_on_this_cd_number(int cd_number_i_want)
|
|---|
| [1] | 1580 | {
|
|---|
| 1581 |
|
|---|
| [128] | 1582 | /*@ int ************************************************************* */
|
|---|
| 1583 | int res = 0;
|
|---|
| [1] | 1584 |
|
|---|
| 1585 |
|
|---|
| [128] | 1586 | /*@ buffers ********************************************************* */
|
|---|
| [3191] | 1587 | char *tmp = NULL;
|
|---|
| [2242] | 1588 | char *mds = NULL;
|
|---|
| [3191] | 1589 | char *request = NULL;
|
|---|
| [1] | 1590 |
|
|---|
| [128] | 1591 | assert(bkpinfo != NULL);
|
|---|
| 1592 | assert(cd_number_i_want > 0);
|
|---|
| [1] | 1593 |
|
|---|
| 1594 | // log_msg(3, "Insisting on CD number %d", cd_number_i_want);
|
|---|
| 1595 |
|
|---|
| [128] | 1596 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
|---|
| 1597 | log_msg(3,
|
|---|
| 1598 | "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
|
|---|
| 1599 | return;
|
|---|
| 1600 | }
|
|---|
| [3719] | 1601 | if (!does_file_exist(MNT_CDROM)) {
|
|---|
| 1602 | mr_asprintf(tmp, "mkdir -p " MNT_CDROM);
|
|---|
| 1603 | run_program_and_log_output(tmp, 5);
|
|---|
| 1604 | mr_free(tmp);
|
|---|
| 1605 | }
|
|---|
| [3191] | 1606 |
|
|---|
| 1607 | if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) {
|
|---|
| [2866] | 1608 | g_ISO_restore_mode = TRUE;
|
|---|
| 1609 | }
|
|---|
| [1645] | 1610 | if ((res = what_number_cd_is_this()) != cd_number_i_want) {
|
|---|
| [3191] | 1611 | log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
|
|---|
| [2866] | 1612 |
|
|---|
| 1613 | /* Now we need to umount the current media to have the next mounted after */
|
|---|
| [2878] | 1614 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
|---|
| [2866] | 1615 | log_msg(3, "Mounting next media %d",cd_number_i_want);
|
|---|
| 1616 | g_current_media_number = cd_number_i_want;
|
|---|
| [3877] | 1617 | mount_media(MNT_CDROM);
|
|---|
| [2866] | 1618 |
|
|---|
| [2242] | 1619 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
|---|
| [3191] | 1620 | log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want);
|
|---|
| 1621 | mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
|
|---|
| [2242] | 1622 | mr_free(mds);
|
|---|
| [3191] | 1623 |
|
|---|
| [1645] | 1624 | while (what_number_cd_is_this() != cd_number_i_want) {
|
|---|
| [3191] | 1625 | sync();
|
|---|
| [128] | 1626 | if (is_this_device_mounted(MNT_CDROM)) {
|
|---|
| 1627 | res =
|
|---|
| [2878] | 1628 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
|---|
| [128] | 1629 | } else {
|
|---|
| 1630 | res = 0;
|
|---|
| 1631 | }
|
|---|
| 1632 | if (res) {
|
|---|
| [541] | 1633 | log_to_screen("WARNING - failed to unmount CD-ROM drive");
|
|---|
| [128] | 1634 | }
|
|---|
| 1635 | if (!bkpinfo->please_dont_eject) {
|
|---|
| 1636 | res = eject_device(bkpinfo->media_device);
|
|---|
| 1637 | } else {
|
|---|
| 1638 | res = 0;
|
|---|
| 1639 | }
|
|---|
| 1640 | if (res) {
|
|---|
| [541] | 1641 | log_to_screen("WARNING - failed to eject CD-ROM disk");
|
|---|
| [128] | 1642 | }
|
|---|
| 1643 | popup_and_OK(request);
|
|---|
| 1644 | if (!bkpinfo->please_dont_eject) {
|
|---|
| 1645 | inject_device(bkpinfo->media_device);
|
|---|
| 1646 | }
|
|---|
| [3191] | 1647 | sync();
|
|---|
| [128] | 1648 | }
|
|---|
| [3191] | 1649 | mr_free(request);
|
|---|
| 1650 |
|
|---|
| [128] | 1651 | log_msg(1, "Thankyou. Proceeding...");
|
|---|
| 1652 | g_current_media_number = cd_number_i_want;
|
|---|
| 1653 | }
|
|---|
| [1] | 1654 | }
|
|---|
| 1655 |
|
|---|
| 1656 |
|
|---|
| [2434] | 1657 | /* Update the bkpinfo structure for exclude & include paths
|
|---|
| 1658 | * in order to handle correctly paths corresponding to devices */
|
|---|
| 1659 | void mr_make_devlist_from_pathlist(char *pathlist, char mode) {
|
|---|
| 1660 |
|
|---|
| 1661 | char *token = NULL;
|
|---|
| 1662 | int lastpos = 0;
|
|---|
| 1663 | char *mounted_on_dsf = NULL;
|
|---|
| 1664 | char *not_mounted_on_dsf = NULL;
|
|---|
| [2713] | 1665 | char token_chars[] ="|\t\r\f\a\0\n";
|
|---|
| [2525] | 1666 | char *tmp = NULL;
|
|---|
| 1667 | char *tmp1 = NULL;
|
|---|
| [2934] | 1668 | char *tmp2 = NULL;
|
|---|
| [2434] | 1669 |
|
|---|
| [2745] | 1670 | if (pathlist == NULL) {
|
|---|
| 1671 | return;
|
|---|
| 1672 | }
|
|---|
| [2434] | 1673 | while ((token = mr_strtok(pathlist, token_chars, &lastpos)) != NULL) {
|
|---|
| 1674 | switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) {
|
|---|
| 1675 | case 1:
|
|---|
| 1676 | if (mode == 'E') {
|
|---|
| 1677 | log_msg(1, "WARNING ! %s doesn't exist in -E option", token);
|
|---|
| 1678 | } else {
|
|---|
| [2453] | 1679 | log_msg(1, "ERROR ! %s doesn't exist in -I option", token);
|
|---|
| [2434] | 1680 | fatal_error("Error processing -I option");
|
|---|
| 1681 | }
|
|---|
| 1682 | break;
|
|---|
| 1683 | /* Everything is OK; proceed to archive data */
|
|---|
| 1684 | case 0:
|
|---|
| 1685 | if (mode == 'E') {
|
|---|
| 1686 | if (strlen(mounted_on_dsf)) {
|
|---|
| [2632] | 1687 | log_to_screen("Excluding the following file systems on %s:", token);
|
|---|
| 1688 | log_to_screen("==> %s", mounted_on_dsf);
|
|---|
| [2434] | 1689 | log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
|
|---|
| [2713] | 1690 | if (bkpinfo->exclude_paths) {
|
|---|
| 1691 | mr_strcat(bkpinfo->exclude_paths,"|%s",mounted_on_dsf);
|
|---|
| 1692 | } else {
|
|---|
| [3185] | 1693 | mr_asprintf(bkpinfo->exclude_paths,"%s",mounted_on_dsf);
|
|---|
| [2713] | 1694 | }
|
|---|
| 1695 | if (bkpinfo->exclude_devs) {
|
|---|
| 1696 | mr_strcat(bkpinfo->exclude_devs,"|%s",token);
|
|---|
| 1697 | } else {
|
|---|
| [3185] | 1698 | mr_asprintf(bkpinfo->exclude_devs,"%s",token);
|
|---|
| [2713] | 1699 | }
|
|---|
| [2434] | 1700 | }
|
|---|
| [2453] | 1701 | } else {
|
|---|
| [2632] | 1702 | log_to_screen("Archiving only the following file systems on %s:", token);
|
|---|
| [2636] | 1703 | log_to_screen("==> %s", mounted_on_dsf);
|
|---|
| [3191] | 1704 | mr_free(bkpinfo->include_paths);
|
|---|
| 1705 | mr_asprintf(bkpinfo->include_paths, "%s", "/");
|
|---|
| [2453] | 1706 | if (strlen(not_mounted_on_dsf)) {
|
|---|
| 1707 | log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
|
|---|
| [2632] | 1708 | log_to_screen("Not archiving the following file systems:");
|
|---|
| 1709 | log_to_screen("==> %s", not_mounted_on_dsf);
|
|---|
| [2713] | 1710 | if (bkpinfo->exclude_paths) {
|
|---|
| 1711 | mr_strcat(bkpinfo->exclude_paths, "|%s",not_mounted_on_dsf);
|
|---|
| 1712 | } else {
|
|---|
| [3185] | 1713 | mr_asprintf(bkpinfo->exclude_paths,"%s",not_mounted_on_dsf);
|
|---|
| [2713] | 1714 | }
|
|---|
| [2453] | 1715 | }
|
|---|
| [2434] | 1716 | }
|
|---|
| 1717 | break;
|
|---|
| 1718 | /* It's a dsf but not a whole disk dsf */
|
|---|
| 1719 | case -2:
|
|---|
| 1720 | log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
|
|---|
| 1721 | break;
|
|---|
| 1722 | /* A device special file was not passed in. Process it as a path. */
|
|---|
| 1723 | case -1:
|
|---|
| [2713] | 1724 | /* Adds a | to ensure correct detection even at both ends */
|
|---|
| [3185] | 1725 | mr_asprintf(tmp1,"|%s",token);
|
|---|
| 1726 | mr_asprintf(tmp2,"|%s|",token);
|
|---|
| [2434] | 1727 | if (mode == 'E') {
|
|---|
| [2473] | 1728 | /* Add the token if not already in the list */
|
|---|
| [3185] | 1729 | mr_asprintf(tmp,"|%s|",bkpinfo->exclude_paths);
|
|---|
| [2934] | 1730 | if (strstr(tmp,tmp2) == NULL) {
|
|---|
| [2713] | 1731 | if (bkpinfo->exclude_paths) {
|
|---|
| 1732 | mr_strcat(bkpinfo->exclude_paths,tmp1);
|
|---|
| 1733 | mr_free(tmp1);
|
|---|
| 1734 | } else {
|
|---|
| 1735 | bkpinfo->exclude_paths = tmp1;
|
|---|
| 1736 | }
|
|---|
| [2473] | 1737 | }
|
|---|
| [2434] | 1738 | } else {
|
|---|
| [2473] | 1739 | /* Add the token if not already in the list */
|
|---|
| [3185] | 1740 | mr_asprintf(tmp,"|%s|",bkpinfo->include_paths);
|
|---|
| [2934] | 1741 | if (strstr(tmp,tmp2) == NULL) {
|
|---|
| [3191] | 1742 | mr_strcat(bkpinfo->include_paths, "%s", tmp1);
|
|---|
| [2473] | 1743 | }
|
|---|
| [2713] | 1744 | mr_free(tmp1);
|
|---|
| [2434] | 1745 | }
|
|---|
| [2525] | 1746 | mr_free(tmp);
|
|---|
| [2934] | 1747 | mr_free(tmp2);
|
|---|
| [2434] | 1748 | break;
|
|---|
| 1749 | }
|
|---|
| 1750 | mr_free(token);
|
|---|
| 1751 |
|
|---|
| 1752 | if (bkpinfo->include_paths != NULL) {
|
|---|
| 1753 | log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
|---|
| 1754 | }
|
|---|
| 1755 | if (bkpinfo->exclude_paths != NULL) {
|
|---|
| 1756 | log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
|
|---|
| 1757 | }
|
|---|
| 1758 | if (bkpinfo->exclude_devs != NULL) {
|
|---|
| 1759 | log_msg(1, "exclude_devs is now '%s'", bkpinfo->exclude_devs);
|
|---|
| 1760 | }
|
|---|
| 1761 | }
|
|---|
| 1762 | }
|
|---|
| 1763 |
|
|---|
| 1764 |
|
|---|
| [3375] | 1765 | /**
|
|---|
| 1766 | * Return the type of boot of the system (UEFI, EFI or BIOS)
|
|---|
| 1767 | */
|
|---|
| [3413] | 1768 | t_boot mr_boot_type(void) {
|
|---|
| [2434] | 1769 |
|
|---|
| [3375] | 1770 | t_boot ret = BIOS;
|
|---|
| [3377] | 1771 | DIR *fd = NULL;
|
|---|
| [2434] | 1772 |
|
|---|
| [3375] | 1773 | #ifdef __IA64__
|
|---|
| [3395] | 1774 | return(EFI);
|
|---|
| [3375] | 1775 | #endif
|
|---|
| 1776 | /* Try to detect whether we are in fact in UEFI mode */
|
|---|
| [3378] | 1777 | fd = opendir("/sys/firmware/efi");
|
|---|
| [3375] | 1778 | if (fd != NULL) {
|
|---|
| 1779 | ret = UEFI;
|
|---|
| [3398] | 1780 | log_msg(2, "UEFI boot mode detected");
|
|---|
| [3377] | 1781 | closedir(fd);
|
|---|
| [3375] | 1782 | }
|
|---|
| 1783 | return(ret);
|
|---|
| 1784 | }
|
|---|
| 1785 |
|
|---|
| 1786 |
|
|---|
| [2434] | 1787 | /**
|
|---|
| [3877] | 1788 | * Find out which boot loader is in use.
|
|---|
| 1789 | * @param which_device Device to look for the boot loader on.
|
|---|
| 1790 | * @return 'L' for LILO, 'E'for ELILO, 'G' for GRUB, 'B' or 'D' for FreeBSD boot loaders, or 'U' for Unknown.
|
|---|
| 1791 | * @note Under Linux, all drives are examined, not just @p which_device.
|
|---|
| 1792 | */
|
|---|
| 1793 | #ifdef __FreeBSD__
|
|---|
| 1794 | char which_boot_loader(const char *which_device)
|
|---|
| 1795 | {
|
|---|
| 1796 | int count_lilos = 0;
|
|---|
| 1797 | int count_grubs = 0;
|
|---|
| 1798 | int count_boot0s = 0;
|
|---|
| 1799 | int count_dangerouslydedicated = 0;
|
|---|
| 1800 |
|
|---|
| 1801 | log_it("looking at drive %s's MBR", which_device);
|
|---|
| 1802 | if (does_string_exist_in_boot_block(which_device, "GRUB")) {
|
|---|
| 1803 | count_grubs++;
|
|---|
| 1804 | }
|
|---|
| 1805 | if (does_string_exist_in_boot_block(which_device, "LILO")) {
|
|---|
| 1806 | count_lilos++;
|
|---|
| 1807 | }
|
|---|
| 1808 | if (does_string_exist_in_boot_block(which_device, "Drive")) {
|
|---|
| 1809 | count_boot0s++;
|
|---|
| 1810 | }
|
|---|
| 1811 | if (does_string_exist_in_first_N_blocks
|
|---|
| 1812 | (which_device, "FreeBSD/i386", 17)) {
|
|---|
| 1813 | count_dangerouslydedicated++;
|
|---|
| 1814 | }
|
|---|
| 1815 | log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n",
|
|---|
| 1816 | count_grubs, count_lilos, count_elilos, count_boot0s,
|
|---|
| 1817 | count_dangerouslydedicated);
|
|---|
| 1818 |
|
|---|
| 1819 | if (count_grubs && !count_lilos) {
|
|---|
| 1820 | return ('G');
|
|---|
| 1821 | } else if (count_lilos && !count_grubs) {
|
|---|
| 1822 | return ('L');
|
|---|
| 1823 | } else if (count_grubs == 1 && count_lilos == 1) {
|
|---|
| 1824 | log_it("I'll bet you used to use LILO but switched to GRUB...");
|
|---|
| 1825 | return ('G');
|
|---|
| 1826 | } else if (count_boot0s == 1) {
|
|---|
| 1827 | return ('B');
|
|---|
| 1828 | } else if (count_dangerouslydedicated) {
|
|---|
| 1829 | return ('D');
|
|---|
| 1830 | } else {
|
|---|
| 1831 | log_it("Unknown boot loader");
|
|---|
| 1832 | return ('U');
|
|---|
| 1833 | }
|
|---|
| 1834 | }
|
|---|
| 1835 |
|
|---|
| 1836 | #else
|
|---|
| 1837 |
|
|---|
| 1838 | char which_boot_loader(const char *which_device)
|
|---|
| 1839 | {
|
|---|
| 1840 | /*@ buffer ***************************************************** */
|
|---|
| 1841 | char *list_drives_cmd = NULL;
|
|---|
| 1842 | char *current_drive;
|
|---|
| 1843 | char *tmp;
|
|---|
| 1844 |
|
|---|
| 1845 | /*@ pointers *************************************************** */
|
|---|
| 1846 | FILE *pdrives;
|
|---|
| 1847 |
|
|---|
| 1848 | /*@ int ******************************************************** */
|
|---|
| 1849 | int count_lilos = 0;
|
|---|
| 1850 | int count_grubs = 0;
|
|---|
| 1851 |
|
|---|
| 1852 | /*@ end vars *************************************************** */
|
|---|
| 1853 |
|
|---|
| 1854 | #ifdef __IA64__
|
|---|
| 1855 | /* No choice for it */
|
|---|
| 1856 | return ('E');
|
|---|
| 1857 | #endif
|
|---|
| 1858 | if (bkpinfo->boot_type == EFI) {
|
|---|
| 1859 | /* No choice for it */
|
|---|
| 1860 | return ('E');
|
|---|
| 1861 | }
|
|---|
| 1862 |
|
|---|
| 1863 | if (bkpinfo->boot_type == UEFI) {
|
|---|
| 1864 | /* hardcoded for now. We can for sure do a better job here ! */
|
|---|
| 1865 | /* RHEL, SLES, Mageia, Debian, Ubuntu use grub as boot loader as it seems for UEFI */
|
|---|
| 1866 | return ('G');
|
|---|
| 1867 | }
|
|---|
| 1868 |
|
|---|
| 1869 | assert(which_device != NULL);
|
|---|
| 1870 |
|
|---|
| 1871 | tmp = where_is_root_mounted();
|
|---|
| 1872 | mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp);
|
|---|
| 1873 | log_it("list_drives_cmd = %s", list_drives_cmd);
|
|---|
| 1874 | mr_free(tmp);
|
|---|
| 1875 | if (!(pdrives = popen(list_drives_cmd, "r"))) {
|
|---|
| 1876 | log_OS_error("Unable to open list of drives");
|
|---|
| 1877 | mr_free(list_drives_cmd);
|
|---|
| 1878 | return ('\0');
|
|---|
| 1879 | }
|
|---|
| 1880 | mr_free(list_drives_cmd);
|
|---|
| 1881 |
|
|---|
| 1882 | malloc_string(current_drive);
|
|---|
| 1883 | if (bkpinfo->boot_type == BIOS) {
|
|---|
| 1884 | for (tmp = fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives) && (tmp != NULL); tmp = fgets(current_drive, MAX_STR_LEN, pdrives)) {
|
|---|
| 1885 | strip_spaces(current_drive);
|
|---|
| 1886 | log_it("looking at drive %s's MBR", current_drive);
|
|---|
| 1887 | if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
|
|---|
| 1888 | count_grubs++;
|
|---|
| 1889 | strcpy(which_device, current_drive);
|
|---|
| 1890 | break;
|
|---|
| 1891 | }
|
|---|
| 1892 | if (does_string_exist_in_boot_block(current_drive, "LILO")) {
|
|---|
| 1893 | count_lilos++;
|
|---|
| 1894 | strcpy(which_device, current_drive);
|
|---|
| 1895 | break;
|
|---|
| 1896 | }
|
|---|
| 1897 | }
|
|---|
| 1898 | if (pclose(pdrives)) {
|
|---|
| 1899 | log_OS_error("Cannot pclose pdrives");
|
|---|
| 1900 | }
|
|---|
| 1901 | log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
|
|---|
| 1902 | if (count_grubs && !count_lilos) {
|
|---|
| 1903 | paranoid_free(current_drive);
|
|---|
| 1904 | return ('G');
|
|---|
| 1905 | } else if (count_lilos && !count_grubs) {
|
|---|
| 1906 | paranoid_free(current_drive);
|
|---|
| 1907 | return ('L');
|
|---|
| 1908 | } else if (count_grubs == 1 && count_lilos == 1) {
|
|---|
| 1909 | log_it("I'll bet you used to use LILO but switched to GRUB...");
|
|---|
| 1910 | paranoid_free(current_drive);
|
|---|
| 1911 | return ('G');
|
|---|
| 1912 | } else {
|
|---|
| 1913 | // We need to look on each partition then
|
|---|
| 1914 | mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/");
|
|---|
| 1915 | log_it("list_drives_cmd = %s", list_drives_cmd);
|
|---|
| 1916 |
|
|---|
| 1917 | if (!(pdrives = popen(list_drives_cmd, "r"))) {
|
|---|
| 1918 | log_OS_error("Unable to open list of drives");
|
|---|
| 1919 | mr_free(list_drives_cmd);
|
|---|
| 1920 | paranoid_free(current_drive);
|
|---|
| 1921 | return ('\0');
|
|---|
| 1922 | }
|
|---|
| 1923 | mr_free(list_drives_cmd);
|
|---|
| 1924 |
|
|---|
| 1925 | for (tmp = fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives) && (tmp != NULL);
|
|---|
| 1926 | tmp = fgets(current_drive, MAX_STR_LEN, pdrives)) {
|
|---|
| 1927 | strip_spaces(current_drive);
|
|---|
| 1928 | log_it("looking at partition %s's BR", current_drive);
|
|---|
| 1929 | if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
|
|---|
| 1930 | count_grubs++;
|
|---|
| 1931 | strcpy(which_device, current_drive);
|
|---|
| 1932 | break;
|
|---|
| 1933 | }
|
|---|
| 1934 | if (does_string_exist_in_boot_block(current_drive, "LILO")) {
|
|---|
| 1935 | count_lilos++;
|
|---|
| 1936 | strcpy(which_device, current_drive);
|
|---|
| 1937 | break;
|
|---|
| 1938 | }
|
|---|
| 1939 | }
|
|---|
| 1940 | if (pclose(pdrives)) {
|
|---|
| 1941 | log_OS_error("Cannot pclose pdrives");
|
|---|
| 1942 | }
|
|---|
| 1943 | log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
|
|---|
| 1944 | paranoid_free(current_drive);
|
|---|
| 1945 | if (count_grubs && !count_lilos) {
|
|---|
| 1946 | return ('G');
|
|---|
| 1947 | } else if (count_lilos && !count_grubs) {
|
|---|
| 1948 | return ('L');
|
|---|
| 1949 | } else if (count_grubs == 1 && count_lilos == 1) {
|
|---|
| 1950 | log_it("I'll bet you used to use LILO but switched to GRUB...");
|
|---|
| 1951 | return ('G');
|
|---|
| 1952 | } else {
|
|---|
| 1953 | log_it("Unknown boot loader");
|
|---|
| 1954 | return ('U');
|
|---|
| 1955 | }
|
|---|
| 1956 | }
|
|---|
| 1957 | }
|
|---|
| 1958 | }
|
|---|
| 1959 | #endif
|
|---|
| 1960 |
|
|---|
| 1961 |
|
|---|
| 1962 | /**
|
|---|
| [3878] | 1963 | * Get a |-separated list of NETFS mounts.
|
|---|
| 1964 | * @return The list created.
|
|---|
| 1965 | * @note The return value points to allocated string that needs to be freed by
|
|---|
| 1966 | * caller
|
|---|
| 1967 | * @bug Even though we only want the mounts, the devices are still checked.
|
|---|
| 1968 | */
|
|---|
| 1969 | char *list_of_NETFS_mounts_only(void)
|
|---|
| 1970 | {
|
|---|
| 1971 | char *exclude_these_directories = NULL;
|
|---|
| 1972 |
|
|---|
| 1973 | exclude_these_directories = call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,vmhgfs,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol,fuse.boostfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' '|' | awk '{print $0;}'");
|
|---|
| 1974 | log_msg(9,"list_of_NETFS_mounts_only returns %s",exclude_these_directories);
|
|---|
| 1975 | return(exclude_these_directories);
|
|---|
| 1976 | }
|
|---|
| 1977 |
|
|---|
| 1978 | /* @} - end of utilityGroup */
|
|---|
| 1979 |
|
|---|
| 1980 |
|
|---|
| 1981 | /**
|
|---|
| [1] | 1982 | * Ask user for details of backup/restore information.
|
|---|
| 1983 | * Called when @c mondoarchive doesn't get any parameters.
|
|---|
| 1984 | * @param bkpinfo The backup information structure to fill out with the user's data.
|
|---|
| 1985 | * @param archiving_to_media TRUE if archiving, FALSE if restoring.
|
|---|
| 1986 | * @return 0, always.
|
|---|
| 1987 | * @bug No point of `int' return value.
|
|---|
| 1988 | * @ingroup archiveGroup
|
|---|
| 1989 | */
|
|---|
| [1645] | 1990 | int interactively_obtain_media_parameters_from_user(bool archiving_to_media)
|
|---|
| [1] | 1991 | // archiving_to_media is TRUE if I'm being called by mondoarchive
|
|---|
| 1992 | // archiving_to_media is FALSE if I'm being called by mondorestore
|
|---|
| 1993 | {
|
|---|
| [2214] | 1994 | char *tmp = NULL;
|
|---|
| [3154] | 1995 | char *sz = NULL;
|
|---|
| [3111] | 1996 | char *tmpro = NULL;
|
|---|
| [2304] | 1997 | char *tmp1 = NULL;
|
|---|
| [3822] | 1998 | char *tmp2 = NULL;
|
|---|
| [2242] | 1999 | char *mds = NULL;
|
|---|
| [3212] | 2000 | char *oldtmp = NULL;
|
|---|
| [2847] | 2001 | char *q = NULL;
|
|---|
| [3062] | 2002 | char p[16*MAX_STR_LEN];
|
|---|
| [3191] | 2003 | char *sz_size = NULL;
|
|---|
| 2004 | char *command = NULL;
|
|---|
| [2771] | 2005 | char *compression_type = NULL;
|
|---|
| [3191] | 2006 | char *comment = NULL;
|
|---|
| [3877] | 2007 | char i = '\0';
|
|---|
| [128] | 2008 | FILE *fin;
|
|---|
| [1] | 2009 |
|
|---|
| [2304] | 2010 | malloc_string(tmp1);
|
|---|
| [128] | 2011 | assert(bkpinfo != NULL);
|
|---|
| [1] | 2012 |
|
|---|
| [2380] | 2013 | // Tape, CD, NETFS, ...?
|
|---|
| [128] | 2014 | srandom(getpid());
|
|---|
| [3881] | 2015 | bkpinfo->backup_media_type = (g_restoring_live_from_cd) ? optical : which_backup_media_type(bkpinfo->restore_data);
|
|---|
| [128] | 2016 | if (bkpinfo->backup_media_type == none) {
|
|---|
| [3653] | 2017 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2018 | finish(1);
|
|---|
| 2019 | }
|
|---|
| [3879] | 2020 | tmp = bkptype_to_string(bkpinfo->backup_media_type);
|
|---|
| 2021 | log_msg(3, "media type = %s", tmp);
|
|---|
| 2022 | mr_free(tmp);
|
|---|
| [3875] | 2023 |
|
|---|
| [1934] | 2024 | /* Why asking to remove the media with tape ?
|
|---|
| [128] | 2025 | if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {
|
|---|
| [1885] | 2026 | popup_and_OK("Please remove media from drive(s)");
|
|---|
| [128] | 2027 | }
|
|---|
| [1934] | 2028 | */
|
|---|
| [3154] | 2029 | if (archiving_to_media) {
|
|---|
| [3875] | 2030 | // TODO: Should be common ?
|
|---|
| [3154] | 2031 | setup_tmpdir(NULL);
|
|---|
| 2032 | /*
|
|---|
| 2033 | * Set the scratchdir to reside on the partition with the most free space.
|
|---|
| 2034 | * Automatically excludes DOS, NTFS, SMB, and NFS filesystems.
|
|---|
| 2035 | */
|
|---|
| 2036 | #ifdef __FreeBSD__
|
|---|
| [3610] | 2037 | tmp = call_program_and_get_last_line_of_output("df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,vmhgfs,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -nr | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done");
|
|---|
| [3154] | 2038 | #else
|
|---|
| [3610] | 2039 | tmp = call_program_and_get_last_line_of_output("df -m -P -x nfs -x nfs4 -x fuse.sshfs -x fuse -x vfat -x ntfs -x ntfs-3g -x vmhgfs -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -nr | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done");
|
|---|
| [3154] | 2040 | #endif
|
|---|
| 2041 |
|
|---|
| 2042 | if (tmp[0] != '/') {
|
|---|
| [3185] | 2043 | mr_asprintf(sz, "%s", tmp);
|
|---|
| [3154] | 2044 | mr_free(tmp);
|
|---|
| [3185] | 2045 | mr_asprintf(tmp, "/%s", sz);
|
|---|
| [3154] | 2046 | mr_free(sz);
|
|---|
| 2047 | }
|
|---|
| 2048 | setup_scratchdir(tmp);
|
|---|
| [3292] | 2049 | mr_free(tmp);
|
|---|
| [3875] | 2050 |
|
|---|
| 2051 | if ((compression_type = which_compression_type()) == NULL) {
|
|---|
| 2052 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| 2053 | finish(1);
|
|---|
| 2054 | }
|
|---|
| 2055 |
|
|---|
| [3882] | 2056 | bkpinfo->compression_level = 5;
|
|---|
| [3875] | 2057 | if ((bkpinfo->compression_level = which_compression_level()) == -1) {
|
|---|
| 2058 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| 2059 | finish(1);
|
|---|
| 2060 | }
|
|---|
| [3882] | 2061 | bkpinfo->use_lzo = FALSE;
|
|---|
| [3154] | 2062 | }
|
|---|
| [128] | 2063 | mvaddstr_and_log_it(2, 0, " ");
|
|---|
| [1] | 2064 |
|
|---|
| [1934] | 2065 | // Find device's /dev (or SCSI) entry
|
|---|
| [128] | 2066 | switch (bkpinfo->backup_media_type) {
|
|---|
| [3881] | 2067 | case optical:
|
|---|
| [1687] | 2068 | case usb:
|
|---|
| [1745] | 2069 | /* Never try to eject a USB device */
|
|---|
| 2070 | if (bkpinfo->backup_media_type == usb) {
|
|---|
| [1746] | 2071 | bkpinfo->please_dont_eject = TRUE;
|
|---|
| [1745] | 2072 | }
|
|---|
| [3875] | 2073 | mds = media_descriptor_string(bkpinfo->backup_media_type);
|
|---|
| 2074 | if (bkpinfo->backup_media_type != usb) {
|
|---|
| 2075 | if (ask_me_yes_or_no("Is your computer a laptop type (manual insert of MondoRescue media)?")) {
|
|---|
| 2076 | bkpinfo->manual_cd_tray = TRUE;
|
|---|
| [128] | 2077 | }
|
|---|
| [3881] | 2078 | if (ask_me_yes_or_no("Do you want to blank your media before burning them (RW type of media)?")) {
|
|---|
| 2079 | bkpinfo->wipe_media_first = TRUE;
|
|---|
| 2080 | }
|
|---|
| [3875] | 2081 | }
|
|---|
| 2082 |
|
|---|
| 2083 | if (bkpinfo->media_device == NULL) {
|
|---|
| 2084 | bkpinfo->media_device = find_device(bkpinfo->backup_media_type);
|
|---|
| 2085 | if (bkpinfo->media_device != NULL) {
|
|---|
| 2086 | log_msg(1, "MondoRescue device found automatically for your %s is %s", mds, bkpinfo->media_device);
|
|---|
| 2087 | } else {
|
|---|
| 2088 | log_msg(1, "No MondoRescue device found yet for your %s", mds);
|
|---|
| [2771] | 2089 | }
|
|---|
| [3875] | 2090 | }
|
|---|
| [3191] | 2091 |
|
|---|
| [3875] | 2092 | if (archiving_to_media) {
|
|---|
| [3882] | 2093 | if (bkpinfo->backup_media_type == optical) {
|
|---|
| [3191] | 2094 | mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
|
|---|
| [3882] | 2095 | log_msg(1, "Setting to DVD defaults ~4.4GB");
|
|---|
| [128] | 2096 | } else {
|
|---|
| [3882] | 2097 | mr_asprintf(sz_size, "%d", 0); // No value for USB
|
|---|
| [128] | 2098 | }
|
|---|
| [3875] | 2099 |
|
|---|
| [3191] | 2100 | mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds);
|
|---|
| [3883] | 2101 | tmp1 = mr_popup_and_get_string("Size", comment, sz_size);
|
|---|
| [3882] | 2102 | if (!tmp1) {
|
|---|
| [3653] | 2103 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2104 | finish(1);
|
|---|
| [3882] | 2105 | } else {
|
|---|
| 2106 | bkpinfo->media_size = atoi(tmp1);
|
|---|
| [128] | 2107 | }
|
|---|
| [3882] | 2108 | mr_free(tmp1);
|
|---|
| [3150] | 2109 | if (bkpinfo->media_size <= 0) {
|
|---|
| [3653] | 2110 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2111 | finish(1);
|
|---|
| 2112 | }
|
|---|
| 2113 | }
|
|---|
| [2242] | 2114 |
|
|---|
| [3875] | 2115 | // If media_device not found ask
|
|---|
| 2116 | if (bkpinfo->media_device == NULL) {
|
|---|
| 2117 | mr_asprintf(comment, "Please specify your Mondorescue %s media /dev entry", mds);
|
|---|
| 2118 | tmp2 = mr_popup_and_get_string("/dev entry?", comment, bkpinfo->media_device);
|
|---|
| 2119 | if (!tmp2) {
|
|---|
| 2120 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| 2121 | finish(1);
|
|---|
| 2122 | } else {
|
|---|
| 2123 | mr_free(bkpinfo->media_device);
|
|---|
| 2124 | bkpinfo->media_device = tmp2;
|
|---|
| [128] | 2125 | }
|
|---|
| [3875] | 2126 | }
|
|---|
| 2127 | log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);
|
|---|
| 2128 | mr_asprintf(tmp, "MondoRescue thinks your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device);
|
|---|
| 2129 | if (!ask_me_yes_or_no(tmp)) {
|
|---|
| 2130 | mr_free(bkpinfo->media_device);
|
|---|
| 2131 | }
|
|---|
| 2132 | mr_free(tmp);
|
|---|
| 2133 |
|
|---|
| 2134 | if (bkpinfo->media_device == NULL) {
|
|---|
| 2135 | mr_asprintf(tmp, "Please then specify your Mondorescue %s media /dev entry", mds);
|
|---|
| 2136 | tmp2 = mr_popup_and_get_string("/dev entry?", tmp, bkpinfo->media_device);
|
|---|
| 2137 | mr_free(tmp);
|
|---|
| 2138 | if (tmp2 == NULL) {
|
|---|
| 2139 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| 2140 | finish(1);
|
|---|
| 2141 | } else {
|
|---|
| [3822] | 2142 | mr_free(bkpinfo->media_device);
|
|---|
| [3875] | 2143 | bkpinfo->media_device = tmp2;
|
|---|
| [128] | 2144 | }
|
|---|
| 2145 | }
|
|---|
| [2242] | 2146 | mr_free(mds);
|
|---|
| [3882] | 2147 | break;
|
|---|
| [2242] | 2148 |
|
|---|
| [128] | 2149 | case udev:
|
|---|
| 2150 | if (!ask_me_yes_or_no
|
|---|
| [541] | 2151 | ("This option is for advanced users only. Are you sure?")) {
|
|---|
| [3653] | 2152 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2153 | finish(1);
|
|---|
| 2154 | }
|
|---|
| 2155 | case tape:
|
|---|
| [1] | 2156 |
|
|---|
| [3870] | 2157 | bkpinfo->media_device = find_tape_device();
|
|---|
| [3822] | 2158 | if (bkpinfo->media_device != NULL) {
|
|---|
| [128] | 2159 | if ((fin = fopen(bkpinfo->media_device, "r"))) {
|
|---|
| 2160 | paranoid_fclose(fin);
|
|---|
| 2161 | } else {
|
|---|
| [3271] | 2162 | if (does_file_exist("/tmp/mondorestore.cfg")) {
|
|---|
| 2163 | read_cfg_var("/tmp/mondorestore.cfg", "media-dev", bkpinfo->media_device);
|
|---|
| [128] | 2164 | }
|
|---|
| 2165 | }
|
|---|
| 2166 | }
|
|---|
| [3822] | 2167 | if (bkpinfo->media_device != NULL) {
|
|---|
| [3875] | 2168 | mr_asprintf(tmp, "Mondorescue thinks your tape streamer at %s; is that correct?", bkpinfo->media_device);
|
|---|
| [128] | 2169 | if (!ask_me_yes_or_no(tmp)) {
|
|---|
| [3822] | 2170 | mr_free(bkpinfo->media_device);
|
|---|
| [128] | 2171 | }
|
|---|
| [2214] | 2172 | mr_free(tmp);
|
|---|
| [128] | 2173 | }
|
|---|
| [3822] | 2174 | if (bkpinfo->media_device == NULL) {
|
|---|
| [3870] | 2175 | tmp2 = mr_popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", "");
|
|---|
| [3822] | 2176 | if (tmp2 == NULL) {
|
|---|
| [3653] | 2177 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2178 | finish(1);
|
|---|
| [3822] | 2179 | } else {
|
|---|
| 2180 | bkpinfo->media_device = tmp2;
|
|---|
| [128] | 2181 | }
|
|---|
| 2182 | }
|
|---|
| [3185] | 2183 | mr_asprintf(tmp, "ls -l %s", bkpinfo->media_device);
|
|---|
| [128] | 2184 | if (run_program_and_log_output(tmp, FALSE)) {
|
|---|
| [541] | 2185 | log_to_screen("User has not specified a valid /dev entry");
|
|---|
| [128] | 2186 | finish(1);
|
|---|
| 2187 | }
|
|---|
| [2214] | 2188 | mr_free(tmp);
|
|---|
| 2189 |
|
|---|
| [3576] | 2190 | mr_asprintf(sz_size,"%ld",bkpinfo->internal_tape_block_size);
|
|---|
| [3377] | 2191 | tmp = mr_popup_and_get_string("Tape block size?", "What is the block size of your tape streamer?", sz_size);
|
|---|
| 2192 | if (tmp == NULL) {
|
|---|
| [3653] | 2193 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [3169] | 2194 | finish(1);
|
|---|
| [128] | 2195 | }
|
|---|
| [3377] | 2196 | bkpinfo->internal_tape_block_size = atol(tmp);
|
|---|
| 2197 | mr_free(sz_size);
|
|---|
| 2198 | mr_free(tmp);
|
|---|
| 2199 |
|
|---|
| [3642] | 2200 | // log the block-size
|
|---|
| 2201 | log_msg(0,"Tape block size= %ld", bkpinfo->internal_tape_block_size);
|
|---|
| 2202 |
|
|---|
| [3169] | 2203 | if (bkpinfo->internal_tape_block_size <= 0) {
|
|---|
| [3653] | 2204 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [3169] | 2205 | finish(1);
|
|---|
| 2206 | }
|
|---|
| 2207 |
|
|---|
| 2208 | bkpinfo->media_size = 0;
|
|---|
| [3150] | 2209 | log_msg(4, "media_size = %ld", bkpinfo->media_size);
|
|---|
| [3169] | 2210 |
|
|---|
| [128] | 2211 | if (archiving_to_media) {
|
|---|
| [3875] | 2212 | bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?");
|
|---|
| 2213 | if (bkpinfo->use_obdr) {
|
|---|
| 2214 | log_msg(4, "obdr mode = TRUE");
|
|---|
| 2215 | } else {
|
|---|
| 2216 | log_msg(4, "obdr mode = FALSE");
|
|---|
| [2771] | 2217 | }
|
|---|
| [128] | 2218 | }
|
|---|
| 2219 | break;
|
|---|
| [1] | 2220 |
|
|---|
| [2380] | 2221 | case netfs:
|
|---|
| 2222 | /* Never try to eject a NETFS device */
|
|---|
| [1848] | 2223 | bkpinfo->please_dont_eject = TRUE;
|
|---|
| [3191] | 2224 | /* Force NFS to be the protocol by default */
|
|---|
| 2225 | if (bkpinfo->netfs_proto == NULL) {
|
|---|
| 2226 | mr_asprintf(bkpinfo->netfs_proto, "nfs");
|
|---|
| 2227 | }
|
|---|
| [1848] | 2228 |
|
|---|
| [2380] | 2229 | /* Initiate bkpinfo netfs_mount path from running environment if not already done */
|
|---|
| [3194] | 2230 | if (bkpinfo->netfs_mount == NULL) {
|
|---|
| [3610] | 2231 | bkpinfo->netfs_mount = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1");
|
|---|
| [128] | 2232 | }
|
|---|
| [1] | 2233 | #ifdef __FreeBSD__
|
|---|
| [128] | 2234 | if (TRUE)
|
|---|
| [1] | 2235 | #else
|
|---|
| [128] | 2236 | if (!bkpinfo->disaster_recovery)
|
|---|
| [1] | 2237 | #endif
|
|---|
| [128] | 2238 | {
|
|---|
| [3777] | 2239 | if (!popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", p,(MAX_STR_LEN / 4)-1)) {
|
|---|
| [3653] | 2240 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2241 | finish(1);
|
|---|
| 2242 | }
|
|---|
| [3191] | 2243 | mr_free(bkpinfo->netfs_mount);
|
|---|
| [3614] | 2244 | // check whether already mounted - we better remove
|
|---|
| 2245 | // surrounding spaces and trailing '/' for this
|
|---|
| 2246 | bkpinfo->netfs_mount = mr_strip_spaces(p);
|
|---|
| [2380] | 2247 | if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
|
|---|
| 2248 | bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
|
|---|
| [2847] | 2249 | q = strchr(bkpinfo->netfs_mount, '@');
|
|---|
| 2250 | if (q != NULL) {
|
|---|
| 2251 | /* User found. Store the 2 values */
|
|---|
| 2252 | q++;
|
|---|
| 2253 | /* new netfs mount */
|
|---|
| [3013] | 2254 | strcpy(tmp1,q);
|
|---|
| [2847] | 2255 | } else {
|
|---|
| [3013] | 2256 | strcpy(tmp1,bkpinfo->netfs_mount);
|
|---|
| [2847] | 2257 | }
|
|---|
| [3191] | 2258 | mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
|
|---|
| [3836] | 2259 | mr_free(bkpinfo->isodir);
|
|---|
| 2260 | bkpinfo->isodir = call_program_and_get_last_line_of_output(command);
|
|---|
| [3191] | 2261 | mr_free(command);
|
|---|
| [256] | 2262 |
|
|---|
| [1847] | 2263 | if (!bkpinfo->restore_data) {
|
|---|
| [3194] | 2264 | mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
|
|---|
| [3191] | 2265 | mr_asprintf(comment, "How much data (in Megabytes) will each media store?");
|
|---|
| 2266 | strcpy(tmp1, sz_size);
|
|---|
| 2267 | mr_free(sz_size);
|
|---|
| 2268 | if (!popup_and_get_string("Size", comment, tmp1, 5)) {
|
|---|
| [3653] | 2269 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [1847] | 2270 | finish(1);
|
|---|
| 2271 | }
|
|---|
| [3191] | 2272 | mr_free(comment);
|
|---|
| 2273 | mr_asprintf(sz_size, "%s", tmp1);
|
|---|
| [1847] | 2274 | } else {
|
|---|
| [3191] | 2275 | mr_asprintf(sz_size, "0");
|
|---|
| [256] | 2276 | }
|
|---|
| [3150] | 2277 | bkpinfo->media_size = atoi(sz_size);
|
|---|
| [3191] | 2278 | mr_free(sz_size);
|
|---|
| 2279 |
|
|---|
| [3150] | 2280 | if (bkpinfo->media_size < 0) {
|
|---|
| [3653] | 2281 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [256] | 2282 | finish(1);
|
|---|
| 2283 | }
|
|---|
| [128] | 2284 | }
|
|---|
| [3746] | 2285 | /* TODO: Useless I think */
|
|---|
| [128] | 2286 | if (bkpinfo->disaster_recovery) {
|
|---|
| [3191] | 2287 | mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
|
|---|
| [3060] | 2288 | paranoid_system(command);
|
|---|
| [3191] | 2289 | mr_free(command);
|
|---|
| 2290 |
|
|---|
| [128] | 2291 | }
|
|---|
| [2628] | 2292 | strcpy(tmp1, bkpinfo->netfs_proto);
|
|---|
| [3777] | 2293 | if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN-1)) {
|
|---|
| [3653] | 2294 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [2628] | 2295 | finish(1);
|
|---|
| 2296 | }
|
|---|
| 2297 | mr_free(bkpinfo->netfs_proto);
|
|---|
| [3185] | 2298 | mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1);
|
|---|
| [3191] | 2299 |
|
|---|
| 2300 | strcpy(tmp1, bkpinfo->netfs_mount);
|
|---|
| [3777] | 2301 | if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN-1)) {
|
|---|
| [3653] | 2302 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [2628] | 2303 | finish(1);
|
|---|
| 2304 | }
|
|---|
| [3191] | 2305 | mr_free(bkpinfo->netfs_mount);
|
|---|
| 2306 | mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1);
|
|---|
| [2628] | 2307 |
|
|---|
| [2847] | 2308 | if (bkpinfo->netfs_user) {
|
|---|
| 2309 | strcpy(tmp1, bkpinfo->netfs_user);
|
|---|
| 2310 | } else {
|
|---|
| 2311 | strcpy(tmp1, "");
|
|---|
| 2312 | }
|
|---|
| [3777] | 2313 | if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1, MAX_STR_LEN-1)) {
|
|---|
| [3653] | 2314 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [2847] | 2315 | finish(1);
|
|---|
| 2316 | }
|
|---|
| 2317 | mr_free(bkpinfo->netfs_user);
|
|---|
| 2318 | if (strcmp(tmp1, "") != 0) {
|
|---|
| [3185] | 2319 | mr_asprintf(bkpinfo->netfs_user, "%s", tmp1);
|
|---|
| [2847] | 2320 | }
|
|---|
| [3751] | 2321 |
|
|---|
| [1858] | 2322 | /* Initiate bkpinfo isodir path from running environment if mount already done */
|
|---|
| [3751] | 2323 | log_msg(3, "Testing mount for %s", bkpinfo->netfs_mount);
|
|---|
| [2380] | 2324 | if (is_this_device_mounted(bkpinfo->netfs_mount)) {
|
|---|
| [3836] | 2325 | mr_free(bkpinfo->isodir);
|
|---|
| 2326 | bkpinfo->isodir = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1");
|
|---|
| [1858] | 2327 | } else {
|
|---|
| [3278] | 2328 | // Why netfsdir ?
|
|---|
| [3836] | 2329 | mr_asprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
|
|---|
| [3191] | 2330 | mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
|
|---|
| [128] | 2331 | run_program_and_log_output(command, 5);
|
|---|
| [3191] | 2332 | mr_free(command);
|
|---|
| [3111] | 2333 |
|
|---|
| [2361] | 2334 | if (bkpinfo->restore_data) {
|
|---|
| [3751] | 2335 | /* mount the FS read-only in restore mode to avoid any erase of whatever */
|
|---|
| [3185] | 2336 | mr_asprintf(tmpro, "-o ro");
|
|---|
| [3111] | 2337 | } else {
|
|---|
| [3185] | 2338 | mr_asprintf(tmpro, "");
|
|---|
| [3111] | 2339 | }
|
|---|
| 2340 |
|
|---|
| 2341 | /* Build the mount string */
|
|---|
| 2342 | if (strstr(bkpinfo->netfs_proto, "smbfs")) {
|
|---|
| [3185] | 2343 | mr_asprintf(tmp, "mount -t cifs %s %s %s",bkpinfo->netfs_mount, bkpinfo->isodir,tmpro);
|
|---|
| [3111] | 2344 | if (bkpinfo->netfs_user) {
|
|---|
| 2345 | mr_strcat(tmp, " -o user=%s", bkpinfo->netfs_user);
|
|---|
| [3107] | 2346 | }
|
|---|
| [3111] | 2347 | else {
|
|---|
| [2380] | 2348 | if (strstr(bkpinfo->netfs_proto, "sshfs")) {
|
|---|
| [3185] | 2349 | mr_asprintf(tmp, "sshfs %s ",tmpro);
|
|---|
| [2380] | 2350 | } else {
|
|---|
| [3185] | 2351 | mr_asprintf(tmp, "mount -t %s -o nolock %s ", bkpinfo->netfs_proto,tmpro);
|
|---|
| [2380] | 2352 | }
|
|---|
| [3111] | 2353 | if (bkpinfo->netfs_user) {
|
|---|
| 2354 | mr_strcat(tmp, "%s@", bkpinfo->netfs_user);
|
|---|
| 2355 | }
|
|---|
| 2356 | mr_strcat(tmp, "%s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
|
|---|
| [2361] | 2357 | }
|
|---|
| [1819] | 2358 | run_program_and_log_output(tmp, 3);
|
|---|
| [2214] | 2359 | mr_free(tmp);
|
|---|
| 2360 |
|
|---|
| [128] | 2361 | malloc_string(g_selfmounted_isodir);
|
|---|
| 2362 | strcpy(g_selfmounted_isodir, bkpinfo->isodir);
|
|---|
| [3111] | 2363 | }
|
|---|
| [128] | 2364 | }
|
|---|
| [3751] | 2365 |
|
|---|
| 2366 | log_msg(3, "Testing mount for %s", bkpinfo->netfs_mount);
|
|---|
| [2380] | 2367 | if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
|
|---|
| [3191] | 2368 | popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
|
|---|
| [128] | 2369 | finish(1);
|
|---|
| 2370 | }
|
|---|
| [3196] | 2371 | if (bkpinfo->netfs_remote_dir == NULL) {
|
|---|
| [3205] | 2372 | fatal_error("bkpinfo->netfs_remote_dir should not be NULL");
|
|---|
| [3196] | 2373 | }
|
|---|
| [2380] | 2374 | strcpy(tmp1, bkpinfo->netfs_remote_dir);
|
|---|
| [3777] | 2375 | if (!popup_and_get_string ("Directory", "Which directory within that mountpoint?", tmp1, MAX_STR_LEN-1)) {
|
|---|
| [3653] | 2376 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2377 | finish(1);
|
|---|
| 2378 | }
|
|---|
| [3196] | 2379 | mr_free(bkpinfo->netfs_remote_dir);
|
|---|
| [128] | 2380 | // check whether writable - we better remove surrounding spaces for this
|
|---|
| [3614] | 2381 | bkpinfo->netfs_remote_dir = mr_strip_spaces(tmp1);
|
|---|
| [1767] | 2382 |
|
|---|
| [3838] | 2383 | tmp = mr_popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
|
|---|
| [3835] | 2384 | if (tmp == NULL) {
|
|---|
| [3653] | 2385 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [251] | 2386 | finish(1);
|
|---|
| 2387 | }
|
|---|
| [3835] | 2388 | mr_free(bkpinfo->prefix);
|
|---|
| 2389 | bkpinfo->prefix = tmp;
|
|---|
| [251] | 2390 | log_msg(3, "prefix set to %s", bkpinfo->prefix);
|
|---|
| [3191] | 2391 | log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);
|
|---|
| [128] | 2392 | log_msg(3, "isodir is still %s", bkpinfo->isodir);
|
|---|
| 2393 | break;
|
|---|
| [1] | 2394 |
|
|---|
| [128] | 2395 | case iso:
|
|---|
| 2396 | if (!bkpinfo->disaster_recovery) {
|
|---|
| [3836] | 2397 | tmp = mr_popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images. Example: /mnt/raid0_0", bkpinfo->isodir);
|
|---|
| 2398 | if (tmp == NULL) {
|
|---|
| [3653] | 2399 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2400 | finish(1);
|
|---|
| [3836] | 2401 | } else {
|
|---|
| 2402 | mr_free(bkpinfo->isodir);
|
|---|
| 2403 | bkpinfo->isodir = tmp;
|
|---|
| [128] | 2404 | }
|
|---|
| 2405 | if (archiving_to_media) {
|
|---|
| [3191] | 2406 | sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
|
|---|
| [3212] | 2407 | if (!popup_and_get_string("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.", tmp1, 16)) {
|
|---|
| [3653] | 2408 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2409 | finish(1);
|
|---|
| 2410 | }
|
|---|
| [3191] | 2411 | bkpinfo->media_size = atoi(tmp1);
|
|---|
| [128] | 2412 | } else {
|
|---|
| [3150] | 2413 | bkpinfo->media_size = 650;
|
|---|
| [128] | 2414 | }
|
|---|
| 2415 | }
|
|---|
| [3838] | 2416 | tmp = mr_popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
|
|---|
| [3835] | 2417 | if (tmp == NULL) {
|
|---|
| [3653] | 2418 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [804] | 2419 | finish(1);
|
|---|
| 2420 | }
|
|---|
| [3835] | 2421 | mr_free(bkpinfo->prefix);
|
|---|
| 2422 | bkpinfo->prefix = tmp;
|
|---|
| [804] | 2423 | log_msg(3, "prefix set to %s", bkpinfo->prefix);
|
|---|
| [128] | 2424 | break;
|
|---|
| 2425 | default:
|
|---|
| [3196] | 2426 | fatal_error("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
|
|---|
| [128] | 2427 | }
|
|---|
| [1] | 2428 |
|
|---|
| [128] | 2429 | if (archiving_to_media) {
|
|---|
| [3594] | 2430 | /* Needs to be done before calling which_boot_loader */
|
|---|
| 2431 | bkpinfo->boot_type = mr_boot_type();
|
|---|
| [3373] | 2432 | mr_free(bkpinfo->boot_device);
|
|---|
| [1] | 2433 | #ifdef __FreeBSD__
|
|---|
| [3610] | 2434 | bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
|
|---|
| [1] | 2435 | #else
|
|---|
| [3610] | 2436 | bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
|
|---|
| [1] | 2437 | #endif
|
|---|
| [128] | 2438 | i = which_boot_loader(bkpinfo->boot_device);
|
|---|
| 2439 | if (i == 'U') // unknown
|
|---|
| 2440 | {
|
|---|
| [1] | 2441 |
|
|---|
| 2442 | #ifdef __FreeBSD__
|
|---|
| [3777] | 2443 | if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device,(MAX_STR_LEN / 4)-1)) {
|
|---|
| [3653] | 2444 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2445 | finish(1);
|
|---|
| 2446 | }
|
|---|
| 2447 | i = which_boot_loader(bkpinfo->boot_device);
|
|---|
| [1] | 2448 | #else
|
|---|
| [3373] | 2449 | strcpy(tmp1, bkpinfo->boot_device);
|
|---|
| [3777] | 2450 | if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", tmp1,(MAX_STR_LEN / 4)-1)) {
|
|---|
| [3653] | 2451 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2452 | finish(1);
|
|---|
| 2453 | }
|
|---|
| [3373] | 2454 | mr_free(bkpinfo->boot_device);
|
|---|
| 2455 | mr_asprintf(bkpinfo->boot_device, "%s", tmp1);
|
|---|
| 2456 |
|
|---|
| 2457 | if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {
|
|---|
| 2458 | i = 'E';
|
|---|
| 2459 | } else
|
|---|
| 2460 | if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
|
|---|
| [128] | 2461 | i = 'L';
|
|---|
| 2462 | } else
|
|---|
| [3191] | 2463 | if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {
|
|---|
| [128] | 2464 | i = 'G';
|
|---|
| 2465 | } else {
|
|---|
| 2466 | i = 'U';
|
|---|
| 2467 | }
|
|---|
| [1] | 2468 | #endif
|
|---|
| [128] | 2469 | if (i == 'U') {
|
|---|
| [3191] | 2470 | if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) {
|
|---|
| [128] | 2471 | i = 'R'; // raw
|
|---|
| 2472 | } else {
|
|---|
| [3191] | 2473 | log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");
|
|---|
| [128] | 2474 | finish(1);
|
|---|
| 2475 | }
|
|---|
| 2476 | }
|
|---|
| [1] | 2477 | }
|
|---|
| [128] | 2478 | bkpinfo->boot_loader = i;
|
|---|
| [3831] | 2479 | /* TODO: Check consistency of boot type and boot loader */
|
|---|
| [3191] | 2480 |
|
|---|
| [3205] | 2481 | if (bkpinfo->include_paths) {
|
|---|
| 2482 | strcpy(tmp1, bkpinfo->include_paths);
|
|---|
| 2483 | mr_free(bkpinfo->include_paths);
|
|---|
| 2484 | } else {
|
|---|
| 2485 | strcpy(tmp1, "/");
|
|---|
| 2486 | }
|
|---|
| [3777] | 2487 | if (!popup_and_get_string("Backup paths", "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).", tmp1, MAX_STR_LEN-1)) {
|
|---|
| [3653] | 2488 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2489 | finish(1);
|
|---|
| [1] | 2490 | }
|
|---|
| [3191] | 2491 | mr_asprintf(bkpinfo->include_paths, "%s", tmp1);
|
|---|
| 2492 |
|
|---|
| [2713] | 2493 | tmp = list_of_NETFS_mounts_only();
|
|---|
| [128] | 2494 | if (strlen(tmp) > 2) {
|
|---|
| [2713] | 2495 | mr_strcat(bkpinfo->exclude_paths, "|%s",tmp);
|
|---|
| [128] | 2496 | }
|
|---|
| [2214] | 2497 | mr_free(tmp);
|
|---|
| [1] | 2498 | // NTFS
|
|---|
| [3610] | 2499 | tmp = call_program_and_get_last_line_of_output("mr-parted2fdisk -l 2>/dev/null | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
|
|---|
| [3777] | 2500 | strncpy(tmp1, tmp,(MAX_STR_LEN / 4)-1);
|
|---|
| [3610] | 2501 | mr_free(tmp);
|
|---|
| [2304] | 2502 | if (strlen(tmp1) > 2) {
|
|---|
| [3777] | 2503 | if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp1,(MAX_STR_LEN / 4)-1)) {
|
|---|
| [3653] | 2504 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2505 | finish(1);
|
|---|
| 2506 | }
|
|---|
| [3822] | 2507 | mr_asprintf(bkpinfo->image_devs, "%s", tmp1);
|
|---|
| [128] | 2508 | }
|
|---|
| [1] | 2509 |
|
|---|
| [2743] | 2510 | if (bkpinfo->exclude_paths != NULL ) {
|
|---|
| [3834] | 2511 | mr_asprintf(p, "%s", bkpinfo->exclude_paths);
|
|---|
| [2743] | 2512 | } else {
|
|---|
| [3834] | 2513 | mr_asprintf(p, "%s", "");
|
|---|
| [2743] | 2514 | }
|
|---|
| [3834] | 2515 | tmp = mr_popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with '|'. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", p);
|
|---|
| 2516 | mr_free(p);
|
|---|
| 2517 | if (tmp == NULL) {
|
|---|
| [3653] | 2518 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2519 | finish(1);
|
|---|
| 2520 | }
|
|---|
| [2697] | 2521 | mr_free(bkpinfo->exclude_paths);
|
|---|
| 2522 | bkpinfo->exclude_paths = tmp;
|
|---|
| 2523 |
|
|---|
| [3212] | 2524 | mr_asprintf(oldtmp, "%s", bkpinfo->tmpdir);
|
|---|
| 2525 | if (bkpinfo->tmpdir != NULL ) {
|
|---|
| [3834] | 2526 | mr_asprintf(p, "%s", bkpinfo->tmpdir);
|
|---|
| [3212] | 2527 | } else {
|
|---|
| [3834] | 2528 | mr_asprintf(p, "%s", "");
|
|---|
| [3212] | 2529 | }
|
|---|
| [3834] | 2530 | tmp = mr_popup_and_get_string("Temporary directory", "Please enter your temporary directory.", p);
|
|---|
| 2531 | mr_free(p);
|
|---|
| 2532 | if (tmp == NULL) {
|
|---|
| 2533 | mr_free(oldtmp);
|
|---|
| [3653] | 2534 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [2220] | 2535 | finish(1);
|
|---|
| 2536 | }
|
|---|
| [3154] | 2537 | /* if modified to another path */
|
|---|
| [3834] | 2538 | if (strcmp(tmp,oldtmp) != 0) {
|
|---|
| 2539 | setup_tmpdir(tmp);
|
|---|
| [3154] | 2540 | }
|
|---|
| [3212] | 2541 | mr_free(oldtmp);
|
|---|
| 2542 |
|
|---|
| 2543 | mr_asprintf(oldtmp, "%s", bkpinfo->scratchdir);
|
|---|
| 2544 | if (bkpinfo->scratchdir != NULL ) {
|
|---|
| [3834] | 2545 | mr_asprintf(p, "%s", bkpinfo->scratchdir);
|
|---|
| [3212] | 2546 | } else {
|
|---|
| [3834] | 2547 | mr_asprintf(p, "%s", "");
|
|---|
| [3212] | 2548 | }
|
|---|
| [3834] | 2549 | tmp = mr_popup_and_get_string("Scratch directory", "Please enter your scratch directory.", p);
|
|---|
| 2550 | mr_free(p);
|
|---|
| 2551 | if (tmp == NULL) {
|
|---|
| 2552 | mr_free(oldtmp);
|
|---|
| [3653] | 2553 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [2220] | 2554 | finish(1);
|
|---|
| 2555 | }
|
|---|
| [3154] | 2556 | /* if modified to another path */
|
|---|
| [3834] | 2557 | if (strcmp(tmp,oldtmp) != 0) {
|
|---|
| 2558 | setup_scratchdir(tmp);
|
|---|
| [3154] | 2559 | }
|
|---|
| [3212] | 2560 | mr_free(oldtmp);
|
|---|
| 2561 |
|
|---|
| [2772] | 2562 | if (ask_me_yes_or_no("Do you want to backup extended attributes?")) {
|
|---|
| [3866] | 2563 | mr_free(g_getfattr);
|
|---|
| 2564 | g_getfattr = find_home_of_exe("getfattr");
|
|---|
| 2565 | mr_free(g_getfacl);
|
|---|
| 2566 | g_getfacl = find_home_of_exe("getfacl");
|
|---|
| [3171] | 2567 | log_it("Backup of extended attributes");
|
|---|
| [2772] | 2568 | }
|
|---|
| [1575] | 2569 | // Interactive mode:
|
|---|
| 2570 | #ifdef __IA64__
|
|---|
| 2571 | bkpinfo->make_cd_use_lilo = TRUE;
|
|---|
| 2572 | #else
|
|---|
| [128] | 2573 | bkpinfo->make_cd_use_lilo = FALSE;
|
|---|
| [1575] | 2574 | #endif
|
|---|
| [128] | 2575 | bkpinfo->backup_data = TRUE;
|
|---|
| [2771] | 2576 | if (strcmp(compression_type,"lzo") == 0) {
|
|---|
| [3831] | 2577 | mr_asprintf(bkpinfo->zip_exe, "%s", "lzop");
|
|---|
| 2578 | mr_asprintf(bkpinfo->zip_suffix, "%s", "lzo");
|
|---|
| [2771] | 2579 | } else if (strcmp(compression_type,"gzip") == 0) {
|
|---|
| [3831] | 2580 | mr_asprintf(bkpinfo->zip_exe, "%s", "gzip");
|
|---|
| 2581 | mr_asprintf(bkpinfo->zip_suffix, "%s", "gz");
|
|---|
| [3191] | 2582 | } else if (strcmp(compression_type,"lzma") == 0) {
|
|---|
| [3831] | 2583 | mr_asprintf(bkpinfo->zip_exe, "%s", "xz");
|
|---|
| 2584 | mr_asprintf(bkpinfo->zip_suffix, "%s", "xz");
|
|---|
| [2771] | 2585 | } else if (strcmp(compression_type,"bzip2") == 0) {
|
|---|
| [3831] | 2586 | mr_asprintf(bkpinfo->zip_exe, "%s", "bzip2");
|
|---|
| 2587 | mr_asprintf(bkpinfo->zip_suffix, "%s", "bz2");
|
|---|
| [2771] | 2588 | } else {
|
|---|
| [3831] | 2589 | mr_free(bkpinfo->zip_exe);
|
|---|
| 2590 | mr_free(bkpinfo->zip_suffix);
|
|---|
| [2771] | 2591 | }
|
|---|
| [3875] | 2592 | mr_free(compression_type);
|
|---|
| 2593 |
|
|---|
| [3350] | 2594 | #if __FreeBSD__ == 5
|
|---|
| [3831] | 2595 | mr_asprintf(bkpinfo->kernel_path, "%s", "/boot/kernel/kernel");
|
|---|
| [3350] | 2596 | #elif __FreeBSD__ == 4
|
|---|
| [3831] | 2597 | mr_asprintf(bkpinfo->kernel_path, "%s", "/kernel");
|
|---|
| [3350] | 2598 | #elif linux
|
|---|
| 2599 | if (figure_out_kernel_path_interactively_if_necessary(bkpinfo->kernel_path)) {
|
|---|
| 2600 | fatal_error("Kernel not found. Please specify manually with the '-k' switch.");
|
|---|
| 2601 | }
|
|---|
| 2602 | #else
|
|---|
| 2603 | #error "I don't know about this system!"
|
|---|
| 2604 | #endif
|
|---|
| [2774] | 2605 |
|
|---|
| [3350] | 2606 |
|
|---|
| [128] | 2607 | bkpinfo->verify_data =
|
|---|
| 2608 | ask_me_yes_or_no
|
|---|
| [541] | 2609 | ("Will you want to verify your backups after Mondo has created them?");
|
|---|
| [1] | 2610 |
|
|---|
| [128] | 2611 | if (!ask_me_yes_or_no
|
|---|
| [541] | 2612 | ("Are you sure you want to proceed? Hit 'no' to abort.")) {
|
|---|
| [3653] | 2613 | log_to_screen("User has chosen not to backup the machine");
|
|---|
| [128] | 2614 | finish(1);
|
|---|
| 2615 | }
|
|---|
| 2616 | } else {
|
|---|
| 2617 | bkpinfo->restore_data = TRUE; // probably...
|
|---|
| 2618 | }
|
|---|
| [1] | 2619 |
|
|---|
| [128] | 2620 | if (bkpinfo->backup_media_type == iso
|
|---|
| [2380] | 2621 | || bkpinfo->backup_media_type == netfs) {
|
|---|
| [128] | 2622 | g_ISO_restore_mode = TRUE;
|
|---|
| 2623 | }
|
|---|
| [1] | 2624 | #ifdef __FreeSD__
|
|---|
| 2625 | // skip
|
|---|
| 2626 | #else
|
|---|
| [2380] | 2627 | if (bkpinfo->backup_media_type == netfs) {
|
|---|
| [3191] | 2628 | log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);
|
|---|
| [128] | 2629 | }
|
|---|
| 2630 | log_it("isodir = %s", bkpinfo->isodir);
|
|---|
| [3191] | 2631 | if (bkpinfo->netfs_mount) {
|
|---|
| 2632 | log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
|
|---|
| [2682] | 2633 | }
|
|---|
| [2380] | 2634 | if (bkpinfo->netfs_user) {
|
|---|
| 2635 | log_it("netfs_user = '%s'", bkpinfo->netfs_user);
|
|---|
| [2224] | 2636 | }
|
|---|
| [3191] | 2637 | if (bkpinfo->netfs_proto) {
|
|---|
| 2638 | log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
|
|---|
| 2639 | }
|
|---|
| [1] | 2640 | #endif
|
|---|
| 2641 |
|
|---|
| [128] | 2642 | log_it("media device = %s", bkpinfo->media_device);
|
|---|
| [3150] | 2643 | log_it("media size = %ld", bkpinfo->media_size);
|
|---|
| [3879] | 2644 | tmp = bkptype_to_string(bkpinfo->backup_media_type);
|
|---|
| 2645 | log_it("media type = %s", tmp);
|
|---|
| 2646 | mr_free(tmp);
|
|---|
| [3835] | 2647 | if (bkpinfo->prefix != NULL) {
|
|---|
| [3191] | 2648 | log_it("prefix = %s", bkpinfo->prefix);
|
|---|
| 2649 | }
|
|---|
| [128] | 2650 | log_it("compression = %ld", bkpinfo->compression_level);
|
|---|
| [2473] | 2651 | log_it("exclude_path = %s", bkpinfo->exclude_paths);
|
|---|
| [3205] | 2652 | if (bkpinfo->include_paths) {
|
|---|
| 2653 | log_it("include_path = %s", bkpinfo->include_paths);
|
|---|
| 2654 | }
|
|---|
| [2424] | 2655 |
|
|---|
| 2656 | /* Handle devices passed in bkpinfo and print result */
|
|---|
| [3194] | 2657 | /* the mr_make_devlist_from_pathlist function appends */
|
|---|
| [3191] | 2658 | /* to the *_paths variables so copy before */
|
|---|
| [2713] | 2659 | mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E');
|
|---|
| 2660 | mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I');
|
|---|
| [2424] | 2661 |
|
|---|
| [128] | 2662 | log_it("scratchdir = '%s'", bkpinfo->scratchdir);
|
|---|
| 2663 | log_it("tmpdir = '%s'", bkpinfo->tmpdir);
|
|---|
| [3191] | 2664 | if (bkpinfo->image_devs) {
|
|---|
| 2665 | log_it("image_devs = '%s'", bkpinfo->image_devs);
|
|---|
| 2666 | }
|
|---|
| 2667 | log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
|
|---|
| [3150] | 2668 | if (bkpinfo->media_size < 0) {
|
|---|
| [128] | 2669 | if (archiving_to_media) {
|
|---|
| 2670 | fatal_error("Media size is less than zero.");
|
|---|
| 2671 | } else {
|
|---|
| 2672 | log_msg(2, "Warning - media size is less than zero.");
|
|---|
| [3150] | 2673 | bkpinfo->media_size = 0;
|
|---|
| [128] | 2674 | }
|
|---|
| [1] | 2675 | }
|
|---|
| [128] | 2676 | paranoid_free(sz_size);
|
|---|
| [2305] | 2677 | paranoid_free(tmp1);
|
|---|
| [128] | 2678 | return (0);
|
|---|
| [1] | 2679 | }
|
|---|
| 2680 |
|
|---|
| 2681 |
|
|---|
| 2682 |
|
|---|
| 2683 |
|
|---|
| 2684 |
|
|---|
| 2685 | /**
|
|---|
| 2686 | * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where
|
|---|
| 2687 | * [random] is a random number between 1 and 32767.
|
|---|
| 2688 | * @param store_name_here Where to store the new filename.
|
|---|
| 2689 | * @param stub A random number will be appended to this to make the FIFO's name.
|
|---|
| 2690 | * @ingroup deviceGroup
|
|---|
| 2691 | */
|
|---|
| [128] | 2692 | void make_fifo(char *store_name_here, char *stub)
|
|---|
| [1] | 2693 | {
|
|---|
| [3352] | 2694 | char *tmp = NULL;
|
|---|
| [1] | 2695 |
|
|---|
| [128] | 2696 | assert_string_is_neither_NULL_nor_zerolength(stub);
|
|---|
| [1] | 2697 |
|
|---|
| [128] | 2698 | sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
|
|---|
| 2699 | (int) (random() % 32768));
|
|---|
| 2700 | make_hole_for_file(store_name_here);
|
|---|
| 2701 | mkfifo(store_name_here, S_IRWXU | S_IRWXG);
|
|---|
| [3352] | 2702 | mr_asprintf(tmp, "chmod 770 %s", store_name_here);
|
|---|
| [128] | 2703 | paranoid_system(tmp);
|
|---|
| [3352] | 2704 | mr_free(tmp);
|
|---|
| [1] | 2705 | }
|
|---|
| 2706 |
|
|---|
| 2707 |
|
|---|
| 2708 |
|
|---|
| 2709 | /**
|
|---|
| 2710 | * @addtogroup deviceGroup
|
|---|
| 2711 | * @{
|
|---|
| 2712 | */
|
|---|
| 2713 | /**
|
|---|
| 2714 | * If we can read @p dev, set @p output to it.
|
|---|
| 2715 | * If @p dev cannot be read, set @p output to "".
|
|---|
| 2716 | * @param dev The device to check for.
|
|---|
| 2717 | * @param output Set to @p dev if @p dev exists, "" otherwise.
|
|---|
| 2718 | * @return TRUE if @p dev exists, FALSE if it doesn't.
|
|---|
| 2719 | */
|
|---|
| [128] | 2720 | bool set_dev_to_this_if_rx_OK(char *output, char *dev)
|
|---|
| [1] | 2721 | {
|
|---|
| [3352] | 2722 | char *command = NULL;
|
|---|
| 2723 | bool ret=FALSE;
|
|---|
| [1] | 2724 |
|
|---|
| [128] | 2725 | if (!dev || dev[0] == '\0') {
|
|---|
| 2726 | output[0] = '\0';
|
|---|
| [3352] | 2727 | return(ret);
|
|---|
| [128] | 2728 | }
|
|---|
| [1] | 2729 | // assert_string_is_neither_NULL_nor_zerolength(dev);
|
|---|
| [2931] | 2730 | if (!bkpinfo->please_dont_eject) {
|
|---|
| 2731 | log_msg(10, "Injecting %s", dev);
|
|---|
| 2732 | inject_device(dev);
|
|---|
| 2733 | }
|
|---|
| [128] | 2734 | if (!does_file_exist(dev)) {
|
|---|
| 2735 | log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
|
|---|
| [3352] | 2736 | return(ret);
|
|---|
| [128] | 2737 | }
|
|---|
| [3352] | 2738 | mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
|
|---|
| 2739 | if (!run_program_and_log_output(command, FALSE) && !run_program_and_log_output(command, FALSE)) {
|
|---|
| [128] | 2740 | strcpy(output, dev);
|
|---|
| 2741 | log_msg(4, "Found it - %s", dev);
|
|---|
| [3352] | 2742 | ret = TRUE;
|
|---|
| [128] | 2743 | } else {
|
|---|
| 2744 | output[0] = '\0';
|
|---|
| 2745 | log_msg(4, "It's not %s", dev);
|
|---|
| 2746 | }
|
|---|
| [3352] | 2747 | mr_free(command);
|
|---|
| 2748 | return(ret);
|
|---|
| [1] | 2749 | }
|
|---|
| 2750 |
|
|---|
| 2751 |
|
|---|
| 2752 |
|
|---|
| 2753 | /**
|
|---|
| 2754 | * Write zeroes over the first 16K of @p device.
|
|---|
| 2755 | * @param device The device to zero.
|
|---|
| 2756 | * @return 0 for success, 1 for failure.
|
|---|
| 2757 | */
|
|---|
| [128] | 2758 | int zero_out_a_device(char *device)
|
|---|
| [1] | 2759 | {
|
|---|
| [128] | 2760 | FILE *fout;
|
|---|
| 2761 | int i;
|
|---|
| [1] | 2762 |
|
|---|
| [128] | 2763 | assert_string_is_neither_NULL_nor_zerolength(device);
|
|---|
| [1] | 2764 |
|
|---|
| [128] | 2765 | log_it("Zeroing drive %s", device);
|
|---|
| 2766 | if (!(fout = fopen(device, "w"))) {
|
|---|
| 2767 | log_OS_error("Unable to open/write to device");
|
|---|
| 2768 | return (1);
|
|---|
| 2769 | }
|
|---|
| 2770 | for (i = 0; i < 16384; i++) {
|
|---|
| 2771 | fputc('\0', fout);
|
|---|
| 2772 | }
|
|---|
| 2773 | paranoid_fclose(fout);
|
|---|
| 2774 | log_it("Device successfully zeroed.");
|
|---|
| 2775 | return (0);
|
|---|
| [1] | 2776 | }
|
|---|
| 2777 |
|
|---|
| 2778 | /**
|
|---|
| 2779 | * Return the device pointed to by @p incoming.
|
|---|
| 2780 | * @param incoming The device to resolve symlinks for.
|
|---|
| 2781 | * @return The path to the real device file.
|
|---|
| 2782 | * @note The returned string points to static storage that will be overwritten with each call.
|
|---|
| 2783 | * @bug Won't work with file v4.0; needs to be written in C.
|
|---|
| 2784 | */
|
|---|
| [128] | 2785 | char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
|
|---|
| [1] | 2786 | {
|
|---|
| [128] | 2787 | static char output[MAX_STR_LEN];
|
|---|
| [3352] | 2788 | char *command = NULL;
|
|---|
| 2789 | char *curr_fname = NULL;
|
|---|
| [2214] | 2790 | char *scratch = NULL;
|
|---|
| 2791 | char *tmp = NULL;
|
|---|
| [128] | 2792 | char *p;
|
|---|
| 2793 |
|
|---|
| 2794 | struct stat statbuf;
|
|---|
| 2795 | malloc_string(curr_fname);
|
|---|
| 2796 | if (!does_file_exist(incoming)) {
|
|---|
| 2797 | log_it
|
|---|
| 2798 | ("resolve_softlinks_to_get_to_actual_device_file --- device not found");
|
|---|
| 2799 | strcpy(output, incoming);
|
|---|
| 2800 | } else {
|
|---|
| 2801 | strcpy(curr_fname, incoming);
|
|---|
| 2802 | lstat(curr_fname, &statbuf);
|
|---|
| 2803 | while (S_ISLNK(statbuf.st_mode)) {
|
|---|
| 2804 | log_msg(1, "curr_fname = %s", curr_fname);
|
|---|
| [3352] | 2805 | mr_asprintf(command, "file %s", curr_fname);
|
|---|
| [3610] | 2806 | tmp = call_program_and_get_last_line_of_output(command);
|
|---|
| [3352] | 2807 | mr_free(command);
|
|---|
| [128] | 2808 | for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
|
|---|
| 2809 | p--);
|
|---|
| 2810 | p++;
|
|---|
| [3185] | 2811 | mr_asprintf(scratch, "%s", p);
|
|---|
| [128] | 2812 | for (p = scratch; *p != '\0' && *p != '\''; p++);
|
|---|
| 2813 | *p = '\0';
|
|---|
| [2214] | 2814 | log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
|
|---|
| 2815 | mr_free(tmp);
|
|---|
| 2816 |
|
|---|
| [128] | 2817 | if (scratch[0] == '/') {
|
|---|
| 2818 | strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink
|
|---|
| 2819 | } else { // copy over the basename cos it's a relative softlink
|
|---|
| 2820 | p = curr_fname + strlen(curr_fname);
|
|---|
| 2821 | while (p != curr_fname && *p != '/') {
|
|---|
| 2822 | p--;
|
|---|
| 2823 | }
|
|---|
| 2824 | if (*p == '/') {
|
|---|
| 2825 | p++;
|
|---|
| 2826 | }
|
|---|
| 2827 | strcpy(p, scratch);
|
|---|
| 2828 | }
|
|---|
| [2214] | 2829 | mr_free(scratch);
|
|---|
| [128] | 2830 | lstat(curr_fname, &statbuf);
|
|---|
| 2831 | }
|
|---|
| 2832 | strcpy(output, curr_fname);
|
|---|
| 2833 | log_it("resolved %s to %s", incoming, output);
|
|---|
| [1] | 2834 | }
|
|---|
| [128] | 2835 | paranoid_free(curr_fname);
|
|---|
| 2836 | return (output);
|
|---|
| [1] | 2837 | }
|
|---|
| 2838 |
|
|---|
| 2839 | /* @} - end of deviceGroup */
|
|---|
| 2840 |
|
|---|
| 2841 | /**
|
|---|
| 2842 | * Return the type of partition format (GPT or MBR)
|
|---|
| 2843 | */
|
|---|
| 2844 | char *which_partition_format(const char *drive)
|
|---|
| 2845 | {
|
|---|
| [3237] | 2846 | char *output = NULL;
|
|---|
| [3352] | 2847 | char *command = NULL;
|
|---|
| [3610] | 2848 |
|
|---|
| [3553] | 2849 | mr_asprintf(command, "mr-disk-type %s", drive);
|
|---|
| [3610] | 2850 | output = call_program_and_get_last_line_of_output(command);
|
|---|
| [3352] | 2851 | mr_free(command);
|
|---|
| 2852 |
|
|---|
| [3263] | 2853 | log_msg(0, "Found %s partition table format type on %s", output, drive);
|
|---|
| [128] | 2854 | return (output);
|
|---|
| [1] | 2855 | }
|
|---|
| 2856 | /* @} - end of deviceGroup */
|
|---|
| [3374] | 2857 |
|
|---|
| 2858 |
|
|---|