Ejemplo n.º 1
0
/*
 * doGetDriveType - get the type of drive A-Z
 */
static drive_type doGetDriveType( int drv )
{
    STUPID_UINT disk;
    ULONG       map;
    int         i;
    char        fname[3];
    HFILE       hf;
    STUPID_UINT act;
    STUPID_UINT type;
    int         rc;

#ifdef __OS_dosos2__
    if( _osmode == 0 ) {
        return( dosDoGetDriveType( drv ) );
    } else {
#endif
        drv = toupper( drv );
        DosQCurDisk( &disk, &map );
        for( i='A';i<='Z';i++ ) {
            if( drv == i ) {
                if( map & 1 ) {
                    fname[0] = tolower( i );
                    fname[1] = ':';
                    fname[2] = 0;
                    rc = DosOpen( fname, &hf, &act, 0, 0,
                                0x0001,
                                0x0040 | 0x8000, 0L );
                    if( rc == 0 ) {
                        DosQHandType( hf, &type, &act );
                        DosClose( hf );
                        if( type & 0x8000 ) {
                            return( DRIVE_IS_REMOTE );
                        }
                    } else {
                        // KLUDGE - this only seems to fail for network drives?!
                        return( DRIVE_IS_REMOTE );
                    }
                    return( DRIVE_IS_FIXED );
                } else {
                    return( DRIVE_NONE );
                }
            }
            map >>= 1;
        }
        return( DRIVE_NONE );
#ifdef __OS_dosos2__
    }
#endif

} /* doGetDriveType */
Ejemplo n.º 2
0
int LocalInteractive( sys_handle fh )
/*******************************/
{
    USHORT type;
    USHORT flags;

    //NYI: really should convert fh to sys_handle, but I know that it's
    // a one-to-one mapping
    if( DosQHandType( fh, &type, &flags ) ) {
        return( 0 );
    }
    if( type == 1 ) {   /* device type */
        return( 1 );
    }
    return( 0 );
}
Ejemplo n.º 3
0
_WCRTLINK int fstat( int handle, struct stat *buf )
#endif
{
    APIRET          error;
    OS_UINT         hand_type;
    OS_UINT         device_attr;
    FF_BUFFER       info;
    unsigned        iomode_flags;

    __handle_check( handle, -1 );

    buf->st_mode = 0;
    iomode_flags = __GetIOMode( handle );
    if( iomode_flags & _READ ) {
        buf->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
    }
    if( iomode_flags & _WRITE ) {
        buf->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
    }

    error = DosQHandType( handle, &hand_type, &device_attr );
    if( error ) {
        return( __set_errno_dos( error ) );
    }
    if( ( hand_type & ~HANDTYPE_NETWORK ) == HANDTYPE_FILE ) {
        /* handle file */
        error = DosQFileInfo( handle, FF_LEVEL, (PBYTE)&info, sizeof( info ) );
        if( error ) {
            return( __set_errno_dos( error ) );
        }
        buf->st_dev = buf->st_rdev = 0;
        /* handle timestamps */
        buf->st_ctime = _d2ttime( TODDATE( info.fdateCreation ),
                                  TODTIME( info.ftimeCreation ) );
        buf->st_atime = _d2ttime( TODDATE( info.fdateLastAccess ),
                                  TODTIME( info.ftimeLastAccess ) );
        buf->st_mtime = _d2ttime( TODDATE( info.fdateLastWrite ),
                                  TODTIME( info.ftimeLastWrite ) );
        buf->st_btime = buf->st_mtime;
#if defined( __INT64__ ) && !defined( _M_I86 )
        if( _FILEAPI64() ) {
#endif
            buf->st_attr = info.attrFile;
            buf->st_mode |= at2mode( info.attrFile );
            buf->st_size = info.cbFile;
#if defined( __INT64__ ) && !defined( _M_I86 )
        } else {
            buf->st_attr = ((FF_BUFFER_32 *)&info)->attrFile;
            buf->st_mode |= at2mode( ((FF_BUFFER_32 *)&info)->attrFile );
            buf->st_size = ((FF_BUFFER_32 *)&info)->cbFile;
        }
#endif
    } else {
        /* handle device */
        /* handle attributes */
        buf->st_attr = 0;
        buf->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
        if( ( hand_type & ~HANDTYPE_NETWORK ) == HANDTYPE_DEVICE ) {
            buf->st_mode |= S_IFCHR;
        } else if( ( hand_type & ~HANDTYPE_NETWORK ) == HANDTYPE_PIPE ) {
            buf->st_mode |= S_IFIFO;
        }
        buf->st_dev = buf->st_rdev = 1;
        /* handle timestamps */
        buf->st_atime = 0;
        buf->st_ctime = 0;
        buf->st_mtime = 0;
        buf->st_btime = 0;
        /* handle size */
        buf->st_size = 0;
    }
    buf->st_nlink = 1;
    buf->st_ino = handle;
    buf->st_uid = buf->st_gid = 0;

    buf->st_archivedID = 0;
    buf->st_updatedID = 0;
    buf->st_inheritedRightsMask = 0;
    buf->st_originatingNameSpace = 0;
    return( 0 );
}
Ejemplo n.º 4
0
bool LocalInteractive( sys_handle fh )
/************************************/
{
    APIRET type;
    APIRET flags;

    //NYI: really should convert fh to sys_handle, but I know that it's
    // a one-to-one mapping
#ifdef _M_I86
    if( DosQHandType( fh, &type, &flags ) ) {
#else
    if( DosQueryHType( fh, &type, &flags ) ) {
#endif
        return( false );
    }
    if( type == 1 ) {   /* device type */
        return( true );
    }
    return( false );
}

void LocalGetBuff( char *buff, unsigned size )
/********************************************/
{
    struct _STRINGINBUF length;

    if( size > UCHAR_MAX ) {
        size = UCHAR_MAX;
    }
    length.cb = size;
    length.cchIn = 0;
    if( KbdStringIn( buff, &length, 0, 0 ) ) {
        buff[0] = '\r';
        buff[1] = NULLCHAR;
        return;
    }
    buff[length.cchIn] = NULLCHAR;
}

error_handle LocalRename( const char *from, const char *to )
/**********************************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosMove( from, to, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosMove( from, to ), OP_LOCAL ) );
#endif
}

error_handle LocalMkDir( const char *name )
/*****************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosMkDir( name, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosCreateDir( name, NULL ), OP_LOCAL ) );
#endif
}

error_handle LocalRmDir( const char *name )
/*****************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosRmDir( name, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosDeleteDir( name ), OP_LOCAL ) );
#endif
}

error_handle LocalSetDrv( int drv )
/*********************************/
{
#ifdef _M_I86
    return( StashErrCode( DosSelectDisk( drv + 1 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosSetDefaultDisk( drv + 1 ), OP_LOCAL ) );
#endif
}

int LocalGetDrv( void )
/*********************/
{
    APIRET    drive;
    ULONG     map;

#ifdef _M_I86
    if( DosQCurDisk( &drive, &map ) ) {
#else
    if( DosQueryCurrentDisk( &drive, &map ) ) {
#endif
        return( -1 );
    }
    return( drive - 1 );
}

error_handle LocalSetCWD( const char *name )
/******************************************/
{
#ifdef _M_I86
    return( StashErrCode( DosChDir( name, 0 ), OP_LOCAL ) );
#else
    return( StashErrCode( DosSetCurrentDir( name ), OP_LOCAL ) );
#endif
}

long LocalGetFileAttr( const char *name )
/***************************************/
{
#ifdef _M_I86
    USHORT attr;

    if( DosQFileMode( name, &attr, 0 ) ) {
        return( -1L );
    }
    return( attr );
#else
    FILESTATUS3 fileinfo;

    if( DosQueryPathInfo( name, FIL_STANDARD, &fileinfo, sizeof( fileinfo ) ) ) {
        return( -1L );
    }
    return( fileinfo.attrFile );
#endif
}