当前位置: 首页>>代码示例>>C++>>正文


C++ bmap函数代码示例

本文整理汇总了C++中bmap函数的典型用法代码示例。如果您正苦于以下问题:C++ bmap函数的具体用法?C++ bmap怎么用?C++ bmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bmap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readi

/* 
 * read data from a locked inode.
 * returns -1 on error.
 * */
int readi(struct inode *ip, char *buf, uint off, uint cnt){
    struct buf *bp;
    uint tot=0, m=0, bn=0;

    // file size limit 
    if ((off > ip->i_size) || (off+cnt < off)){
        cu->p_error = E2BIG;
        return -1;
    }
    if (off+cnt > ip->i_size) {
        cnt = ip->i_size - off;
    }
    // read
    for(tot=0; tot<cnt; tot+=m, off+=m, buf+=m){
        m = min(cnt - tot, BLK - off%BLK);
        bn = bmap(ip, off/BLK, 0);
        if (bn == 0) {
            memset(bp->b_data + off%BLK, 0, m);
        }
        else {
            bp = bread(ip->i_dev, bn);
            memcpy(buf, bp->b_data + off%BLK, m);
            brelse(bp);
        }
    }
    return cnt;
}
开发者ID:astrotycoon,项目名称:fleurix,代码行数:31,代码来源:rdwri.c

示例2: dirlookup

// Look for a directory entry in a directory.
// If found, set *poff to byte offset of entry.
// Caller must have already locked dp.
struct inode*
dirlookup(struct inode *dp, char *name, uint *poff)
{
  uint off, inum;
  struct buf *bp;
  struct dirent *de;

  if(dp->type != T_DIR)
    panic("dirlookup not DIR");

  for(off = 0; off < dp->logical_size; off += BSIZE){
    bp = bread(dp->dev, bmap(dp, off / BSIZE));
    for(de = (struct dirent*)bp->data;
        de < (struct dirent*)(bp->data + BSIZE);
        de++){
      if(de->inum == 0)
        continue;
      if(namecmp(name, de->name) == 0){
        // entry matches path element
        if(poff)
          *poff = off + (uchar*)de - bp->data;
        inum = de->inum;
        brelse(bp);
        return iget(dp->dev, inum);
      }
    }
    brelse(bp);
  }
  return 0;
}
开发者ID:SongZhao,项目名称:Operation-System-Project-Collection,代码行数:33,代码来源:fs.c

示例3: readi

// PAGEBREAK!
// Read data from inode.
int readi(struct inode* ip, char* dst, uint off, uint n)
{
    uint tot, m;
    struct buf* bp;
    struct superblock sb;
    //      cprintf("readi \n");
    sb = sbs[ip->part->number];
    if (ip->type == T_DEV) {
        if (ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read)
            return -1;
        return devsw[ip->major].read(ip, dst, n);
    }

    if (off > ip->size || off + n < off)
        return -1;
    if (off + n > ip->size)
        n = ip->size - off;

    for (tot = 0; tot < n; tot += m, off += m, dst += m) {
        uint bmapOut = bmap(ip, off / BSIZE);
        // cprintf("bout %d \n",bmapOut);
        bp = bread(ip->dev, sb.offset + bmapOut);
        m = min(n - tot, BSIZE - off % BSIZE);
        memmove(dst, bp->data + off % BSIZE, m);
        brelse(bp);
    }
    return n;
}
开发者ID:asafbennatan,项目名称:xv6-public,代码行数:30,代码来源:fs.c

示例4: frameAtIndex

void BitmapImage::checkForSolidColor()
{
    m_checkedForSolidColor = true;
    if (frameCount() > 1) {
        m_isSolidColor = false;
        return;
    }

    CGImageRef image = frameAtIndex(0);
    
    // Currently we only check for solid color in the important special case of a 1x1 image.
    if (image && CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
        unsigned char pixel[4]; // RGBA
        static CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
        RetainPtr<CGContextRef> bmap(AdoptCF, CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), space,
            kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
        if (!bmap)
            return;
        GraphicsContext(bmap.get()).setCompositeOperation(CompositeCopy);
        CGRect dst = { {0, 0}, {1, 1} };
        CGContextDrawImage(bmap.get(), dst, image);
        if (pixel[3] == 0)
            m_solidColor = Color(0, 0, 0, 0);
        else
            m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
        m_isSolidColor = true;
    }
}
开发者ID:dzip,项目名称:webkit,代码行数:28,代码来源:ImageCG.cpp

示例5: dreaddir

/*
 * get next entry in a directory.
 */
struct direct *
dreaddir(struct dirstuff *dirp)
{
	struct direct *dp;
	diskaddr_t lbn, d;

	for (;;) {
		if (dirp->loc >= (int)dirp->ip->di_size)
			return (NULL);
		if (blkoff(&sblock, dirp->loc) == 0) {
			lbn = lblkno(&sblock, dirp->loc);
			d = bmap(lbn);
			if (d == 0)
				return (NULL);
			bread(fsbtodb(&sblock, d), dirp->dbuf,
			    (int)dblksize(&sblock, dirp->ip, (int)lbn));
		}
		dp = (struct direct *)
		    (dirp->dbuf + blkoff(&sblock, dirp->loc));
		dirp->loc += dp->d_reclen;
		if (dp->d_ino == 0)
			continue;
		return (dp);
	}
}
开发者ID:AlainODea,项目名称:illumos-gate,代码行数:28,代码来源:ff.c

示例6: readi

//PAGEBREAK!
// Read data from inode.
int
readi(struct inode *ip, char *dst, uint off, uint n)
{
  uint tot, m;
  struct buf *bp;

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

  if(off > ip->size || off + n < off)
    return -1;
  if(off + n > ip->size)
    n = ip->size - off;

  for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
    bp = bread(ip->dev, bmap(ip, off/BSIZE));
    m = min(n - tot, BSIZE - off%BSIZE);
    memmove(dst, bp->data + off%BSIZE, m);
    brelse(bp);
  }
  return n;
}
开发者ID:SilunWang,项目名称:xv6,代码行数:27,代码来源:fs.c

示例7: file_read

int file_read(struct m_inode * inode, struct file * filp, char * buf, int count)
{
	int left,chars,nr;
	struct buffer_head * bh;

	if ((left=count)<=0)
		return 0;
	while (left) {
		if ((nr = bmap(inode,(filp->f_pos)/BLOCK_SIZE))) {
			if (!(bh=bread(inode->i_dev,nr)))
				break;
		} else
			bh = NULL;
		nr = filp->f_pos % BLOCK_SIZE;
		chars = MIN( BLOCK_SIZE-nr , left );
		filp->f_pos += chars;
		left -= chars;
		if (bh) {
			char * p = nr + bh->b_data;
			while (chars-->0)
				put_fs_byte(*(p++),buf++);
			brelse(bh);
		} else {
			while (chars-->0)
				put_fs_byte(0,buf++);
		}
	}
	inode->i_atime = CURRENT_TIME;
	return (count-left)?(count-left):-ERROR;
}
开发者ID:Dayanand-Chinchure,项目名称:linux-0.01,代码行数:30,代码来源:file_dev.c

示例8: writei

// PAGEBREAK!
// Write data to inode.
int writei(struct inode* ip, char* src, uint off, uint n)
{
    // cprintf("writei \n");

    uint tot, m;
    struct buf* bp;
    struct superblock sb;
    sb = sbs[ip->part->number];

    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 > ip->size || off + n < off)
        return -1;
    if (off + n > MAXFILE * BSIZE)
        return -1;

    for (tot = 0; tot < n; tot += m, off += m, src += m) {
        uint bmapOut = bmap(ip, off / BSIZE);
        bp = bread(ip->dev, sb.offset + bmapOut);
        m = min(n - tot, BSIZE - off % BSIZE);
        memmove(bp->data + off % BSIZE, src, m);
        log_write(bp, ip->part->number);
        brelse(bp);
    }

    if (n > 0 && off > ip->size) {
        ip->size = off;
        iupdate(ip);
    }
    return n;
}
开发者ID:asafbennatan,项目名称:xv6-public,代码行数:37,代码来源:fs.c

示例9: writei

/*
 * write data to a regular file.
 * */
int writei(struct inode *ip, char *buf, uint off, uint cnt){
    struct buf *bp;
    uint tot=0, m=0, bn=0;

    if (off+cnt < off){
        return -1;
    }
    if (off+cnt > MAX_FILESIZ) {
        cnt = MAX_FILESIZ - off;
    }
    // do write.
    for(tot=0; tot<cnt; tot+=m, off+=m, buf+=m){
        m = min(cnt - tot, BLK - off%BLK);
        bn = bmap(ip, off/BLK, 1);
        if (bn==0) {
            panic("bad block.");
        }
        else {
            bp = bread(ip->i_dev, bn); // note here!
            memcpy(bp->b_data + off%BLK, buf, m);
            bwrite(bp);
            brelse(bp);
        }
    }
    // adjust the inode's file size
    if (cnt > 0 && off > ip->i_size) {
        ip->i_size = off;
        iupdate(ip);
    }
    return cnt;
}
开发者ID:astrotycoon,项目名称:fleurix,代码行数:34,代码来源:rdwri.c

示例10: writei

// PAGEBREAK!
// Write data to inode.
int
writei(struct inode *ip, char *src, uint off, uint n)
{
  uint tot, m;
  struct buf *bp;

  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 > ip->size || off + n < off)
    return -1;
  if(off + n > MAXFILE*BSIZE)
    return -1;

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

  if(n > 0 && off > ip->size){
    ip->size = off;
    iupdate(ip);
  }
  return n;
}
开发者ID:SilunWang,项目名称:xv6,代码行数:33,代码来源:fs.c

示例11: if

struct block *bmap_block(struct inode *inode, int blk, int create)
{
	if ((blk = bmap(inode, blk, create)) < 0)
		return NULL;
	else if (blk == 0)
		return MINIX_ZERO_BLOCK;
	return minix_get_block(inode->i_sb, blk);
}
开发者ID:chobits,项目名称:tinyos,代码行数:8,代码来源:map.c

示例12: checki

// Check data from inode to see if it is in the buffer cache.
int
checki(struct inode *ip, int off)
{
	if(off > ip->size)
		return -1;
	//cprintf("checki: calling bcheck\n");
    return bcheck(ip->dev, bmap(ip, off/BSIZE, 0));

 }
开发者ID:fenster,项目名称:xv6-staus-treffert,代码行数:10,代码来源:fs.c

示例13: do_readahead

static int do_readahead(journal_t *journal, unsigned int start)
{
	int err;
	unsigned int max, nbufs, next, blocknr;
	struct buffer_head *bh;
	
	struct buffer_head * bufs[MAXBUF];
	
	/* Do up to 128K of readahead */
	max = start + (128 * 1024 / journal->j_blocksize);
	if (max > journal->j_maxlen)
		max = journal->j_maxlen;

	/* Do the readahead itself.  We'll submit MAXBUF buffer_heads at
	 * a time to the block device IO layer. */
	
	nbufs = 0;
	
	for (next = start; next < max; next++) {
		blocknr = next;
		if (journal->j_inode)
			blocknr = bmap(journal->j_inode, next);
		if (!blocknr) {
			printk (KERN_ERR "JFS: bad block at offset %u\n",
				next);
			err = -EIO;
			goto failed;
		}
		
		bh = getblk(journal->j_dev, blocknr, journal->j_blocksize);
		if (!bh) {
			err = -ENOMEM;
			goto failed;
		}

		if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
			bufs[nbufs++] = bh;
			if (nbufs == MAXBUF) {
				ll_rw_block(READ, nbufs, bufs);
				brelse_array(bufs, nbufs);
				nbufs = 0;
			}
		} else
			brelse(bh);
	}

	if (nbufs)
		ll_rw_block(READ, nbufs, bufs);
	err = 0;
	
failed:	
	if (nbufs) 
		brelse_array(bufs, nbufs);
	return err;
}
开发者ID:crossmeta,项目名称:linux,代码行数:55,代码来源:recovery.c

示例14: agei

//return age of buffer containing data, or 0 if no buffer
int
agei(struct inode *ip, uint off)
{
  if (ip->type == T_DEV)
     return 0;

  if(off > ip->size)
    return 0;

   return bage(ip->dev, bmap(ip, off/BSIZE, 0));
}
开发者ID:aaronb,项目名称:CS637,代码行数:12,代码来源:fs.c

示例15: writei

// Write data to inode.
int
writei(struct inode *ip, char *src, uint off, uint n)
{
  uint tot, m;
  struct buf *bp;
  char *addr;

  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 > ip->size || off + n < off)
    return -1;

  if(ip->type == T_SMALLFILE){ // handle T_SMALLFILE
    // cprintf("before n in readi : %d\t off = %d\t size = %d\n", n, off, ip->size);
    if(off + n > 52)
      n = 52 - off;    
    addr = (char*)(ip->addrs); // get NDIRECT address
    memmove(addr + off, src, n);
    off += n;
    ip->size = off;
    iupdate(ip);    
    return n;
    // cprintf("after n in readi : %d\t off = %d\t size = %d\n", n, off, ip->size);
    // cprintf("write addr: %s\n", *(addr + off));

  } else { // handle T_FILE
    if(off + n > MAXFILE*BSIZE)
      n = MAXFILE*BSIZE - off;    
    for(tot=0; tot<n; tot+=m, off+=m, src+=m){
      uint sector_number = bmap(ip, off/BSIZE);
      if(sector_number == 0){ //failed to find block
        n = tot; //return number of bytes written so far
        break;
      }
      
      bp = bread(ip->dev, sector_number);
      m = min(n - tot, BSIZE - off%BSIZE);
      memmove(bp->data + off%BSIZE, src, m);
      bwrite(bp);
      brelse(bp);
    }
  }
  if(n > 0 && off > ip->size){
    ip->size = off;
    iupdate(ip);
    // cprintf("last n in readi : %d\t off = %d\t size = %d\n", n, off, ip->size);
  }
  return n;
}
开发者ID:squallee,项目名称:CS537,代码行数:54,代码来源:fs.c


注:本文中的bmap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。