Ignore:
Timestamp:
Jul 27, 2007, 2:11:55 AM (13 years ago)
Author:
Bruno Cornec
Message:

Continue to remove floppy support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-archive.c

    r1572 r1581  
    4444extern struct mr_ar_conf *mr_conf;
    4545
    46 
    47 
    48 /** @def DEFAULT_1722MB_DISK The default 1.722M floppy disk to write images to. */
    49 /** @def BACKUP_1722MB_DISK  The 1.722M floppy disk to try if the default fails. */
    50 
    51 #ifdef __FreeBSD__
    52 #define DEFAULT_1722MB_DISK "/dev/fd0.1722"
    53 #define BACKUP_1722MB_DISK "/dev/fd0.1722"
    54 #else
    55 #define DEFAULT_1722MB_DISK "/dev/fd0u1722"
    56 #define BACKUP_1722MB_DISK "/dev/fd0H1722"
     46#ifndef __FreeBSD__
    5747#ifndef _SEMUN_H
    5848#define _SEMUN_H
     
    6757    struct seminfo *__buf;
    6858};
    69 #endif
    7059#endif                          /* __FreeBSD__ */
    7160
     
    793782        res++;
    794783        log_OS_error("Unable to make images directory");
    795     }
    796     mr_free(command);
    797 
    798     mr_asprintf(&command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
    799     if (system(command)) {
    800         res++;
    801         log_OS_error("Unable to make mnt floppy directory");
    802784    }
    803785    mr_free(command);
     
    13071289    }
    13081290    return (retval);
    1309 }
    1310 
    1311 
    1312 /**
    1313  * Calls floppy-formatting @c cmd and tracks its progress if possible.
    1314  *
    1315  * @param cmd The command to run (e.g. @c fdformat @c /dev/fd0).
    1316  * @param title The human-friendly description of the floppy you are writing.
    1317  * This will be used as the title in the progress bar window. Example:
    1318  * "Formatting disk /dev/fd0".
    1319  * @see format_disk
    1320  * @return The exit code of fdformat/superformat.
    1321  */
    1322 int format_disk_SUB(char *cmd, char *title)
    1323 {
    1324 
    1325     /*@ int *************************************************************** */
    1326     int res = 0;
    1327     int percentage = 0;
    1328     int maxtracks = 0;
    1329     int trackno = 0;
    1330     int last_trkno = 0;
    1331 
    1332     /*@ buffers *********************************************************** */
    1333     char *command = NULL;
    1334     char *tempfile;
    1335 
    1336     /*@ pointers ********************************************************** */
    1337     FILE *pin;
    1338 
    1339     assert_string_is_neither_NULL_nor_zerolength(cmd);
    1340     assert_string_is_neither_NULL_nor_zerolength(title);
    1341 
    1342     malloc_string(tempfile);
    1343 #ifdef __FreeBSD__
    1344 /* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
    1345    impossible to parse. It looks like
    1346    VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVF-------------------
    1347    where V means verified, E means error, F means formatted, and - means
    1348    not done yet.
    1349 */
    1350     return (run_program_and_log_to_screen(cmd, title));
    1351 #endif
    1352 
    1353 /* if Debian then do bog-standard superformat; don't be pretty */
    1354     if (strstr(cmd, "superformat")) {
    1355         return (run_program_and_log_to_screen(cmd, title));
    1356     }
    1357 /* if not Debian then go ahead & use fdformat */
    1358     strcpy(tempfile,
    1359            call_program_and_get_last_line_of_output
    1360            ("mktemp -q /tmp/mondo.XXXXXXXX"));
    1361     mr_asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile, tempfile);
    1362     mr_msg(3, command);
    1363     open_evalcall_form(title);
    1364     if (!(pin = popen(command, "r"))) {
    1365         log_OS_error("fmt err");
    1366         return (1);
    1367     }
    1368     if (strstr(command, "1722")) {
    1369         maxtracks = 82;
    1370     } else {
    1371         maxtracks = 80;
    1372     }
    1373     mr_free(command);
    1374 
    1375     for (sleep(1); does_file_exist(tempfile); sleep(1)) {
    1376         trackno = get_trackno_from_logfile(tempfile);
    1377         if (trackno < 0 || trackno > 80) {
    1378             mr_msg(1, "Weird track#");
    1379             continue;
    1380         }
    1381         percentage = trackno * 100 / maxtracks;
    1382         if (trackno <= 5 && last_trkno > 40) {
    1383             close_evalcall_form();
    1384             strcpy(title, "Verifying format");
    1385             open_evalcall_form(title);
    1386         }
    1387         last_trkno = trackno;
    1388         update_evalcall_form(percentage);
    1389     }
    1390     close_evalcall_form();
    1391     if (pclose(pin)) {
    1392         res++;
    1393         log_OS_error("Unable to pclose");
    1394     }
    1395     unlink(tempfile);
    1396     mr_free(tempfile);
    1397     return (res);
    1398 }
    1399 
    1400 
    1401 /**
    1402  * Wrapper around @c format_disk_SUB().
    1403  * This function calls @c format_disk_SUB() with a @c device of its @c device
    1404  * parameter and a @c title of Formatting disk @c device. If the format
    1405  * fails, the user will be given the option of retrying.
    1406  *
    1407  * @param device The floppy drive to write to.
    1408  * @see format_disk_SUB
    1409  * @return The exit code of fdformat/superformat.
    1410  * @ingroup deviceGroup
    1411  */
    1412 int format_disk(char *device)
    1413 {
    1414 
    1415     /*@ int ************************************************************** */
    1416     int res = 0;
    1417 
    1418     /*@ buffer *********************************************************** */
    1419     char *command;
    1420     char *title;
    1421 
    1422     assert_string_is_neither_NULL_nor_zerolength(device);
    1423 
    1424     if (!system("which superformat > /dev/null 2> /dev/null")) {
    1425         mr_asprintf(&command, "superformat %s", device);
    1426     } else {
    1427 #ifdef __FreeBSD__
    1428         mr_asprintf(&command, "fdformat -y %s", device);
    1429 #else
    1430         mr_asprintf(&command, "fdformat %s", device);
    1431 #endif
    1432     }
    1433     mr_asprintf(&title, "Formatting disk %s", device);
    1434     while ((res = format_disk_SUB(command, title))) {
    1435         if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
    1436             return (res);
    1437         }
    1438     }
    1439     mr_free(title);
    1440     mr_free(command);
    1441     return (res);
    14421291}
    14431292
     
    26072456
    26082457/**
    2609  * Offer to write boot and data disk images to 3.5" floppy disks.
    2610  * @param bkpinfo The backup information structure. Only the
    2611  * @c backup_media_type field is used in this function.
    2612  * @param imagesdir The directory containing the floppy images (usually
    2613  * /var/cache/mindi).
    2614  *
    2615  * @return The number of errors encountered (0 for success)
    2616  * @see write_image_to_floppy
    2617  * @see format_disk
    2618  * @ingroup MLarchiveGroup
    2619  */
    2620 int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
    2621 {
    2622     /*@ buffer ************************************************************ */
    2623     char *tmp = NULL;
    2624     char *comment = NULL;
    2625     char *bootdisk_dev =NULL;
    2626     char *datadisk_dev = NULL;
    2627     char *bootdisk_file = NULL;
    2628     char *rootdisk_file = NULL;
    2629 
    2630     /*@ int *************************************************************** */
    2631     int i = 0;
    2632     int res = 0;
    2633 
    2634     /*@ bool ************************************************************** */
    2635     bool format_first;
    2636     bool root_disk_exists = FALSE;
    2637 
    2638     assert(bkpinfo != NULL);
    2639     assert_string_is_neither_NULL_nor_zerolength(imagesdir);
    2640 
    2641     if (!ask_me_yes_or_no
    2642         ("Write boot and data disk images to 3.5\" floppy disks?")) {
    2643         return (0);
    2644     }
    2645     if (does_device_exist(DEFAULT_1722MB_DISK)) {
    2646 #ifdef __FreeBSD__
    2647         // tell the system that this is a 1.72m floppy
    2648         system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
    2649 #endif
    2650         mr_asprintf(&bootdisk_dev, DEFAULT_1722MB_DISK);
    2651     } else if (does_device_exist(BACKUP_1722MB_DISK)) {
    2652         mr_asprintf(&bootdisk_dev, "/dev/fd0H1722");
    2653     } else {
    2654         mr_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
    2655         mr_asprintf(&bootdisk_dev, DEFAULT_1722MB_DISK);
    2656     }
    2657     mr_asprintf(&datadisk_dev, "/dev/fd0");
    2658     if (!does_device_exist(datadisk_dev)) {
    2659         mr_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
    2660     }
    2661     format_first = ask_me_yes_or_no
    2662         ("Do you want me to format the disks before I write to them?");
    2663 
    2664     /* boot disk */
    2665     if (ask_me_OK_or_cancel("About to write boot disk")) {
    2666         log_to_screen("Writing boot floppy");
    2667 #ifdef __FreeBSD__
    2668         mr_asprintf(&tmp, "%s/mindi-kern.1722.img", imagesdir);
    2669         if (format_first) {
    2670             format_disk(bootdisk_dev);
    2671         }
    2672         res += write_image_to_floppy(bootdisk_dev, tmp);
    2673         mr_free(tmp);
    2674 
    2675         if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
    2676             log_to_screen("Writing mfsroot floppy");
    2677             if (format_first) {
    2678                 format_disk(datadisk_dev);
    2679             }
    2680             mr_asprintf(&tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
    2681             write_image_to_floppy(datadisk_dev, tmp);
    2682             mr_free(tmp);
    2683         }
    2684 #else
    2685         mr_asprintf(&bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
    2686         if (does_file_exist(bootdisk_file)) {
    2687             if (format_first) {
    2688                 format_disk(bootdisk_dev);
    2689             }
    2690             res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
    2691         } else {
    2692             mr_free(bootdisk_file);
    2693             mr_asprintf(&bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
    2694             mr_asprintf(&rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
    2695             root_disk_exists = TRUE;
    2696             if (!does_file_exist(rootdisk_file)
    2697                 || !does_file_exist(bootdisk_file)) {
    2698                 popup_and_OK
    2699                     ("Cannot write boot/root floppies. Files not found.");
    2700                 log_to_screen
    2701                     ("Failed to find boot/root floppy images. Oh dear.");
    2702                 mr_free(bootdisk_file);
    2703                 mr_free(rootdisk_file);
    2704                 mr_free(bootdisk_dev);
    2705                 return (1);
    2706             }
    2707             if (format_first) {
    2708                 format_disk(datadisk_dev);
    2709             }
    2710             res += write_image_to_floppy(datadisk_dev, bootdisk_file);
    2711             if (ask_me_OK_or_cancel("About to write root disk")) {
    2712                 log_to_screen("Writing root floppy");
    2713                 if (format_first) {
    2714                     format_disk(datadisk_dev);
    2715                 }
    2716                 mr_asprintf(&tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
    2717                 mr_msg(1, "tmp = '%s'", tmp);
    2718                 res +=
    2719                     run_external_binary_with_percentage_indicator_NEW
    2720                     ("Writing root floppy", tmp);
    2721 //              res += write_image_to_floppy (datadisk_dev, rootdisk_file);
    2722                 mr_free(tmp);
    2723             }
    2724             mr_free(rootdisk_file);
    2725            
    2726         }
    2727         mr_free(bootdisk_file);
    2728 #endif
    2729     }
    2730     mr_free(bootdisk_dev);
    2731 
    2732     if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    2733         log_to_screen
    2734             ("FYI, the data disks are stored on tape/CD for your convenience.");
    2735         return (0);
    2736     }
    2737     for (i = 1; i < 99; i++) {
    2738         mr_asprintf(&tmp, "%s/mindi-data-%d.img", imagesdir, i);
    2739         mr_msg(3, tmp);
    2740         if (!does_file_exist(tmp)) {
    2741             mr_msg(3, "...not found");
    2742             break;
    2743         }
    2744         mr_asprintf(&comment, "About to write data disk #%d", i);
    2745         if (ask_me_OK_or_cancel(comment)) {
    2746             mr_free(comment);
    2747             mr_asprintf(&comment, "Writing data disk #%3d", i);
    2748             log_to_screen(comment);
    2749             mr_free(comment);
    2750             if (format_first) {
    2751                 res += format_disk(datadisk_dev);
    2752             }
    2753             res += write_image_to_floppy(datadisk_dev, tmp);
    2754         }
    2755         mr_free(tmp);
    2756     }
    2757     /* In case of break free mem as well */
    2758     mr_free(tmp);
    2759     mr_free(datadisk_dev);
    2760     return (res);
    2761 }
    2762 
    2763 
    2764 /**
    2765  * Wrapper around @c offer_to_write_floppies().
    2766  * @param bkpinfo The backup information structure. Used only
    2767  * in the call to @c offer_to_write_floppies().
    2768  * @return 0 if the boot floppies were found (not necessarily written OK),
    2769  * 1 otherwise.
    2770  * @see offer_to_write_floppies
    2771  * @ingroup MLarchiveGroup
    2772  */
    2773 
    2774 int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo) {
    2775    
    2776     int res = 0;
    2777 
    2778     assert(bkpinfo != NULL);
    2779 
    2780     mvaddstr_and_log_it(g_currentY, 0,
    2781                         "Writing boot+data floppy images to disk");
    2782 
    2783     if (!bkpinfo->nonbootable_backup) {
    2784 #ifdef __FreeBSD__
    2785         if (!does_file_exist(MINDI_CACHE"/mindi-kern.1722.img"))
    2786 #else
    2787         /* BERLIOS: To be improved */
    2788         if (!does_file_exist(MINDI_CACHE"/mindi-bootroot.1722.img")
    2789             && !does_file_exist(MINDI_CACHE"/mindi-boot.1440.img")
    2790             && !does_file_exist(MINDI_CACHE"/mindi-boot.2880.img")
    2791             && !does_file_exist(MINDI_CACHE"/mindi-boot.5760.img")
    2792             && !does_file_exist(MINDI_CACHE"/mindi-boot.8192.img"))
    2793 #endif
    2794         {
    2795             mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
    2796             if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
    2797                 popup_and_OK
    2798                     ("Boot+data floppy creation failed. However, FYI, you may burn "MINDI_CACHE"/mondorescue.iso to a CD and boot from that instead if you wish.");
    2799                 res++;
    2800             }
    2801         } else {
    2802             offer_to_write_floppies(bkpinfo, MINDI_CACHE);
    2803             mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2804         }
    2805     } else {
    2806         popup_and_OK
    2807             ("Since you opted for a nonbootable backup, no boot floppies were created.");
    2808     }
    2809 
    2810     return (res);
    2811 }
    2812 
    2813 
    2814 /**
    28152458 * @addtogroup LLarchiveGroup
    28162459 * @{
     
    38123455
    38133456
    3814 /**
    3815  * @addtogroup utilityGroup
    3816  * @{
    3817  */
    3818 /**
    3819  * Write an image to a real 3.5" floppy disk.
    3820  * @param device The device to write to (e.g. @c /dev/fd0)
    3821  * @param datafile The image to write to @p device.
    3822  * @return The number of errors encountered (0 for success)
    3823  * @see write_image_to_floppy
    3824  */
    3825 int write_image_to_floppy_SUB(char *device, char *datafile)
    3826 {
    3827     /*@ int *************************************************************** */
    3828     int res = 0;
    3829     int percentage = 0;
    3830     int blockno = 0;
    3831     int maxblocks = 0;
    3832 
    3833     /*@ buffers************************************************************ */
    3834     char *tmp;
    3835     char blk[1024];
    3836     char *title;
    3837 
    3838     /*@ pointers ********************************************************** */
    3839     char *p;
    3840     FILE *fout, *fin;
    3841 
    3842 
    3843     /* pretty stuff */
    3844     if (!(p = strrchr(datafile, '/'))) {
    3845         p = datafile;
    3846     } else {
    3847         p++;
    3848     }
    3849     mr_asprintf(&title, "Writing %s to floppy", p);
    3850     open_evalcall_form(title);
    3851     mr_free(title);
    3852 
    3853     /* functional stuff */
    3854     for (p = device + strlen(device); p != device && isdigit(*(p - 1));
    3855          p--);
    3856     maxblocks = atoi(p);
    3857     if (!maxblocks) {
    3858         maxblocks = 1440;
    3859     }
    3860     mr_asprintf(&tmp, "maxblocks = %d; p=%s", maxblocks, p);
    3861     mr_msg(2, tmp);
    3862     mr_free(tmp);
    3863 
    3864     /* copy data from image to floppy */
    3865     if (!(fin = fopen(datafile, "r"))) {
    3866         log_OS_error("Cannot open img");
    3867         return (1);
    3868     }
    3869     if (!(fout = fopen(device, "w"))) {
    3870         log_OS_error("Cannot open fdd");
    3871         return (1);
    3872     }
    3873     for (blockno = 0; blockno < maxblocks; blockno++) {
    3874         percentage = blockno * 100 / maxblocks;
    3875         if (fread(blk, 1, 1024, fin) != 1024) {
    3876             if (feof(fin)) {
    3877                 mr_msg(1,
    3878                         "img read err - img ended prematurely - non-fatal error");
    3879                 sleep(3);
    3880                 return (res);
    3881             }
    3882             res++;
    3883             log_to_screen("img read err");
    3884         }
    3885         if (fwrite(blk, 1, 1024, fout) != 1024) {
    3886             res++;
    3887             log_to_screen("fdd write err");
    3888         }
    3889         if (((blockno + 1) % 128) == 0) {
    3890             sync(); /* fflush doesn't work; dunno why */
    3891             update_evalcall_form(percentage);
    3892         }
    3893     }
    3894     paranoid_fclose(fin);
    3895     paranoid_fclose(fout);
    3896     close_evalcall_form();
    3897     return (res);
    3898 }
    3899 
    3900 
    3901 /**
    3902  * Wrapper around @c write_image_to_floppy_SUB().
    3903  * This function, unlike @c write_image_to_floppy_SUB(),
    3904  * gives the user the opportunity to retry if the write fails.
    3905  * @see write_image_to_floppy_SUB
    3906  */
    3907 int write_image_to_floppy(char *device, char *datafile)
    3908 {
    3909     /*@ int ************************************************************** */
    3910     int res = 0;
    3911 
    3912     assert_string_is_neither_NULL_nor_zerolength(device);
    3913     assert_string_is_neither_NULL_nor_zerolength(datafile);
    3914 
    3915     while ((res = write_image_to_floppy_SUB(device, datafile))) {
    3916         if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
    3917             return (res);
    3918         }
    3919     }
    3920     return (res);
    3921 }
    3922 
    3923 /* @} - end of utilityGroup */
    3924 
    39253457void setenv_mondo_var(void) {
    39263458
Note: See TracChangeset for help on using the changeset viewer.