Ejemplo n.º 1
0
static  void    ExClose( void ) {
//=========================

    byte        cl_stat;
    byte        op_stat;

    if( IOCB->flags & BAD_UNIT ) {
        IOErr( IO_IUNIT );
    }
    FindFtnFile();
    if( IOCB->fileinfo != NULL ) {
        CloseFile( IOCB->fileinfo );
        cl_stat = FindKWord( ClStatTab, STAT_SPEC, STATUS_UNKNOWN,
             ( IOCB->set_flags & SET_STATPTR ) ? IOCB->statptr : NULL );
        op_stat = IOCB->fileinfo->status;
        if( cl_stat == STATUS_UNKNOWN ) {
            cl_stat = STATUS_KEEP;
            if( op_stat == STATUS_SCRATCH ) {
                cl_stat = STATUS_DELETE;
            }
        }
        if( ( cl_stat == STATUS_KEEP ) && ( op_stat == STATUS_SCRATCH ) ) {
            IOErr( IO_ISTAT );
        }
        if( (cl_stat == STATUS_DELETE) && (IOCB->fileinfo->flags & FTN_FSEXIST) ) {
            CloseDeleteFile( IOCB->fileinfo );
        } else {
            CloseFile( IOCB->fileinfo );
        }
        DiscoFile( IOCB->fileinfo );
    }
}
Ejemplo n.º 2
0
static  void    InCplx( void ) {
//========================

    ftnfile     *fcb;
    uint        rpt;
    xcomplex    value;

    fcb = IOCB->fileinfo;
    fcb->col++;
    Blanks();
    GetFloat( &value.realpart, ( IOCB->typ - PT_CPLX_8 ) );
    Blanks();
    CheckEor();
    if( fcb->buffer[ fcb->col ] != ',' ) {
        IOErr( IO_BAD_CHAR );
    }
    fcb->col++;
    Blanks();
    CheckEor();
    GetFloat( &value.imagpart, ( IOCB->typ - PT_CPLX_8 ) );
    Blanks();
    if( fcb->buffer[ fcb->col ] != ')' ) {
        IOErr( IO_BAD_CHAR );
    }
    fcb->col++;
    rpt = IOCB->rptnum;
    for(;;) {
        switch( IOCB->typ ) {
        case PT_CPLX_8:
            ((scomplex PGM *)(IORslt.pgm_ptr))->realpart = value.realpart;
            ((scomplex PGM *)(IORslt.pgm_ptr))->imagpart = value.imagpart;
            break;
        case PT_CPLX_16:
            ((dcomplex PGM *)(IORslt.pgm_ptr))->realpart = value.realpart;
            ((dcomplex PGM *)(IORslt.pgm_ptr))->imagpart = value.imagpart;
            break;
        case PT_CPLX_32:
            ((xcomplex PGM *)(IORslt.pgm_ptr))->realpart = value.realpart;
            ((xcomplex PGM *)(IORslt.pgm_ptr))->imagpart = value.imagpart;
            break;
        default:
            IOErr( IO_FREE_MISMATCH );
            break;
        }
        FreeIOType();
        if( ( rpt-- <= 1 ) || ( IOCB->typ == PT_NOTYPE ) ) break;
    }
}
Ejemplo n.º 3
0
static void FOString( uint width ) {
//==================================

    ftnfile     *fcb;
    uint        length;

    fcb = IOCB->fileinfo;
    if( IOCB->typ != PT_CHAR ) {
        length = GetLen();
    } else {
        length = IORslt.string.len;
    }
    if( width == 0 ) {
        width = length;
    }
    if( fcb->col + width > fcb->bufflen ) {
        IOErr( IO_BUFF_LEN );
    }
    if( width > length ) {
        SendChar( ' ', width - length );
        width = length;
    }
    if( IOCB->typ == PT_CHAR ) {
        SendStrRtn( IORslt.string.strptr, width );
    } else {
        SendStrRtn( (char *)&IORslt, width );
    }
}
Ejemplo n.º 4
0
void    R_ChkType( PTYPE lower, PTYPE upper ) {
//===========================================

    if( ( IOCB->typ < lower ) || ( IOCB->typ > upper ) ) {
        IOErr( IO_FMT_MISMATCH );
    }
}
Ejemplo n.º 5
0
static  void    IUnBytes( char HPGM *dst, unsigned long len ) {
//=============================================================

    uint        amt;
    ftnfile     *fcb;
    char        *src;

    fcb = IOCB->fileinfo;
    if( IsFixed() && ( fcb->col + len > fcb->len ) ) {
        IOErr( IO_UNFMT_RECL );
    }
    src = fcb->buffer + fcb->col;
    for(;;) {
        amt = fcb->len - fcb->col;
        if( amt > len ) {
            amt = len;
        }
        pgm_memput( dst, src, amt );
        fcb->col += amt;
        len -= amt;
        if( len == 0 ) break;
        dst += amt;
        src = fcb->buffer;
        NextUnFmtRec();
    }
}
Ejemplo n.º 6
0
void    CloseFile( ftnfile *fcb ) {
//=================================

// Close a 'ftnfile'.

    file_handle         fh;

    if( fcb->fileptr == NULL ) return;
    if( fcb->fileptr == FStdIn ) return;
    if( fcb->fileptr == FStdOut ) {
        // check if standard output device redirected to a disk file
        if( ((a_file *)(fcb->fileptr))->attrs & BUFFERED ) {
            FlushBuffer( fcb->fileptr );
            ChkIOErr( fcb );
        }
        return;
    }
    if( fcb->fileptr == FStdErr ) return;
    Closef( fcb->fileptr );
    // save file handle
    fh = fcb->fileptr;
    // set file handle in fcb to NULL - we don't want
    // to get the i/o status from the file handle since
    // it will no longer be valid if the close succeeded
    fcb->fileptr = NULL;
    if( GetIOErr( fcb ) ) {
        // close failed so restore file handle in fcb
        fcb->fileptr = fh;
        IOErr( IO_FILE_PROBLEM );
    }
}
Ejemplo n.º 7
0
static  void    StreamUnFmtIn( void ) {
//===============================

    ftnfile     *fcb;

    fcb = IOCB->fileinfo;
    for(;;) {
        IOCB->typ = IOTypeRtn();
        if( IOCB->typ == PT_NOTYPE ) break;
        if( IOCB->typ == PT_CHAR ) {
            IUnStream( IORslt.string.strptr, IORslt.string.len );
        } else if( IOCB->typ == PT_ARRAY ) {

            uint        elmt_size;

            if( IORslt.arr_desc.typ == PT_CHAR ) {
                elmt_size = IORslt.arr_desc.elmt_size;
            } else {
                elmt_size = SizeVars[ IORslt.arr_desc.typ ];
            }
            IUnStream( IORslt.arr_desc.data,
                       IORslt.arr_desc.num_elmts * elmt_size );
        } else {
            fcb->len = SizeVars[ IOCB->typ ];
            if( fcb->len > fcb->bufflen ) {
                IOErr( IO_UNFMT_RECL );
            }
            NextRec();
            UnFmtItem( fcb->buffer );
        }
    }
}
Ejemplo n.º 8
0
void    ChkBuffLen( uint width ) {
//================================

    if( IOCB->fileinfo->col + width > IOCB->fileinfo->len ) {
        IOErr( IO_BUFF_LEN );
    }
}
Ejemplo n.º 9
0
static  void    RecordUnFmtIn( void ) {
//===============================

    ftnfile     *fcb;
    int         len;

    fcb = IOCB->fileinfo;
    NextRec();
    for(;;) {
        IOCB->typ = IOTypeRtn();
        if( IOCB->typ == PT_NOTYPE ) break;
        if( fcb->col == fcb->len ) {
            NextUnFmtRec();
        }
        if( IOCB->typ == PT_CHAR ) {
            IUnString();
        } else if( IOCB->typ == PT_ARRAY ) {
            IUnArray();
        } else {
            len = SizeVars[ IOCB->typ ];
            if( fcb->col + len > fcb->len ) {
                IOErr( IO_UNFMT_RECL );
            }
            UnFmtItem( fcb->buffer + fcb->col );
            fcb->col += len;
        }
    }
}
Ejemplo n.º 10
0
static  void    InNumber( void ) {
//==========================

    extended    value;
    intstar4    intval;
    int         col;

    col = IOCB->fileinfo->col; // save position in case of repeat specifier
    for(;;) {
        IOCB->fileinfo->col = col;
        if( IOCB->typ >= PT_REAL_4 ) {
            GetFloat( &value, ( IOCB->typ - PT_REAL_4 ) );
            switch( IOCB->typ ) {
            case PT_REAL_4:
                *(single PGM *)(IORslt.pgm_ptr) = value;
                break;
            case PT_REAL_8:
                *(double PGM *)(IORslt.pgm_ptr) = value;
                break;
            case PT_REAL_16:
                *(extended PGM *)(IORslt.pgm_ptr) = value;
                break;
            default:
                IOErr( IO_FREE_MISMATCH );
                break;
            }
        } else {
            GetInt( &intval );
            switch( IOCB->typ ) {
            case PT_INT_1:
                *(intstar1 PGM *)(IORslt.pgm_ptr) = intval;
                break;
            case PT_INT_2:
                *(intstar2 PGM *)(IORslt.pgm_ptr) = intval;
                break;
            case PT_INT_4:
                *(intstar4 PGM *)(IORslt.pgm_ptr) = intval;
                break;
            default:
                IOErr( IO_FREE_MISMATCH );
                break;
            }
        }
        FreeIOType();
        if( ( IOCB->rptnum-- <= 1 ) || ( IOCB->typ == PT_NOTYPE ) ) break;
    }
}
Ejemplo n.º 11
0
void    SendEOR( void ) {
//=================

    ftnfile     *fcb;
    int         len;
    bool        ifile;

    fcb = IOCB->fileinfo;
    ifile = fcb->internal != NULL;
    if( ifile ) {
        if( fcb->flags & FTN_EOF ) {
            IOErr( IO_IFULL );
        }
        if( fcb->recnum >= IOCB->elmts ) {
            fcb->flags |= FTN_EOF;
            SendIFBuff( fcb->buffer, fcb->bufflen, fcb->recnum, fcb->internal );
        } else {
            SendIFBuff( fcb->buffer, fcb->bufflen, fcb->recnum, fcb->internal );
            memset( fcb->buffer, ' ', fcb->bufflen );
        }
    } else {
        if( IsFixed() ) {
            fcb->col = fcb->bufflen;
        }
        if( fcb->fileptr != NULL ) {
            FPutBuff( fcb );
            ChkIOErr( fcb );
        }
    }
    // Write to the listing file after we've written to DB_STD_OUTPUT so
    // that if we get an error writing to the listing file, the buffer for
    // DB_STD_OUTPUT will be empty (i.e. when we report the error writing
    // to the listing file we will need to use DB_STD_OUTPUT's buffer).
    // Note that we have to set fcb->col to 0 so that the error message
    // will go at the beginning of the buffer.
    len = fcb->col;
    fcb->col = 0;
    if( ( IOCB->flags & IOF_NOCR ) == 0 ) {
        UpdateRecNum( fcb );
        // eofrecnum used to be updated in ExWrite().
        // We MUST set eofrecnum here in case we abort the WRITE and
        // suicide which will NOT return to ExWrite().
        // If we don't do this here, the next time a WRITE is executed
        // on this unit, we get IO_PAST_EOF error.
        if( !ifile && !NoEOF( fcb ) ) {
            if( fcb->accmode <= ACCM_SEQUENTIAL ) {
                fcb->eofrecnum = fcb->recnum;
            }
        }
        if( !ifile ) {
            memset( fcb->buffer, ' ', fcb->bufflen );
        }
    }
    IOCB->flags &= ~IOF_NOCR;
}
Ejemplo n.º 12
0
static void NextUnFmtRec( void ) {
//================================

    if( _LogicalRecordOrganization( IOCB->fileinfo ) ) {
        if( CheckLogicalRecord( IOCB->fileinfo ) ) {
            NextRec();
            return;
        }
    }
    IOErr( IO_UNFMT_RECL );
}
Ejemplo n.º 13
0
static  void    GetInt( intstar4 *result ) {
//==========================================

    ftnfile     *fcb;
    char        *start;
    uint        len;
    int         status;

    fcb = IOCB->fileinfo;
    start = fcb->buffer + fcb->col;
    len = GetDelim( start, fcb->buffer + fcb->len ) - start;
    status = FmtS2I( start, len, false, result, false, NULL );
    if( status == INT_OK ) {
        fcb->col += len;
    } else if( status == INT_INVALID ) {
        IOErr( IO_BAD_CHAR );
    } else {
        IOErr( IO_IOVERFLOW );
    }
}
Ejemplo n.º 14
0
static  void    FreeIOErr( uint err ) {
//=====================================

// Report error during list-directed or NAMELIST-directed i/o.

    if( IOCB->flags & NML_DIRECTED ) {
        IOCB->flags |= NML_CONTINUE;
        RTSuicide();
    }
    IOErr( err );
}
Ejemplo n.º 15
0
static  void    FmtPrepOp( void ) {
//===========================

    ftnfile     *fcb;
    byte        width;

    fcb = IOCB->fileinfo;
    width = IOCB->fmtptr->fmt1.fld1;
    if( width + fcb->col > fcb->bufflen ) {
        IOErr( IO_BUFF_LEN );
    }
}
Ejemplo n.º 16
0
void    R_FIInt( void ) {
//=================

    intstar4    value;
    uint        width;
    uint        new_width;
    int         status;
    ftnfile     *fcb;
    bool        comma;

    fcb = IOCB->fileinfo;
    width = IOCB->fmtptr->fmt2.fld1;
    ChkBuffLen( width );
    comma = __AllowCommaSep();
    status = FmtS2I( fcb->buffer + fcb->col, width, ( fcb->blanks == BLANK_ZERO ), &value, comma, &new_width );
    if( status == INT_INVALID ) {
        IOErr( IO_BAD_CHAR );
    } else if( status == INT_OVERFLOW ) {
        IOErr( IO_IOVERFLOW );
    } else {
        if( comma && ( width != new_width ) ) { // use comma as field separator
            fcb->col += new_width;
            if( fcb->buffer[ fcb->col ] == ',' ) {
                fcb->col++;
            } else {
                IOErr( IO_BAD_CHAR );
            }
        } else {
            fcb->col += width;
        }
        if( IOCB->typ == PT_INT_1 ) {
            *(intstar1 PGM *)(IORslt.pgm_ptr) = value;
        } else if( IOCB->typ == PT_INT_2 ) {
            *(intstar2 PGM *)(IORslt.pgm_ptr) = value;
        } else {
            *(intstar4 PGM *)(IORslt.pgm_ptr) = value;
        }
    }
}
Ejemplo n.º 17
0
static  void    GetFloat( extended *result, int prec ) {
//======================================================

    ftnfile     *fcb;
    char        *start;
    uint        len;
    int         status;

    fcb = IOCB->fileinfo;
    start = fcb->buffer + fcb->col;
    len = GetDelim( start, fcb->buffer + fcb->len ) - start;
    status = FmtS2F( start, len, 0, false, 0, prec, result, false, NULL, false );
    if( status == FLT_OK ) {
        fcb->col += len;
    } else {
        if( status == FLT_INVALID ) {
            IOErr( IO_BAD_CHAR );
        } else { // FLT_RANGE_EXCEEDED
            IOErr( IO_FRANGE_EXCEEDED );
        }
    }
}
Ejemplo n.º 18
0
void    SysCreateFile( ftnfile *fcb ) {
//=====================================

// Cause the file to exist in the file system.

    fcb->fileptr = Openf( fcb->filename, REC_TEXT | WRONLY );
    if( fcb->fileptr != NULL ) {
        Closef( fcb->fileptr );
        fcb->fileptr = NULL;
        fcb->flags |= FTN_FSEXIST;
    } else {
        IOErr( IO_FILE_PROBLEM );
    }
}
Ejemplo n.º 19
0
static  void    InString( void ) {
//===========================

    int         save_col;

    if( IOCB->rptnum == 0 ) {
        if( IOCB->typ != PT_CHAR ) {
            IOErr( IO_FREE_MISMATCH );
        }
        GetString();
        FreeIOType();
    } else {
        save_col = IOCB->fileinfo->col;
        for(;;) {
            if( IOCB->typ != PT_CHAR ) {
                IOErr( IO_FREE_MISMATCH );
            }
            IOCB->fileinfo->col = save_col;
            GetString();
            FreeIOType();
            if( ( IOCB->rptnum-- <= 1 ) || ( IOCB->typ == PT_NOTYPE ) ) break;
        }
    }
}
Ejemplo n.º 20
0
static int do_revert(int err, struct dentry *wh_dentry, struct dentry *dentry,
		     aufs_bindex_t bwh, struct dtime *dt, int dlgt)
{
	int rerr;

	rerr = au_unlink_wh_dentry(wh_dentry->d_parent->d_inode, wh_dentry,
				   dentry, dlgt);
	//rerr = -1;
	if (!rerr) {
		set_dbwh(dentry, bwh);
		dtime_revert(dt, !CPUP_LOCKED_GHDIR);
		return 0;
	}

	IOErr("%.*s reverting whiteout failed(%d, %d)\n",
	      DLNPair(dentry), err, rerr);
	return -EIO;
}
Ejemplo n.º 21
0
void    R_FILog( void ) {
//=================

    ftnfile     *fcb;
    uint        width;
    char        ch;

    fcb = IOCB->fileinfo;
    width = IOCB->fmtptr->fmt1.fld1;
    ChkBuffLen( width );
    for(;;) {
        if( fcb->buffer[ fcb->col ] != ' ' ) break;
        fcb->col++;
        if( --width == 0 ) break;
    }
    if( fcb->buffer[ fcb->col ] == '.' ) {
         --width;
         fcb->col++;
    }
    if( width == 0 ) {
        IOErr( IO_BAD_CHAR );
    } else {
        ch = toupper( fcb->buffer[ fcb->col ] );
        if( ch == 'F' ) {
            SetLogValue( _LogValue( false ) );
        } else if( ch == 'T' ) {
            SetLogValue( _LogValue( true ) );
        }
    }
    if( __AllowCommaSep() ) { // don't flush but search for comma separator
        fcb->col++;
        width--;
        while( width > 0 ) {
            if( fcb->buffer[ fcb->col ] == ',' ) {
                fcb->col++;
                break;
            }
            fcb->col++;
            width--;
        }
    } else {
        fcb->col += width; // flush over other stuff
    }
}
Ejemplo n.º 22
0
static  void    InLog( void ) {
//=======================

    ftnfile     *fcb;
    logstar4    value;
    char        *chptr;

    fcb = IOCB->fileinfo;
    chptr = &fcb->buffer[ fcb->col ];
    if( toupper( *chptr ) == 'T' ) {
        value = _LogValue( true );
    } else {
        value = _LogValue( false );
    }
    for(;;) {
        chptr++;
        fcb->col++;
        if( fcb->col == fcb->len )
            break;
        switch( *chptr ) {
        case ' ':
        case '\t':
        case '/':
        case ',':
            goto big_break;
        }
    }
big_break:
    for(;;) {
        switch( IOCB->typ ) {
        case PT_LOG_1:
            *(logstar1 PGM *)(IORslt.pgm_ptr) = value;
            break;
        case PT_LOG_4:
            *(logstar4 PGM *)(IORslt.pgm_ptr) = value;
            break;
        default:
            IOErr( IO_FREE_MISMATCH );
            break;
        }
        FreeIOType();
        if( ( IOCB->rptnum-- <= 1 ) || ( IOCB->typ == PT_NOTYPE ) ) break;
    }
}
Ejemplo n.º 23
0
void    CloseDeleteFile( ftnfile *fcb ) {
//=======================================

// Close and delete 'ftnfile'.

    bool win_con = false;

#if defined( __IS_WINDOWED__ )
    if( fcb->fileptr ) {

        win_con = _dwDeleteOnClose( ((a_file *)(fcb->fileptr))->handle );
    }
#endif
    CloseFile( fcb );
    if( win_con )
        return;
    if( Scrtched( fcb ) )
        return;
    IOErr( IO_FILE_PROBLEM );
}
Ejemplo n.º 24
0
static  void   R_FEH( uint dummy1 , char dummy2 ) {
//======================

    ftnfile     *fcb;
    uint        len;
    char PGM    *str;

    fcb = IOCB->fileinfo;
    if( IOCB->flags & IOF_OUTPT ) {
        len = IOCB->fmtptr->fmtstring.fld1;
        if( fcb->col + len > fcb->bufflen ) {
            IOErr( IO_BUFF_LEN );
        }
        str = IOCB->fmtptr->fmtstring.str;
        SendStr( str, len );
    } else {
        RTErr( FM_NOT_INP );
    }
    R_ChkRecLen();
    IOCB->fmtptr = (fmt_desc PGM *)((char PGM *)IOCB->fmtptr + sizeof( fmt4 ) +
                           len * sizeof( char ));
}
Ejemplo n.º 25
0
static  void    RptNum( void ) {
//========================

    ftnfile     *fcb;
    int col;
    signed_32   num;

    fcb = IOCB->fileinfo;
    col = fcb->col;
    num = GetNum();
    if( fcb->buffer[ fcb->col ] == '*' ) {
        if( num > 0 ) {
            fcb->col++;
        } else {
            IOErr( IO_BAD_CHAR );
        }
    } else {
        fcb->col = col;
        num = 0;
    }
    IOCB->rptnum = num;
}
Ejemplo n.º 26
0
void    R_FIHex( void ) {
//=================

    uint        width;
    int         len;
    ftnfile     *fcb;
    PTYPE       typ;
    void        PGM *ptr;

    fcb = IOCB->fileinfo;
    width = IOCB->fmtptr->fmt1.fld1;
    len =  GetLen();
    typ = IOCB->typ;
    ChkBuffLen( width );
    if( typ == PT_CHAR ) {
        ptr = IORslt.string.strptr;
    } else {
        ptr = IORslt.pgm_ptr;
        if( typ == PT_CPLX_8 ) {
            if( IOCB->flags & IOF_FMTREALPART ) {
                ptr = &((scomplex *)ptr)->realpart;
            } else {
                ptr = &((scomplex *)ptr)->imagpart;
            }
        } else if( typ == PT_CPLX_16 ) {
            if( IOCB->flags & IOF_FMTREALPART ) {
                ptr = &((dcomplex *)ptr)->imagpart;
            } else {
                ptr = &((dcomplex *)ptr)->imagpart;
            }
        }
    }
    if( !FmtH2B( &fcb->buffer[ fcb->col ], width, ptr, len, typ ) ) {
        IOErr( IO_BAD_CHAR );
    }
    fcb->col += width;
}
Ejemplo n.º 27
0
static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
			   struct aufs_nhash *whlist, struct inode *dir)
{
	int rmdir_later, err;
	struct dentry *hidden_dentry;

	LKTRTrace("%.*s, b%d\n", DLNPair(dentry), bindex);

	err = rename_whtmp(dentry, bindex);
	//err = -1;
	//todo: bug
	if (unlikely(err)) {
		au_direval_inc(dentry->d_parent);
		return err;
	}

	hidden_dentry = au_h_dptr_i(dentry, bindex);
	if (!au_is_nfs(hidden_dentry->d_sb)) {
		const int dirwh = stosi(dentry->d_sb)->si_dirwh;
		rmdir_later = (dirwh <= 1);
		if (!rmdir_later)
			rmdir_later = is_longer_wh(whlist, bindex, dirwh);
		if (rmdir_later)
			return rmdir_later;
	}

	err = rmdir_whtmp(hidden_dentry, whlist, bindex, dir, dentry->d_inode);
	//err = -1;
	if (unlikely(err)) {
		IOErr("rmdir %.*s, b%d failed, %d. ignored\n",
		      DLNPair(hidden_dentry), bindex, err);
		err = 0;
	}
	TraceErr(err);
	return err;
}
Ejemplo n.º 28
0
static  void    SysIOInfo( ftnfile *fcb ) {
//=========================================

// Get system file information.

    struct stat         info;
    char                *sys_name;
    bool                exist = true;

    if( fcb->bufflen == 0 ) {
        fcb->bufflen = SYS_DFLT_RECSIZE;
    }
    if( fcb->blocksize == 0 ) {
        fcb->blocksize = IO_BUFFER;
    }
    fcb->device = 0;
    if( fcb->fileptr != NULL ) { // file is open
#if defined( __NETWARE__ )
        if( ( ((a_file *)(fcb->fileptr))->handle == STDIN_FILENO ) ||
            ( ((a_file *)(fcb->fileptr))->handle == STDOUT_FILENO ) ||
            ( ((a_file *)(fcb->fileptr))->handle == STDERR_FILENO ) ) {
            fcb->device |= INFO_DEV;
        } else {
#endif
        // for stdin, don't use file name "CON" since information will always
        // indicate it's a device even if stdin is redirected
            if( fstat( ((a_file *)(fcb->fileptr))->handle, &info ) == -1 ) {
                FSetSysErr( fcb->fileptr );
                IOErr( IO_FILE_PROBLEM );
                return;
            }
            if( S_ISCHR( info.st_mode ) ) {
                fcb->device |= INFO_DEV;
#if defined( __DOS__ ) || defined( __WINDOWS__ )
            } else {
                fcb->device |= INFO_VALID_DRIVE;
#endif
            }
#if defined( __NETWARE__ )
        }
#endif
    } else {
        if( stat( fcb->filename, &info ) == -1 ) {
            // if we are trying to open a file in a non-existent
            // directory we don't want to issue an error
            if( fcb->flags & FTN_FSEXIST ) {
                FSetSysErr( fcb->fileptr );
                IOErr( IO_FILE_PROBLEM );
                return;
            }
            exist = false;
        } else if( S_ISCHR( info.st_mode ) ) {
            fcb->device |= INFO_DEV;
            // devices always exist
            fcb->flags |= FTN_FSEXIST;
#if !defined( __UNIX__ )
        } else {
            fcb->device |= INFO_VALID_DRIVE;
#endif
        }
    }
    if( ( fcb->flags & FTN_FSEXIST ) && !IsDevice( fcb ) ) {
#if !defined( __UNIX__ )
        // Assume the two most significant bits contain no useful information
        fcb->device = INFO_DRIVE & info.st_dev; // save drive letter
#endif
        if( ( info.st_mode & S_IRUSR ) && ( info.st_mode & S_IWUSR ) ) {
            fcb->action = ACTION_RW;
        } else if( info.st_mode & S_IRUSR ) {
            fcb->action = ACTION_READ;
        } else if( info.st_mode & S_IWUSR ) {
            fcb->action = ACTION_WRITE;
        } else {
            // if none of the above are set,
            // assume read/write
            fcb->action = ACTION_RW;
        }
    }
    sys_name = GetSysName( fcb );
    if( sys_name == NULL ) {
        if( exist ) {
            FSetSysErr( fcb->fileptr );
            IOErr( IO_FILE_PROBLEM );
        }
        return;
    }
    RMemFree( fcb->filename );
    fcb->filename = sys_name;
}
Ejemplo n.º 29
0
void    IOPrologue( void ) {
//====================

    ftnfile     *fcb;
    byte        form;
    byte        accm;

    IOCB->typ = PT_NOT_STARTED;
    if( IOCB->flags & BAD_REC ) {
        IOErr( IO_IREC );
    }
    if( IOCB->set_flags & SET_INTERNAL ) {
        F_Connect();
    } else {
        ChkUnitId();
        FindFtnFile();
        if( IOCB->fileinfo == NULL ) {
            IOCB->set_flags &= ~SET_FILENAME;
            ConnectFile();
        }
    }
    fcb = IOCB->fileinfo;
    if( fcb->action == ACT_DEFAULT ) {
        fcb->action = ACTION_RW;
    }
    ChkIOOperation( fcb );
    if( fcb->cctrl == CC_DEFAULT ) {
        fcb->cctrl = CC_NO;
    }
    accm = fcb->accmode;
    if( accm == ACCM_DEFAULT ) {
        if( IOCB->set_flags & SET_RECORDNUM ) {
            accm = ACCM_DIRECT;
        } else {
            accm = ACCM_SEQUENTIAL;
        }
        fcb->accmode = accm;
    } else {
        if( ( accm == ACCM_DIRECT ) && (IOCB->set_flags & SET_RECORDNUM) == 0 ) {
            IOErr( IO_REC1_ACCM );
        } else if( ( ( accm == ACCM_SEQUENTIAL ) || ( accm == ACCM_APPEND ) ) &&
                   (IOCB->set_flags & SET_RECORDNUM) ) {
            IOErr( IO_REC2_ACCM );
        }
    }
    if( accm == ACCM_DIRECT ) {
        fcb->recnum = IOCB->recordnum; // set up recordnumber
    }
    form = fcb->formatted;
    if( form == 0 ) {                    // set up format if it was
        if( (IOCB->flags & IOF_NOFMT) == 0 ) {     // not previously set
            form = FORMATTED_IO;
        } else {
            form = UNFORMATTED_IO;
        }
        fcb->formatted = form;
    } else {
        if( (form == FORMATTED_IO) && (IOCB->flags & IOF_NOFMT) ) {
            IOErr( IO_AF1 );
        } else if( (form == UNFORMATTED_IO) && (IOCB->flags & IOF_NOFMT) == 0 ) {
            IOErr( IO_AF2 );
        }
    }
    if( fcb->internal != NULL ) {
        fcb->bufflen = fcb->internal->len;
        fcb->buffer = RChkAlloc( fcb->bufflen );
    } else {
        if( ( accm <= ACCM_SEQUENTIAL ) &&
            ( fcb->eofrecnum != 0 ) &&
            ( fcb->recnum >= fcb->eofrecnum ) &&
            // Consider: READ( 1, *, END=10 )
            //           ...
            //     10    WRITE( 1, * ) 'write after EOF'
            // if an EOF condition was encounterd, we don't want IO_PAST_EOF
            // on the write
            (IOCB->flags & IOF_OUTPT) == 0 ) {
            if( fcb->recnum != fcb->eofrecnum ) {
                IOErr( IO_PAST_EOF );
            } else {
                fcb->recnum++;
                SysEOF();
            }
        }
        _AllocBuffer( fcb );
        if( fcb->fileptr == NULL ) {
            DoOpen();
        }
        if( fcb->accmode == ACCM_DIRECT ) {
            SeekFile( fcb );
            ChkIOErr( fcb );
        }
        fcb->col = 0;
    }
    if( (IOCB->flags & IOF_OUTPT) && ( fcb->col == 0 ) ) {
        memset( fcb->buffer, ' ', fcb->bufflen );
    }
}
Ejemplo n.º 30
0
/*
 * copyup the deleted file for writing.
 */
static int cpup_wh_file(struct file *file, aufs_bindex_t bdst, loff_t len)
{
	int err;
	struct dentry *dentry, *parent, *hidden_parent, *tmp_dentry;
	struct dentry *hidden_dentry_bstart, *hidden_dentry_bdst;
	struct inode *hidden_dir;
	aufs_bindex_t bstart;
	struct aufs_dinfo *dinfo;
	struct dtime dt;
	struct lkup_args lkup;
	struct super_block *sb;

	dentry = file->f_dentry;
	LKTRTrace("%.*s, bdst %d, len %Lu\n", DLNPair(dentry), bdst, len);
	DEBUG_ON(S_ISDIR(dentry->d_inode->i_mode)
		 || !(file->f_mode & FMODE_WRITE));
	DiMustWriteLock(dentry);
	parent = dentry->d_parent;
	IiMustAnyLock(parent->d_inode);
	hidden_parent = au_h_dptr_i(parent, bdst);
	DEBUG_ON(!hidden_parent);
	hidden_dir = hidden_parent->d_inode;
	DEBUG_ON(!hidden_dir);
	IMustLock(hidden_dir);

	sb = parent->d_sb;
	lkup.nfsmnt = au_nfsmnt(sb, bdst);
	lkup.dlgt = need_dlgt(sb);
	tmp_dentry = lkup_whtmp(hidden_parent, &dentry->d_name, &lkup);
	//if (LktrCond) {dput(tmp_dentry); tmp_dentry = ERR_PTR(-1);}
	err = PTR_ERR(tmp_dentry);
	if (IS_ERR(tmp_dentry))
		goto out;

	dtime_store(&dt, parent, hidden_parent);
	dinfo = dtodi(dentry);
	bstart = dinfo->di_bstart;
	hidden_dentry_bdst = dinfo->di_hdentry[0 + bdst].hd_dentry;
	hidden_dentry_bstart = dinfo->di_hdentry[0 + bstart].hd_dentry;
	dinfo->di_bstart = bdst;
	dinfo->di_hdentry[0 + bdst].hd_dentry = tmp_dentry;
	dinfo->di_hdentry[0 + bstart].hd_dentry = au_h_fptr(file)->f_dentry;
	err = cpup_single(dentry, bdst, bstart, len,
			  au_flags_cpup(!CPUP_DTIME, parent));
	//if (LktrCond) err = -1;
	if (!err)
		err = au_reopen_nondir(file);
		//err = -1;
	if (unlikely(err)) {
		dinfo->di_hdentry[0 + bstart].hd_dentry = hidden_dentry_bstart;
		dinfo->di_hdentry[0 + bdst].hd_dentry = hidden_dentry_bdst;
		dinfo->di_bstart = bstart;
		goto out_tmp;
	}

	DEBUG_ON(!d_unhashed(dentry));
	err = vfsub_unlink(hidden_dir, tmp_dentry, lkup.dlgt);
	//if (LktrCond) err = -1;
	if (unlikely(err)) {
		IOErr("failed remove copied-up tmp file %.*s(%d)\n",
		      DLNPair(tmp_dentry), err);
		err = -EIO;
	}
	dtime_revert(&dt, !CPUP_LOCKED_GHDIR);

 out_tmp:
	dput(tmp_dentry);
 out:
	TraceErr(err);
	return err;
}