Ignore:
Timestamp:
Mar 8, 2024, 12:15:10 PM (4 months ago)
Author:
Bruno Cornec
Message:

Fix compiler errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mondo/src/common/libmondo-devices.c

    r3877 r3878  
    5555extern char *call_program_and_get_last_line_of_output(const char *);
    5656
    57 static char g_cd_drive_is_here[MAX_STR_LEN / 4] = "";
    58 static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = "";
    59 static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = "";
    60 
    61 
    6257/**
    6358 * ????? @bug ?????
     
    8479
    8580
    86 void set_g_cdrom_and_g_dvd_to_bkpinfo_value()
    87 {
    88     strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
    89     strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
    90 }
    91 
    92 
    93 
    9481/**
    9582 * Retract all CD trays and wait for autorun to complete.
     
    9885void retract_CD_tray_and_defeat_autorun(void)
    9986{
    100 //  log_it("rctada: Retracting all CD trays", __LINE__);
     87//  log_it("rctada: Retracting optical tray", __LINE__);
    10188    if (!bkpinfo->please_dont_eject) {
    102         if (strlen(g_cdrom_drive_is_here) > 0) {
    103             inject_device(g_cdrom_drive_is_here);
    104         }
    105         if (strlen(g_dvd_drive_is_here) > 0) {
    106             inject_device(g_dvd_drive_is_here);
    107         }
    108     }
    109 //  log_it("rctada: killing autorun");
    110 //  run_program_and_log_output("killall autorun", TRUE);
     89        if (bkpinfo->media_device != NULL) {
     90            inject_device(bkpinfo->media_device);
     91    }
    11192    if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) {
    11293        log_it("autorun detected; sleeping for 2 seconds");
    11394        sleep(2);
    11495    }
    115     log_it("rctada: Unmounting all CD drives", __LINE__);
    116     run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
     96}
     97
     98
     99
     100/**
     101 * Find out what device is mounted as root (/).
     102 * @return Root device.
     103 * @note The returned string points to storage that needs to be freed by
     104 * caller
     105 * @bug A bit of a misnomer; it's actually finding out the root device.
     106 * The mountpoint (where it's mounted) will obviously be '/'.
     107 */
     108char *where_is_root_mounted(void) {
     109
     110/*@ buffers **************** */
     111char *tmp = NULL;
     112
     113#ifdef __FreeBSD__
     114    tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
     115#else
     116    tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
     117    if (strstr(tmp, "/dev/cciss/")) {
     118        mr_free(tmp);
     119        tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
     120    }
     121    if (strstr(tmp, "/dev/md")) {
     122        mr_free(tmp);
     123        tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
     124    }
     125#endif
     126
     127return (tmp);
    117128}
    118129
     
    447458
    448459
    449 /**
    450  * Try to mount CD/DVD at @p mountpoint. If the CD/DVD is not found or has
    451  * not been specified, call find_optical_device() to find it.
    452  * @param mountpoint Where to mount the CD-ROM.
    453  * @return TRUE for success, FALSE for failure.
    454  * @see mount_media
    455  */
    456 bool find_and_mount_actual_cd(char *mountpoint) {
    457 
    458     /*@ buffers ***************************************************** */
    459 
    460     /*@ int's  ****************************************************** */
    461     bool res;
    462 
    463     /*@ end vars **************************************************** */
    464 
    465     assert(bkpinfo != NULL);
    466     assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    467 
    468     if (bkpinfo->media_device == NULL) {
    469         bkpinfo->media_device = find_optical_device();
    470     }
    471 
    472     if (bkpinfo->backup_media_type != iso) {
    473         retract_CD_tray_and_defeat_autorun();
    474     }
    475 
    476     if ((bkpinfo->media_device == NULL) || (res = mount_media(mountpoint))) {
    477         mr_free(bkpinfo->media_device);
    478         if ((bkpinfo->media_device = mr_popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", "/dev/cdrom")) == NULL) {
    479             res = TRUE;
    480         } else {
    481             res = mount_media(mountpoint);
    482         }
    483     }
    484     if (res) {
    485         log_msg(1, "mount failed");
    486     } else {
    487         log_msg(1, "mount succeeded with %s", bkpinfo->media_device);
    488     }
    489     return (res);
    490 }
    491 /*
    492  * This function tries to find a USB media device
    493  * and return it's device file to the caller that needs to free it
    494  */
    495 char *find_usb_device(void)
    496 {
    497     char *dev = NULL;
    498     char *tmp1 = NULL;
    499     char *command = NULL;
    500 
    501     log_to_screen("I am looking for your USB key. Please wait.");
    502 
    503     if (bkpinfo->media_device != NULL) {
    504         log_msg(3, "Been there, done that. Returning %s", bkpinfo->media_device);
    505         return (bkpinfo->media_device);
    506     }
    507 
    508     tmp1 = find_home_of_exe("lsscsi");
    509     if (tmp1 != NULL) {
    510         mr_asprintf(command, "%s | grep ' disk' | grep USB | awk '{print $NF}' | head -1", tmp1);
    511         dev = call_program_and_get_last_line_of_output(command);
    512         mr_free(command);
    513     }
    514     mr_free(tmp1);
    515 
    516     if ((dev == NULL) || !does_file_exist(dev)) {
    517         tmp1 = find_home_of_exe("lsblk");
    518         if (tmp1 != NULL) {
    519             mr_asprintf(command, "%s --noheadings --raw --output rm,tran,type,path --sort path | awk '/^1 usb disk/ {d=$4} END {print d}'", tmp1);
    520             dev = call_program_and_get_last_line_of_output(command);
    521             mr_free(command);
    522         }
    523         mr_free(tmp1);
    524         log_it("Unable to find a tape device on this system");
    525     }
    526     if (dev != NULL) {
    527         log_it("find_usb_device found %s manually", dev);
    528     }
    529 
    530     if ((dev != NULL) && does_file_exist(dev)) {
    531         log_it("find_usb_device returns %s", dev);
    532     } else {
    533         mr_free(dev);
    534         log_it("find_usb_device found no USB key on your system returning NULL");
    535     }
    536     return(dev);
    537 }
    538 
    539 
    540460/*
    541461 * This function tries to find an optical media device
    542462 * and return it's device file to the caller that needs to free it
    543463 */
    544 char *find_optical_device(void)
    545 {
     464char *find_optical_device(void) {
    546465    char *dev = NULL;
    547466    char *tmp1 = NULL;
     
    582501                        if (!does_file_exist(dev)) {
    583502                            log_it("Unable to find a tape device on this system");
     503                        }
     504                    }
    584505                }
    585506            }
     
    598519    return(dev);
    599520}
     521/**
     522* Mount the CD-ROM or USB device at /mnt/cdrom.
     523* @param bkpinfo The backup information structure. Fields used:
     524* - @c bkpinfo->backup_media_type
     525* - @c bkpinfo->disaster_recovery
     526* - @c bkpinfo->isodir
     527* - @c bkpinfo->media_device
     528* @return TRUE for success, FALSE for failure.
     529*/
     530bool mount_media(const char *mountpoint) {
     531
     532    char *mount_cmd = NULL;
     533    char *mountdir = NULL;
     534    char *tmp = NULL;
     535    int i = 0, res = 0;
     536#ifdef __FreeBSD__
     537    char mdd[32];
     538    char *mddev = mdd;
     539    char *dev;
     540#endif
     541
     542    if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
     543        log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
     544        return(TRUE);
     545    }
     546
     547    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     548
     549    mr_asprintf(tmp, "mount | grep -F %s", mountpoint);
     550    if (!run_program_and_log_output(tmp, FALSE)) {
     551        log_msg(2, "mount_media() - media already mounted. Fair enough.");
     552        mr_free(tmp);
     553        return (TRUE);
     554    }
     555    mr_free(tmp);
     556
     557    make_hole_for_dir(mountpoint);
     558
     559    if (bkpinfo->backup_media_type == netfs) {
     560        log_msg(2, "Mounting for Network thingy");
     561        log_msg(2, "isodir = %s", bkpinfo->isodir);
     562        if (((bkpinfo->isodir == NULL) || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) {
     563            mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
     564            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
     565        }
     566#ifdef __FreeBSD__
     567        if (bkpinfo->netfs_remote_dir != NULL) {
     568            // NETFS
     569            mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
     570        } else {
     571            // ISO
     572            mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
     573        }
     574        mddev = make_vn(mount_cmd);
     575        mr_free(mount_cmd);
     576
     577        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint);
     578#else
     579        if (bkpinfo->netfs_remote_dir != NULL) {
     580            // NETFS
     581            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);
     582        } else {
     583            // ISO
     584            mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, mountpoint);
     585        }
     586#endif
     587
     588    } else if (bkpinfo->backup_media_type == iso) {
     589        if (bkpinfo->subdir) {
     590            mr_asprintf(mountdir, "%s/%s", bkpinfo->isodir, bkpinfo->subdir);
     591        } else {
     592            mr_asprintf(mountdir, "%s", bkpinfo->isodir);
     593        }
     594#ifdef __FreeBSD__
     595        mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number);
     596        mddev = make_vn(mount_cmd);
     597        mr_free(mount_cmd);
     598
     599        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint);
     600#else
     601        mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, mountpoint);
     602#endif
     603        mr_free(mountdir);
     604    } else if (bkpinfo->backup_media_type == usb) {
     605        mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, mountpoint);
     606    } else {    //  optical
     607        if (bkpinfo->disaster_recovery
     608            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     609            mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     610        } else {
     611            if (bkpinfo->media_device == NULL) {
     612                bkpinfo->media_device = find_optical_device();
     613            }
     614        }
     615
     616#ifdef __FreeBSD__
     617        if (g_ISO_restore_mode) {
     618            mr_asprintf(dev, "%s", make_vn(bkpinfo->media_device));
     619            if (!dev) {
     620                mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", bkpinfo->media_device);
     621                fatal_error(command);
     622            }
     623            mr_free(bkpinfo->media_device);
     624            bkpinfo->media_device = dev
     625        }
     626
     627        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE);
     628#else
     629        mr_asprintf(mount_cmd, "mount %s -o loop,ro -t iso9660 %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE);
     630#endif
     631        log_msg(2, "(mount_media) --- command = %s", mount_cmd);
     632        // usefull ??
     633        if (strncmp(bkpinfo->media_device, "/dev/", 5) == 0) {
     634            retract_CD_tray_and_defeat_autorun();
     635        }
     636    }
     637
     638    for (i = 0; i < 2; i++) {
     639        res = run_program_and_log_output(mount_cmd, FALSE);
     640        if (!res) {
     641            break;
     642        } else {
     643            log_msg(2, "Failed to mount device.");
     644            sleep(5);
     645            sync();
     646        }
     647    }
     648    mr_free(mount_cmd);
     649
     650    if (res) {
     651        log_msg(2, "Failed, despite %d attempts", i);
     652        return(FALSE);
     653    } else {
     654        log_msg(2, "Mounted media drive OK");
     655        return(TRUE);
     656    }
     657}
     658/**************************************************************************
     659*END_MOUNT_MEDIA                                                         *
     660**************************************************************************/
     661
     662
     663
     664
     665/**
     666 * Try to mount CD/DVD at @p mountpoint. If the CD/DVD is not found or has
     667 * not been specified, call find_optical_device() to find it.
     668 * @param mountpoint Where to mount the CD-ROM.
     669 * @return TRUE for success, FALSE for failure.
     670 * @see mount_media
     671 */
     672bool find_and_mount_actual_cd(char *mountpoint) {
     673
     674    /*@ buffers ***************************************************** */
     675
     676    /*@ int's  ****************************************************** */
     677    bool res;
     678
     679    /*@ end vars **************************************************** */
     680
     681    assert(bkpinfo != NULL);
     682    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     683
     684    if (bkpinfo->media_device == NULL) {
     685        bkpinfo->media_device = find_optical_device();
     686    }
     687
     688    if (bkpinfo->backup_media_type != iso) {
     689        retract_CD_tray_and_defeat_autorun();
     690    }
     691
     692    if ((bkpinfo->media_device == NULL) || (res = mount_media(mountpoint))) {
     693        mr_free(bkpinfo->media_device);
     694        if ((bkpinfo->media_device = mr_popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", "/dev/cdrom")) == NULL) {
     695            res = TRUE;
     696        } else {
     697            res = mount_media(mountpoint);
     698        }
     699    }
     700    if (res) {
     701        log_msg(1, "mount failed");
     702    } else {
     703        log_msg(1, "mount succeeded with %s", bkpinfo->media_device);
     704    }
     705    return (res);
     706}
     707/*
     708 * This function tries to find a USB media device
     709 * and return it's device file to the caller that needs to free it
     710 */
     711char *find_usb_device(void)
     712{
     713    char *dev = NULL;
     714    char *tmp1 = NULL;
     715    char *command = NULL;
     716
     717    log_to_screen("I am looking for your USB key. Please wait.");
     718
     719    if (bkpinfo->media_device != NULL) {
     720        log_msg(3, "Been there, done that. Returning %s", bkpinfo->media_device);
     721        return (bkpinfo->media_device);
     722    }
     723
     724    tmp1 = find_home_of_exe("lsscsi");
     725    if (tmp1 != NULL) {
     726        mr_asprintf(command, "%s | grep ' disk' | grep USB | awk '{print $NF}' | head -1", tmp1);
     727        dev = call_program_and_get_last_line_of_output(command);
     728        mr_free(command);
     729    }
     730    mr_free(tmp1);
     731
     732    if ((dev == NULL) || !does_file_exist(dev)) {
     733        tmp1 = find_home_of_exe("lsblk");
     734        if (tmp1 != NULL) {
     735            mr_asprintf(command, "%s --noheadings --raw --output rm,tran,type,path --sort path | awk '/^1 usb disk/ {d=$4} END {print d}'", tmp1);
     736            dev = call_program_and_get_last_line_of_output(command);
     737            mr_free(command);
     738        }
     739        mr_free(tmp1);
     740        log_it("Unable to find a tape device on this system");
     741    }
     742    if (dev != NULL) {
     743        log_it("find_usb_device found %s manually", dev);
     744    }
     745
     746    if ((dev != NULL) && does_file_exist(dev)) {
     747        log_it("find_usb_device returns %s", dev);
     748    } else {
     749        mr_free(dev);
     750        log_it("find_usb_device found no USB key on your system returning NULL");
     751    }
     752    return(dev);
     753}
     754
     755
    600756
    601757/* Generic fund to find a media
     
    9711127
    9721128/**
    973 * Mount the CD-ROM or USB device at /mnt/cdrom.
    974 * @param bkpinfo The backup information structure. Fields used:
    975 * - @c bkpinfo->backup_media_type
    976 * - @c bkpinfo->disaster_recovery
    977 * - @c bkpinfo->isodir
    978 * - @c bkpinfo->media_device
    979 * @return TRUE for success, FALSE for failure.
    980 */
    981 bool mount_media(const char *mountpoint) {
    982 
    983     char *mount_cmd = NULL;
    984     char *mountdir = NULL;
     1129 * Find out what number CD is in the drive.
     1130 * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used.
     1131 * @return The current CD number, or -1 if it could not be found.
     1132 * @note If the CD is not mounted, it will be mounted
     1133 * (and remain mounted after this function returns).
     1134 */
     1135int what_number_cd_is_this(void) {
     1136
     1137    int cd_number = -1;
     1138    char *mountdev = NULL;
    9851139    char *tmp = NULL;
    986     int i = 0, res = 0;
    987 #ifdef __FreeBSD__
    988     char mdd[32];
    989     char *mddev = mdd;
    990     char *dev;
    991 #endif
    992 
    993     if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
    994         log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
    995         return(TRUE);
    996     }
    997 
    998     assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    999 
    1000     mr_asprintf(tmp, "mount | grep -F %s", mountpoint);
    1001     if (!run_program_and_log_output(tmp, FALSE)) {
    1002         log_msg(2, "mount_media() - media already mounted. Fair enough.");
     1140
     1141    assert(bkpinfo != NULL);
     1142//  log_it("Asking what_number_cd_is_this");
     1143    if ((g_ISO_restore_mode) || (g_restoring_live_from_cd)) {
     1144        tmp = call_program_and_get_last_line_of_output("mount | grep iso9660 | awk '{print $3;}'");
     1145        mr_asprintf(mountdev, "%s%s", tmp, "/archives/THIS-CD-NUMBER");
    10031146        mr_free(tmp);
    1004         return (TRUE);
    1005     }
    1006     mr_free(tmp);
    1007 
    1008     make_hole_for_dir(mountpoint);
    1009 
    1010     if (bkpinfo->backup_media_type == netfs) {
    1011         log_msg(2, "Mounting for Network thingy");
    1012         log_msg(2, "isodir = %s", bkpinfo->isodir);
    1013         if (((bkpinfo->isodir == NULL) || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) {
    1014             mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
    1015             log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    1016         }
    1017 #ifdef __FreeBSD__
    1018         if (bkpinfo->netfs_remote_dir != NULL) {
    1019             // NETFS
    1020             mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
    1021         } else {
    1022             // ISO
    1023             mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
    1024         }
    1025         mddev = make_vn(mount_cmd);
    1026         mr_free(mount_cmd);
    1027 
    1028         mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint);
    1029 #else
    1030         if (bkpinfo->netfs_remote_dir != NULL) {
    1031             // NETFS
    1032             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);
    1033         } else {
    1034             // ISO
    1035             mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, mountpoint);
    1036         }
    1037 #endif
    1038 
    1039     } else if (bkpinfo->backup_media_type == iso) {
    1040         if (bkpinfo->subdir) {
    1041             mr_asprintf(mountdir, "%s/%s", bkpinfo->isodir, bkpinfo->subdir);
    1042         } else {
    1043             mr_asprintf(mountdir, "%s", bkpinfo->isodir);
    1044         }
    1045 #ifdef __FreeBSD__
    1046         mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number);
    1047         mddev = make_vn(mount_cmd);
    1048         mr_free(mount_cmd);
    1049 
    1050         mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint);
    1051 #else
    1052         mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, mountpoint);
    1053 #endif
    1054         mr_free(mountdir);
    1055     } else if (bkpinfo->backup_media_type == usb) {
    1056         mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, mountpoint);
    1057     } else {    //  optical
    1058         if (bkpinfo->disaster_recovery
    1059             && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    1060             mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    1061         } else {
    1062             if (bkpinfo->media_device == NULL) {
    1063                 bkpinfo->media_device = find_optical_device();
    1064             }
    1065         }
    1066 
    1067 #ifdef __FreeBSD__
    1068         if (g_ISO_restore_mode) {
    1069             mr_asprintf(dev, "%s", make_vn(bkpinfo->media_device));
    1070             if (!dev) {
    1071                 mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", bkpinfo->media_device);
    1072                 fatal_error(command);
    1073             }
    1074             mr_free(bkpinfo->media_device);
    1075             bkpinfo->media_device = dev
    1076         }
    1077 
    1078         mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE);
    1079 #else
    1080         mr_asprintf(mount_cmd, "mount %s -o loop,ro -t iso9660 %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE);
    1081 #endif
    1082         log_msg(2, "(mount_media) --- command = %s", mount_cmd);
    1083         // usefull ??
    1084         if (strncmp(device, "/dev/", 5) == 0) {
    1085             retract_CD_tray_and_defeat_autorun();
    1086         }
    1087     }
    1088 
    1089     for (i = 0; i < 2; i++) {
    1090         res = run_program_and_log_output(mount_cmd, FALSE);
    1091         if (!res) {
    1092             break;
    1093         } else {
    1094             log_msg(2, "Failed to mount device.");
    1095             sleep(5);
    1096             sync();
    1097         }
    1098     }
    1099     mr_free(mount_cmd);
    1100 
    1101     if (res) {
    1102         log_msg(2, "Failed, despite %d attempts", i);
    1103         return(FALSE);
    1104     } else {
    1105         log_msg(2, "Mounted media drive OK");
    1106         return(TRUE);
    1107     }
    1108 }
    1109 /**************************************************************************
    1110 *END_MOUNT_MEDIA                                                         *
    1111 **************************************************************************/
     1147        cd_number = atoi(last_line_of_file(mountdev));
     1148        mr_free(mountdev);
     1149        return (cd_number);
     1150    }
     1151
     1152    if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) {
     1153        log_it("ERROR: bkpinfo->media_device shoulnd't be unaccessible here\n");
     1154        /* trying again ! */
     1155        bkpinfo->media_device = find_optical_device();
     1156    }
     1157    if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) {
     1158        fatal_error("ERROR: bkpinfo->media_device shoulnd't really be unaccessible here\n");
     1159    }
     1160    if (!is_this_device_mounted(MNT_CDROM)) {
     1161        mount_media(MNT_CDROM);
     1162    }
     1163
     1164    cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
     1165    return(cd_number);
     1166}
    11121167
    11131168
     
    20002055
    20012056/**
     2057 * Get a |-separated list of NETFS mounts.
     2058 * @return The list created.
     2059 * @note The return value points to allocated string that needs to be freed by
     2060 * caller
     2061 * @bug Even though we only want the mounts, the devices are still checked.
     2062 */
     2063char *list_of_NETFS_mounts_only(void)
     2064{
     2065    char *exclude_these_directories = NULL;
     2066
     2067    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;}'");
     2068    log_msg(9,"list_of_NETFS_mounts_only returns %s",exclude_these_directories);
     2069    return(exclude_these_directories);
     2070}
     2071
     2072/* @} - end of utilityGroup */
     2073
     2074
     2075/**
    20022076 * Ask user for details of backup/restore information.
    20032077 * Called when @c mondoarchive doesn't get any parameters.
     
    27172791
    27182792
    2719 /**
    2720  * Get a |-separated list of NETFS mounts.
    2721  * @return The list created.
    2722  * @note The return value points to allocated string that needs to be freed by
    2723  * caller
    2724  * @bug Even though we only want the mounts, the devices are still checked.
    2725  */
    2726 char *list_of_NETFS_mounts_only(void)
    2727 {
    2728     char *exclude_these_directories = NULL;
    2729 
    2730     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;}'");
    2731     log_msg(9,"list_of_NETFS_mounts_only returns %s",exclude_these_directories);
    2732     return(exclude_these_directories);
    2733 }
    2734 
    2735 /* @} - end of utilityGroup */
    2736 
    2737 
    27382793
    27392794
     
    28042859    return(ret);
    28052860}
    2806 
    2807 
    2808 
    2809 
    2810 
    2811 /**
    2812  * Find out what number CD is in the drive.
    2813  * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used.
    2814  * @return The current CD number, or -1 if it could not be found.
    2815  * @note If the CD is not mounted, it will be mounted
    2816  * (and remain mounted after this function returns).
    2817  */
    2818 int what_number_cd_is_this(void) {
    2819 
    2820     int cd_number = -1;
    2821     char *mountdev = NULL;
    2822     char *tmp = NULL;
    2823 
    2824     assert(bkpinfo != NULL);
    2825 //  log_it("Asking what_number_cd_is_this");
    2826     if ((g_ISO_restore_mode) || (g_restoring_live_from_cd)) {
    2827         tmp = call_program_and_get_last_line_of_output("mount | grep iso9660 | awk '{print $3;}'");
    2828         mr_asprintf(mountdev, "%s%s", tmp, "/archives/THIS-CD-NUMBER");
    2829         mr_free(tmp);
    2830         cd_number = atoi(last_line_of_file(mountdev));
    2831         mr_free(mountdev);
    2832         return (cd_number);
    2833     }
    2834 
    2835     if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) {
    2836         log_it("ERROR: bkpinfo->media_device shoulnd't be unaccessible here\n");
    2837         /* trying again ! */
    2838         bkpinfo->media_device = find_optical_device();
    2839     }
    2840     if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) {
    2841         fatal_error("ERROR: bkpinfo->media_device shoulnd't really be unaccessible here\n");
    2842     }
    2843     if (!is_this_device_mounted(bkpinfo->media_device, MNT_CDROM)) {
    2844         mount_media(MNT_CDROM);
    2845     }
    2846 
    2847     cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    2848     return(cd_number);
    2849 }
    2850 
    2851 
    2852 /**
    2853  * Find out what device is mounted as root (/).
    2854  * @return Root device.
    2855  * @note The returned string points to storage that needs to be freed by
    2856  * caller
    2857  * @bug A bit of a misnomer; it's actually finding out the root device.
    2858  * The mountpoint (where it's mounted) will obviously be '/'.
    2859  */
    2860 char *where_is_root_mounted(void) {
    2861 
    2862 /*@ buffers **************** */
    2863 char *tmp = NULL;
    2864 
    2865 #ifdef __FreeBSD__
    2866     tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
    2867 #else
    2868     tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
    2869     if (strstr(tmp, "/dev/cciss/")) {
    2870         mr_free(tmp);
    2871         tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
    2872     }
    2873     if (strstr(tmp, "/dev/md")) {
    2874         mr_free(tmp);
    2875         tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
    2876     }
    2877 #endif
    2878 
    2879 return (tmp);
    2880 }
    2881 
    28822861
    28832862
Note: See TracChangeset for help on using the changeset viewer.