Date: Sun, 14 Jul 2013 10:31:55 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254779 - soc2013/dpl/head/contrib/xz/src/xz Message-ID: <201307141031.r6EAVt1H038284@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Sun Jul 14 10:31:54 2013 New Revision: 254779 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254779 Log: Open all the files before working with them, and limit them in the process. We call cap_init() before working with any file. Modified: soc2013/dpl/head/contrib/xz/src/xz/coder.c soc2013/dpl/head/contrib/xz/src/xz/coder.h soc2013/dpl/head/contrib/xz/src/xz/file_io.c soc2013/dpl/head/contrib/xz/src/xz/file_io.h Modified: soc2013/dpl/head/contrib/xz/src/xz/coder.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/coder.c Sun Jul 14 10:29:55 2013 (r254778) +++ soc2013/dpl/head/contrib/xz/src/xz/coder.c Sun Jul 14 10:31:54 2013 (r254779) @@ -609,59 +609,52 @@ extern void -coder_run(const char *filename) +coder_run(file_pair pairs[], int files) { - // Set and possibly print the filename for the progress message. - message_filename(filename); + int i; - // Try to open the input file. - file_pair *pair = io_open_src(filename); - if (pair == NULL) - return; - - // Assume that something goes wrong. - bool success = false; - - // Read the first chunk of input data. This is needed to detect - // the input file type (for now, only for decompression). - strm.next_in = in_buf.u8; - strm.avail_in = io_read(pair, &in_buf, IO_BUFFER_SIZE); - - if (strm.avail_in != SIZE_MAX) { - // Initialize the coder. This will detect the file format - // and, in decompression or testing mode, check the memory - // usage of the first Block too. This way we don't try to - // open the destination file if we see that coding wouldn't - // work at all anyway. This also avoids deleting the old - // "target" file if --force was used. - const enum coder_init_ret init_ret = coder_init(pair); - - if (init_ret != CODER_INIT_ERROR && !user_abort) { - // Don't open the destination file when --test - // is used. - if (opt_mode == MODE_TEST || !io_open_dest(pair)) { + for( i=0; i < files; i++) { + // Set and possibly print the filename for the progress message. + message_filename(pairs[i].src_name); + + // Assume that something goes wrong. + bool success = false; + + // Read the first chunk of input data. This is needed to detect + // the input file type (for now, only for decompression). + strm.next_in = in_buf.u8; + strm.avail_in = io_read(&pairs[i], &in_buf, IO_BUFFER_SIZE); + + if (strm.avail_in != SIZE_MAX) { + // Initialize the coder. This will detect the file format + // and, in decompression or testing mode, check the memory + // usage of the first Block too. This way we don't try to + // open the destination file if we see that coding wouldn't + // work at all anyway. This also avoids deleting the old + // "target" file if --force was used. + const enum coder_init_ret init_ret = coder_init(&pairs[i]); + + if (init_ret != CODER_INIT_ERROR && !user_abort) { // Initialize the progress indicator. const uint64_t in_size - = pair->src_st.st_size <= 0 - ? 0 : pair->src_st.st_size; + = pairs[i].src_st.st_size <= 0 + ? 0 : pairs[i].src_st.st_size; message_progress_start(&strm, in_size); // Do the actual coding or passthru. if (init_ret == CODER_INIT_NORMAL) - success = coder_normal(pair); + success = coder_normal(&pairs[i]); else - success = coder_passthru(pair); + success = coder_passthru(&pairs[i]); message_progress_end(success); } } + + // Close the file pair. It needs to know if coding was successful to + // know if the source or target file should be unlinked. + io_close(&pairs[i], success); } - // Close the file pair. It needs to know if coding was successful to - // know if the source or target file should be unlinked. - io_close(pair, success); - return; - - } Modified: soc2013/dpl/head/contrib/xz/src/xz/coder.h ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/coder.h Sun Jul 14 10:29:55 2013 (r254778) +++ soc2013/dpl/head/contrib/xz/src/xz/coder.h Sun Jul 14 10:31:54 2013 (r254779) @@ -58,4 +58,4 @@ extern void coder_set_compression_settings(void); /// Compress or decompress the given file -extern void coder_run(const char *filename); +extern void coder_run(file_pair *pairs[], int files); Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.c Sun Jul 14 10:29:55 2013 (r254778) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.c Sun Jul 14 10:31:54 2013 (r254779) @@ -527,6 +527,15 @@ .dest_pending_sparse = 0, }; +/* pair = (file_pair *)malloc(sizeof(file_pair);*/ +/* pair.src_name = src_name;*/ +/* pair.dest_name = NULL;*/ +/* pair.src_fd = -1;*/ +/* pair.dest_fd = -1;*/ +/* pair.src_eof = false;*/ +/* pair.dest_try_sparse = false;*/ +/* pair.dest_pending_sparse = 0;*/ + // Block the signals, for which we have a custom signal handler, so // that we don't need to worry about EINTR. signals_block(); @@ -956,10 +965,58 @@ return io_write_buf(pair, buf->u8, size); } -extern file_pair -io_open_files(char *filenames[], int files) +extern file_pair ** +io_list_open(char *filename[], int files) { - return; + int i; + file_pair *pairs[files]; + + //Open files a la list_file() + if (opt_format != FORMAT_XZ && opt_format != FORMAT_AUTO) + message_fatal(_("--list works only on .xz files " + "(--format=xz or --format=auto)")); + + for ( i = 0; i < files; i++) { + message_filename(filename[i]); + + if (filename[i] == stdin_filename) { + message_error(_("--list does not support reading from " + "standard input")); + continue; + } + + // Unset opt_stdout so that io_open_src() won't accept special files. + // Set opt_force so that io_open_src() will follow symlinks. + opt_stdout = false; + opt_force = true; + pairs[i] = io_open_src(filename[i]); +#if defined(CAPSICUM) + limitfd(pairs[i]); +#endif + } + return pairs; +} + +extern file_pair ** +io_coder_open(char *filename[], int files) +{ + int i; + file_pair *pairs[files]; + + for ( i = 0; i < files; i++) { + // Set and possibly print the filename for the progress message. + message_filename(filename[i]); + + // Try to open the input file. + pairs[i] = io_open_src(filename[i]); + if( opt_mode != MODE_TEST ) + io_open_dest(pairs[i]); +#if defined(CAPSICUM) + limitfd(pairs[i]); +#endif + } + + return pairs; } #if defined(CAPSICUM) Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.h ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.h Sun Jul 14 10:29:55 2013 (r254778) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.h Sun Jul 14 10:31:54 2013 (r254779) @@ -28,42 +28,6 @@ } io_buf; -typedef struct { - /// Name of the source filename (as given on the command line) or - /// pointer to static "(stdin)" when reading from standard input. - const char *src_name; - - /// Destination filename converted from src_name or pointer to static - /// "(stdout)" when writing to standard output. - char *dest_name; - - /// File descriptor of the source file - int src_fd; - - /// File descriptor of the target file - int dest_fd; - - /// True once end of the source file has been detected. - bool src_eof; - - /// If true, we look for long chunks of zeros and try to create - /// a sparse file. - bool dest_try_sparse; - - /// This is used only if dest_try_sparse is true. This holds the - /// number of zero bytes we haven't written out, because we plan - /// to make that byte range a sparse chunk. - off_t dest_pending_sparse; - - /// Stat of the source file. - struct stat src_st; - - /// Stat of the destination file. - struct stat dest_st; - -} file_pair; - - /// \brief Initialize the I/O module extern void io_init(void); @@ -129,14 +93,21 @@ extern bool io_write(file_pair *pair, const io_buf *buf, size_t size); -/// \brief Open all the files as needed. +/// \brief Open all the files as needed in lit_file(). /// /// \param filenames Array containing all the filenames to be open. /// \param files Number of files to open. /// /// \return Returns an array of file_pairs. -extern file_pair io_open_files(char *filenames[], int files); +extern file_pair ** io_list_open(char *filenames[], int files); +/// \brief Open all the files as needed in coder_run(). +/// +/// \param filenames Array containing all the filenames to be open. +/// \param files Number of files to open. +/// +/// \return Returns an array of file_pairs. +extern file_pair ** io_coder_open(char *filenames[], int files); #if defined(CAPSICUM) /// \brief Limits fd using FreeBSD's Capsicum framework.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307141031.r6EAVt1H038284>