1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-16 16:55:36 +00:00

Add more I/O error codes.

This commit is contained in:
Josh Elsasser 2007-04-20 02:05:07 +00:00
parent f9613c4dbc
commit 63bb617fa4
5 changed files with 39 additions and 21 deletions

View file

@ -67,7 +67,6 @@ static tr_fd_t * gFd = NULL;
/***********************************************************************
* Local prototypes
**********************************************************************/
static int ErrorFromErrno();
static int OpenFile( int i, char * folder, char * name, int write );
static void CloseFile( int i );
@ -406,16 +405,6 @@ void tr_fdClose()
* Local functions
**********************************************************************/
/***********************************************************************
* ErrorFromErrno
**********************************************************************/
static int ErrorFromErrno()
{
if( errno == EACCES || errno == EROFS )
return TR_ERROR_IO_PERMISSIONS;
return TR_ERROR_IO_OTHER;
}
/***********************************************************************
* CheckFolder
***********************************************************************
@ -426,6 +415,7 @@ static int OpenFile( int i, char * folder, char * name, int write )
tr_openFile_t * file = &gFd->open[i];
struct stat sb;
char * path;
int ret;
tr_dbg( "Opening %s in %s (%d)", name, folder, write );
@ -450,9 +440,10 @@ static int OpenFile( int i, char * folder, char * name, int write )
{
if( mkdir( path, 0777 ) )
{
ret = tr_ioErrorFromErrno();
tr_err( "Could not create folder '%s'", path );
free( path );
return ErrorFromErrno();
return ret;
}
}
else
@ -471,14 +462,14 @@ static int OpenFile( int i, char * folder, char * name, int write )
/* Now try to really open the file */
file->file = open( path, write ? ( O_RDWR | O_CREAT ) : O_RDONLY, 0666 );
free( path );
if( file->file < 0 )
{
int ret = ErrorFromErrno();
ret = tr_ioErrorFromErrno();
free( path );
tr_err( "Could not open %s in %s (%d, %d)", name, folder, write, ret );
return ret;
}
free( path );
return TR_OK;
}

View file

@ -409,8 +409,8 @@ static int readOrWriteBytes( tr_io_t * io, uint64_t offset, int size,
/* do what we are here to do... */
if( readOrWrite( file, buf, cur ) != cur )
{
ret = tr_ioErrorFromErrno();
tr_fdFileRelease( file );
ret = TR_ERROR_IO_OTHER;
goto cleanup;
}

View file

@ -65,14 +65,16 @@ extern "C" {
#define TR_ERROR 0x81000000
#define TR_ERROR_ASSERT 0x82000000
/* I/O errors */
#define TR_ERROR_IO_MASK 0x0000000F
#define TR_ERROR_IO_MASK 0x000000FF
#define TR_ERROR_IO_PARENT 0x80000001
#define TR_ERROR_IO_PERMISSIONS 0x80000002
#define TR_ERROR_IO_OTHER 0x80000008
#define TR_ERROR_IO_SPACE 0x80000004
#define TR_ERROR_IO_RESOURCES 0x80000008
#define TR_ERROR_IO_OTHER 0x80000010
/* Misc */
#define TR_ERROR_TC_MASK 0x000000F0
#define TR_ERROR_TC_ERROR 0x80000010
#define TR_ERROR_TC_WARNING 0x80000020
#define TR_ERROR_TC_MASK 0x00000F00
#define TR_ERROR_TC_ERROR 0x80000100
#define TR_ERROR_TC_WARNING 0x80000200
/***********************************************************************
* tr_init

View file

@ -359,6 +359,25 @@ tr_dupstr( const char * base, int len )
return ret;
}
int
tr_ioErrorFromErrno( void )
{
if( EACCES == errno || EROFS == errno )
{
return TR_ERROR_IO_PERMISSIONS;
}
else if( ENOSPC == errno )
{
return TR_ERROR_IO_SPACE;
}
else if( EMFILE == errno || EFBIG == errno )
{
return TR_ERROR_IO_RESOURCES;
}
tr_dbg( "generic i/o errno from errno: %s", strerror( errno ) );
return TR_ERROR_IO_OTHER;
}
char *
tr_errorString( int code )
{
@ -374,6 +393,10 @@ tr_errorString( int code )
return "Download folder does not exist";
case TR_ERROR_IO_PERMISSIONS:
return "Insufficient permissions";
case TR_ERROR_IO_SPACE:
return "Insufficient free space";
case TR_ERROR_IO_RESOURCES:
return "Insufficient resources";
case TR_ERROR_IO_OTHER:
return "Generic I/O error";
}

View file

@ -73,6 +73,8 @@ int tr_concat( char ** buf, int * used, int * max,
**********************************************************************/
char * tr_dupstr( const char * base, int len );
int tr_ioErrorFromErrno( void );
char * tr_errorString( int code );
/***********************************************************************