Exemple #1
0
static int
ext2_htree_writebuf(struct ext2fs_htree_lookup_info *info)
{
	int i, error;

	for (i = 0; i < info->h_levels_num; i++) {
		struct buf *bp = info->h_levels[i].h_bp;
		error = bwrite(bp);
		if (error)
			return (error);
	}

	return (0);
}
void
flush(int fd, struct bufarea *bp)
{
	int i;

	if (!bp->b_dirty)
		return;
	if (bp->b_errs != 0)
		pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
		    (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
		    bp->b_bno);
	bp->b_dirty = 0;
	bp->b_errs = 0;
	bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
	if (bp != &sblk)
		return;
	for (i = 0; i < sblock.e2fs_ngdb; i++) {
		bwrite(fswritefd, (char *)
			&sblock.e2fs_gd[i* sblock.e2fs_bsize / sizeof(struct ext2_gd)],
		    fsbtodb(&sblock, ((sblock.e2fs_bsize>1024)?0:1)+i+1),
		    sblock.e2fs_bsize);
	}
}
Exemple #3
0
// Copy committed blocks from log to their home location
static void 
install_trans(void)
{
  int tail;

  for (tail = 0; tail < log.lh.n; tail++) {
    struct buf *lbuf = bread(log.dev, log.start+tail+1); // read log block
    struct buf *dbuf = bread(log.dev, log.lh.sector[tail]); // read dst
    memmove(dbuf->data, lbuf->data, BSIZE);  // copy block to dst
    bwrite(dbuf);  // write dst to disk
    brelse(lbuf); 
    brelse(dbuf);
  }
}
Exemple #4
0
/*Write the block*/
static int block_write_data(int dev,int block,int size,const unsigned char *data) { 
  int major;
  int ret = 0;
  int blocks = 0;
  int blksize = 0;
  int rem ;
  if(! size ) {
    goto out;
  }

  major = MAJOR(dev);
  blksize = blkdev[major].block_size;
  if(! blksize) {
    goto out;
  }
  blocks = size / blksize;
  rem = size % blksize;
  ret = size;
  while(blocks) { 
    struct buffer_head *bh ;
    bh = bwrite(dev,block++,blksize,data);
    if(! bh ) {
      goto out;
    }
    data += blksize;
    --blocks;
  }
  if( rem ) {
    struct buffer_head *bh;
    bh = bwrite(dev,block,rem,data);
    if(! bh ) {
      goto out;
    }
  }
 out:
  return ret - blocks*blksize;
}
Exemple #5
0
int
log_writei(struct inode *ip, char *src, uint off, uint n)
{
  uint tot, m, i, j;
  struct buf *tbp;

  if(ip->type == T_DEV){
    if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
      return -1;
    return devsw[ip->major].write(ip, src, n);
  }

  if(off + n < off)
    return -1;
  if(off + n > MAXFILE*BSIZE)
    n = MAXFILE*BSIZE - off;


  b_index = 0; // new xfer, start keeping track of open bufs

  /* allocate all space needed */
  for(i=0, j=off; i<n; i+=m, j+=m){
    log_bmap(ip, j/BSIZE);
    m = min(n - i, BSIZE - j%BSIZE);
  }

  for(tot=0; tot<n; tot+=m, off+=m, src+=m){
    bp[b_index] = bread(ip->dev, log_lookup(ip, off/BSIZE));
    m = min(n - tot, BSIZE - off%BSIZE);
    memmove(bp[b_index]->data + off%BSIZE, src, m);
    b_index++;
  }

  if(n > 0 && off > ip->size){
    ip->size = off;
    log_iupdate(ip);
  }

  log_start();
  for(i = 0; i < b_index; i++){
    bwrite(bp[i]);
    brelse(bp[i]);
  }

  log_end();

  return n;

}
Exemple #6
0
//发送options处理后的响应
int send_options_reply(RTSP_buffer * pRtsp, long cseq)
{
    char r[1024];
    sprintf(r, "%s %d %s"RTSP_EL"CSeq: %ld"RTSP_EL, RTSP_VER, 200, get_stat(200), cseq);
    strcat(r, "Public: OPTIONS,DESCRIBE,SETUP,PLAY,PAUSE,TEARDOWN"RTSP_EL);
    strcat(r, RTSP_EL);

    bwrite(r, (unsigned short) strlen(r), pRtsp);

#ifdef RTSP_DEBUG
//	fprintf(stderr ,"SERVER SEND Option Replay: %s\n", r);
#endif

    return ERR_NOERROR;
}
Exemple #7
0
/*
 * Write a superblock and associated information back to disk.
 */
int
ext2fs_sbupdate(struct ufsmount *mp, int waitfor)
{
	struct m_ext2fs *fs = mp->um_e2fs;
	struct buf *bp;
	int error = 0;

	bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0);
	e2fs_sbsave(&fs->e2fs, (struct ext2fs *) bp->b_data);
	if (waitfor == MNT_WAIT)
		error = bwrite(bp);
	else
		bawrite(bp);
	return (error);
}
Exemple #8
0
static void 
init_Boot_Block (void)

/* 
*  Since there isn't any BootBlock yet, simply clear the contents
*  of the first block on disc.
*/

{
     	struct buf *bp;

	bp = getblk(filedrive,0,1,NOSAVE);
	clr_buf (bp);
	bwrite(bp->b_tbp);						
}
Exemple #9
0
int
putino(struct uufsd *disk)
{
	struct fs *fs;

	fs = &disk->d_fs;
	if (disk->d_inoblock == NULL) {
		ERROR(disk, "No inode block allocated");
		return (-1);
	}
	if (bwrite(disk, fsbtodb(fs, ino_to_fsba(&disk->d_fs, disk->d_inomin)),
	    disk->d_inoblock, disk->d_fs.fs_bsize) <= 0)
		return (-1);
	return (0);
}
Exemple #10
0
static int
msdosfs_updatede(struct denode *dep)
{
	struct buf *bp;
	struct direntry *dirp;
	int error;

	dep->de_flag &= ~DE_MODIFIED;
	error = readde(dep, &bp, &dirp);
	if (error)
		return error;
	DE_EXTERNALIZE(dirp, dep);
	error = bwrite(bp);
	return error;
}
/* block moving */
static unsigned long move_generic_block(unsigned long block, unsigned long bnd, int h)
{
    struct buffer_head * bh, * bh2;

	/* primitive fsck */
	if (block > rs_block_count(rs)) {
		fprintf(stderr, "resize_reiserfs: invalid block number (%lu) found.\n", block);
		quit_resizer();
	}
	/* progress bar, 3D style :) */
	if (opt_verbose)
	    print_how_far(&total_node_cnt, blocks_used, 1, 0);
	else
	    total_node_cnt ++;

	/* infinite loop check */
	if( total_node_cnt > blocks_used && !block_count_mismatch) {
		fputs("resize_reiserfs: warning: block count exeeded\n",stderr);
		block_count_mismatch = 1;
	}

	if (block < bnd) /* block will not be moved */
		return 0;
	
	/* move wrong block */ 
	bh = bread(fs->s_dev, block, fs->s_blocksize);

	reiserfs_bitmap_find_zero_bit(bmp, &unused_block);
	if (unused_block == 0 || unused_block >= bnd) {
		fputs ("resize_reiserfs: can\'t find free block\n", stderr);
		quit_resizer();
	}

	/* blocknr changing */
	bh2 = getblk(fs->s_dev, unused_block, fs->s_blocksize);
	memcpy(bh2->b_data, bh->b_data, bh2->b_size);
	reiserfs_bitmap_clear_bit(bmp, block);
	reiserfs_bitmap_set_bit(bmp, unused_block);

	brelse(bh);
	mark_buffer_uptodate(bh2,1);
	mark_buffer_dirty(bh2);
	bwrite(bh2);
	brelse(bh2);

	total_moved_cnt++;
	return unused_block;
}
Exemple #12
0
int send_play_reply(RTSP_buffer * pRtsp, RTSP_session * pRtspSessn)
{
	char s8Str[1024];
	char s8Temp[30];
	sprintf(s8Str, "%s %d %s"RTSP_EL"CSeq: %d"RTSP_EL"Server: %s/%s"RTSP_EL, RTSP_VER, 200,\
			get_stat(200), pRtsp->rtsp_cseq, PACKAGE, VERSION);
	add_time_stamp(s8Str, 0);

	sprintf(s8Temp, "Session: %d"RTSP_EL, pRtspSessn->session_id);
	strcat(s8Str, s8Temp);
	strcat(s8Str, RTSP_EL);

	bwrite(s8Str, (unsigned short) strlen(s8Str), pRtsp);

	return ERR_NOERROR;
}
Exemple #13
0
/*
 * Write a superblock and associated information back to disk.
 */
int
ext2fs_sbupdate(struct ufsmount *mp, int waitfor)
{
	printf("In file: %s, fun: %s,lineno: %d\n",__FILE__, __func__, __LINE__);
	struct m_ext2fs *fs = mp->um_e2fs;
	struct buf *bp;
	int error = 0;

	bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0);
	e2fs_sbsave(&fs->e2fs, (struct ext2fs*)bp->b_data);
	if (waitfor == MNT_WAIT)
		error = bwrite(bp);
	else
		bawrite(bp);
	return (error);
}
Exemple #14
0
Fichier : inode.c Projet : qpig/sfs
static int clr_imap_bit( struct d_block_table_entry *bt, struct m_inode *inode )
{
	int imap_nr = bt->start_imap_nr;
	int off = inode->inode_num - bt->first_inode_num;
	if( inode->inode_num < bt->free_inode_num )
		bt->free_inode_num = inode->inode_num;
	int block = off / SECTOR_SIZE;
	struct buffer_head *bh = bread( bt->dev, imap_nr + block, 0 );
	int i = off / 32;
	int j = off % 32;
	u32 *tmp = (u32 *)(bh->pdata);
	tmp = tmp + i;
	*tmp = *tmp & ~(1<<j);
	bwrite( bh );
	return 1;
}
Exemple #15
0
Fichier : inode.c Projet : qpig/sfs
static int set_imap_first_zero( struct d_block_table_entry *bt, struct m_inode *inode )
{
	int imap_nr = bt->start_imap_nr ;
	int free_block = (bt->free_inode_num - bt->first_inode_num )/SECTOR_SIZE ;
	int i,j,inode_nr;
	struct buffer_head *bh ;

	for( ; free_block < bt->inode_count/SECTOR_SIZE +1; free_block++ )
	{
		bh = bread( bt->dev, imap_nr + free_block, 0 );
		u32 *tmp = (u32 *)(bh->pdata);
		for( i=0; i<SECTOR_SIZE/32; i++,tmp++ )
		{
			if( *tmp != 0xffffffff )
			{
				for( j=0; j<32; j++ )
					if( (~(*tmp) & (1<<j)) != 0 )
						break;
				inode_nr = bt->free_inode_num + free_block *512 + i * 32 + j;
				if( j > bt->free_inode_num + bt->inode_count )
				{
					printk("inode is used up!\n");
					return 0;
				}

				*tmp = *tmp | 1 << j;
				bwrite( bh );

				bt->free_inode_num = inode_nr + 1;
				inode->dev = bt->dev;
				inode->size = bt->block_size;
				inode->inode_num = inode_nr;
				inode->start_data_sect = bt->start_data_nr + (inode_nr - bt->first_inode_num) * bt->block_size;
				inode->start_itable_sect = bt->start_itable_nr + (inode_nr - bt->first_inode_num)/8;
				inode->start_imap_sect = bt->start_imap_nr + (inode_nr - bt->first_inode_num)/SECTOR_SIZE;
				inode->zone_first_inode_num = bt->first_inode_num;
				inode->next_inode_id = 0;
				inode->nlinks = 1;
				inode->update = 1;
				inode->dirt = 0;
				return inode_nr;
			}
		}
		brelse( bh );
	}
	return 0;
}
Exemple #16
0
// Copy inode, which has changed, from memory to disk.
void
iupdate(struct inode *ip)
{
  struct buf *bp;
  struct dinode *dip;

  bp = bread(ip->dev, IBLOCK(ip->inum));
  dip = (struct dinode*)bp->data + ip->inum%IPB;
  dip->type = ip->type;
  dip->major = ip->major;
  dip->minor = ip->minor;
  dip->nlink = ip->nlink;
  dip->size = ip->size;
  memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
  bwrite(bp);
  brelse(bp);
}
Exemple #17
0
int bfree(int bno) //释放磁盘块
{
    if(super->nextFreeBlock==BLOCKNUM)
    {
        bwrite(&super->freeBlock,bno,0,sizeof(unsigned int),BLOCKNUM);
        super->nextFreeBlock=1;
        super->freeBlock[0]=bno;
    }
    else
    {
        super->freeBlock[super->nextFreeBlock]=bno;
        super->nextFreeBlock++;
    }
    super->freeBlockNum++;
    write_super();
    return 1;
}
/*
 ****************************************************************
 *	Atualiza um Super Bloco V7				*
 ****************************************************************
 */
void
v7_update (const SB *sp)
{
	V7SB	*v7sp = sp->sb_ptr;
	BHEAD		*bp;

	/*
	 *	Tenta trancar as listas Livres
	 */
	if (SLEEPTEST (&v7sp->s_ilock) < 0)
		return;

	if (SLEEPTEST (&v7sp->s_flock) < 0)
		{ SLEEPFREE (&v7sp->s_ilock); return; }

	/*
	 *	Prepara para escrever o SB no Disco
	 */
	bp = bread (sp->sb_dev, V7_SBNO, 0);

	*(time_t *)v7sp->s_time = time;

	memmove (bp->b_addr, v7sp, sizeof (V7SB));

#ifdef	LITTLE_ENDIAN
	/*
	 *	Se for o caso, converte, ...
	 */
	v7_sb_endian_conversion ((V7SB *)bp->b_addr);
#endif	LITTLE_ENDIAN

	/*
	 *	Escreve o SB no Disco
	 */
	bwrite (bp);

#ifdef	MSG
	if (CSWT (6))
		printf ("%g: SB, dev = %v\n", sp->sb_dev);
#endif	MSG

	SLEEPFREE (&v7sp->s_flock);
	SLEEPFREE (&v7sp->s_ilock);

}	/* end v7_update */
Exemple #19
0
// Write in-memory log header to disk.
// This is the true point at which the
// current transaction commits.
static void write_head(void)
{
    struct buf *buf;
    struct logheader *hb;
    int i;

    buf = bread(log.dev, log.start);
    hb = (struct logheader *) (buf->data);

    hb->n = log.lh.n;

    for (i = 0; i < log.lh.n; i++) {
        hb->sector[i] = log.lh.sector[i];
    }

    bwrite(buf);
    brelse(buf);
}
Exemple #20
0
/*
 * Update the access, modified, and inode change times as specified by the
 * IACCESS, IUPDATE, and ICHANGE flags respectively. The IMODIFIED flag is
 * used to specify that the inode needs to be updated but that the times have
 * already been set. The access and modified times are taken from the second
 * and third parameters; the inode change time is always taken from the current
 * time. If waitfor is set, then wait for the disk write of the inode to
 * complete.
 */
int
ext2fs_update(struct inode *ip, int waitfor)
{
	struct m_ext2fs *fs;
	struct buf *bp;
	int error;
	caddr_t cp;

	if (ITOV(ip)->v_mount->mnt_flag & MNT_RDONLY)
		return (0);
	EXT2FS_ITIMES(ip);
	if ((ip->i_flag & IN_MODIFIED) == 0)
		return (0);
	ip->i_flag &= ~IN_MODIFIED;
	fs = ip->i_e2fs;
	error = bread(ip->i_devvp,
			  fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
			  (int)fs->e2fs_bsize, &bp);
	if (error) {
		brelse(bp);
		return (error);
	}
	ip->i_flag &= ~(IN_MODIFIED);
	cp = (caddr_t)bp->b_data +
	    (ino_to_fsbo(fs, ip->i_number) * EXT2_DINODE_SIZE(fs));

	/*
	 * See note about 16-bit UID/GID limitation in ext2fs_vget(). Now
	 * that we are about to write the inode, construct the split UID and
	 * GID fields out of the two 32-bit fields we kept in memory.
	 */
	ip->i_e2fs_uid_low = (u_int16_t)ip->i_e2fs_uid;
	ip->i_e2fs_gid_low = (u_int16_t)ip->i_e2fs_gid;
	ip->i_e2fs_uid_high = ip->i_e2fs_uid >> 16;
	ip->i_e2fs_gid_high = ip->i_e2fs_gid >> 16;

	e2fs_isave(fs, ip->i_e2din, (struct ext2fs_dinode *)cp);
	if (waitfor)
		return (bwrite(bp));
	else {
		bdwrite(bp);
		return (0);
	}
}
Exemple #21
0
int
deupdat(struct denode *dep, int waitfor)
{
	struct direntry dir;
	struct timespec ts;
	struct buf *bp;
	struct direntry *dirp;
	int error;

	if (DETOV(dep)->v_mount->mnt_flag & MNT_RDONLY) {
		dep->de_flag &= ~(DE_UPDATE | DE_CREATE | DE_ACCESS |
		    DE_MODIFIED);
		return (0);
	}
	getnanotime(&ts);
	DETIMES(dep, &ts, &ts, &ts);
	if ((dep->de_flag & DE_MODIFIED) == 0 && waitfor == 0)
		return (0);
	dep->de_flag &= ~DE_MODIFIED;
	if (DETOV(dep)->v_vflag & VV_ROOT)
		return (EINVAL);
	if (dep->de_refcnt <= 0)
		return (0);
	error = readde(dep, &bp, &dirp);
	if (error)
		return (error);
	DE_EXTERNALIZE(&dir, dep);
	if (bcmp(dirp, &dir, sizeof(dir)) == 0) {
		if (waitfor == 0 || (bp->b_flags & B_DELWRI) == 0) {
			brelse(bp);
			return (0);
		}
	} else
		*dirp = dir;
	if ((DETOV(dep)->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
		bp->b_flags |= B_CLUSTEROK;
	if (waitfor)
		error = bwrite(bp);
	else if (vm_page_count_severe() || buf_dirty_count_severe())
		bawrite(bp);
	else
		bdwrite(bp);
	return (error);
}
Exemple #22
0
ino_t
cgialloc(struct uufsd *disk)
{
	struct ufs2_dinode *dp2;
	u_int8_t *inosused;
	struct cg *cgp;
	struct fs *fs;
	ino_t ino;
	int i;

	fs = &disk->d_fs;
	cgp = &disk->d_cg;
	inosused = cg_inosused(cgp);
	for (ino = 0; ino < fs->fs_ipg; ino++)
		if (isclr(inosused, ino))
			goto gotit;
	return (0);
gotit:
	if (fs->fs_magic == FS_UFS2_MAGIC &&
	    ino + INOPB(fs) > cgp->cg_initediblk &&
	    cgp->cg_initediblk < cgp->cg_niblk) {
		char block[MAXBSIZE];
		bzero(block, (int)fs->fs_bsize);
		dp2 = (struct ufs2_dinode *)&block;
		for (i = 0; i < INOPB(fs); i++) {
			dp2->di_gen = arc4random() / 2 + 1;
			dp2++;
		}
		if (bwrite(disk, ino_to_fsba(fs,
		    cgp->cg_cgx * fs->fs_ipg + cgp->cg_initediblk),
		    block, fs->fs_bsize))
			return (0);
		cgp->cg_initediblk += INOPB(fs);
	}

	setbit(inosused, ino);
	cgp->cg_irotor = ino;
	cgp->cg_cs.cs_nifree--;
	fs->fs_cstotal.cs_nifree--;
	fs->fs_cs(fs, cgp->cg_cgx).cs_nifree--;
	fs->fs_fmod = 1;

	return (ino + (cgp->cg_cgx * fs->fs_ipg));
}
Exemple #23
0
Fichier : bio.c Projet : phoboz/vmx
struct buf* buf_getblk (
    struct vnode * vp,
    lblkno_t       blkno,
    unsigned       size
    ) {
    struct buf *bp;
    LIST *pBufHead = &vp->v_mount->mnt_buflist;

loop:
    if ((bp = buf_incore (vp, blkno)) != NULL) {
        if (bp->b_flags & B_BUSY) {
            bp->b_flags |= B_WANTED;
            semTake (&bp->b_sem, WAIT_FOREVER);
        }
        bp->b_flags |= (B_BUSY | B_CACHE);
        /*
         * check for size inconsistancies
         */
        if (bp->b_size != size) {
            logMsg ("getblk: invalid buffer size: %d\n",
                    (ARG) bp->b_size,
                    0, 0, 0, 0, 0);
            bp->b_flags |= B_INVAL;
            bwrite (bp);
            goto loop;
        }
    } else {
        if ((bp = buf_new (vp, blkno)) == NULL) {
            logMsg ("buf_getblk: no buffers",
                    0, 0, 0, 0, 0, 0);
            goto loop;
        }
        bp->b_dev = vp->v_mount->mnt_dev;
        bp->b_lblkno = blkno;
        bp->b_vp = vp;
        bio_new (bp);
        
        /* Put buffer at head */
        listRemove (pBufHead, &bp->b_node);
        listInsert (pBufHead, NULL, &bp->b_node);
    }

    return (bp);
}
Exemple #24
0
// Return the disk block address of the nth block in inode ip.
// If there is no such block, bmap allocates one.
static uint
bmap(struct inode *ip, uint bn)
{
  uint addr, *a;
  struct buf *bp;
  
  if(bn < NDIRECT){
    if((addr = ip->addrs[bn]) == 0)
      ip->addrs[bn] = addr = balloc(ip->dev);
    if(ip->type == T_CHECKED) {
      addr &= 0x00FFFFFF;
    }
    return addr;
  }
  bn -= NDIRECT;

  if(bn < NINDIRECT){
    // Load indirect block, allocating if necessary.
    if((addr = ip->addrs[NDIRECT]) == 0)
      ip->addrs[NDIRECT] = addr = balloc(ip->dev);
    /*
   if(ip->type == T_CHECKED) {
      addr &= 0x00FFFFFF;
    }
    */
  
    bp = bread(ip->dev, addr);
    a = (uint*)bp->data;
    if((addr = a[bn]) == 0){
      if(ip->type == T_CHECKED) {
	addr &= 0x00FFFFFF;
      }      
      a[bn] = addr = balloc(ip->dev);
      bwrite(bp);
    }
    brelse(bp);
    if(ip->type == T_CHECKED) {
      addr &= 0x00FFFFFF;
    }
     return addr;
  }

  panic("bmap: out of range");
}
Exemple #25
0
void savelev()
{
    extern char *tfile;
    
    int fd;

    fd = creat(tfile, FMASK);

    if(fd < 0) {
        panic("Cannot create %s\n", tfile);
    }

    bwrite(fd, (char *)levl, sizeof(levl));
    bwrite(fd, (char *)nul, sizeof(long));
    bwrite(fd, (char *)&xupstair, sizeof(xupstair));
    bwrite(fd, (char *)&yupstair, sizeof(yupstair));
    bwrite(fd, (char *)&xdnstair, sizeof(xdnstair));
    bwrite(fd, (char *)&ydnstair, sizeof(ydnstair));

    savemonchn(fd, fmon);
    savegenchn(fd, fgold);
    savegenchn(fd, ftrap);
    saveobjchn(fd, fobj);
    saveobjchn(fd, (struct obj *)0);

    bwrite(fd, (char *)nul, sizeof(unsigned));
    
#ifndef QUEST
    bwrite(fd, (char *)rooms, sizeof(rooms));
    bwrite(fd, (char *)doors, sizeof(doors));
#endif

    ftrap = 0;
    fgold = 0;
    fobj = 0;
}
Exemple #26
0
// Free a disk block.
static void
bfree(int dev, uint b)
{
  struct buf *bp;
  struct superblock sb;
  int bi, m;

  bzero(dev, b);

  readsb(dev, &sb);
  bp = bread(dev, BBLOCK(b, sb.ninodes));
  bi = b % BPB;
  m = 1 << (bi % 8);
  if((bp->data[bi/8] & m) == 0)
    panic("freeing free block");
  bp->data[bi/8] &= ~m;  // Mark block free on disk.
  bwrite(bp);
  brelse(bp);
}
Exemple #27
0
/*
 * Invalidate buffer for specified device.
 * This is called when unmount.
 */
void
binval(dev_t dev)
{
    struct buf *bp;
    int i;

    BIO_LOCK();
    for (i = 0; i < NBUFS; i++) {
        bp = &buf_table[i];
        if (bp->b_dev == dev) {
            if (ISSET(bp->b_flags, B_DELWRI))
                bwrite(bp);
            else if (ISSET(bp->b_flags, B_BUSY))
                brelse(bp);
            bp->b_flags = B_INVAL;
        }
    }
    BIO_UNLOCK();
}
Exemple #28
0
/*
 * Extend a directory block in 'blk' by copying it to a full size block
 * and inserting the new journal inode into .sujournal.
 */
static int
dir_extend(ufs2_daddr_t blk, ufs2_daddr_t nblk, off_t size, ino_t ino)
{
	char block[MAXBSIZE];

	if (bread(&disk, fsbtodb(&sblock, blk), block,
	    roundup(size, sblock.fs_fsize)) <= 0) {
		warn("Failed to read dir block");
		return (-1);
	}
	dir_clear_block(block, size);
	if (bwrite(&disk, fsbtodb(&sblock, nblk), block, sblock.fs_bsize)
	    <= 0) {
		warn("Failed to write dir block");
		return (-1);
	}

	return (dir_insert(nblk, size, ino));
}
Exemple #29
0
static bool store_data(BFILE *bfd, char *data, const int32_t length)
{
   if (is_win32_stream(attr->data_stream) && !have_win32_api()) {
      set_portable_backup(bfd);
      if (!processWin32BackupAPIBlock(bfd, data, length)) {
         berrno be;
         Emsg2(M_ERROR_TERM, 0, _("Write error on %s: %s\n"),
               attr->ofname, be.bstrerror());
         return false;
      }
   } else if (bwrite(bfd, data, length) != (ssize_t)length) {
      berrno be;
      Emsg2(M_ERROR_TERM, 0, _("Write error on %s: %s\n"),
            attr->ofname, be.bstrerror());
      return false;
   }

   return true;
}
Exemple #30
0
int rmdir(char* filename,struct m_inode* inode)
{
    struct m_inode* rminode=NULL;
    dir * dir=(struct dir*)calloc(1,sizeof(struct dir));
    for(int addr=0; addr<inode->finode.addrnum; addr++)
    {
        bread(dir,inode->finode.addr[addr],0,sizeof(struct dir),1);
        for(int i=0; i<dir->dirNum; i++)
        {
            if(strcmp(dir->direct[i].directName,filename)==0)
            {
                rminode=iget(dir->direct[i].inodeID);
                for(int j=i; j<dir->dirNum; j++)
                    dir->direct[j]=dir->direct[j+1];
                dir->dirNum--;
                bwrite(dir,inode->finode.addr[addr],0,sizeof(struct dir),1);
                break;
            }
        }
        if(rminode)
            break;
    }
    if(rminode==NULL)
        return -1;
    else
    {
        if(rminode->finode.mode==1)//删除项为目录
            _rmdir(rminode);//递归删除
        else
        {
            for(int i=0; i<rminode->finode.addrnum; i++)
                bfree(rminode->finode.addr[i]);
            rminode->finode.i_free=0;
            super->freeInodeNum++;
            write_super();
            write_finode(rminode);
        }

    }
    inode->finode.fileSize-=sizeof(struct direct);
    write_finode(inode);
    return 1;
}