Unified burn_file_source and burn_fd_source

This commit is contained in:
Thomas Schmitt 2007-01-26 17:32:31 +00:00
parent 22b941331c
commit 66440d811d
3 changed files with 11 additions and 82 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2007.01.25.185214" #define Cdrskin_timestamP "2007.01.26.173236"

View File

@ -42,7 +42,7 @@ static int file_read(struct burn_source *source,
unsigned char *buffer, unsigned char *buffer,
int size) int size)
{ {
struct burn_source_fd *fs = source->data; struct burn_source_file *fs = source->data;
return read_full_buffer(fs->datafd, buffer, size); return read_full_buffer(fs->datafd, buffer, size);
} }
@ -75,9 +75,6 @@ static off_t file_size(struct burn_source *source)
return fs->fixed_size; return fs->fixed_size;
if (fstat(fs->datafd, &buf) == -1) if (fstat(fs->datafd, &buf) == -1)
return (off_t) 0; return (off_t) 0;
/* for now we keep it compatible to the old (int) return value */
if(buf.st_size >= 1308622848) /* 2 GB - 800 MB to prevent rollover */
return (off_t) 1308622848;
return (off_t) buf.st_size; return (off_t) buf.st_size;
} }
@ -132,84 +129,27 @@ struct burn_source *burn_file_source_new(const char *path, const char *subpath)
} }
/* ------ provisory location for the new source subclass fd --------- */ /* ts A70126 : removed class burn_source_fd in favor of burn_source_file */
static off_t fd_get_size(struct burn_source *source)
{
struct stat buf;
struct burn_source_fd *fs = source->data;
if (fs->fixed_size > 0)
return fs->fixed_size;
if (fstat(fs->datafd, &buf) == -1)
return (off_t) 0;
/* for now we keep it compatible to the old (int) return value */
if (buf.st_size >= 1308622848) /* 2 GB - 800 MB to prevent rollover */
return (off_t) 1308622848;
return buf.st_size;
}
/* ts A70125 */
static int fd_set_size(struct burn_source *source, off_t size)
{
struct burn_source_fd *fs = source->data;
fs->fixed_size = size;
return 1;
}
static int fd_read(struct burn_source *source,
unsigned char *buffer,
int size)
{
struct burn_source_fd *fs = source->data;
return read_full_buffer(fs->datafd, buffer, size);
}
static int fd_read_sub(struct burn_source *source,
unsigned char *buffer,
int size)
{
struct burn_source_fd *fs = source->data;
return read_full_buffer(fs->subfd, buffer, size);
}
static void fd_free_data(struct burn_source *source)
{
struct burn_source_fd *fs = source->data;
close(fs->datafd);
if (source->read_sub)
close(fs->subfd);
free(fs);
}
struct burn_source *burn_fd_source_new(int datafd, int subfd, off_t size) struct burn_source *burn_fd_source_new(int datafd, int subfd, off_t size)
{ {
struct burn_source_fd *fs; struct burn_source_file *fs;
struct burn_source *src; struct burn_source *src;
if (datafd == -1) if (datafd == -1)
return NULL; return NULL;
fs = malloc(sizeof(struct burn_source_fd)); fs = malloc(sizeof(struct burn_source_file));
fs->datafd = datafd; fs->datafd = datafd;
fs->subfd = subfd; fs->subfd = subfd;
fs->fixed_size = size; fs->fixed_size = size;
src = burn_source_new(); src = burn_source_new();
src->read = fd_read; src->read = file_read;
if(subfd != -1) if(subfd != -1)
src->read = fd_read_sub; src->read = file_read_sub;
src->get_size = fd_get_size; src->get_size = file_size;
src->set_size = fd_set_size; src->set_size = file_set_size;
src->free_data = fd_free_data; src->free_data = file_free;
src->data = fs; src->data = fs;
return src; return src;
} }

View File

@ -3,11 +3,6 @@
#ifndef BURN__FILE_H #ifndef BURN__FILE_H
#define BURN__FILE_H #define BURN__FILE_H
/* ts A70125 :
Looks like burn_source_file and burn_source_fd become identical because
of the need to set a fixed_size of at least 600 kB.
I will try to unify both classes.
*/
struct burn_source_file struct burn_source_file
{ {
int datafd; int datafd;
@ -16,13 +11,7 @@ struct burn_source_file
}; };
/* ------ provisory location for the new source subclass fd --------- */ /* ts A70126 : burn_source_file obsoleted burn_source_fd */
struct burn_source_fd
{
int datafd;
int subfd;
off_t fixed_size;
};
#endif /* LIBBURN__FILE_H */ #endif /* LIBBURN__FILE_H */