示例#1
0
文件: regdblk.c 项目: mingpen/OpenNT
VOID
INTERNAL
RgSweepDatablocks(
    LPFILE_INFO lpFileInfo
    )
{

    UINT BlocksLeft;
    LPDATABLOCK_INFO lpDatablockInfo;

    for (BlocksLeft = lpFileInfo-> FileHeader.BlockCount, lpDatablockInfo =
        lpFileInfo-> lpDatablockInfo; BlocksLeft > 0; BlocksLeft--,
        lpDatablockInfo++) {

        if (((lpDatablockInfo-> Flags & (DIF_PRESENT | DIF_ACCESSED |
            DIF_DIRTY)) == DIF_PRESENT) && (lpDatablockInfo-> LockCount == 0)) {

            NOISE(("discarding datablock #%d of ",
                lpFileInfo-> FileHeader.BlockCount - BlocksLeft));
            NOISE((lpFileInfo-> FileName));
            NOISE(("\n"));

            RgFreeDatablockInfoBuffers(lpDatablockInfo);

            lpDatablockInfo-> Flags = 0;

        }

        //  Reset the accessed bit for the next sweep.
        lpDatablockInfo-> Flags &= ~DIF_ACCESSED;

    }

}
示例#2
0
文件: model.cpp 项目: dmalmer/EMG
//randomally seed the sigma, pi, lambda ws etc...
void component::initialize_bounds(double mu, segment * data , int K, double scale, double noise_w, 
	double termination, double fp, double forward_bound, double reverse_bound){//random seeds...
	foot_print 	= fp;
	EXIT=false;
	if (noise_w>0){
		noise 	= NOISE(data->minX, data->maxX, 
			noise_w, 0.5);
		type 	= 0; 
	}else{

		int complexity=1;
		if (data->strand == "."){
			complexity=3;
		}else{
			complexity=2;
		}

		//====================================
		random_device rd;
		mt19937 mt(rd());
		
		double sigma,lambda, pi_EMG, w_EMG  ;	
		double b_forward,  w_forward;
		double a_reverse,  w_reverse;

		//====================================
		//start sampling
		//for the bidirectional/EMG component
		uniform_real_distribution<double> dist_lambda_2(1, 250);
		uniform_real_distribution<double> dist_sigma_2(1, 250);
		gamma_distribution<double> dist_lengths(1,( (data->maxX-data->minX)/(K)));
		
		sigma 				= dist_sigma_2(mt)/scale;
		lambda 				= scale/dist_lambda_2(mt) ;
		double dist 		=  (1.0/lambda);
		int j 				= get_nearest_position(data, mu, dist);
		int k 				= get_nearest_position(data, mu, forward_bound-mu);
		double pi 			= 0.5;
		if (data->strand == "+"){
			pi 				= 1.0;
		}else if (data->strand=="-") {
			pi 				= 0.;
		}
		forward 			= UNI(mu+(1.0/lambda), data->maxX, 1.0 / (complexity*K), 1, j, pi);
		forward.j=j, forward.k=k;
		

		bidir 				= EMG(mu, sigma, lambda, 1.0 / (complexity*K), 0.5);
		bidir.foot_print 	= fp;
		dist 				=  -(1.0/lambda);
		j 					= get_nearest_position(  data, mu, dist);
		k 					= get_nearest_position(data, mu, reverse_bound-mu);
		reverse 			= UNI(data->minX, mu-(1.0/lambda),  1.0 / (complexity*K) , -1, j,1-pi);
		reverse.j=k, reverse.k=j;
		termination 		= (termination > 1);
		
		type 		= 1;
		
	}
} 
示例#3
0
float Speckle::SpeckleFunc(Point3 p) {
	float sum, s, q[3];

	s = 1.0f;
	sum = 0.0f;
	q[0] = p.x; q[1] = p.y; q[2] = p.z;
	for (int i = 0; i < 6; i++) {
		sum += NOISE(q)/s;
		s *= 2.0f;
		q[0] *= 2.0f; q[1] *= 2.0f; q[2] *= 2.0f;
	}
	return(sum);
}
示例#4
0
float Splat::splatter(Point3 p) {
	float fact, ss, q[3], t;

	q[0] = p[0]/size;
	q[1] = p[1]/size;
	q[2] = p[2]/size;
	fact = 1.0f;
	for (int i = 0; i < iter; i++) {
		t = NOISE(q);
		if (t > 1.0) 
			t = 1.0f;
		ss = smoothstep(thresh-EPSILON, thresh+EPSILON, t);
		fact *= ss;
		q[0] *= 2.0f;	q[1] *= 2.0f;	q[2] *= 2.0f;
	}
	return(1.0f-fact);
}
示例#5
0
/*
 * NAME:        jfs_lookup(dvp, vpp, pname, flag, vattrp, crp)
 *
 * FUNCTION:    resolve <pname> in directory <dvp> to vnode <vpp>
 *              with a reference acquired and attribute <vattrp>.
 *
 * PARAMETERS:  dvp     _ directory vnode
 *              vpp     - object vnode (out)
 *              pname   - object name
 *              flag    -
 *              vattrp  - object attribute (out)
 *              crp     - credential
 *
 * RETURN:      errors from subroutines.
 */
jfs_lookup(
        struct vnode    *dvp,
        struct vnode    **vpp,
	UniChar		*pname, /* NULL terminated */
        int32           flag,
        struct vattr    *vattrp,
        struct ucred    *crp)
{
        int32   rc = 0;
        struct vfs      *vfsp = dvp->v_vfsp;
        inode_t *dip = VP2IP(dvp);      /* parent directory inode */
        ino_t   ino;            /* object i_number */
        inode_t *ip;            /* object inode */
        component_t     dname;  /* object name */
        ncookie_t       ncookie;
        btstack_t       btstack;

NOISE(1,("jfs_lookup: dip:0x%08x name:%s\n", dip, pname));

        *vpp = NULL;

        /* <dvp> must be a directory */
        if ((dip->i_mode & IFMT) != IFDIR)
                return ENOTDIR;

        IREAD_LOCK(dip);

        if (dip->i_nlink == 0)
        {
                rc = ENOENT;
                goto out;
        }

        /*
         * resolve name to i_number via dnlc/directory lookup
         */
getInumber:

        /*
         * for "." or "..", lookup directory inode
         */
        if (pname[0] == '.')
        {
                /* looking up ".." */
                if (pname[1] == '.' && pname[2] == '\0')
                {
                        ino = dip->i_parent;
                        goto getInode;
                }
                /* looking up "." */
                else if (pname[1] == '\0')
                {
                        ip = dip;

                        jfs_hold(dvp);

                        *vpp = dvp;
                        goto getAttribute;
                }
        }

        /*
         * search dnlc/directory
         */
        dname.name = pname;
	dname.namlen = UniStrlen(pname);
        if ((ino = ncLookup(dip->i_ipimap, dip->i_number, &dname, &ncookie)) == 0)
        {
                /*
                 * dnlc miss: search directory
                 */
                if (rc = dtSearch(dip, &dname, &ino, &btstack, JFS_LOOKUP))
                        goto out;

                /* insert name entry to dnlc */
                ncEnter(dip->i_ipimap, dip->i_number, &dname, ino, &ncookie);
        }

        /*
         * resolve i_number to inode/vnode with a reference
         */
getInode:
        ICACHE_LOCK();
        rc = iget(vfsp, ino, &ip, 0);
        ICACHE_UNLOCK();
        if (rc)
                goto out;

        *vpp = IP2VP(ip);

        /*
         * get attribute
         */
getAttribute:
        if (vattrp != NULL)
                get_vattr(ip, vattrp);

out:
        IREAD_UNLOCK(dip);

NOISE(1,("jfs_lookup: rc:%d\n", rc));
        return rc;
}
示例#6
0
/*
 * NAME:	jfs_statfs(vfsp, sfsp, crp)
 *
 * FUNCTION:	get file system status <sfsp> from vfs <vfsp>
 *
 * PARAMETER:	vfsp	- virtual file system
 *		sfsp	- file status information structure
 *		crp	- credential
 *
 * RETURN:	zero on success, non-zero on failure
 *			
 * serialization: statfs() and extendfs() serializes by inode lock
 *	of the inode map for both inode map and block allocation map. 
 *	All other access to fragment allocation map is serialized 
 *	under VMM locking.
 *
 * note: percolation of file system information:
 * support struct statfs (sys/statfs.h) for get file system status
 * service call statfs().
 * (XPG4.2 defines struct statvfs in sys/statvfs.h for statvfs()
 * which requires statfs() and additional information)
 */
jfs_statfs(
	register struct vfs	*vfsp,
	register struct statfs	*statfsp,
	struct ucred		*crp)
{
	register int32	rc;
	register inode_t *ipmnt;	/* mount inode */
	inode_t	*ipimap, *ipbmap;
	cbuf_t	*bpsuper;
	struct superblock *sb = NULL;
	int32	fsck_length, log_length;

NOISE(1,("jfs_statfs: vfs:0x%08x\n", vfsp));

	/*
	 * get the file system stats from the superblock
	 */
	ipimap = (struct inode *)vfsp->vfs_data;
	ipmnt = ipimap->i_ipmnt;
	if (rc = readSuper(ipmnt, &bpsuper))
		goto out;
	sb = (struct superblock *)(bpsuper->cm_cdata);

/*
	bcopy(sb->s_fname, statfsp->f_fname, sizeof(sb->s_fname));
*/
	bcopy(sb->s_fpack, statfsp->f_fpack, sizeof(sb->s_fpack));
	statfsp->f_bsize = PSIZE; /* preferred i/o block size */
	statfsp->f_fsize = sb->s_bsize; /* fundamental block size */
	fsck_length = lengthPXD(&(sb->s_fsckpxd));
	log_length = lengthPXD(&(sb->s_logpxd));

	rawRelease(bpsuper);

 	/* statfs()/extendfs() serialized by inode lock of the inode map 
	 * for both inode map and block allocation map. 
	 */
	IREAD_LOCK(ipimap);

	/*
	 * get the block stats from the bmap
	 */
	ipbmap = ipmnt->i_ipbmap;
	statfsp->f_blocks = (ipbmap->i_bmap->db_mapsize + fsck_length +
				log_length) >> ipbmap->i_bmap->db_l2nbperpage;
	statfsp->f_bfree = statfsp->f_bavail =
		ipbmap->i_bmap->db_nfree >> ipbmap->i_bmap->db_l2nbperpage;

	/*
	 * get the file stats from the ipimap
	 */
	statfsp->f_files = ipimap->i_imap->im_numinos;
	statfsp->f_ffree = ipimap->i_imap->im_numfree;

	/*
	 * fill in from vfs
	 */
	statfsp->f_fsid = vfsp->vfs_fsid;
	statfsp->f_vfstype = MNT_XJFS;
	statfsp->f_vfsnumber = vfsp->vfs_number;
	statfsp->f_name_max = JFS_NAME_MAX;

	/*
	 * fields in the statfs structure that we don't fill in ...
	 *
	long f_version;		version/type of statfs, 0 for now
	long f_type;		type of info, 0 for now
	long f_vfsoff;		reserved, for vfs specific data offset
	long f_vfslen;		reserved, for len of vfs specific data
	long f_vfsvers;		reserved, for vers of vfs specific data
	 */

out:
	IREAD_UNLOCK(ipimap);

	return rc;
}
示例#7
0
/*
 * NAME:	jfs_readlink(vp, uiop, crp)
 *
 * FUNCTION:	read a symbolic link <vp> into <uiop>
 *
 * PARAMETER:	vp 	- pointer to the vnode that represents the 
 *			  symlink we want to read
 *		uiop	- How much to read and where it goes
 *		crp	- credential
 *
 * RETURN:	EINVAL	- if not a symbolic link
 *		errors from subroutines
 */
jfs_readlink(
	struct vnode	*vp,		/* symlink vnode */
	struct uio	*uiop,
	struct ucred	*crp)
{
	int32	rc = 0;
	inode_t *ip = VP2IP(vp);
	int32	cnt;
	jbuf_t	*bp;

NOISE(1,("jfs_readlink: ip:0x%08x\n", ip));

	if (vp->v_vntype != VLNK)
		return EINVAL;

	IREAD_LOCK(ip);

	/* validate the buffer size vs target path name size
	 * (AES requires ERANGE if the link name won't fit)
	 */
	if (ip->i_size > uiop->uio_resid)
	{
		rc = ERANGE;
		goto out; 
	}

	/*
	 * read the target path name
	 */
	if (ip->i_size <= IDATASIZE)
	{
		/*
		 * fast symbolic link
		 *
		 * read target path name inline from on-disk inode
		 */
		cnt = MIN(ip->i_size, uiop->uio_iov->iov_len);
		rc = uiomove(ip->i_fastsymlink, cnt, UIO_READ, uiop);
	}
	else
	{
		/* 
		 * read target path name from a single extent
		 *
		 * target path name <= PATH_MAX < buffer page size
		 *
		 * even though the data of symlink object (target 
		 * path name) is treated as non-journaled user data,
		 * it is read/written thru buffer cache for performance.
		 */
		if (rc = bmRead(ip, 0, ip->i_size, bmREAD_PAGE, &bp))
			goto out;

		cnt = MIN(ip->i_size, uiop->uio_iov->iov_len);
		rc = uiomove(bp->b_bdata, cnt, UIO_READ, uiop);

		bmRelease(bp);
	}

out:
	IREAD_UNLOCK(ip);

NOISE(1,("jfs_readlink: rc:%d\n", rc));
	return rc;
}
示例#8
0
/*
 * NAME:	jfs_mkdir(dvp, name, mode, crp)
 *
 * FUNCTION:	create a child directory in the parent directory <dvp>
 *		with name = <name> and mode = <mode>
 *
 * PARAMETER:	dvp 	- parent directory vnode
 *		name	- name of child directory
 *		mode	- create mode (rwxrwxrwx).
 *		crp	- credential
 *
 * RETURN:	Errors from subroutines
 *
 * note:
 * EACCESS: user needs search+write permission on the parent directory
 */
jfs_mkdir(
	struct vnode	*dvp,
	UniChar		*name,
	mode_t		mode,
#ifdef _JFS_OS2
        EAOP		*pEABuf,
#endif	/* _JFS_OS2 */
	struct ucred	*crp)
{
	int32 	rc = 0, rc1 = 0;
	int32	tid;		/* transaction id */
	struct vfs	*vfsp = dvp->v_vfsp;
	inode_t	*dip = VP2IP(dvp); /* parent directory inode */
	struct dasd_usage	*du;				// F226941
	inode_t *ip = NULL;	/* child directory inode */
	ino_t	ino;
	component_t dname;	/* child directory name */
	btstack_t	btstack;
	inode_t	*iplist[2];
	int64	orig_nblocks;					// F226941
#ifdef _JFS_LAZYCOMMIT
	tblock_t *tblk;						// D230860
#endif
#ifdef _JFS_OS2
	FEALIST		*pfealist = NULL;
#endif	/* _JFS_OS2 */

NOISE(1,("jfs_mkdir: dip:0x%08x name:%s\n", dip, name));

	/*
	 * the named file exists for "." or ".."
	 */
	if (name[0] == '.')
	{
		if ((name[1] == '.' && name[2] == '\0') ||
		    name[1] == '\0')
			return EEXIST;
	}

#ifdef _JFS_OS2
	/* validate the EAOP buffer, FEALIST size storage location and the
	 * entire FEALIST storage area.  Once all the storage has been
	 * validated, the entire FEALIST is validated for format and the size is
	 * computed and compared against the limit.
	 */
	if (pEABuf)
	{
		if (rc = jfs_ValidateUserFEAList(pEABuf, &pfealist,
				&pEABuf->oError))
		{
			/* something failed -- bail out */
			return rc;
		}
	}
#endif	/* _JFS_OS2 */

	if (dip->i_nlink == 0)
	{
		rc = ENOENT;
		goto out1;
	}

	/* link count overflow on parent directory ? */
	if (dip->i_nlink >= LINK_MAX)
	{
		rc = EMLINK;
		goto out1;
	}

	/*
	 * search parent directory for entry/freespace
	 * (dtSearch() returns parent directory page pinned)
	 */
	dname.name = name;
	dname.namlen = UniStrlen(name);
	if (dname.namlen > JFS_NAME_MAX-1)
	{
		rc = ERROR_FILENAME_EXCED_RANGE;
		goto out1;
	}

// BEGIN D233382
#ifdef _JFS_LAZYCOMMIT
	if (isReadOnly(dip))
	{
		rc = EROFS;
		goto out1;
	}

	/*
	 * Either iAlloc() or txBegin() may block.  Deadlock can occur if we
	 * block there while holding dtree page, so we allocate the inode &
	 * begin the transaction before we search the directory.
	 */
	if (rc = iAlloc(vfsp, dip, IFDIR|mode|IDIRECTORY, &ip, crp))
		goto out1;

	txBegin(dip->i_ipmnt, &tid, 0);

	if (rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))
	{
		ip->i_nlink = 0;
		ICACHE_LOCK();
		iput(ip, vfsp);
		ICACHE_UNLOCK();
		txEnd(tid);
		goto out1;
	}

	tblk = &TxBlock[tid];					// D230860
	tblk->xflag |= COMMIT_CREATE;				// D230860
	tblk->ip = ip;						// D230860

#else /* ! _JFS_LAZYCOMMIT */
// END D233382

	if (rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))
		goto out1;

	if (isReadOnly(dip))
	{
		rc = EROFS;

		/* release parent directory page */
		BT_PUTSEARCH(&btstack);
		goto out1;
	}

	/*
	 * allocate on-disk/in-memory inode for child directory:
	 * (iAlloc() returns new, locked inode)
	 */
	if (rc = iAlloc(vfsp, dip, IFDIR|mode|IDIRECTORY, &ip, crp))
	{
		/* release parent directory page */
		BT_PUTSEARCH(&btstack);

jEVENT(0,("jfs_mkdir: iAlloc error(%d)\n", rc));
		goto out1;
	}

	txBegin(dip->i_ipmnt, &tid, 0);
#endif /* _JFS_LAZYCOMMIT */

	du = ip->i_dasdlim = dip->i_dasdlim;			// F226941

	orig_nblocks = dip->i_nblocks;				// F226941

	iplist[0] = dip;
	iplist[1] = ip;
	
	/*
	 * initialize the child directory in-line in inode
	 */
	dtInitRoot(tid, ip, dip->i_number);

	/*
	 * create entry in parent directory for child directory
	 * (dtInsert() releases parent directory page)
	 */
	ino = ip->i_number;
	if (rc = dtInsert(tid, dip, &dname, &ino, &btstack))
	{	
		/* discard new directory inode */
		ip->i_nlink = 0;

		if (rc == EIO)
			txAbort(tid, 1);	/* Marks Filesystem dirty */
		else
			txAbort(tid, 0);	/* Filesystem full */
		txEnd(tid);
		goto out3;
	}

	/* update child directory inode */
// BEGIN F226941
	setDASDLIMIT(&ip->i_DASD, 0);
	setDASDUSED(&ip->i_DASD, 0);
// END F226941

	ip->i_nlink++;	/* for '.' */ 
	imark(ip, IACC|ICHG|IUPD|IFSYNC);	

	/* update parent directory inode */
	dip->i_nlink++; /* for '..' from child directory */
	imark(dip, ICHG|IUPD|IFSYNC);	

	/*
	 * insert entry for the new file to dnlc
	 */
	ncEnter(dip->i_ipimap, dip->i_number, &dname, ino, NULL);

#ifdef _JFS_OS2

	if ((rc1 == 0) && pfealist)				// F226941
		rc1 = jfs_InitializeFEAList(ip, tid, pfealist);

	if ((rc1 == 0) && (dip->i_acl.flag) && (dip->i_acl.size))
		rc1 = jfs_CopyACL(ip, dip, tid);

#endif	/* _JFS_OS2 */

// BEGIN FF226941
	DLIM_UPDATE(tid, dip, dip->i_nblocks + ip->i_nblocks - orig_nblocks);
	setDASDUSED(&ip->i_DASD, ip->i_nblocks);		// D233382
#ifndef _JFS_FASTDASD						// D233382
	/*
	 * If the transaction modified the ancestors of the inode, the
	 * parent will be in the dasd usage list.  Otherwise, transaction
	 * will only change new directory and parent.
	 */
	if (du && (du->flag & DLIM_LOGGED))
		rc = dasd_commit(tid, ip, 0);
	else
#endif /* _JFS_FASTDASD */					// D233382
// END FF226941

		rc = txCommit(tid, 2, &iplist[0], 0);
	txEnd(tid);

#ifdef _JFS_OS2

	/* If we successfully added the directory, but failed adding the EA or
	 * ACL, we must cleanup the created directory entry and return the
	 * error.
	 */
	if (rc1)
	{
// BEGIN D230860
		if ((du) && (du->first_locked))
		{
			/*
			 * txCommit unlocked one or more inodes.
			 * We need to unlock all the directories &
			 * relock them.
			 */
			dip->i_dasdlim = 0;
			DLIM_WRITE_UNLOCK_DETACH(ip, du);
			DLIM_WRITE_LOCK_ATTACH(ip, du);
			dip->i_dasdlim = du;
		}
// END D230860
		jfs_xrmdir(dip, ip, name);
		rc = rc1;
	}

#endif	/* _JFS_OS2 */

out3:
	ip->i_dasdlim = 0;					// F226941
	IWRITE_UNLOCK(ip);

	ICACHE_LOCK();
	iput(ip, vfsp);
	ICACHE_UNLOCK();

out1:

#ifdef _JFS_OS2
		/*
		 * this buffer was allocated by
		 * jfs_ValidateUserFEAList() at twice the
		 * size of the given list to provide buffer
		 * space for eliminating duplicate names
		 */
	if (pfealist)
		jfs_EABufFree((char *)pfealist, (pfealist->cbList << 1));
#endif	/* _JFS_OS2 */

NOISE(1,("jfs_mkdir: rc:%d\n", rc));
	return rc;
}
示例#9
0
文件: regdblk.c 项目: mingpen/OpenNT
int
INTERNAL
RgExtendDatablock(
    LPFILE_INFO lpFileInfo,
    UINT BlockIndex,
    UINT Length
    )
{

    LPDATABLOCK_INFO lpDatablockInfo;
    DWORD NewBlockSize;
    LPDATABLOCK_HEADER lpNewDatablockHeader;
    LPFREEKEY_RECORD lpFreeKeyRecord;

    ASSERT(BlockIndex < lpFileInfo-> FileHeader.BlockCount);
    lpDatablockInfo = RgIndexDatablockInfoPtr(lpFileInfo, BlockIndex);
    ASSERT(lpDatablockInfo-> Flags & DIF_PRESENT);

    //  Check if enough free bytes already exist: if so, no need to extend.
    if (lpDatablockInfo-> FreeBytes >= Length) {
        DEBUG_OUT(("RgExtendDatablock: unexpectedly called\n"));
        return ERROR_SUCCESS;
    }

    NewBlockSize = RgAlignBlockSize(lpDatablockInfo-> BlockSize + Length -
        lpDatablockInfo-> FreeBytes);

    if (NewBlockSize > MAXIMUM_DATABLOCK_SIZE) {
        TRACE(("RgExtendDatablock: datablock too big\n"));
        return ERROR_OUTOFMEMORY;
    }

    NOISE(("RgExtendDatablock: block %d\n", BlockIndex));
    NOISE(("block size=%x, new block size=%x\n", lpDatablockInfo-> BlockSize,
        NewBlockSize));

    if (IsNullPtr((lpNewDatablockHeader = (LPDATABLOCK_HEADER)
        RgReAllocMemory(lpDatablockInfo-> lpDatablockHeader, (UINT)
        NewBlockSize))))
        return ERROR_OUTOFMEMORY;

    lpDatablockInfo-> lpDatablockHeader = lpNewDatablockHeader;

    RgCompactDatablock(lpDatablockInfo);

    if (lpNewDatablockHeader-> FirstFreeOffset == REG_NULL) {
        lpNewDatablockHeader-> FirstFreeOffset = lpDatablockInfo-> BlockSize;
        lpFreeKeyRecord = (LPFREEKEY_RECORD) ((LPBYTE) lpNewDatablockHeader +
            SmallDword(lpNewDatablockHeader-> FirstFreeOffset));
        lpFreeKeyRecord-> DatablockAddress = REG_NULL;
        lpFreeKeyRecord-> NextFreeOffset = REG_NULL;
    }

    else {
        lpFreeKeyRecord = (LPFREEKEY_RECORD) ((LPBYTE) lpNewDatablockHeader +
            SmallDword(lpNewDatablockHeader-> FirstFreeOffset));
    }

    lpDatablockInfo-> FreeBytes += (UINT) NewBlockSize - lpDatablockInfo->
        BlockSize;
    lpFreeKeyRecord-> AllocatedSize = lpDatablockInfo-> FreeBytes;
    lpDatablockInfo-> BlockSize = (UINT) NewBlockSize;

    lpDatablockInfo-> Flags |= (DIF_DIRTY | DIF_EXTENDED);
    //  BUGBUG:  Extending a datablock does not necessarily mean "rewrite the
    //  whole file again", but it works for now...
    lpFileInfo-> Flags |= FI_DIRTY | FI_EXTENDED;
    RgDelayFlush();

    return ERROR_SUCCESS;

}
示例#10
0
文件: regdblk.c 项目: mingpen/OpenNT
BOOL
INTERNAL
RgCompactDatablock(
    LPDATABLOCK_INFO lpDatablockInfo
    )
{

    LPDATABLOCK_HEADER lpDatablockHeader;
    LPFREEKEY_RECORD lpFreeKeyRecord;
    LPBYTE lpSource;
    LPBYTE lpDestination;
    UINT Offset;
    UINT BlockSize;
    UINT BytesToPushDown;

    lpDatablockHeader = lpDatablockInfo-> lpDatablockHeader;

    //  Only need to compact if there's a free record in this datablock.
    if (lpDatablockHeader-> FirstFreeOffset == REG_NULL)
        return FALSE;

    lpFreeKeyRecord = (LPFREEKEY_RECORD) ((LPBYTE) lpDatablockHeader +
        SmallDword(lpDatablockHeader-> FirstFreeOffset));

    //  Only need to compact if the all the free bytes aren't already at the end
    //  of the datablock (datablocks can't be greater than 64K-1, so no overflow
    //  is possible).
    if ((SmallDword(lpDatablockHeader-> FirstFreeOffset) +
        SmallDword(lpFreeKeyRecord-> AllocatedSize) >= lpDatablockInfo->
        BlockSize) && (lpFreeKeyRecord-> NextFreeOffset == REG_NULL))
        return FALSE;

    NOISE(("RgCompactDatablock: block %d\n", lpDatablockHeader-> BlockIndex));

    lpSource = NULL;
    lpDestination = NULL;
    Offset = sizeof(DATABLOCK_HEADER);
    BlockSize = lpDatablockInfo-> BlockSize;

    while (Offset < BlockSize) {

        //  Advance to the next free record or the end of the block.
        for (;;) {

            lpFreeKeyRecord = (LPFREEKEY_RECORD) ((LPBYTE) lpDatablockHeader +
                Offset);

            if (Offset >= BlockSize || IsKeyRecordFree(lpFreeKeyRecord)) {

                //
                //  If lpSource is valid, then we can push down the bytes from
                //  lpSource through lpFreeKeyRecord to lpDestination.
                //

                if (!IsNullPtr(lpSource)) {
                    BytesToPushDown = (LPBYTE) lpFreeKeyRecord -
                        (LPBYTE) lpSource;
                    MoveMemory(lpDestination, lpSource, BytesToPushDown);
                    lpDestination += BytesToPushDown;
                }

                if (IsNullPtr(lpDestination))
                    lpDestination = (LPBYTE) lpFreeKeyRecord;

                break;

            }

            Offset += SmallDword(lpFreeKeyRecord-> AllocatedSize);

        }

        //  Advance to the next key record.
        while (Offset < BlockSize) {

            lpFreeKeyRecord = (LPFREEKEY_RECORD) ((LPBYTE) lpDatablockHeader +
                Offset);

            if (!IsKeyRecordFree(lpFreeKeyRecord)) {
                lpSource = (LPBYTE) lpFreeKeyRecord;
                break;
            }

            Offset += SmallDword(lpFreeKeyRecord-> AllocatedSize);

        }

    }

    //  lpDestination now points at the end of the datablock where the giant
    //  free record is to be placed.  Initialize this record and patch up the
    //  datablock header.
    lpDatablockHeader-> FirstFreeOffset = (LPBYTE) lpDestination -
        (LPBYTE) lpDatablockHeader;
    ((LPFREEKEY_RECORD) lpDestination)-> AllocatedSize = lpDatablockInfo->
        FreeBytes;
    ((LPFREEKEY_RECORD) lpDestination)-> DatablockAddress = REG_NULL;
    ((LPFREEKEY_RECORD) lpDestination)-> NextFreeOffset = REG_NULL;

    //  The key record table is now invalid, so we must refresh its contents.
    RgBuildKeyRecordTable(lpDatablockInfo);

    return TRUE;

}
示例#11
0
文件: regdblk.c 项目: mingpen/OpenNT
int
INTERNAL
RgLockDatablock(
    LPFILE_INFO lpFileInfo,
    UINT BlockIndex
    )
{

    int ErrorCode;
    LPDATABLOCK_INFO lpDatablockInfo;
    HFILE hFile = HFILE_ERROR;

    if (BlockIndex >= lpFileInfo-> FileHeader.BlockCount) {
        TRACE(("RgLockDatablock: invalid datablock number\n"));
        return ERROR_BADDB;
    }

    lpDatablockInfo = RgIndexDatablockInfoPtr(lpFileInfo, BlockIndex);

    //
    //  Is the datablock currently in memory?
    //

    if (!(lpDatablockInfo-> Flags & DIF_PRESENT)) {

        NOISE(("RgLockDatablock: "));
        NOISE((lpFileInfo-> FileName));
        NOISE((", block %d\n", BlockIndex));

        ASSERT(lpDatablockInfo-> FileOffset != -1);

        if ((ErrorCode = RgAllocDatablockInfoBuffers(lpDatablockInfo)) !=
            ERROR_SUCCESS)
            goto CleanupAfterError;

        NOISE(("    lpDatablockHeader=%x\n", lpDatablockInfo-> lpDatablockHeader));
        NOISE(("    lpKeyRecordTable=%x\n", lpDatablockInfo-> lpKeyRecordTable));

        if ((hFile = RgOpenFile(lpFileInfo-> FileName, OF_READ)) == HFILE_ERROR)
            goto CleanupAfterFileError;

        if (!RgSeekFile(hFile, lpDatablockInfo-> FileOffset))
            goto CleanupAfterFileError;

        if (!RgReadFile(hFile, lpDatablockInfo-> lpDatablockHeader,
            (UINT) lpDatablockInfo-> BlockSize))
            goto CleanupAfterFileError;

        if (!RgIsValidDatablockHeader(lpDatablockInfo-> lpDatablockHeader)) {
            ErrorCode = ERROR_BADDB;
            goto CleanupAfterError;
        }

        if ((ErrorCode = RgBuildKeyRecordTable(lpDatablockInfo)) !=
            ERROR_SUCCESS)
            goto CleanupAfterError;

        RgCloseFile(hFile);

    }

    lpDatablockInfo-> Flags |= (DIF_ACCESSED | DIF_PRESENT);
    lpDatablockInfo-> LockCount++;

    INCREMENT_DEBUG_COUNT(g_RgDatablockLockCount);
    return ERROR_SUCCESS;

CleanupAfterFileError:
    ErrorCode = ERROR_REGISTRY_IO_FAILED;

CleanupAfterError:
    if (hFile != HFILE_ERROR)
        RgCloseFile(hFile);

    RgFreeDatablockInfoBuffers(lpDatablockInfo);

    DEBUG_OUT(("RgLockDatablock() returning error %d\n", ErrorCode));
    return ErrorCode;

}
示例#12
0
文件: regdblk.c 项目: mingpen/OpenNT
int
INTERNAL
RgInitDatablockInfo(
    LPFILE_INFO lpFileInfo,
    HFILE hFile
    )
{

    UINT BlockCount;
    UINT BlockIndex;
    LPDATABLOCK_INFO lpDatablockInfo;
    LONG FileOffset;
    DATABLOCK_HEADER DatablockHeader;

    BlockCount = lpFileInfo-> FileHeader.BlockCount;

    if (IsNullPtr((lpDatablockInfo = (LPDATABLOCK_INFO)
        RgSmAllocMemory((BlockCount + DATABLOCK_INFO_SLACK_ALLOC) *
        sizeof(DATABLOCK_INFO)))))
        return ERROR_OUTOFMEMORY;

    ZeroMemory(lpDatablockInfo, BlockCount * sizeof(DATABLOCK_INFO));
    lpFileInfo-> lpDatablockInfo = lpDatablockInfo;
    lpFileInfo-> DatablockInfoAllocCount = BlockCount +
        DATABLOCK_INFO_SLACK_ALLOC;

    FileOffset = lpFileInfo-> FileHeader.Size;

    for (BlockIndex = 0; BlockIndex < BlockCount; BlockIndex++,
        lpDatablockInfo++) {

        if (!RgSeekFile(hFile, FileOffset))
            return ERROR_REGISTRY_IO_FAILED;

        if (!RgReadFile(hFile, &DatablockHeader, sizeof(DATABLOCK_HEADER)))
            return ERROR_REGISTRY_IO_FAILED;

        if (!RgIsValidDatablockHeader(&DatablockHeader))
            return ERROR_BADDB;

        //  Following fields already zeroed by above ZeroMemory.
        //  lpDatablockInfo-> lpDatablockHeader = NULL;
        //  lpDatablockInfo-> lpKeyRecordTable = NULL;
        //  lpDatablockInfo-> Flags = 0;
        //  lpDatablockInfo-> LockCount = 0;

        lpDatablockInfo-> FileOffset = FileOffset;

        //  Cache these fields from the datablock header.  These fields should
        //  not be considered valid when the datablock is physically in memory.
        lpDatablockInfo-> BlockSize = SmallDword(DatablockHeader.BlockSize);
        lpDatablockInfo-> FreeBytes = SmallDword(DatablockHeader.FreeBytes);
        lpDatablockInfo-> FirstFreeIndex = DatablockHeader.FirstFreeIndex;

        NOISE(("DB#%d fileoff=%lx, size=%x free=%x 1stindex=%d\n", BlockIndex,
            FileOffset, lpDatablockInfo-> BlockSize, lpDatablockInfo->
            FreeBytes, lpDatablockInfo-> FirstFreeIndex));

        FileOffset += lpDatablockInfo-> BlockSize;

    }

    return ERROR_SUCCESS;

}
示例#13
0
文件: regdblk.c 项目: mingpen/OpenNT
int
INTERNAL
RgWriteDatablocks(
    LPFILE_INFO lpFileInfo,
    HFILE hSourceFile,
    HFILE hDestinationFile
    )
{

    UINT BlockIndex;
    LPDATABLOCK_INFO lpDatablockInfo;
    LPDATABLOCK_HEADER lpDatablockHeader;
    LONG FileOffset;

    lpDatablockInfo = lpFileInfo-> lpDatablockInfo;
    FileOffset = lpFileInfo-> FileHeader.Size;

    for (BlockIndex = 0; BlockIndex < lpFileInfo-> FileHeader.BlockCount;
        BlockIndex++, lpDatablockInfo++) {

        if (lpDatablockInfo-> Flags & DIF_PRESENT) {

            //  The block is currently in memory.  If we're either extending
            //  the file or the block is dirty, then write out our in-memory
            //  copy to disk.
            if (hSourceFile != HFILE_ERROR || lpDatablockInfo-> Flags &
                DIF_DIRTY) {

                NOISE(("writing datablock #%d of ", BlockIndex));
                NOISE((lpFileInfo-> FileName));
                NOISE(("\n"));

                lpDatablockHeader = lpDatablockInfo-> lpDatablockHeader;

                //  Copy back the fields that we've been maintaining in the
                //  DATABLOCK_INFO structure.
                lpDatablockHeader-> BlockSize = lpDatablockInfo-> BlockSize;
                lpDatablockHeader-> FreeBytes = lpDatablockInfo-> FreeBytes;
                lpDatablockHeader-> FirstFreeIndex = (WORD) lpDatablockInfo->
                    FirstFreeIndex;

                //  The checksum is not currently calculated, so we must clear
                //  the flag so we don't confuse Win95.
                lpDatablockHeader-> Flags &= ~DHF_HASCHECKSUM;

                if (!RgSeekFile(hDestinationFile, FileOffset))
                    return ERROR_REGISTRY_IO_FAILED;

                if (!RgWriteFile(hDestinationFile, lpDatablockHeader,
                    lpDatablockInfo-> BlockSize))
                    return ERROR_REGISTRY_IO_FAILED;

            }

        }

        else {

            //  The block is not currently in memory.  If we're extending the
            //  file, then we must write out this datablock.  The overhead is
            //  too great to lock the datablock down, so just copy it from the
            //  original file to the extended file.
            if (hSourceFile != HFILE_ERROR) {

                if (RgCopyFileBytes(hSourceFile, lpDatablockInfo-> FileOffset,
                    hDestinationFile, FileOffset, lpDatablockInfo->
                    BlockSize) != ERROR_SUCCESS)
                    return ERROR_REGISTRY_IO_FAILED;

            }

        }

        FileOffset += lpDatablockInfo-> BlockSize;

    }

    return ERROR_SUCCESS;

}
示例#14
0
/**
 * @short Calculates the chunk for just an oscillator (actually 4), its is more like a voice.
 */
void Polybase::Oscillator::oscillatorChunk(float *data, unsigned int nsamples){
	if (note==0){ // freq 0 == stopped
		memset(data,0,sizeof(float)*nsamples);
		return;
	}

#define NWAVES 5
#define NWAVESBLOCK (128/NWAVES)

#define SIN(x) (sin(x*2.0*M_PI))
#define SAW(x) (fmod(1.0f+(x*4.0f),2.0)-1.0)
#define TRIANGLE(x) ((x>0.25 && x<0.75) ? - SAW(x) : SAW(x))
#define SQUARE(x) (x < 0.5 ? 1.0 : -1.0);
#define NOISE(x) (((float(rand())/RAND_MAX)*2.0) - 1.0)

	unsigned int i;
	float *temp=data;
	float os,ds,v;
	float sr=poly->samplerate();
	float pstep[4]={freq[0]/sr, freq[1]/sr, freq[2]/sr, freq[3]/sr};
	
	for (i=0;i<nsamples;i++){
		float r=0;
		for (int o=0;o<4;o++){
			phase[o]+=pstep[o];
			
			float form=(poly->oscillatorForm[o]%NWAVESBLOCK)/float(NWAVESBLOCK);
			int nform=poly->oscillatorForm[o]/NWAVESBLOCK;
			float mphase=fmod(phase[o],1.0);
			
			//DEBUG("nform %d",nform);
			
			switch(nform){
				case 0:
					os=SIN(mphase);
					ds=SAW(mphase);
					break;
				case 1:
					os=SAW(mphase);
					ds=TRIANGLE(mphase);
					break;
				case 2:
					os=TRIANGLE(mphase);
					ds=SQUARE(mphase);
					break;
				case 3:
					os=SQUARE(mphase);
					ds=SIN(mphase);
					break;
				default:
					//DEBUG("NOISE");
					os=NOISE(mphase);
					ds=NOISE(mphase);
			}

			v=(os*(1.0-form)) + (ds*form);
			
			r+=v*poly->oscillatorLevel[o]/64.0;
		}
		*temp=r;
		temp++;
	}
	phase[0]=fmod(phase[0],1.0);
	phase[1]=fmod(phase[1],1.0);
	phase[2]=fmod(phase[2],1.0);
	phase[3]=fmod(phase[3],1.0);
}