Changeset 1763


Ignore:
Timestamp:
Apr 20, 2007, 2:05:07 AM (15 years ago)
Author:
joshe
Message:

Add more I/O error codes.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r1441 r1763  
    6868 * Local prototypes
    6969 **********************************************************************/
    70 static int  ErrorFromErrno();
    7170static int  OpenFile( int i, char * folder, char * name, int write );
    7271static void CloseFile( int i );
     
    408407
    409408/***********************************************************************
    410  * ErrorFromErrno
    411  **********************************************************************/
    412 static int ErrorFromErrno()
    413 {
    414     if( errno == EACCES || errno == EROFS )
    415         return TR_ERROR_IO_PERMISSIONS;
    416     return TR_ERROR_IO_OTHER;
    417 }
    418 
    419 /***********************************************************************
    420409 * CheckFolder
    421410 ***********************************************************************
     
    427416    struct stat sb;
    428417    char * path;
     418    int ret;
    429419
    430420    tr_dbg( "Opening %s in %s (%d)", name, folder, write );
     
    451441                if( mkdir( path, 0777 ) )
    452442                {
     443                    ret = tr_ioErrorFromErrno();
    453444                    tr_err( "Could not create folder '%s'", path );
    454445                    free( path );
    455                     return ErrorFromErrno();
     446                    return ret;
    456447                }
    457448            }
     
    472463    /* Now try to really open the file */
    473464    file->file = open( path, write ? ( O_RDWR | O_CREAT ) : O_RDONLY, 0666 );
    474     free( path );
    475 
    476465    if( file->file < 0 )
    477466    {
    478         int ret = ErrorFromErrno();
     467        ret = tr_ioErrorFromErrno();
     468        free( path );
    479469        tr_err( "Could not open %s in %s (%d, %d)", name, folder, write, ret );
    480470        return ret;
    481471    }
     472    free( path );
    482473
    483474    return TR_OK;
  • trunk/libtransmission/inout.c

    r1608 r1763  
    410410            if( readOrWrite( file, buf, cur ) != cur )
    411411            {
     412                ret = tr_ioErrorFromErrno();
    412413                tr_fdFileRelease( file );
    413                 ret = TR_ERROR_IO_OTHER;
    414414                goto cleanup;
    415415            }
  • trunk/libtransmission/transmission.h

    r1655 r1763  
    6666#define TR_ERROR_ASSERT         0x82000000
    6767/* I/O errors */
    68 #define TR_ERROR_IO_MASK        0x0000000F
     68#define TR_ERROR_IO_MASK        0x000000FF
    6969#define TR_ERROR_IO_PARENT      0x80000001
    7070#define TR_ERROR_IO_PERMISSIONS 0x80000002
    71 #define TR_ERROR_IO_OTHER       0x80000008
     71#define TR_ERROR_IO_SPACE       0x80000004
     72#define TR_ERROR_IO_RESOURCES   0x80000008
     73#define TR_ERROR_IO_OTHER       0x80000010
    7274/* Misc */
    73 #define TR_ERROR_TC_MASK        0x000000F0
    74 #define TR_ERROR_TC_ERROR       0x80000010
    75 #define TR_ERROR_TC_WARNING     0x80000020
     75#define TR_ERROR_TC_MASK        0x00000F00
     76#define TR_ERROR_TC_ERROR       0x80000100
     77#define TR_ERROR_TC_WARNING     0x80000200
    7678
    7779/***********************************************************************
  • trunk/libtransmission/utils.c

    r1579 r1763  
    360360}
    361361
     362int
     363tr_ioErrorFromErrno( void )
     364{
     365    if( EACCES == errno || EROFS == errno )
     366    {
     367        return TR_ERROR_IO_PERMISSIONS;
     368    }
     369    else if( ENOSPC == errno )
     370    {
     371        return TR_ERROR_IO_SPACE;
     372    }
     373    else if( EMFILE == errno || EFBIG == errno )
     374    {
     375        return TR_ERROR_IO_RESOURCES;
     376    }
     377    tr_dbg( "generic i/o errno from errno: %s", strerror( errno ) );
     378    return TR_ERROR_IO_OTHER;
     379}
     380
    362381char *
    363382tr_errorString( int code )
     
    375394        case TR_ERROR_IO_PERMISSIONS:
    376395            return "Insufficient permissions";
     396        case TR_ERROR_IO_SPACE:
     397            return "Insufficient free space";
     398        case TR_ERROR_IO_RESOURCES:
     399            return "Insufficient resources";
    377400        case TR_ERROR_IO_OTHER:
    378401            return "Generic I/O error";
  • trunk/libtransmission/utils.h

    r1579 r1763  
    7474char * tr_dupstr( const char * base, int len );
    7575
     76int    tr_ioErrorFromErrno( void );
     77
    7678char * tr_errorString( int code );
    7779
Note: See TracChangeset for help on using the changeset viewer.