Changeset 3860 in MondoRescue


Ignore:
Timestamp:
Mar 7, 2024, 11:00:54 AM (3 months ago)
Author:
Bruno Cornec
Message:

Fix proto for write_header_block_to_stream

Location:
branches/3.3/mondo/src/common
Files:
4 edited

Legend:

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

    r3858 r3860  
    21592159        res = make_afioballs_and_images_OLD();
    21602160#endif
    2161         write_header_block_to_stream((off_t)0, "stop-afioballs",
    2162                                      BLK_STOP_AFIOBALLS);
     2161        write_header_block_to_stream((off_t)0, "stop-afioballs", BLK_STOP_AFIOBALLS);
    21632162    } else {
    21642163        res = make_afioballs_and_images();
     
    24232422        /* ask for new tape if necessary */
    24242423        length_of_incoming_file = length_of_file(curr_file);
    2425         write_header_block_to_stream(length_of_incoming_file, curr_file,
    2426                                      start_chr);
     2424        write_header_block_to_stream(length_of_incoming_file, curr_file, start_chr);
    24272425        res = write_file_to_stream_from_file(curr_file);
    24282426        retval += res;
  • branches/3.3/mondo/src/common/libmondo-stream-EXT.h

    r3857 r3860  
    3636extern int write_file_to_stream_from_file(
    3737                                          char *infile);
    38 extern int write_header_block_to_stream(off_t length_of_incoming_file,
    39                                         char *filename, int control_char);
     38extern int write_header_block_to_stream(off_t length_of_incoming_file, const char *filename, int control_char);
    4039extern void wrong_marker(int should_be, int it_is);
    4140extern int closein_cdstream();
  • branches/3.3/mondo/src/common/libmondo-stream.c

    r3857 r3860  
    9191{
    9292    return (closein_tape());
     93}
     94
     95/**
     96 * Write a header block to the opened stream (CD or tape).
     97 * @param length_of_incoming_file The length to store in the header block.
     98 * Usually matters only if this is a file-related header, in which case it should
     99 * be the length of the file that will follow.
     100 * @param filename The filename to store in the header block. Usually matters
     101 * only if this is a file-related header, in which case this should be the name
     102 * if the file that will follow.
     103 * @param control_char The type of header block this is (start-file, end-file, start-tape, ...)
     104 * @return 0 for success, nonzero for failure.
     105 */
     106int write_header_block_to_stream(off_t length_of_incoming_file, const char *filename, int control_char)
     107{
     108    /*@ buffers **************************************************** */
     109    char tempblock[TAPE_BLOCK_SIZE];
     110    char *p;
     111    char *tmp = NULL;
     112
     113    /*@ int ******************************************************** */
     114    int i;
     115
     116    off_t olen;
     117
     118    /*@ end vars *************************************************** */
     119
     120    olen = length_of_incoming_file;
     121    p = strrchr(filename, '/'); /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */
     122    if (!p) {
     123        p = filename;
     124    } else {
     125        p++;
     126    }
     127    if (!g_tape_stream) {
     128        log_to_screen("You're not backing up to tape. Why write a tape header?");
     129        return (1);
     130    }
     131    for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) {
     132        tempblock[i] = 0;
     133    }
     134    sprintf(tempblock + 6000 + control_char, STR_HEADER);
     135    tempblock[7000] = control_char;
     136    if (length_of_incoming_file > 0) {
     137        memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t));
     138    }
     139    strcpy(tempblock + 1000, filename);
     140    g_tape_posK += fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
     141    tmp = marker_to_string(control_char);
     142    log_msg(6, "%s (fname=%s, size=%ld K)", tmp, p, (long) length_of_incoming_file >> 10);
     143    mr_free(tmp);
     144    return (0);
    93145}
    94146
     
    418470    if (g_getfattr) {
    419471    // xattr
    420         write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
    421                              BLK_START_EXTENDED_ATTRIBUTES);
    422         write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
    423                              BLK_START_EXAT_FILE);
     472        write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_START_EXTENDED_ATTRIBUTES);
     473        write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_START_EXAT_FILE);
    424474        write_file_to_stream_from_file(xattr_fname);
    425475        write_header_block_to_stream((off_t)-1, xattr_fname, BLK_STOP_EXAT_FILE);
    426         write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
    427                              BLK_STOP_EXTENDED_ATTRIBUTES);
     476        write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_STOP_EXTENDED_ATTRIBUTES);
    428477    }
    429478    if (g_getfacl) {
    430479    // acl
    431         write_header_block_to_stream(length_of_file(acl_fname), acl_fname,
    432                              BLK_START_EXTENDED_ATTRIBUTES);
    433         write_header_block_to_stream(length_of_file(acl_fname), acl_fname,
    434                              BLK_START_EXAT_FILE);
     480        write_header_block_to_stream(length_of_file(acl_fname), acl_fname, BLK_START_EXTENDED_ATTRIBUTES);
     481        write_header_block_to_stream(length_of_file(acl_fname), acl_fname, BLK_START_EXAT_FILE);
    435482        write_file_to_stream_from_file(acl_fname);
    436483        write_header_block_to_stream((off_t)-1, acl_fname, BLK_STOP_EXAT_FILE);
    437         write_header_block_to_stream(length_of_file(acl_fname), acl_fname,
    438                              BLK_STOP_EXTENDED_ATTRIBUTES);
     484        write_header_block_to_stream(length_of_file(acl_fname), acl_fname, BLK_STOP_EXTENDED_ATTRIBUTES);
    439485    }
    440486    return (res);
     
    15191565            log_msg(6, "Can't write %s - it doesn't exist.", fname);
    15201566        } else {
    1521             write_header_block_to_stream(length_of_file(fname),
    1522                                          "start-backcatalog-afio-or-slice",
    1523                                          BLK_START_AN_AFIO_OR_SLICE);
     1567            write_header_block_to_stream(length_of_file(fname), "start-backcatalog-afio-or-slice", BLK_START_AN_AFIO_OR_SLICE);
    15241568            log_msg(2, "Writing %s", fname);
    15251569            if (write_file_to_stream_from_file(fname)) {
     
    15281572            }
    15291573            if (i != last) {
    1530                 write_header_block_to_stream((off_t)0,
    1531                                              "stop-backcatalog-afio-or-slice",
    1532                                              BLK_STOP_AN_AFIO_OR_SLICE);
     1574                write_header_block_to_stream((off_t)0, "stop-backcatalog-afio-or-slice", BLK_STOP_AN_AFIO_OR_SLICE);
    15331575            }
    15341576        }
     
    16511693    }
    16521694    filesize = length_of_file(infile);
    1653     if (should_we_write_to_next_tape
    1654         (bkpinfo->media_size, filesize)) {
     1695    if (should_we_write_to_next_tape(bkpinfo->media_size, filesize)) {
    16551696        start_to_write_to_next_tape();
    16561697        write_backcatalog_to_tape();
     
    16631704    }
    16641705    log_it("Writing file '%s' to tape (%ld KB)", p, (long) filesize >> 10);
    1665     write_header_block_to_stream(filesize, infile_basename,
    1666                                  BLK_START_FILE);
     1706    write_header_block_to_stream(filesize, infile_basename, BLK_START_FILE);
    16671707//go_here_to_restart_saving_of_file:
    16681708    if (!(fin = fopen(infile, "r"))) {
     
    17171757
    17181758
    1719 /**
    1720  * Write a header block to the opened stream (CD or tape).
    1721  * @param length_of_incoming_file The length to store in the header block.
    1722  * Usually matters only if this is a file-related header, in which case it should
    1723  * be the length of the file that will follow.
    1724  * @param filename The filename to store in the header block. Usually matters
    1725  * only if this is a file-related header, in which case this should be the name
    1726  * if the file that will follow.
    1727  * @param control_char The type of header block this is (start-file, end-file, start-tape, ...)
    1728  * @return 0 for success, nonzero for failure.
    1729  */
    1730 int
    1731 write_header_block_to_stream(off_t length_of_incoming_file,
    1732                              char *filename, int control_char)
    1733 {
    1734     /*@ buffers **************************************************** */
    1735     char tempblock[TAPE_BLOCK_SIZE];
    1736     char *p;
    1737     char *tmp = NULL;
    1738 
    1739     /*@ int ******************************************************** */
    1740     int i;
    1741 
    1742     off_t olen;
    1743 
    1744     /*@ end vars *************************************************** */
    1745 
    1746     olen = length_of_incoming_file;
    1747     p = strrchr(filename, '/'); /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */
    1748     if (!p) {
    1749         p = filename;
    1750     } else {
    1751         p++;
    1752     }
    1753     if (!g_tape_stream) {
    1754         log_to_screen("You're not backing up to tape. Why write a tape header?");
    1755         return (1);
    1756     }
    1757     for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) {
    1758         tempblock[i] = 0;
    1759     }
    1760     sprintf(tempblock + 6000 + control_char, STR_HEADER);
    1761     tempblock[7000] = control_char;
    1762     if (length_of_incoming_file > 0) {
    1763         memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t));
    1764     }
    1765     strcpy(tempblock + 1000, filename);
    1766     g_tape_posK += fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
    1767     tmp = marker_to_string(control_char);
    1768     log_msg(6, "%s (fname=%s, size=%ld K)", tmp, p, (long) length_of_incoming_file >> 10);
    1769     mr_free(tmp);
    1770     return (0);
    1771 }
    1772 
    1773 
    1774 
    17751759
    17761760
  • branches/3.3/mondo/src/common/libmondo-stream.h

    r3857 r3860  
    3535int write_file_to_stream_from_file(
    3636                                   char *infile);
    37 int write_header_block_to_stream(off_t length_of_incoming_file,
    38                                  char *filename, int control_char);
    3937void wrong_marker(int should_be, int it_is);
    4038int closein_cdstream();
Note: See TracChangeset for help on using the changeset viewer.