Ignore:
Timestamp:
Oct 20, 2007, 8:07:36 PM (17 years ago)
Author:
Bruno Cornec
Message:

Try to add USB support for mondoarchive with new functions

File:
1 edited

Legend:

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

    r1687 r1688  
    18441844}
    18451845
     1846
     1847
     1848
     1849/**
     1850 * Create a USB image in @c destfile, from files in @c bkpinfo->scratchdir.
     1851 *
     1852 * @param bkpinfo The backup information structure. Fields used:
     1853 * - @c backup_media_type
     1854 * - @c nonbootable_backup
     1855 * - @c scratchdir
     1856 *
     1857 * @param destfile Where to put the generated USB image.
     1858 * @return The number of errors encountered (0 for success)
     1859 */
     1860int make_usb_fs(char *destfile)
     1861{
     1862    /*@ int ********************************************** */
     1863    int retval = 0;
     1864    int res;
     1865
     1866    /*@ buffers ****************************************** */
     1867    char *tmp = NULL;
     1868    char *tmp1 = NULL;
     1869    char *message_to_screen = NULL;
     1870    char *old_pwd;
     1871
     1872    malloc_string(old_pwd);
     1873    assert(bkpinfo != NULL);
     1874    assert_string_is_neither_NULL_nor_zerolength(destfile);
     1875
     1876    log_msg(2, "make_usb_fs --- scratchdir=%s --- destfile=%s",
     1877            bkpinfo->scratchdir, destfile);
     1878    (void) getcwd(old_pwd, MAX_STR_LEN - 1);
     1879    asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir);
     1880    run_program_and_log_output(tmp, FALSE);
     1881    paranoid_free(tmp);
     1882    chdir(bkpinfo->scratchdir);
     1883
     1884    asprintf(&message_to_screen, "Copying data to make %s #%d",
     1885                media_descriptor_string(bkpinfo->backup_media_type),
     1886                g_current_media_number);
     1887    log_msg(1, message_to_screen);
     1888
     1889    if (is_this_device_mounted(bkpinfo->media_device)) {
     1890        log_msg(1, "USB device mounted. Remounting it at the right place");
     1891        asprintf(&tmp, "umount %s", bkpinfo->media_device);
     1892        run_program_and_log_output(tmp, FALSE);
     1893        paranoid_free(tmp);
     1894    }
     1895    log_msg(1, "Mounting USB device.");
     1896    asprintf(&tmp1, "%s/usb", bkpinfo->tmpdir);
     1897    asprintf(&tmp, "mkdir -p %s", tmp1);
     1898    run_program_and_log_output(tmp, FALSE);
     1899    paranoid_free(tmp);
     1900    asprintf(&tmp, "mount %s %s", bkpinfo->media_device, tmp1);
     1901    run_program_and_log_output(tmp, FALSE);
     1902    paranoid_free(tmp);
     1903    paranoid_free(tmp1);
     1904
     1905    if (bkpinfo->nonbootable_backup) {
     1906        log_msg(1, "Making nonbootable USB backup not implemented yet");
     1907    } else {
     1908        log_msg(1, "Making bootable backup");
     1909
     1910        asprintf(&tmp,"cp -rp %s/* %s", bkpinfo->scratchdir, ); /* Command to execute */
     1911        res = eval_call_to_make_USB(tmp, message_to_screen);
     1912        if (res) {
     1913            asprintf(&result_sz, "%s ...failed",tmp);
     1914        } else {
     1915            asprintf(&result_sz, "%s ...OK",tmp);
     1916        }
     1917        log_to_screen(result_sz);
     1918        paranoid_free(result_sz);
     1919        paranoid_free(tmp);
     1920        retval += res;
     1921    }
     1922    paranoid_free(message_to_screen);
     1923
     1924    if (is_this_device_mounted(bkpinfo->media_device)) {
     1925        asprintf(&tmp, "umount %s", bkpinfo->media_device);
     1926        run_program_and_log_output(tmp, FALSE);
     1927        paranoid_free(tmp);
     1928    }
     1929
     1930    chdir(old_pwd);
     1931    if (retval) {
     1932        log_msg(1, "WARNING - make_usb_fs returned an error");
     1933    }
     1934    paranoid_free(old_pwd);
     1935    return (retval);
     1936}
    18461937
    18471938
     
    38433934            g_current_media_number);
    38443935    for (that_one_was_ok = FALSE; !that_one_was_ok;) {
    3845         res = make_iso_fs(isofile);
     3936        if (bkpinfo->backup_media_type != usb) {
     3937            res = make_iso_fs(isofile);
     3938        } else {
     3939            res = make_usb_fs(isofile);
     3940        }
    38463941        if (g_current_media_number == 1 && !res
    38473942            && (bkpinfo->backup_media_type == cdr
Note: See TracChangeset for help on using the changeset viewer.