コード例 #1
0
ファイル: inv_core.c プロジェクト: crossmeta/sgi
intgen_t
put_invtrecord( int fd, void *buf, size_t bufsz, off64_t off, 
	        int whence, bool_t dolock )
{
	int nwritten;
	
	if ( dolock )
		INVLOCK( fd, LOCK_EX );
	
	if ( lseek( fd, (off_t)off, whence ) < 0 ) {
		INV_PERROR( "Error in writing inventory record "
			    "(lseek failed): " );
		if ( dolock ) 
			INVLOCK( fd, LOCK_UN );
		return -1;
	}
	
	if (( nwritten = write( fd, buf, bufsz ) ) != (int) bufsz ) {
		INV_PERROR( "Error in writing inventory record :" );
		if ( dolock )
			INVLOCK( fd, LOCK_UN );
		return -1;
	}

	if ( dolock )
		INVLOCK( fd, LOCK_UN );
	return nwritten;
}
コード例 #2
0
ファイル: inv_core.c プロジェクト: crossmeta/sgi
intgen_t
get_invtrecord( int fd, void *buf, size_t bufsz, off64_t off, 
	        int whence, bool_t dolock )
{
	int  nread;
	
	ASSERT ( fd >= 0 );
	
	if ( dolock ) 
		INVLOCK( fd, LOCK_SH );

	if ( lseek( fd, (off_t)off, whence ) < 0 ) {
		INV_PERROR( "Error in reading inventory record "
			    "(lseek failed): " );
		if ( dolock ) 
			INVLOCK( fd, LOCK_UN );
		return -1;
	}
	
	nread = read( fd, buf, bufsz );

	if (  nread != (int) bufsz ) {
		INV_PERROR( "Error in reading inventory record :" );
		if ( dolock ) 
			INVLOCK( fd, LOCK_UN );
		return -1;
	}

	if ( dolock ) 
		INVLOCK( fd, LOCK_UN );

	return nread;
}
コード例 #3
0
ファイル: inv_core.c プロジェクト: crossmeta/sgi
intgen_t
get_headerinfo( int fd, void **hdrs, void **cnt,
	        size_t hdrsz, size_t cntsz, bool_t dolock )
{	
	int num; 

	/* get a lock on the table for reading */
	if ( dolock ) INVLOCK( fd, LOCK_SH );

	num = get_counters( fd, cnt, cntsz );

	/* If there are no sessions recorded yet, we're done too */
	if ( num > 0 ) {
		if ( get_headers( fd, hdrs, hdrsz * (size_t)num, cntsz ) < 0 ) {
			free ( *cnt );
			num = -1;
		}
	}

	if ( dolock ) INVLOCK( fd, LOCK_UN );
	return num;
}
コード例 #4
0
ファイル: inv_stobj.c プロジェクト: ystk/debian-xfsdump
/* NOTE: this doesnt update counters or headers in the inv_index */
int
stobj_create( char *fname )
{
	int fd;	
	invt_sescounter_t sescnt;
	inv_oflag_t forwhat = INV_SEARCH_N_MOD;

#ifdef INVT_DEBUG
	mlog( MLOG_VERBOSE | MLOG_INV, "INV: creating storage obj %s\n", fname);
#endif	

	/* create the new storage object */
	if (( fd = open( fname, INV_OFLAG(forwhat) | O_EXCL | O_CREAT, S_IRUSR|S_IWUSR )) < 0 ) {
		INV_PERROR ( fname );
		memset( fname, 0, INV_STRLEN );
		return -1;
	}
	
	INVLOCK( fd, LOCK_EX );
	fchmod( fd, INV_PERMS );
	
	sescnt.ic_vernum = INV_VERSION;
	sescnt.ic_curnum = 0; /* there are no sessions as yet */
	sescnt.ic_maxnum = INVT_STOBJ_MAXSESSIONS;
	sescnt.ic_eof = SC_EOF_INITIAL_POS;

	if ( PUT_SESCOUNTERS ( fd, &sescnt ) < 0 ) {
		memset( fname, 0, INV_STRLEN );
		INVLOCK( fd, LOCK_UN );
		close( fd );
		return -1;
	}
	
	INVLOCK( fd, LOCK_UN );
	return fd;
}
コード例 #5
0
ファイル: inv_stobj.c プロジェクト: ystk/debian-xfsdump
/*----------------------------------------------------------------------*/
intgen_t
stobj_insert_session( invt_idxinfo_t *idx,
		      int fd, /* kept locked EX by caller */
		      invt_sessinfo_t *s )
{
	invt_sescounter_t *sescnt = NULL;
	
	if ( GET_SESCOUNTERS( fd, &sescnt ) < 0 ) {
		INVLOCK( fd, LOCK_UN );
		return -1;
	}

	/* Check the existing sessions to make sure that we're not
	   duplicating this session */
	if ( sescnt->ic_curnum > 0 ) {
		u_int i;
		invt_session_t	*sessions = calloc( sescnt->ic_curnum, 
				   sizeof( invt_session_t ) );
		if ( GET_REC_NOLOCK( fd, sessions, sescnt->ic_curnum *
				     sizeof( invt_session_t ), 
				     (off64_t) ( sizeof( *sescnt ) + 
         		sescnt->ic_maxnum * sizeof( invt_seshdr_t ))) < 0 ) {
			free ( sescnt );
			free ( sessions );
			return -1;
		}

		for( i = 0; i <  sescnt->ic_curnum; i++ ) {
			if ( uuid_compare( sessions[i].s_sesid, 
					   s->ses->s_sesid ) == 0 )
				break;

		}
		free ( sessions );
		if ( i < sescnt->ic_curnum ) {
			mlog( MLOG_DEBUG | MLOG_INV, 
			      "INV: attempt to insert an "
			      "existing session.\n"
			     );
			free ( sescnt );
			return 1;
		}

	}

	if ( sescnt->ic_curnum >= sescnt->ic_maxnum ) {
		if ( stobj_split( idx, fd, sescnt, s ) < 0 ) {
			free( sescnt );
			return -1;
		}
		free( sescnt );
		return 1;
		
	}
			
	if ( stobj_put_session( fd, sescnt, s->ses, s->seshdr, s->strms,
			        s->mfiles ) < 0 ){
		free ( sescnt);
		return -1;
	}
	
	free ( sescnt);
	return 1;
}