Changeset 783 in MondoRescue for trunk/mondo/mondo/common/libmondo-devices.c
- Timestamp:
- Aug 31, 2006, 5:09:20 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-devices.c
r729 r783 63 63 if (bkpinfo->media_device != NULL) { 64 64 paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 65 }66 if (bkpinfo->media_device != NULL) {67 65 paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case 68 66 } … … 95 93 log_it("rctada: Unmounting all CD drives", __LINE__); 96 94 run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5); 95 } 96 97 98 /** 99 * Mount the CD-ROM at @p mountpoint. 100 * @param device The device (or file if g_ISO_restore_mode) to mount. 101 * @param mountpoint The place to mount it. 102 * @return TRUE for success, FALSE for failure. 103 */ 104 bool mount_CDROM_here(char *device, char *mountpoint) 105 { 106 /*@ buffer ****************************************************** */ 107 char *command = NULL; 108 int retval = 0; 109 110 assert_string_is_neither_NULL_nor_zerolength(device); 111 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 112 113 make_hole_for_dir(mountpoint); 114 if (isdigit(device[0])) { 115 paranoid_free(device); 116 device = find_cdrom_device(FALSE); 117 } 118 if (g_ISO_restore_mode) { 119 120 #ifdef __FreeBSD__ 121 char *dev = NULL; 122 123 dev = make_vn(device)); 124 if (!dev) { 125 asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)", 126 device); 127 fatal_error(command); 128 } 129 paranoid_free(device); 130 device = dev; 131 #endif 132 } 133 134 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 135 mountpoint); 136 /*@ end vars *************************************************** */ 137 138 #ifdef __FreeBSD__ 139 asprintf(&command, "mount_cd9660 -r %s %s 2>> %s", 140 device, mountpoint, MONDO_LOGFILE); 141 #else 142 asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s", 143 device, mountpoint, MONDO_LOGFILE); 144 #endif 145 146 log_msg(4, command); 147 if (strncmp(device, "/dev/", 5) == 0) { 148 retract_CD_tray_and_defeat_autorun(); 149 } 150 retval = system(command); 151 log_msg(1, "system(%s) returned %d", command, retval); 152 paranoid_free(command); 153 154 if (retval == 0) { 155 return(TRUE); 156 } else { 157 return(FALSE); 158 } 97 159 } 98 160 … … 1232 1294 1233 1295 /** 1234 * Mount the CD-ROM at @p mountpoint.1235 * @param device The device (or file if g_ISO_restore_mode) to mount.1236 * @param mountpoint The place to mount it.1237 * @return TRUE for success, FALSE for failure.1238 */1239 bool mount_CDROM_here(char *device, char *mountpoint)1240 {1241 /*@ buffer ****************************************************** */1242 char *command = NULL;1243 int retval = 0;1244 1245 assert_string_is_neither_NULL_nor_zerolength(device);1246 assert_string_is_neither_NULL_nor_zerolength(mountpoint);1247 1248 make_hole_for_dir(mountpoint);1249 if (isdigit(device[0])) {1250 paranoid_free(device);1251 device = find_cdrom_device(FALSE);1252 }1253 if (g_ISO_restore_mode) {1254 1255 #ifdef __FreeBSD__1256 char *dev = NULL;1257 1258 dev = make_vn(device));1259 if (!dev) {1260 asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)",1261 device);1262 fatal_error(command);1263 }1264 paranoid_free(device);1265 device = dev;1266 #endif1267 }1268 1269 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,1270 mountpoint);1271 /*@ end vars *************************************************** */1272 1273 #ifdef __FreeBSD__1274 asprintf(&command, "mount_cd9660 -r %s %s 2>> %s",1275 device, mountpoint, MONDO_LOGFILE);1276 #else1277 asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s",1278 device, mountpoint, MONDO_LOGFILE);1279 #endif1280 1281 log_msg(4, command);1282 if (strncmp(device, "/dev/", 5) == 0) {1283 retract_CD_tray_and_defeat_autorun();1284 }1285 retval = system(command);1286 log_msg(1, "system(%s) returned %d", command, retval);1287 paranoid_free(command);1288 1289 if (retval == 0) {1290 return(TRUE);1291 } else {1292 return(FALSE);1293 }1294 }1295 1296 1297 /**1298 1296 * Ask the user for CD number @p cd_number_i_want. 1299 1297 * Sets g_current_media_number once the correct CD is inserted. … … 1355 1353 "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir", 1356 1354 bkpinfo->isodir); 1357 strcpy(bkpinfo->isodir, "/tmp/isodir");1355 paranoid_alloc(bkpinfo->isodir, "/tmp/isodir"); 1358 1356 } 1359 1357 } … … 1368 1366 cd_number_i_want); 1369 1367 asprintf(&tmp, "Insisting on %s #%d", 1370 media_descriptor_string(bkpinfo->backup_media_type),1368 bkpinfo->backup_media_string, 1371 1369 cd_number_i_want); 1372 1370 asprintf(&request, "Please insert %s #%d and press Enter.", 1373 media_descriptor_string(bkpinfo->backup_media_type),1371 bkpinfo->backup_media_string, 1374 1372 cd_number_i_want); 1375 1373 log_msg(3, tmp); … … 1451 1449 popup_and_OK(_("Please remove CD/floppy from drive(s)")); 1452 1450 } 1453 log_msg(3, "media type = %s", 1454 bkptype_to_string(bkpinfo->backup_media_type)); 1451 bkpinfo->backup_media_string = bkptype_to_string(bkpinfo->backup_media_type); 1452 log_msg(3, "media type = %s",bkpinfo->backup_media_string); 1453 1455 1454 if (archiving_to_media) { 1456 1455 sensibly_set_tmpdir_and_scratchdir(bkpinfo); … … 1496 1495 } 1497 1496 asprintf(&comment, _("What speed is your %s (re)writer?"), 1498 media_descriptor_string(bkpinfo->backup_media_type));1497 bkpinfo->backup_media_string); 1499 1498 if (bkpinfo->backup_media_type == dvd) { 1499 paranoid_free(bkpinfo->media_device); 1500 1500 bkpinfo->media_device = find_dvd_device(); 1501 1501 asprintf(&tmp, "1"); … … 1521 1521 asprintf(&comment, 1522 1522 _("How much data (in Megabytes) will each %s store?"), 1523 media_descriptor_string(bkpinfo->backup_media_type));1523 bkpinfo->backup_media_string); 1524 1524 1525 1525 if (!popup_and_get_string("Size", comment, sz_size)) { … … 1551 1551 log_msg(1, "bkpinfo->media_device = %s", 1552 1552 bkpinfo->media_device); 1553 tmp = find_cdrom_device(FALSE); 1553 1554 if ((bkpinfo->backup_media_type == dvd) 1554 || ((tmp = find_cdrom_device(FALSE)) != NULL)) { 1555 paranoid_free(bkpinfo->media_device); 1556 bkpinfo->media_device = tmp; 1555 || (tmp != NULL)) { 1556 paranoid_alloc(bkpinfo->media_device, tmp); 1557 1557 log_msg(1, "bkpinfo->media_device = %s", 1558 1558 bkpinfo->media_device); 1559 1559 asprintf(&comment, 1560 1560 _("Please specify your %s drive's /dev entry"), 1561 media_descriptor_string(bkpinfo-> 1562 backup_media_type)); 1561 bkpinfo->backup_media_string); 1563 1562 if (!popup_and_get_string 1564 1563 (_("Device?"), comment, bkpinfo->media_device)) { … … 1568 1567 paranoid_free(comment); 1569 1568 } 1569 paranoid_free(tmp); 1570 1570 1571 log_msg(2, "%s device found at %s", 1571 media_descriptor_string(bkpinfo->backup_media_type),1572 bkpinfo->backup_media_string, 1572 1573 bkpinfo->media_device); 1573 1574 } else { … … 1576 1577 asprintf(&tmp, 1577 1578 _("I think I've found your %s burner at SCSI node %s; am I right on the money? Say no if you have an IDE burner and you are running a 2.6 kernel. Instead, specify the IDE burner's /dev address at the next screen."), 1578 media_descriptor_string(bkpinfo-> 1579 backup_media_type), 1579 bkpinfo->backup_media_string, 1580 1580 bkpinfo->media_device); 1581 1581 if (!ask_me_yes_or_no(tmp)) { … … 1628 1628 } else { 1629 1629 if (does_file_exist("/tmp/mondo-restore.cfg")) { 1630 paranoid_free(bkpinfo->media_device); 1630 1631 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", 1631 1632 bkpinfo->media_device); … … 1639 1640 } 1640 1641 paranoid_free(tmp); 1641 } 1642 if (bkpinfo->media_device == NULL) { 1642 } else { 1643 1643 if (!popup_and_get_string 1644 1644 (_("Device name?"), … … 1677 1677 1678 1678 case nfs: 1679 if (!bkpinfo->nfs_mount[0]) { 1680 strcpy(bkpinfo->nfs_mount, 1681 call_program_and_get_last_line_of_output 1682 ("mount | grep \":\" | cut -d' ' -f1 | head -n1")); 1679 if (bkpinfo->nfs_mount == NULL) { 1680 bkpinfo->nfs_mount = call_program_and_get_last_line_of_output 1681 ("mount | grep \":\" | cut -d' ' -f1 | head -n1"); 1683 1682 } 1684 1683 #ifdef __FreeBSD__ … … 1704 1703 // check whether already mounted - we better remove 1705 1704 // surrounding spaces and trailing '/' for this 1705 /* BERLIOS: Useless 1706 1706 strip_spaces(bkpinfo->nfs_mount); 1707 */ 1707 1708 if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/') 1708 1709 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0'; 1709 1710 asprintf(&command, "mount | grep \"%s \" | cut -d' ' -f3", 1710 1711 bkpinfo->nfs_mount); 1711 strcpy(bkpinfo->isodir,1712 call_program_and_get_last_line_of_output(command));1712 paranoid_free(bkpinfo->isodir); 1713 bkpinfo->isodir = call_program_and_get_last_line_of_output(command); 1713 1714 paranoid_free(command); 1714 1715 … … 1738 1739 } 1739 1740 if (!is_this_device_mounted(bkpinfo->nfs_mount)) { 1740 sprintf(bkpinfo->isodir, "/tmp/isodir.mondo.%d", 1741 paranoid_free(bkpinfo->isodir); 1742 asprintf(&bkpinfo->isodir, "/tmp/isodir.mondo.%d", 1741 1743 (int) (random() % 32768)); 1742 1744 asprintf(&command, "mkdir -p %s", bkpinfo->isodir); … … 1748 1750 run_program_and_log_output(tmp, 5); 1749 1751 paranoid_free(tmp); 1750 malloc_string(g_selfmounted_isodir); 1751 strcpy(g_selfmounted_isodir, bkpinfo->isodir); 1752 asprintf(&g_selfmounted_isodir, bkpinfo->isodir); 1752 1753 } 1753 1754 if (!is_this_device_mounted(bkpinfo->nfs_mount)) { … … 1845 1846 if (archiving_to_media) { 1846 1847 1848 if (bkpinfo->boot_device) { 1849 paranoid_free(bkpinfo->boot_device); 1850 } 1847 1851 #ifdef __FreeBSD__ 1848 1852 bkpinfo->boot_device = call_program_and_get_last_line_of_output 1849 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'") );1853 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"); 1850 1854 #else 1851 1855 bkpinfo->boot_device = call_program_and_get_last_line_of_output 1852 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'") );1856 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"); 1853 1857 #endif 1854 1858 i = which_boot_loader(bkpinfo->boot_device); … … 1989 1993 log_it("media device = %s", bkpinfo->media_device); 1990 1994 log_it("media size = %ld", bkpinfo->media_size[1]); 1991 log_it("media type = %s", 1992 bkptype_to_string(bkpinfo->backup_media_type));1995 log_it("media type = %s", bkpinfo->backup_media_string); 1996 paranoid_free(tmp); 1993 1997 log_it("prefix = %s", bkpinfo->prefix); 1994 1998 log_it("compression = %ld", bkpinfo->compression_level); … … 1999 2003 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, 2000 2004 bkpinfo->boot_loader); 2001 log_it("prefix = %s", bkpinfo->prefix);2002 2005 if (bkpinfo->media_size[0] < 0) { 2003 2006 if (archiving_to_media) { … … 2033 2036 2034 2037 /** 2035 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where2036 * [random] is a random number between 1 and 32767.2037 * @param store_name_here Where to store the new filename.2038 * @param stub A random number will be appended to this to make the FIFO's name.2039 * @ingroup deviceGroup2040 */2041 void make_fifo(char *store_name_here, char *stub)2042 {2043 char *tmp;2044 2045 assert_string_is_neither_NULL_nor_zerolength(stub);2046 2047 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),2048 (int) (random() % 32768));2049 make_hole_for_file(store_name_here);2050 mkfifo(store_name_here, S_IRWXU | S_IRWXG);2051 asprintf(&tmp, "chmod 770 %s", store_name_here);2052 paranoid_system(tmp);2053 paranoid_free(tmp);2054 }2055 2056 2057 /**2058 2038 * Set the tmpdir and scratchdir to reside on the partition with the most free space. 2059 2039 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems. … … 2087 2067 } 2088 2068 i = (int) (random() % 32768); 2069 paranoid_free(bkpinfo->tmpdir); 2089 2070 asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i); 2090 2071 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2091 2072 2073 paranoid_free(bkpinfo->scratchdir); 2092 2074 asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i); 2093 2075 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); … … 2277 2259 2278 2260 char which_boot_loader(char *which_device) 2261 /* which_device is allocated here and needs to be freed by caller */ 2279 2262 { 2280 2263 /*@ buffer ***************************************************** */ … … 2315 2298 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2316 2299 count_grubs++; 2317 strcpy(which_device,current_drive);2300 paranoid_alloc(which_device,current_drive); 2318 2301 break; 2319 2302 } 2320 2303 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2321 2304 count_lilos++; 2322 strcpy(which_device,current_drive);2305 paranoid_alloc(which_device,current_drive); 2323 2306 break; 2324 2307 } 2325 2308 } 2326 paranoid_free(current_drive);2327 2309 2328 2310 if (pclose(pdrives)) {
Note:
See TracChangeset
for help on using the changeset viewer.