xorriso  1.5.4.pl02
About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.
  Fossies Dox: xorriso-1.5.4.pl02.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

file.c File Reference
#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <pthread.h>
#include "source.h"
#include "libburn.h"
#include "file.h"
#include "async.h"
#include "init.h"
#include "util.h"
#include "libdax_msgs.h"
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define O_BINARY   0
 

Functions

static int read_full_buffer (int fd, unsigned char *buffer, int size)
 
static int file_read (struct burn_source *source, unsigned char *buffer, int size)
 
static int file_read_sub (struct burn_source *source, unsigned char *buffer, int size)
 
static void file_free (struct burn_source *source)
 
static off_t file_size (struct burn_source *source)
 
static int file_set_size (struct burn_source *source, off_t size)
 
struct burn_sourceburn_file_source_new (const char *path, const char *subpath)
 
struct burn_sourceburn_fd_source_new (int datafd, int subfd, off_t size)
 
static int fifo_sleep (int flag)
 
static int fifo_read (struct burn_source *source, unsigned char *buffer, int size)
 
static off_t fifo_get_size (struct burn_source *source)
 
static int fifo_set_size (struct burn_source *source, off_t size)
 
static void fifo_free (struct burn_source *source)
 
int burn_fifo_source_shoveller (struct burn_source *source, int flag)
 
int burn_fifo_cancel (struct burn_source *source)
 
struct burn_sourceburn_fifo_source_new (struct burn_source *inp, int chunksize, int chunks, int flag)
 
int burn_fifo_inquire_status (struct burn_source *source, int *size, int *free_bytes, char **status_text)
 
void burn_fifo_get_statistics (struct burn_source *source, int *total_min_fill, int *interval_min_fill, int *put_counter, int *get_counter, int *empty_counter, int *full_counter)
 
void burn_fifo_next_interval (struct burn_source *source, int *interval_min_fill)
 
int burn_fifo_fill_data (struct burn_source *source, char *buf, int bufsize, int flag)
 
int burn_fifo_peek_data (struct burn_source *source, char *buf, int bufsize, int flag)
 
int burn_fifo_fill (struct burn_source *source, int bufsize, int flag)
 
static void offst_free (struct burn_source *source)
 
static struct burn_source_offstoffst_auth (struct burn_source *source, int flag)
 
static off_t offst_get_size (struct burn_source *source)
 
static int offst_set_size (struct burn_source *source, off_t size)
 
static int offst_read (struct burn_source *source, unsigned char *buffer, int size)
 
static int offst_cancel (struct burn_source *source)
 
struct burn_sourceburn_offst_source_new (struct burn_source *inp, struct burn_source *prev, off_t start, off_t size, int flag)
 
int burn_drive_extract_audio (struct burn_drive *drive, int start_sector, int sector_count, char *target_path, int flag)
 
int burn_drive_extract_audio_track (struct burn_drive *drive, struct burn_track *track, char *target_path, int flag)
 

Variables

struct libdax_msgs * libdax_messenger
 

Macro Definition Documentation

◆ O_BINARY

#define O_BINARY   0

Definition at line 27 of file file.c.

Function Documentation

◆ burn_drive_extract_audio()

int burn_drive_extract_audio ( struct burn_drive drive,
int  start_sector,
int  sector_count,
char *  target_path,
int  flag 
)

Extract an interval of audio sectors from CD and store it as a WAVE audio file on hard disk.

Parameters
driveThe drive from which to read.
start_sectorThe logical block address of the first audio sector which shall be read.
sector_countThe number of audio sectors to be read. Each sector consists of 2352 bytes.
target_pathThe address of the file where to store the extracted audio data. Will be opened O_WRONLY | O_CREAT. The file name should have suffix ".wav".
flagBitfield for control purposes: bit0= Report about progress by UPDATE messages bit3= Enable DAP : "flaw obscuring mechanisms like audio data mute and interpolate"
Since
1.3.2

Definition at line 981 of file file.c.

References BURN_ALLOC_MEM, BURN_FREE_MEM, burn_int_to_lsb(), burn_lba_to_msf(), burn_read_audio(), libdax_messenger, LIBDAX_MSGS_PRIO_HIGH, LIBDAX_MSGS_SEV_FAILURE, LIBDAX_MSGS_SEV_UPDATE, libdax_msgs_submit(), and O_BINARY.

Referenced by burn_drive_extract_audio_track().

◆ burn_drive_extract_audio_track()

int burn_drive_extract_audio_track ( struct burn_drive drive,
struct burn_track track,
char *  target_path,
int  flag 
)

Extract all audio sectors of a track from CD and store them as a WAVE audio file on hard disk.

Parameters
driveThe drive from which to read.
trackThe track which shall be extracted.
target_pathThe address of the file where to store the extracted audio data. Will be opened O_WRONLY | O_CREAT. The file name should have suffix ".wav".
flagBitfield for control purposes: bit0= Report about progress by UPDATE messages bit3= Enable DAP : "flaw obscuring mechanisms like audio data mute and interpolate"
Since
1.3.2

Definition at line 1101 of file file.c.

References burn_drive_extract_audio(), burn_track_get_entry(), burn_toc_entry::extensions_valid, libdax_messenger, LIBDAX_MSGS_PRIO_HIGH, LIBDAX_MSGS_SEV_FATAL, libdax_msgs_submit(), burn_toc_entry::start_lba, and burn_toc_entry::track_blocks.

◆ burn_fd_source_new()

struct burn_source* burn_fd_source_new ( int  datafd,
int  subfd,
off_t  size 
)

Creates a data source for an image file (a track) from an open readable filedescriptor, an eventually open readable subcodes file descriptor and eventually a fixed size in bytes.

Parameters
datafdThe source of data.
subfdThe eventual source of subchannel data. Only used in exotic raw write modes. Submit -1 for normal tasks.
sizeThe eventual fixed size of eventually both fds. If this value is 0, the size will be determined from datafd.
Returns
Pointer to a burn_source object, NULL indicates failure

Definition at line 178 of file file.c.

References burn_alloc_mem(), burn_source_new(), burn_source::data, burn_source_file::datafd, file_free(), file_read(), file_read_sub(), file_set_size(), file_size(), burn_source_file::fixed_size, burn_source::free_data, burn_source::get_size, burn_source::read, burn_source::read_sub, burn_source::set_size, and burn_source_file::subfd.

Referenced by cue_create_file_source(), and Xorriso_burn_track().

◆ burn_fifo_cancel()

int burn_fifo_cancel ( struct burn_source source)

Definition at line 530 of file file.c.

References burn_source_cancel(), burn_source::data, and burn_source_fifo::inp.

Referenced by burn_fifo_source_new().

◆ burn_fifo_fill()

int burn_fifo_fill ( struct burn_source fifo,
int  fill,
int  flag 
)

Start the fifo worker thread and wait either until the requested number of bytes have arrived or until it becomes clear that this will not happen. Filling will go on asynchronously after burn_fifo_fill() returned. This call and burn_fifo_peek_data() do not disturb each other.

Parameters
fifoThe fifo object to start
fillNumber of bytes desired. Expect to get return 1 if at least fifo size - 32k were read.
flagBitfield for control purposes. bit0= fill fifo to maximum size
Returns
<0 on severe error, 0 if not enough data, 1 if desired amount or fifo full
Since
0.7.4

Definition at line 796 of file file.c.

References burn_fifo_fill_data().

◆ burn_fifo_fill_data()

◆ burn_fifo_get_statistics()

void burn_fifo_get_statistics ( struct burn_source fifo,
int *  total_min_fill,
int *  interval_min_fill,
int *  put_counter,
int *  get_counter,
int *  empty_counter,
int *  full_counter 
)

Inquire various counters which reflect the fifo operation.

Parameters
fifoThe fifo object to inquire
total_min_fillThe minimum number of bytes in the fifo. Beginning from the moment when fifo consumption is enabled.
interval_min_fillThe minimum byte number beginning from the moment when fifo consumption is enabled or from the most recent moment when burn_fifo_next_interval() was called.
put_counterThe number of data transactions into the fifo.
get_counterThe number of data transactions out of the fifo.
empty_counterThe number of times the fifo was empty.
full_counterThe number of times the fifo was full.
Since
0.7.4

Definition at line 650 of file file.c.

References burn_source::data, burn_source_fifo::empty_counter, burn_source_fifo::full_counter, burn_source_fifo::get_counter, burn_source_fifo::interval_min_fill, burn_source_fifo::put_counter, and burn_source_fifo::total_min_fill.

◆ burn_fifo_inquire_status()

int burn_fifo_inquire_status ( struct burn_source fifo,
int *  size,
int *  free_bytes,
char **  status_text 
)

Inquires state and fill parameters of a fifo burn_source which was created by burn_fifo_source_new() . Do not use with other burn_source variants.

Parameters
fifoThe fifo object to inquire
sizeThe total size of the fifo
free_bytesThe current free capacity of the fifo
status_textReturns a pointer to a constant text, see below
Returns
<0 reply invalid, >=0 fifo status code: bit0+1=input status, bit2=consumption status, i.e: 0="standby" : data processing not started yet 1="active" : input and consumption are active 2="ending" : input has ended without error 3="failing" : input had error and ended, 4="unused" : ( consumption has ended before processing start ) 5="abandoned" : consumption has ended prematurely 6="ended" : consumption has ended without input error 7="aborted" : consumption has ended after input error
Since
0.4.0

Definition at line 607 of file file.c.

References burn_source_fifo::buf, burn_source_fifo::buf_readpos, burn_source_fifo::buf_writepos, burn_source_fifo::chunks, burn_source_fifo::chunksize, burn_source::data, burn_source_fifo::end_of_consumption, burn_source_fifo::end_of_input, fifo_free(), burn_source::free_data, burn_source_fifo::input_error, libdax_messenger, LIBDAX_MSGS_PRIO_HIGH, LIBDAX_MSGS_SEV_FATAL, and libdax_msgs_submit().

Referenced by burn_fifo_fill_data(), burn_fifo_next_interval(), and Xorriso_pacifier_loop().

◆ burn_fifo_next_interval()

void burn_fifo_next_interval ( struct burn_source fifo,
int *  interval_min_fill 
)

Inquire the fifo minimum fill counter for intervals and reset that counter.

Parameters
fifoThe fifo object to inquire
interval_min_fillThe minimum number of bytes in the fifo. Beginning from the moment when fifo consumption is enabled or from the most recent moment when burn_fifo_next_interval() was called.
Since
0.7.4

Definition at line 667 of file file.c.

References burn_fifo_inquire_status(), burn_source::data, and burn_source_fifo::interval_min_fill.

◆ burn_fifo_peek_data()

int burn_fifo_peek_data ( struct burn_source fifo,
char *  buf,
int  bufsize,
int  flag 
)

Obtain a preview of the first input data of a fifo which was created by burn_fifo_source_new(). The data will later be delivered normally to the consumer track of the fifo. bufsize may not be larger than the fifo size (chunk_size * chunks) - 32k. This call will succeed only if data consumption by the track has not started yet, i.e. best before the call to burn_disc_write(). It will start the worker thread of the fifo with the expectable side effects on the external data source. Then it waits either until enough data have arrived or until it becomes clear that this will not happen. The call may be repeated with increased bufsize. It will always yield the bytes beginning from the first one in the fifo.

Parameters
fifoThe fifo object to start and to inquire
bufPointer to memory of at least bufsize bytes where to deliver the peeked data.
bufsizeNumber of bytes to peek from the start of the fifo data
flagBitfield for control purposes (unused yet, submit 0).
Returns
<0 on severe error, 0 if not enough data, 1 if bufsize bytes read
Since
0.5.0

Definition at line 788 of file file.c.

References burn_source_fifo::buf, and burn_fifo_fill_data().

Referenced by Xorriso_burn_track().

◆ burn_fifo_source_new()

struct burn_source* burn_fifo_source_new ( struct burn_source inp,
int  chunksize,
int  chunks,
int  flag 
)

Creates a fifo which acts as proxy for an already existing data source. The fifo provides a ring buffer which shall smoothen the data stream between burn_source and writer thread. Each fifo serves only for one data source. It may be attached to one track as its only data source by burn_track_set_source(), or it may be used as input for other burn sources. A fifo starts its life in "standby" mode with no buffer space allocated. As soon as its consumer requires bytes, the fifo establishes a worker thread and allocates its buffer. After input has ended and all buffer content is consumed, the buffer space gets freed and the worker thread ends. This happens asynchronously. So expect two buffers and worker threads to exist for a short time between tracks. Be modest in your size demands if multiple tracks are to be expected.

Parameters
inpThe burn_source for which the fifo shall act as proxy. It can be disposed by burn_source_free() immediately after this call.
chunksizeThe size in bytes of a chunk. Use 2048 for sources suitable for BURN_BLOCK_MODE1, 2352 for sources which deliver for BURN_BLOCK_AUDIO, 2056 for sources which shall get treated by burn_track_set_cdxa_conv(track, 1). Some variations of burn_source might work only with a particular chunksize. E.g. libisofs demands 2048.
chunksThe number of chunks to be allocated in ring buffer. This value must be >= 2.
flagBitfield for control purposes: bit0= The read method of inp is capable of delivering arbitrary amounts of data per call. Not only one sector. Suitable for inp from burn_file_source_new() and burn_fd_source_new() if not the fd has exotic limitations on read size. You MUST use this on inp which uses an fd opened with burn_os_open_track_src(). Better do not use with other inp types.
Since
0.7.4
Returns
A pointer to the newly created burn_source. Later both burn_sources, inp and the returned fifo, have to be disposed by calling burn_source_free() for each. inp can be freed immediately, the returned fifo may be kept as handle for burn_fifo_inquire_status().
Since
0.4.0

Definition at line 542 of file file.c.

References burn_source_fifo::buf, burn_source_fifo::buf_readpos, burn_source_fifo::buf_writepos, burn_alloc_mem(), burn_fifo_cancel(), burn_source_new(), burn_source::cancel, burn_source_fifo::chunks, burn_source_fifo::chunksize, burn_source::data, burn_source_fifo::do_abort, burn_source_fifo::empty_counter, burn_source_fifo::end_of_consumption, burn_source_fifo::end_of_input, fifo_free(), fifo_get_size(), fifo_read(), fifo_set_size(), burn_source::free_data, burn_source_fifo::full_counter, burn_source_fifo::get_counter, burn_source::get_size, burn_source_fifo::in_counter, burn_source_fifo::inp, burn_source_fifo::inp_read_size, burn_source_fifo::input_error, burn_source_fifo::interval_min_fill, burn_source_fifo::is_started, libdax_messenger, LIBDAX_MSGS_PRIO_HIGH, LIBDAX_MSGS_SEV_SORRY, libdax_msgs_submit(), burn_source_fifo::out_counter, burn_source_fifo::put_counter, burn_source::read, burn_source::read_sub, burn_source::read_xt, burn_source::refcount, burn_source::set_size, burn_source_fifo::thread_handle, burn_source_fifo::thread_is_valid, burn_source_fifo::thread_pid, burn_source_fifo::total_min_fill, and burn_source::version.

Referenced by cue_interpret_line(), and Xorriso_burn_track().

◆ burn_fifo_source_shoveller()

◆ burn_file_source_new()

struct burn_source* burn_file_source_new ( const char *  path,
const char *  subpath 
)

Creates a data source for an image file (and maybe subcode file)

Parameters
pathThe file address for the main channel payload.
subpathEventual address for subchannel data. Only used in exotic raw write modes. Submit NULL for normal tasks.
Returns
Pointer to a burn_source object, NULL indicates failure

Definition at line 121 of file file.c.

References burn_source_new(), burn_source::data, burn_source_file::datafd, file_free(), file_read(), file_read_sub(), file_set_size(), file_size(), burn_source_file::fixed_size, burn_source::free_data, burn_source::get_size, O_BINARY, burn_source::read, burn_source::read_sub, burn_source::set_size, and burn_source_file::subfd.

◆ burn_offst_source_new()

struct burn_source* burn_offst_source_new ( struct burn_source inp,
struct burn_source prev,
off_t  start,
off_t  size,
int  flag 
)

Creates an offset source which shall provide a byte interval of a stream to its consumer. It is supposed to be chain-linked with other offset sources which serve neighboring consumers. The chronological sequence of consumers and the sequence of offset sources must match. The intervals of the sources must not overlap.

A chain of these burn_source objects may be used to feed multiple tracks from one single stream of input bytes. Each of the offset sources will skip the bytes up to its start address and provide the prescribed number of bytes to the track. Skipping takes into respect the bytes which have been processed by eventual predecessors in the chain. Important: It is not allowed to free an offset source before its successor has ended its work. Best is to keep them all until all tracks are done.

Parameters
inpThe burn_source object from which to read stream data. E.g. created by burn_file_source_new().
prevThe eventual offset source object which shall read data from inp before the new offset source will begin its own work. This must either be a result of burn_offst_source_new() or it must be NULL.
startThe byte address where to start reading bytes for the consumer. inp bytes may get skipped to reach this address.
sizeThe number of bytes to be delivered to the consumer. If size is <= 0 then it may be set later by a call of method set_size(). If it is >= 0, then it can only be changed if flag bit0 was set with burn_offst_source_new().
flagBitfield for control purposes bit0 = Prevent set_size() from overriding interval sizes > 0. If such a size is already set, then the new one will only affect the reply of get_size(). See also above struct burn_source.
Since
1.2.0
Returns
Pointer to a burn_source object, later to be freed by burn_source_free(). NULL indicates failure.
Since
0.8.8

Definition at line 913 of file file.c.

References burn_source_new(), burn_source::cancel, burn_source::data, burn_source::free_data, burn_source::get_size, burn_source_offst::inp, libdax_messenger, LIBDAX_MSGS_PRIO_HIGH, LIBDAX_MSGS_SEV_FAILURE, libdax_msgs_submit(), burn_source_offst::next, burn_source_offst::nominal_size, offst_auth(), offst_cancel(), offst_free(), offst_get_size(), offst_read(), offst_set_size(), burn_source_offst::pos, burn_source_offst::prev, burn_source::read, burn_source::read_sub, burn_source::read_xt, burn_source::refcount, burn_source_offst::running, burn_source::set_size, burn_source_offst::size, burn_source_offst::size_adjustable, burn_source_offst::start, and burn_source::version.

Referenced by cue_interpret_line().

◆ fifo_free()

◆ fifo_get_size()

static off_t fifo_get_size ( struct burn_source source)
static

Definition at line 315 of file file.c.

References burn_source::data, burn_source::get_size, and burn_source_fifo::inp.

Referenced by burn_fifo_source_new().

◆ fifo_read()

◆ fifo_set_size()

static int fifo_set_size ( struct burn_source source,
off_t  size 
)
static

Definition at line 323 of file file.c.

References burn_source::data, burn_source_fifo::inp, and burn_source::set_size.

Referenced by burn_fifo_source_new().

◆ fifo_sleep()

static int fifo_sleep ( int  flag)
static

Definition at line 219 of file file.c.

Referenced by burn_fifo_source_shoveller(), and fifo_read().

◆ file_free()

static void file_free ( struct burn_source source)
static

◆ file_read()

static int file_read ( struct burn_source source,
unsigned char *  buffer,
int  size 
)
static

Definition at line 68 of file file.c.

References burn_source::data, burn_source_file::datafd, and read_full_buffer().

Referenced by burn_fd_source_new(), and burn_file_source_new().

◆ file_read_sub()

static int file_read_sub ( struct burn_source source,
unsigned char *  buffer,
int  size 
)
static

Definition at line 77 of file file.c.

References burn_source::data, read_full_buffer(), and burn_source_file::subfd.

Referenced by burn_fd_source_new(), and burn_file_source_new().

◆ file_set_size()

static int file_set_size ( struct burn_source source,
off_t  size 
)
static

Definition at line 112 of file file.c.

References burn_source::data, and burn_source_file::fixed_size.

Referenced by burn_fd_source_new(), and burn_file_source_new().

◆ file_size()

◆ offst_auth()

◆ offst_cancel()

static int offst_cancel ( struct burn_source source)
static

Definition at line 902 of file file.c.

References burn_source_cancel(), burn_source_offst::inp, and offst_auth().

Referenced by burn_offst_source_new().

◆ offst_free()

static void offst_free ( struct burn_source source)
static

◆ offst_get_size()

static off_t offst_get_size ( struct burn_source source)
static

Definition at line 823 of file file.c.

References burn_source_offst::nominal_size, and offst_auth().

Referenced by burn_offst_source_new().

◆ offst_read()

static int offst_read ( struct burn_source source,
unsigned char *  buffer,
int  size 
)
static

◆ offst_set_size()

static int offst_set_size ( struct burn_source source,
off_t  size 
)
static

◆ read_full_buffer()

static int read_full_buffer ( int  fd,
unsigned char *  buffer,
int  size 
)
static

Definition at line 49 of file file.c.

Referenced by file_read(), and file_read_sub().

Variable Documentation

◆ libdax_messenger