Ignore:
Timestamp:
Mar 2, 2008, 12:38:35 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Remove floppy support from mindi and mondo and adapt docs
  • Align more mindi with the version from stable
File:
1 edited

Legend:

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

    r1878 r1885  
    195195
    196196
    197 /** @def DEFAULT_1722MB_DISK The default 1.722M floppy disk to write images to. */
    198 /** @def BACKUP_1722MB_DISK  The 1.722M floppy disk to try if the default fails. */
    199 
    200 #ifdef __FreeBSD__
    201 #define DEFAULT_1722MB_DISK "/dev/fd0.1722"
    202 #define BACKUP_1722MB_DISK "/dev/fd0.1722"
    203 #else
    204 #define DEFAULT_1722MB_DISK "/dev/fd0u1722"
    205 #define BACKUP_1722MB_DISK "/dev/fd0H1722"
    206197#ifndef _SEMUN_H
    207198#define _SEMUN_H
     
    10321023        log_OS_error("Unable to make images directory");
    10331024    }
    1034     sprintf(command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
    1035     if (system(command)) {
    1036         res++;
    1037         log_OS_error("Unable to make mnt floppy directory");
    1038     }
    10391025    sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
    10401026            bkpinfo->kernel_path);
     
    14561442}
    14571443
    1458 
    1459 /**
    1460  * Calls floppy-formatting @c cmd and tracks its progress if possible.
    1461  *
    1462  * @param cmd The command to run (e.g. @c fdformat @c /dev/fd0).
    1463  * @param title The human-friendly description of the floppy you are writing.
    1464  * This will be used as the title in the progress bar window. Example:
    1465  * "Formatting disk /dev/fd0".
    1466  * @see format_disk
    1467  * @return The exit code of fdformat/superformat.
    1468  */
    1469 int format_disk_SUB(char *cmd, char *title)
    1470 {
    1471 
    1472     /*@ int *************************************************************** */
    1473     int res = 0;
    1474     int percentage = 0;
    1475     int maxtracks = 0;
    1476     int trackno = 0;
    1477     int last_trkno = 0;
    1478 
    1479     /*@ buffers *********************************************************** */
    1480     char *command;
    1481     char *tempfile;
    1482 
    1483     /*@ pointers ********************************************************** */
    1484     FILE *pin;
    1485 
    1486     assert_string_is_neither_NULL_nor_zerolength(cmd);
    1487     assert_string_is_neither_NULL_nor_zerolength(title);
    1488 
    1489     malloc_string(command);
    1490     malloc_string(tempfile);
    1491 #ifdef __FreeBSD__
    1492 /* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
    1493    impossible to parse. It looks like
    1494    VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVF-------------------
    1495    where V means verified, E means error, F means formatted, and - means
    1496    not done yet.
    1497 */
    1498     return (run_program_and_log_to_screen(cmd, title));
    1499 #endif
    1500 
    1501 /* if Debian then do bog-standard superformat; don't be pretty */
    1502     if (strstr(cmd, "superformat")) {
    1503         return (run_program_and_log_to_screen(cmd, title));
    1504     }
    1505 /* if not Debian then go ahead & use fdformat */
    1506     sprintf(tempfile, "%s/mondo.floppy.log", bkpinfo->tmpdir);
    1507     sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    1508             tempfile);
    1509     log_msg(3, command);
    1510     open_evalcall_form(title);
    1511     if (!(pin = popen(command, "r"))) {
    1512         log_OS_error("fmt err");
    1513         return (1);
    1514     }
    1515     if (strstr(command, "1722")) {
    1516         maxtracks = 82;
    1517     } else {
    1518         maxtracks = 80;
    1519     }
    1520     for (sleep(1); does_file_exist(tempfile); sleep(1)) {
    1521         trackno = get_trackno_from_logfile(tempfile);
    1522         if (trackno < 0 || trackno > 80) {
    1523             log_msg(1, "Weird track#");
    1524             continue;
    1525         }
    1526         percentage = trackno * 100 / maxtracks;
    1527         if (trackno <= 5 && last_trkno > 40) {
    1528             close_evalcall_form();
    1529             strcpy(title, "Verifying format");
    1530             open_evalcall_form(title);
    1531         }
    1532         last_trkno = trackno;
    1533         update_evalcall_form(percentage);
    1534     }
    1535     close_evalcall_form();
    1536     if (pclose(pin)) {
    1537         res++;
    1538         log_OS_error("Unable to pclose");
    1539     }
    1540     unlink(tempfile);
    1541     paranoid_free(command);
    1542     paranoid_free(tempfile);
    1543     return (res);
    1544 }
    1545 
    1546 /**
    1547  * Wrapper around @c format_disk_SUB().
    1548  * This function calls @c format_disk_SUB() with a @c device of its @c device
    1549  * parameter and a @c title of Formatting disk @c device. If the format
    1550  * fails, the user will be given the option of retrying.
    1551  *
    1552  * @param device The floppy drive to write to.
    1553  * @see format_disk_SUB
    1554  * @return The exit code of fdformat/superformat.
    1555  * @ingroup deviceGroup
    1556  */
    1557 int format_disk(char *device)
    1558 {
    1559 
    1560     /*@ int ************************************************************** */
    1561     int res = 0;
    1562 
    1563     /*@ buffer *********************************************************** */
    1564     char *command;
    1565     char *title;
    1566 
    1567 
    1568     assert_string_is_neither_NULL_nor_zerolength(device);
    1569     malloc_string(title);
    1570     command = malloc(1000);
    1571     if (!system("which superformat > /dev/null 2> /dev/null")) {
    1572         sprintf(command, "superformat %s", device);
    1573     } else {
    1574 #ifdef __FreeBSD__
    1575         sprintf(command, "fdformat -y %s", device);
    1576 #else
    1577         sprintf(command, "fdformat %s", device);
    1578 #endif
    1579     }
    1580     sprintf(title, "Formatting disk %s", device);
    1581     while ((res = format_disk_SUB(command, title))) {
    1582         if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
    1583             return (res);
    1584         }
    1585     }
    1586     paranoid_free(title);
    1587     paranoid_free(command);
    1588     return (res);
    1589 }
    15901444
    15911445/**
     
    28792733
    28802734
    2881 
    2882 
    2883 
    2884 
    2885 /**
    2886  * Offer to write boot and data disk images to 3.5" floppy disks.
    2887  * @param bkpinfo The backup information structure. Only the
    2888  * @c backup_media_type field is used in this function.
    2889  * @param imagesdir The directory containing the floppy images (usually
    2890  * /root/images/mindi).
    2891  *
    2892  * @return The number of errors encountered (0 for success)
    2893  * @see write_image_to_floppy
    2894  * @see format_disk
    2895  * @ingroup MLarchiveGroup
    2896  */
    2897 int offer_to_write_floppies(char *imagesdir)
    2898 {
    2899     /*@ buffer ************************************************************ */
    2900     char *tmp;
    2901     char *comment;
    2902     char *bootdisk_dev;
    2903     char *datadisk_dev;
    2904     char *bootdisk_file;
    2905     char *rootdisk_file;
    2906 
    2907     /*@ int *************************************************************** */
    2908     int i = 0;
    2909     int res = 0;
    2910 
    2911     /*@ bool ************************************************************** */
    2912     bool format_first;
    2913     bool root_disk_exists = FALSE;
    2914 
    2915     malloc_string(tmp);
    2916     malloc_string(comment);
    2917     malloc_string(bootdisk_dev);
    2918     malloc_string(datadisk_dev);
    2919     malloc_string(rootdisk_file);
    2920     malloc_string(bootdisk_file);
    2921     assert(bkpinfo != NULL);
    2922     assert_string_is_neither_NULL_nor_zerolength(imagesdir);
    2923 
    2924 
    2925     if (!ask_me_yes_or_no
    2926         ("Write boot and data disk images to 3.5\" floppy disks?")) {
    2927         return (0);
    2928     }
    2929     if (does_device_exist(DEFAULT_1722MB_DISK)) {
    2930 #ifdef __FreeBSD__
    2931         // tell the system that this is a 1.72m floppy
    2932         system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
    2933 #endif
    2934         strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
    2935     } else if (does_device_exist(BACKUP_1722MB_DISK)) {
    2936         sprintf(bootdisk_dev, "/dev/fd0H1722");
    2937     } else {
    2938         log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
    2939         strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
    2940 //      return (1);
    2941     }
    2942     strcpy(datadisk_dev, "/dev/fd0");
    2943     if (!does_device_exist(datadisk_dev)) {
    2944         log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
    2945         strcpy(datadisk_dev, "/dev/fd0");
    2946 //      return (1);
    2947     }
    2948     format_first =
    2949         ask_me_yes_or_no
    2950         ("Do you want me to format the disks before I write to them?");
    2951 
    2952 /* boot disk */
    2953     if (ask_me_OK_or_cancel("About to write boot disk")) {
    2954         log_to_screen("Writing boot floppy");
    2955 #ifdef __FreeBSD__
    2956         sprintf(tmp, "%s/mindi-kern.1722.img", imagesdir);
    2957         if (format_first) {
    2958             format_disk(bootdisk_dev);
    2959         }
    2960         res += write_image_to_floppy(bootdisk_dev, tmp);
    2961         if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
    2962             log_to_screen("Writing mfsroot floppy");
    2963             if (format_first) {
    2964                 format_disk(datadisk_dev);
    2965             }
    2966             sprintf(tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
    2967             write_image_to_floppy(datadisk_dev, tmp);
    2968         }
    2969 #else
    2970         sprintf(bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
    2971         if (does_file_exist(bootdisk_file)) {
    2972             if (format_first) {
    2973                 format_disk(bootdisk_dev);
    2974             }
    2975             res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
    2976         } else {
    2977             sprintf(bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
    2978             sprintf(rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
    2979             root_disk_exists = TRUE;
    2980             if (!does_file_exist(rootdisk_file)
    2981                 || !does_file_exist(bootdisk_file)) {
    2982                 popup_and_OK
    2983                     ("Cannot write boot/root floppies. Files not found.");
    2984                 log_to_screen
    2985                     ("Failed to find boot/root floppy images. Oh dear.");
    2986                 return (1);
    2987             }
    2988             if (format_first) {
    2989                 format_disk(datadisk_dev);
    2990             }
    2991             /*
    2992                sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
    2993                res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
    2994              */
    2995             res += write_image_to_floppy(datadisk_dev, bootdisk_file);
    2996             if (ask_me_OK_or_cancel("About to write root disk")) {
    2997                 log_to_screen("Writing root floppy");
    2998                 if (format_first) {
    2999                     format_disk(datadisk_dev);
    3000                 }
    3001                 sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
    3002                 log_msg(1, "tmp = '%s'", tmp);
    3003                 res +=
    3004                     run_external_binary_with_percentage_indicator_NEW
    3005                     ("Writing root floppy", tmp);
    3006 //              res += write_image_to_floppy (datadisk_dev, rootdisk_file);
    3007             }
    3008         }
    3009 #endif
    3010     }
    3011     if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    3012         log_to_screen
    3013             ("FYI, the data disks are stored on tape/CD for your convenience.");
    3014         return (0);
    3015     }
    3016     for (i = 1; i < 99; i++) {
    3017         sprintf(tmp, "%s/mindi-data-%d.img", imagesdir, i);
    3018         log_msg(3, tmp);
    3019         if (!does_file_exist(tmp)) {
    3020             log_msg(3, "...not found");
    3021             break;
    3022         }
    3023         sprintf(comment, "About to write data disk #%d", i);
    3024         if (ask_me_OK_or_cancel(comment)) {
    3025             sprintf(comment, "Writing data disk #%3d", i);
    3026             log_to_screen(comment);
    3027             if (format_first) {
    3028                 res += format_disk(datadisk_dev);
    3029             }
    3030             res += write_image_to_floppy(datadisk_dev, tmp);
    3031         }
    3032     }
    3033     paranoid_free(tmp);
    3034     paranoid_free(comment);
    3035     paranoid_free(bootdisk_dev);
    3036     paranoid_free(datadisk_dev);
    3037     return (res);
    3038 }
    3039 
    3040 
    3041 
    3042 
    3043 
    3044 
    3045 
    3046 
    3047 /**
    3048  * Wrapper around @c offer_to_write_floppies().
    3049  * @param bkpinfo The backup information structure. Used only
    3050  * in the call to @c offer_to_write_floppies().
    3051  * @return 0 if the boot floppies were found (not necessarily written OK),
    3052  * 1 otherwise.
    3053  * @see offer_to_write_floppies
    3054  * @ingroup MLarchiveGroup
    3055  */
    3056 
    3057 int offer_to_write_boot_floppies_to_physical_disks()
    3058 {
    3059     int res = 0;
    3060 
    3061     assert(bkpinfo != NULL);
    3062 
    3063     mvaddstr_and_log_it(g_currentY, 0,
    3064                         "Writing boot+data floppy images to disk");
    3065 
    3066     if (!bkpinfo->nonbootable_backup) {
    3067 #ifdef __FreeBSD__
    3068         if (!does_file_exist(MINDI_CACHE"/mindi-kern.1722.img"))
    3069 #else
    3070         if (!does_file_exist(MINDI_CACHE"/mindi-bootroot.1722.img") && !does_file_exist(MINDI_CACHE"/mindi-boot.1440.img"))
    3071 #endif
    3072         {
    3073             mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
    3074             if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
    3075                 popup_and_OK
    3076                     ("No regular Boot+data floppies were created due of space constraints. However, you can burn "MINDI_CACHE"/mondorescue.iso to a CD and boot from that.");
    3077                 res++;
    3078             }
    3079         } else {
    3080             offer_to_write_floppies(MINDI_CACHE);
    3081             mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    3082         }
    3083     } else {
    3084         popup_and_OK
    3085             ("Since you opted for a nonbootable backup, no boot floppies were created.");
    3086     }
    3087 
    3088     return (res);
    3089 }
    3090 
    3091 
    3092 
    3093 
    30942735/**
    30952736 * @addtogroup LLarchiveGroup
     
    41073748
    41083749
    4109 
    4110 
    4111 
    4112 /**
    4113  * @addtogroup utilityGroup
    4114  * @{
    4115  */
    4116 /**
    4117  * Write an image to a real 3.5" floppy disk.
    4118  * @param device The device to write to (e.g. @c /dev/fd0)
    4119  * @param datafile The image to write to @p device.
    4120  * @return The number of errors encountered (0 for success)
    4121  * @see write_image_to_floppy
    4122  */
    4123 int write_image_to_floppy_SUB(char *device, char *datafile)
    4124 {
    4125     /*@ int *************************************************************** */
    4126     int res = 0;
    4127     int percentage = 0;
    4128     int blockno = 0;
    4129     int maxblocks = 0;
    4130 
    4131     /*@ buffers************************************************************ */
    4132     char *tmp;
    4133     char blk[1024];
    4134     char *title;
    4135 
    4136     /*@ pointers ********************************************************** */
    4137     char *p;
    4138     FILE *fout, *fin;
    4139 
    4140 
    4141     malloc_string(tmp);
    4142     malloc_string(title);
    4143     /* pretty stuff */
    4144     if (!(p = strrchr(datafile, '/'))) {
    4145         p = datafile;
    4146     } else {
    4147         p++;
    4148     }
    4149     sprintf(title, "Writing %s to floppy", p);
    4150     open_evalcall_form(title);
    4151     /* functional stuff */
    4152     for (p = device + strlen(device); p != device && isdigit(*(p - 1));
    4153          p--);
    4154     maxblocks = atoi(p);
    4155     if (!maxblocks) {
    4156         maxblocks = 1440;
    4157     }
    4158     sprintf(tmp, "maxblocks = %d; p=%s", maxblocks, p);
    4159     log_msg(2, tmp);
    4160     /* copy data from image to floppy */
    4161     if (!(fin = fopen(datafile, "r"))) {
    4162         log_OS_error("Cannot open img");
    4163         return (1);
    4164     }
    4165     if (!(fout = fopen(device, "w"))) {
    4166         log_OS_error("Cannot open fdd");
    4167         return (1);
    4168     }
    4169     for (blockno = 0; blockno < maxblocks; blockno++) {
    4170         percentage = blockno * 100 / maxblocks;
    4171         if (fread(blk, 1, 1024, fin) != 1024) {
    4172             if (feof(fin)) {
    4173                 log_msg(1,
    4174                         "img read err - img ended prematurely - non-fatal error");
    4175                 sleep(3);
    4176                 return (res);
    4177             }
    4178             res++;
    4179             log_to_screen("img read err");
    4180         }
    4181         if (fwrite(blk, 1, 1024, fout) != 1024) {
    4182             res++;
    4183             log_to_screen("fdd write err");
    4184         }
    4185         if (((blockno + 1) % 128) == 0) {
    4186             paranoid_system("sync");    /* fflush doesn't work; dunno why */
    4187             update_evalcall_form(percentage);
    4188         }
    4189     }
    4190     paranoid_fclose(fin);
    4191     paranoid_fclose(fout);
    4192     paranoid_free(tmp);
    4193     paranoid_free(title);
    4194     close_evalcall_form();
    4195     return (res);
    4196 }
    4197 
    4198 
    4199 
    4200 
    4201 
    4202 
    4203 
    4204 
    4205 
    4206 /**
    4207  * Wrapper around @c write_image_to_floppy_SUB().
    4208  * This function, unlike @c write_image_to_floppy_SUB(),
    4209  * gives the user the opportunity to retry if the write fails.
    4210  * @see write_image_to_floppy_SUB
    4211  */
    4212 int write_image_to_floppy(char *device, char *datafile)
    4213 {
    4214     /*@ int ************************************************************** */
    4215     int res = 0;
    4216 
    4217     assert_string_is_neither_NULL_nor_zerolength(device);
    4218     assert_string_is_neither_NULL_nor_zerolength(datafile);
    4219 
    4220     while ((res = write_image_to_floppy_SUB(device, datafile))) {
    4221         if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
    4222             return (res);
    4223         }
    4224     }
    4225     return (res);
    4226 }
    4227 
    4228 /* @} - end of utilityGroup */
    4229 
    42303750void setenv_mondo_share(void) {
    42313751
Note: See TracChangeset for help on using the changeset viewer.