Beispiel #1
0
/*
 * place the specified disk block
 * back on the free list of the
 * specified device.
 */
free(dev, bno)
{
    register *fp, *bp, *ip;

    fp = getfs(dev);
    fp->s_fmod = 1;
    while(fp->s_flock)
        sleep(&fp->s_flock, PINOD);
    if (badblock(fp, bno, dev))
        return;
    if(fp->s_nfree <= 0) {
        fp->s_nfree = 1;
        fp->s_free[0] = 0;
    }
    if(fp->s_nfree >= 100) {
        fp->s_flock++;
        bp = getblk(dev, bno);
        ip = bp->b_addr;
        *ip++ = fp->s_nfree;
        bcopy(fp->s_free, ip, 100);
        fp->s_nfree = 0;
        bwrite(bp);
        fp->s_flock = 0;
        wakeup(&fp->s_flock);
    }
    fp->s_free[fp->s_nfree++] = bno;
    fp->s_fmod = 1;
}
Beispiel #2
0
/*
 * place the specified disk block
 * back on the free list of the
 * specified device.
 */
void free(dev_t dev, daddr_t bno) {
	struct filsys *fp;
	struct buf *bp;

  if (debugFree) {
    printf("-----  free dev = 0x%08X, bno = 0x%08X  -----\n", dev, bno);
  }
	fp = getfs(dev);
	fp->s_fmod = 1;
	while(fp->s_flock)
		sleep((caddr_t)&fp->s_flock, PINOD);
	if (badblock(fp, bno, dev))
		return;
	if(fp->s_nfree <= 0) {
		fp->s_nfree = 1;
		fp->s_free[0] = 0;
	}
	if(fp->s_nfree >= NICFREE) {
		fp->s_flock++;
		bp = getblk(dev, bno);
		((FBLKP)(bp->b_un.b_addr))->df_nfree = fp->s_nfree;
		bcopy((caddr_t)fp->s_free,
			(caddr_t)((FBLKP)(bp->b_un.b_addr))->df_free,
			sizeof(fp->s_free));
		fp->s_nfree = 0;
		bwrite(bp);
		fp->s_flock = 0;
		wakeup((caddr_t)&fp->s_flock);
	}
	fp->s_free[fp->s_nfree++] = bno;
	fp->s_fmod = 1;
}
Beispiel #3
0
/*
 * Free the specified I node
 * on the specified device.
 * The algorithm stores up
 * to 100 I nodes in the super
 * block and throws away any more.
 */
ifree(dev, ino)
{
    register *fp;

    fp = getfs(dev);
    if(fp->s_ilock)
        return;
    if(fp->s_ninode >= 100)
        return;
    fp->s_inode[fp->s_ninode++] = ino;
    fp->s_fmod = 1;
}
Beispiel #4
0
/*
 * Free the specified I node
 * on the specified device.
 * The algorithm stores up
 * to NICINOD I nodes in the super
 * block and throws away any more.
 */
void ifree(dev_t dev, ino_t ino) {
	struct filsys *fp;

  if (debugIfree) {
    printf("-----  ifree dev = 0x%08X, ino = 0x%08X  -----\n", dev, ino);
  }
	fp = getfs(dev);
	if(fp->s_ilock)
		return;
	if(fp->s_ninode >= NICINOD)
		return;
	fp->s_inode[fp->s_ninode++] = ino;
	fp->s_fmod = 1;
}
Beispiel #5
0
/*
 * alloc will obtain the next available
 * free disk block from the free list of
 * the specified device.
 * The super block has up to NICFREE remembered
 * free blocks; the last of these is read to
 * obtain NICFREE more . . .
 *
 * no space on dev x/y -- when
 * the free list is exhausted.
 */
struct buf *alloc(dev_t dev) {
	daddr_t bno;
	struct filsys *fp;
	struct buf *bp;

  if (debugAlloc) {
    printf("-----  alloc dev = 0x%08X  -----\n", dev);
  }
	fp = getfs(dev);
	while(fp->s_flock)
		sleep((caddr_t)&fp->s_flock, PINOD);
	do {
		if(fp->s_nfree <= 0)
			goto nospace;
		if (fp->s_nfree > NICFREE) {
			prdev("bad free count", dev);
			goto nospace;
		}
		bno = fp->s_free[--fp->s_nfree];
		if(bno == 0)
			goto nospace;
	} while (badblock(fp, bno, dev));
	if(fp->s_nfree <= 0) {
		fp->s_flock++;
		bp = bread(dev, bno);
		if ((bp->b_flags&B_ERROR) == 0) {
			fp->s_nfree = ((FBLKP)(bp->b_un.b_addr))->df_nfree;
			bcopy((caddr_t)((FBLKP)(bp->b_un.b_addr))->df_free,
			    (caddr_t)fp->s_free, sizeof(fp->s_free));
		}
		brelse(bp);
		fp->s_flock = 0;
		wakeup((caddr_t)&fp->s_flock);
		if (fp->s_nfree <=0)
			goto nospace;
	}
	bp = getblk(dev, bno);
	clrbuf(bp);
	fp->s_fmod = 1;
	if (debugAlloc) {
	  printf("       alloc = 0x%08X\n", bp->b_blkno);
	}
	return(bp);

nospace:
	fp->s_nfree = 0;
	prdev("no space", dev);
	u.u_error = ENOSPC;
	return(NULL);
}
Beispiel #6
0
/*
 * Allocate an unused I node
 * on the specified device.
 * Used with file creation.
 * The algorithm keeps up to
 * NICINOD spare I nodes in the
 * super block. When this runs out,
 * a linear search through the
 * I list is instituted to pick
 * up NICINOD more.
 */
struct inode *ialloc(dev_t dev) {
	struct filsys *fp;
	struct buf *bp;
	struct inode *ip;
	int i;
	struct dinode *dp;
	ino_t ino;
	int index;
	daddr_t adr;

  if (debugIalloc) {
    printf("-----  ialloc dev = 0x%08X  -----\n", dev);
  }
	fp = getfs(dev);
	while(fp->s_ilock)
		sleep((caddr_t)&fp->s_ilock, PINOD);
loop:
	if(fp->s_ninode > 0) {
		ino = fp->s_inode[--fp->s_ninode];
		if (ino < ROOTINO)
			goto loop;
		ip = iget(dev, ino);
		if(ip == NULL)
			return(NULL);
		if(ip->i_mode == 0) {
			for (i=0; i<NADDR; i++)
				ip->i_un.i_s1.i_addr[i] = 0;
			fp->s_fmod = 1;
			if (debugIalloc) {
			  printf("       ialloc = 0x%08X\n", ip->i_number);
			}
			return(ip);
		}
		/*
		 * Inode was allocated after all.
		 * Look some more.
		 */
		iput(ip);
		goto loop;
	}
	fp->s_ilock++;
	ino = 0;  /* HG: we start numbering inodes with 0 */
	index = NICINOD;  /* HG: start filling at upper end */
	for(adr = SUPERB + 1; adr < SUPERB + 1 + fp->s_isize; adr++) {
		bp = bread(dev, adr);
		if (bp->b_flags & B_ERROR) {
			brelse(bp);
			ino += INOPB;
			continue;
		}
		dp = bp->b_un.b_dino;
		for(i=0; i<INOPB; i++) {
			if(dp->di_mode != 0)
				goto cont;
			for(ip = &inode[0]; ip < &inode[NINODE]; ip++)
			if(dev==ip->i_dev && ino==ip->i_number)
				goto cont;
			fp->s_inode[--index] = ino;
			fp->s_ninode++;
			if(fp->s_ninode >= NICINOD)
				break;
		cont:
			ino++;
			dp++;
		}
		brelse(bp);
		if(fp->s_ninode >= NICINOD)
			break;
	}
	/* HG: if the list is not completely filled, shift entries down */
	if (index > 0) {
	  for (i = 0; i < fp->s_ninode; i++) {
	    fp->s_inode[i] = fp->s_inode[index++];
	  }
	}
	fp->s_ilock = 0;
	wakeup((caddr_t)&fp->s_ilock);
	if(fp->s_ninode > 0)
		goto loop;
	prdev("out of inodes", dev);
	u.u_error = ENOSPC;
	return(NULL);
}
Beispiel #7
0
struct fstab *
getfsent(void)
{
	return getfs(NULL, NULL, FS_GET_ENT);
}
Beispiel #8
0
struct fstab *
getfsfile(const char *name)
{
	return getfs(NULL, name, FS_GET_FILE);
}
Beispiel #9
0
struct fstab *
getfsspec(const char *name)
{
	return getfs(name, NULL, FS_GET_SPEC);
}
Beispiel #10
0
int
main(void) {
  QLA_ColorMatrix O, iQ, tmp, matI;
  QLA_M_eq_zero(&matI);

  for(int i=0; i<QLA_Nc; i++) {
    QLA_c_eq_r_plus_ir(QLA_elem_M(matI,i,i), 1.0, 0.0);
  }
  printm(&matI);

  QLA_Complex tr;
  QLA_Real half = 0.5;

  for(int i=0; i<QLA_Nc; i++) {
    for(int j=0; j<QLA_Nc; j++) {
      QLA_c_eq_r_plus_ir(QLA_elem_M(O,i,j), i+1, QLA_Nc*(j+1));
    }
    QLA_c_eq_r_plus_ir(QLA_elem_M(O,i,i), 2+1, 1);
  }

#if QDP_Colors == 3
  QLA_Complex ci;
  QLA_c_eq_r_plus_ir(ci, 0, 1);

  //use my own implementation
  QLA_ColorMatrix expiQ;
  QLA_ColorMatrix QQ;
  QLA_ColorMatrix QQQ;
  QLA_M_eq_M_times_M(&QQ, &iQ, &iQ); //-Q^2
  QLA_M_eq_M_times_M(&QQQ, &QQ, &iQ); //-iQ^3
  QLA_M_eq_c_times_M(&QQQ, &ci, &QQQ); //Q^3
 
  QLA_Complex c0, c1;
  QLA_C_eq_trace_M(&c0, &QQQ);
  QLA_c_eq_r_times_c(c0, 0.3333333, c0);

  QLA_C_eq_trace_M(&c1, &QQ);
  QLA_c_eq_r_times_c(c1, -0.5, c1);

  double _Complex tf0, tf1, tf2;
  getfs(&tf0, &tf1, &tf2, QLA_real(c0), QLA_real(c1));

  QLA_Complex f0, f1, f2;
  f0 = tf0; 
  f1 = tf1;
  f2 = tf2;

  printm(&O);
  printf("iQ = \n");
  printm(&iQ);
  printf("QLA: exp(iQ) = \n");
  printm(&qla_exp);
  printf("Q^3 = \n");
  printm(&QQQ);
  printf("c0 = "); printc(&c0);
  printf("c1 = "); printc(&c1);  
#endif

#if QDP_Colors == 2
  QLA_ColorMatrix expO;
  QLA_Complex Tr, det;
  QLA_c_eq_c_times_c(det, QLA_elem_M(O,0,0),QLA_elem_M(O,1,1));
  QLA_c_meq_c_times_c(det, QLA_elem_M(O,0,1), QLA_elem_M(O,1,0));

  QLA_C_eq_trace_M(&Tr, &O);
  QLA_Complex s, t;
  QLA_c_eq_r_times_c(s, 0.5, Tr); // s=TrA/2

  QLA_Complex s2;
  QLA_c_eq_c_times_c(s2, s, s); //s2 = s^2
  QLA_c_meq_c(s2, det); //s2 = s^2 - detA

  double _Complex dc_t = QLA_real(s2) + QLA_imag(s2) * _Complex_I;
  dc_t = csqrt(dc_t); // sqrt(s^2 - det A)
  QLA_c_eq_r_plus_ir(t, creal(dc_t), cimag(dc_t)); // t = sqrt(s^2 - det A)

  printf(" Matrix O = \n"); printm(&O);
  printf("TrO = ");         printc(&Tr);
  printf("detO = ");        printc(&det); 
  printf("s = ");           printc(&s);
  printf("t^2 = ");         printc(&s2);
  printf("t = ");           printc(&t);

  //use the QLA exp function
  QLA_ColorMatrix qla_exp;
  QLA_M_eq_exp_M(&qla_exp, &O); //exp(O)
  
  double _Complex cosht, sinht, sinht_t;

  if(QLA_real(t) == 0 && QLA_imag(t) == 0) {
    cosht = 1;
    sinht = 0;
    sinht_t = 1;	
  } else {
    cosht = ccosh(dc_t);
    sinht = csinh(dc_t);
    sinht_t = sinht/dc_t;
  }

  double _Complex dc_s = QLA_real(s) + QLA_imag(s) * _Complex_I;
  double _Complex dc_f0, dc_f1;
  
  dc_f0 = cexp(dc_s) * (cosht - dc_s * sinht_t);
  dc_f1 = cexp(dc_s) * sinht_t;

  QLA_Complex f0, f1;
  QLA_c_eq_r_plus_ir(f0, creal(dc_f0), cimag(dc_f0));
  QLA_c_eq_r_plus_ir(f1, creal(dc_f1), cimag(dc_f1));

  QLA_M_eq_c_times_M(&expO, &f1, &O);
  QLA_M_peq_c(&expO, &f0);
  printf("QLA exp = \n"); printm(&qla_exp);
  printf("my expO = \n"); printm(&expO);


#endif

  return 0;
}