Called statvfs() for size estimation of regular stdio-files.

This commit is contained in:
Thomas Schmitt 2007-09-09 09:35:23 +00:00
parent ccad19e055
commit ea09a516bd
4 changed files with 60 additions and 19 deletions

View File

@ -270,9 +270,10 @@ Warning: Superusers must take care not to spoil their hard disk via its raw
block device (like /dev/hda or /dev/sd0).
.br
Pseudo-drives behave much like DVD-RAM. They allow -dummy, nevertheless, and
their reply with --tell_media_space is utopic. If the given address does
not exist yet, then it gets created as regular file.
Note: -dummy runs touch the file.
their reply with --tell_media_space can be utopic. If the given address does
not exist yet but its directory exists, then it gets created as regular file
as soon as a write operation occurs.
Note: -dummy burn runs touch the file.
.br
.SH OPTIONS
.TP
@ -397,7 +398,7 @@ Try to perform the drive operations without actually affecting the inserted
media. There is no warranty that this will work with a particular combination
of drive, media, and write mode. Blanking is prevented reliably, though.
To avoid inadverted real burning, -dummy refuses burn runs on anything but
CD-R[W] and DVD-R[W].
CD-R[W], DVD-R[W], or emulated stdio-drives.
.TP
.BI \-eject
Eject the disc after work is done.

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2007.09.08.174757"
#define Cdrskin_timestamP "2007.09.09.093535"

View File

@ -16,6 +16,7 @@
#include <string.h>
#include <ctype.h>
#include <pthread.h>
#include <sys/statvfs.h>
#include "libburn.h"
#include "drive.h"
#include "transport.h"
@ -1091,16 +1092,41 @@ int burn_drive_is_banned(char *device_address)
int burn_drive_grab_dummy(struct burn_drive_info *drive_infos[], char *fname)
{
int ret;
off_t size = ((off_t) (1024 * 1024 * 1024) * (off_t) 2048);
off_t add_size = 0;
struct burn_drive *d= NULL, *regd_d;
struct stat stbuf;
struct statvfs vfsbuf;
char testpath[4096];
testpath[0] = 0;
if (fname[0] != 0) {
if (stat(fname, &stbuf) == -1) {
strcpy(testpath,fname);
if(strrchr(testpath,'/') == NULL)
strcpy(testpath,".");
else if(strrchr(testpath,'/') == testpath)
testpath[1] = 0;
else
*strrchr(testpath,'/') = 0;
if (stat(testpath, &stbuf) == -1) {
libdax_msgs_submit(libdax_messenger, -1,
0x00020009,
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
"Neither stdio-path nor its directory exist",
0, 0);
return 0;
}
/* >>> ? reject ? try to create ? */;
} else if(S_ISBLK(stbuf.st_mode)) {
} else if(S_ISREG(stbuf.st_mode) || S_ISBLK(stbuf.st_mode)) {
/* >>> ? open for a test ? */;
/* >>> ? how to obtain the number of blocks ? */
} else if(S_ISREG(stbuf.st_mode)) {
add_size = stbuf.st_blocks * (off_t) 512;
size -= add_size;
strcpy(testpath,fname);
} else {
libdax_msgs_submit(libdax_messenger, -1,
0x00020149,
@ -1137,6 +1163,14 @@ int burn_drive_grab_dummy(struct burn_drive_info *drive_infos[], char *fname)
d->current_is_supported_profile = 1;
d->block_types[BURN_WRITE_TAO] = BURN_BLOCK_MODE1;
d->block_types[BURN_WRITE_SAO] = BURN_BLOCK_SAO;
if (testpath[0])
if (statvfs(testpath, &vfsbuf) != -1)
size = ((off_t) vfsbuf.f_bsize) *
(off_t) vfsbuf.f_bavail;
d->media_capacity_remaining = size + add_size;
/* >>> ? open file for a test ? */;
} else
d->current_profile = 0; /* Drives return this if empty */
@ -1731,14 +1765,14 @@ off_t burn_disc_available_space(struct burn_drive *d,
if (d->drive_role == 0)
return 0;
if (d->drive_role == 2) {
/* >>> how to estimate available space for a stdio file ? */
return ((off_t) (1024 * 1024 * 1024) * (off_t) 2048);
if (d->media_capacity_remaining <= 0)
d->media_capacity_remaining =
((off_t) (1024 * 1024 * 1024) * (off_t) 2048);
} else {
if (o != NULL)
d->send_write_parameters(d, o);
d->get_nwa(d, -1, &lba, &nwa);
}
if (o != NULL)
d->send_write_parameters(d, o);
d->get_nwa(d, -1, &lba, &nwa);
if (o != NULL) {
if (o->start_byte > 0) {
if (o->start_byte > d->media_capacity_remaining)
@ -1938,6 +1972,8 @@ int burn_disc_get_multi_caps(struct burn_drive *d, enum burn_write_types wt,
int status, num_formats, ret, type, i;
off_t size;
unsigned dummy;
struct statvfs vfsbuf;
struct stat stbuf;
*caps = NULL;
s = burn_disc_get_status(d);
@ -1963,11 +1999,14 @@ int burn_disc_get_multi_caps(struct burn_drive *d, enum burn_write_types wt,
if (d->drive_role == 2) {
/* stdio file dummy drive */
o->start_adr = 1;
size = ((off_t) (1024 * 1024 * 1024) * (off_t) 2048);
/* >>> obtain realistic file size */
size = d->media_capacity_remaining;
if (stat(d->devname, &stbuf) != -1)
if(S_ISREG(stbuf.st_mode))
if (statvfs(d->devname, &vfsbuf) != -1)
size = ((off_t) vfsbuf.f_bsize) *
(off_t) vfsbuf.f_bavail;
d->media_capacity_remaining = size;
o->start_range_high = size;
o->start_alignment = 2048; /* imposting a drive, not a file */
o->might_do_sao = 4;
o->might_do_tao = 2;

View File

@ -305,6 +305,7 @@ Range "scdbackup" : 0x00020000 to 0x0002ffff
0x00020006 (FATAL,HIGH) = Too many scsi siblings
0x00020007 (NOTE,HIGH) = Closed O_EXCL scsi siblings
0x00020008 (SORRY,HIGH) = Device busy. Failed to fcntl-lock
0x00020009 (SORRY,HIGH) = Neither stdio-path nor its directory exist
General library operations: