Opened 14 years ago

Last modified 14 years ago

#619 closed defect (fixed)

pb when trying to create an image on a full disk

Reported by: route@… Owned by: warmerdam
Priority: high Milestone:
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords:
Cc: wjimage@…

Description

When creating an image on a disk where there is not enough space left to write 
the image, no "failed" error code is returned.
The version used is GDAL 1.2.2.0
See code snippet :
void testGDAL()
{
	GDALAllRegister();
    GDALDriver *poDriver;
    char **papszMetadata;

    poDriver = GetGDALDriverManager()->GetDriverByName("BMP");

    if( poDriver == NULL )
       return;

    papszMetadata = poDriver->GetMetadata();
    if( !CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
	{
	printf( "Driver %s does not support Create() method.\n" );
        return;
	}
 	int x = 40;
	int y = 40;
    GDALDataset* m_gdalDataSet = poDriver->Create( "T:\\foo.bmp", x, y, 3, 
GDT_Byte, NULL);
	if ( m_gdalDataSet == NULL )
		return;

	GDALRasterBand *poBand = m_gdalDataSet->GetRasterBand(1);
	if ( poBand == NULL )
		return;

	unsigned char* value = (unsigned char*)malloc(x*y);
	memset(value,255,x*y);
	CPLErr err = poBand->RasterIO( GF_Write, 0, 0, x, y, value, x, y, 
GDT_Byte, 0, 0 );    
	free(value);
	if ( err != CE_None )
	{
		return;
	}
	m_gdalDataSet->FlushCache();
	GDALClose(m_gdalDataSet);
};

as output (in stdout) I have :
ERROR 3: Can't write block with X offset 0 and Y offset 0
ERROR 3: Can't write block with X offset 0 and Y offset 1
ERROR 3: Can't write block with X offset 0 and Y offset 2
ERROR 3: Can't write block with X offset 0 and Y offset 3
(...)
ERROR 3: Can't write block with X offset 0 and Y offset 33
ERROR 3: Can't write block with X offset 0 and Y offset 34

RasterIO returns CE_None and the created file is wrong.


Stephane.

Change History (5)

comment:1 Changed 14 years ago by warmerdam

OK, I have made some adjustments to the bmpdataset.cpp code. 

1) Check returns values in VSIFWriteL() in header writing code.  

2) Report the error message in the block writer if something goes wrong. 

Unfortunately (1) doesn't do much good because on linux (at least) the output
is buffered and we can't detect an error till the OS tries to flush it down
into the filesystem code. 

However, with (2) at least we get a meaningful error message about being out
of disk space.

comment:2 Changed 14 years ago by route@…

Hi Frank,

thanks a lot for your fix.
Just one question : what about the other formats ?

Best Regards,

Stephane

comment:3 Changed 14 years ago by warmerdam

Stephane,

The quality of IO error checking in other drivers varies, but I'm not really
prepared to start doing a comprehensive review at this point.  The techniques
I applied in the BMP driver have been used in some of the other drivers. 

comment:4 Changed 14 years ago by route@…

Hi Frank,

Thank you for this explaination.
I'm not asking you to work on the other formats. It was just for me to know.
Thanks again for the fix.

Stephane

comment:5 Changed 14 years ago by warmerdam

*** Bug 621 has been marked as a duplicate of this bug. ***
Note: See TracTickets for help on using tickets.