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


C++ ospfs_block函数代码示例

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


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

示例1: remove_block

static int
remove_block(ospfs_inode_t *oi)
{
	// current number of blocks in file
	uint32_t n = ospfs_size2nblocks(oi->oi_size);
	uint32_t block_no = 0;
	uint32_t *ptr;

	// keep track of allocations to free in case of -ENOSPC
	uint32_t allocated[2] = { 0, 0 };

	/* EXERCISE: Your code here */
	if (0 < n && n <= OSPFS_NDIRECT) {
		oi->oi_direct[n - 1] = 0;
		free_block(n - 1);
		goto out;
	}

	// The block to be allocated has to be in indirect or indirect2
	n -= OSPFS_NDIRECT;
	if (0 < n && n <= OSPFS_NINDIRECT) {
		if (oi->oi_indirect) {
			ptr = ospfs_block(oi->oi_indirect);
			free_block(ptr[n - 1]);
			ptr[n - 1] = 0;
			if ((n - 1) == 0) {
				free_block(oi->oi_indirect);
				oi->oi_indirect = 0;
			}
		}
		goto out;
	}

	// next block must lie in indirect2
	n -= OSPFS_NINDIRECT;
	if (0 < n && n <= (OSPFS_NINDIRECT * OSPFS_NINDIRECT)) {
		uint32_t *ptrl1, *ptrl2;
		uint32_t level1 = (n - 1) / OSPFS_NINDIRECT;
		uint32_t level2 = (n - 1) % OSPFS_NINDIRECT;

		ptrl1 = ospfs_block(oi->oi_indirect2);
		ptrl2 = ospfs_block(ptrl1[level1]);
		if (ptrl2[level2]) {
			free_block(ptrl2[level2]);
			ptrl2[level2] = 0;
		}
		if (level2 == 0) {
			free_block(ptrl1[level1]);
			ptrl1[level1] = 0;
			if (level1 == 0) {
				free_block(oi->oi_indirect2);
				oi->oi_indirect2 = 0;
			}
		}
	}
 out:
	return 0;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:58,代码来源:ospfs-fsckmod.c

示例2: remove_block

static int
remove_block(ospfs_inode_t *oi)
{
	// current number of blocks in file
	uint32_t n = ospfs_size2nblocks(oi->oi_size);
	//the nth block is the one to remove
	if (n < 0 || n > OSPFS_MAXFILEBLKS)
		return -EIO;
	if (n == 0)
		return 0;
	n--;
	//just remove n and free the block
	if (n < OSPFS_NDIRECT) {
		free_block(oi->oi_direct[n]);
		oi->oi_direct[n] = 0;
	}
	// we have single indirection
	else if (n < OSPFS_NDIRECT + OSPFS_NINDIRECT) {
		// actual indirect block in memory
		uint32_t* indirect_block = (uint32_t *) ospfs_block(oi->oi_indirect);

		// free the direct block, data block is simply unbound after freeing the direct block
		free_block(indirect_block[direct_index(n)]);
		// set the block number of n in the indirect block to 0
		indirect_block[direct_index(n)] = 0;

		// if we freed the last block indirected to, we free the indirect block and variable as well
		if (!direct_index(n)) {
			free_block(oi->oi_indirect);
			oi->oi_indirect = 0;
		}
	}
	// ugh, double indirection
	else {
		uint32_t* indirect2_block = (uint32_t *) ospfs_block(oi->oi_indirect2);
		uint32_t* indirect_block = (uint32_t *) ospfs_block(indirect2_block[indir_index(n)]);

		// free the direct block
		free_block(indirect_block[direct_index(n)]);
		indirect_block[direct_index(n)] = 0;

		if (direct_index(n) == 0) {
			free_block(indirect2_block[indir_index(n)]);
			indirect2_block[indir_index(n)] = 0;
		}
		
		if (indir_index(n) == 0) {
			free_block(oi->oi_indirect2);
			oi->oi_indirect2 = 0;
		}
	}

	oi->oi_size = oi->oi_size - OSPFS_BLKSIZE;
	return 0;
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:55,代码来源:ospfsmod.c

示例3: allocate_block

static uint32_t
allocate_block(void)
{
	/* EXERCISE: Your code here */
	uint32_t i; 
	for(i = 1; i < ospfs_super->os_nblocks; i++){
		if(bitvector_test(ospfs_block(OSPFS_FREEMAP_BLK),i)){
			bitvector_clear(ospfs_block(OSPFS_FREEMAP_BLK),i);
			return i;
		}
	}
	return 0;
}
开发者ID:Davidy22,项目名称:111Project3,代码行数:13,代码来源:ospfsmod.c

示例4: free_block

static void
free_block(uint32_t blockno)
{
	/* EXERCISE: Your code here */
	if(blockno > ospfs_super->os_firstinob + ospfs_super->os_ninodes/OSPFS_BLKINODES && blockno < ospfs_super->os_nblocks)
		bitvector_set(ospfs_block(OSPFS_FREEMAP_BLK),blockno);
}
开发者ID:Davidy22,项目名称:111Project3,代码行数:7,代码来源:ospfsmod.c

示例5: ospfs_inode_blockno

static inline uint32_t
ospfs_inode_blockno(ospfs_inode_t *oi, uint32_t offset)
{
	uint32_t blockno = offset / OSPFS_BLKSIZE;
	if (offset >= oi->oi_size || oi->oi_ftype == OSPFS_FTYPE_SYMLINK)
		return 0;
	else if (blockno >= OSPFS_NDIRECT + OSPFS_NINDIRECT) {
		uint32_t blockoff = blockno - (OSPFS_NDIRECT + OSPFS_NINDIRECT);
		uint32_t *indirect2_block = ospfs_block(oi->oi_indirect2);
		uint32_t *indirect_block = ospfs_block(indirect2_block[blockoff / OSPFS_NINDIRECT]);
		return indirect_block[blockoff % OSPFS_NINDIRECT];
	} else if (blockno >= OSPFS_NDIRECT) {
		uint32_t *indirect_block = ospfs_block(oi->oi_indirect);
		return indirect_block[blockno - OSPFS_NDIRECT];
	} else
		return oi->oi_direct[blockno];
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:17,代码来源:ospfsmod_freeblock.c

示例6: mark_inode_bitmap

int
mark_inode_bitmap(ospfs_inode_t *oi, uint8_t *bitmap)
{
	int i, j;
	uint32_t *ptrl1, *ptrl2;
	int next_block = ospfs_size2nblocks(oi->oi_size);

	if (next_block == 0) {
		return 0;
	}

	for (i = 0; (i < OSPFS_NDIRECT) && oi->oi_direct[i]; i++) {
		bitvector_clear(bitmap, oi->oi_direct[i]);
	}

	if (i < OSPFS_NDIRECT || !oi->oi_indirect) {
		return 0;
	}

	next_block -= OSPFS_NDIRECT;
	bitvector_clear(bitmap, oi->oi_indirect);
	ptrl1 = ospfs_block(oi->oi_indirect);
	for (i = 0; i < OSPFS_NINDIRECT && ptrl1[i]; i++) {
		bitvector_clear(bitmap, ptrl1[i]);
	}

	if (i < OSPFS_NINDIRECT || !oi->oi_indirect2) {
		return 0;
	}

	next_block -= OSPFS_NINDIRECT;
	bitvector_clear(bitmap, oi->oi_indirect2);
	ptrl1 = ospfs_block(oi->oi_indirect);
	for (i = 0; i < OSPFS_NINDIRECT && ptrl1[i]; i++) {
		ptrl2 = ospfs_block(ptrl1[i]);
		bitvector_clear(bitmap, ptrl1[i]);
		for (j = 0; j < OSPFS_NINDIRECT && ptrl2[j]; j++) {
			bitvector_clear(bitmap, ptrl2[j]);
		}
		if (j < OSPFS_NINDIRECT) {
			break;
		}
	}

	return 0;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:46,代码来源:ospfs-fsckmod.c

示例7: zero_block

static void
zero_block(uint32_t block){
	char *ptr = (char*)ospfs_block(block);
	int i;
	for(i = 0; i < OSPFS_BLKSIZE; i++){
		ptr[i] = 0;	
	}
}
开发者ID:Graceychin,项目名称:CS111,代码行数:8,代码来源:ospfsmod.c

示例8: ospfs_read

static ssize_t
ospfs_read(struct file *filp, char __user *buffer, size_t count, loff_t *f_pos)
{
	ospfs_inode_t *oi = ospfs_inode(filp->f_dentry->d_inode->i_ino);
	int retval = 0;
	size_t amount = 0;

	// Make sure we don't read past the end of the file!
	// Change 'count' so we never read past the end of the file.
	if(*f_pos > oi->oi_size)
		return 0;
	//we do not read past the end of the file
	if(*f_pos + count > oi->oi_size)
		count = oi->oi_size - *f_pos;
	/* EXERCISE: Your code here */

	// Copy the data to user block by block
	while (amount < count && retval >= 0) {
		uint32_t blockno = ospfs_inode_blockno(oi, *f_pos);
		uint32_t n;
		char *data;
		//eprintk("reading!!");
		// ospfs_inode_blockno returns 0 on error
		if (blockno == 0) {
			retval = -EIO;
			goto done;
		}

		data = ospfs_block(blockno);
		int offs = *f_pos % OSPFS_BLKSIZE;
		n = OSPFS_BLKSIZE - offs;
		int left = count - amount;
		n = (n > left) ? left : n;
		if(copy_to_user (buffer, data, n))
			//if copy success return 0;
		{
			retval = -EFAULT;
			goto done;
		}
		//to: Destination address, in user space.
 		//from: Source address, in kernel space.
 		//n: Number of bytes to copy.
		// Figure out how much data is left in this block to read.
		// Copy data into user space. Return -EFAULT if unable to write
		// into user space.
		// Use variable 'n' to track number of bytes moved.
		/* EXERCISE: Your code here */
		//retval = -EIO; // Replace these lines
		//goto done;

		buffer += n;
		amount += n;
		*f_pos += n;
	}

    done:
	return (retval >= 0 ? amount : retval);
}
开发者ID:qinyiyan,项目名称:CS111,代码行数:58,代码来源:ospfsmod.c

示例9: ospfs_inode

static inline ospfs_inode_t *
ospfs_inode(ino_t ino)
{
	ospfs_inode_t *oi;
	if (ino >= ospfs_super->os_ninodes)
		return 0;
	oi = ospfs_block(ospfs_super->os_firstinob);
	return &oi[ino];
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:9,代码来源:ospfsmod_freeblock.c

示例10: free_block

static void
free_block(uint32_t blockno)
{
	void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK);

	// TODO: check validity of block

	bitvector_set(bitmap, blockno); // mark as free (set i bit to 1)
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:9,代码来源:ospfsmod_add_block.c

示例11: free_block

static void
free_block(uint32_t blockno)
{
	/* EXERCISE: Your code here */
	if(blockno < ospfs_super->os_firstinob)
		return;
	bitvector_set(ospfs_block(blockno / OSPFS_BLKBITSIZE + OSPFS_FREEMAP_BLK),
			blockno % OSPFS_BLKBITSIZE);
}
开发者ID:bngo92,项目名称:CS-111,代码行数:9,代码来源:ospfsmod.c

示例12: ospfs_symlink

static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	//eprintk("simlink");
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	//EXERCISE: Your code here. 
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;
	//create a new symlink inode
	ospfs_inode_t *free_inode = ospfs_block(ospfs_super->os_firstinob);
	uint32_t count = 1;
	while(count<ospfs_super->os_ninodes)
	{
		if (free_inode[count].oi_nlink == 0)
			break;
		count++;
	}
	//no free inode
	if (count == ospfs_super->os_ninodes)
	{
		count = 0;
		return -ENOSPC;
	}
	else 
		entry_ino = count;
	//create new inode and entry;
	ospfs_symlink_inode_t* symlink_oi = ospfs_inode(entry_ino);
	ospfs_direntry_t * sym_dentry = create_blank_direntry(dir_oi);
	if (IS_ERR(sym_dentry))
		return PTR_ERR(sym_dentry);
	//init symlink inode:
	if (strlen(symname)>OSPFS_MAXSYMLINKLEN)
		return -ENAMETOOLONG;
	symlink_oi->oi_size = strlen(symname);
	symlink_oi->oi_ftype = OSPFS_FTYPE_SYMLINK;
	symlink_oi->oi_nlink = 1;
	memcpy (symlink_oi->oi_symlink, symname, strlen(symname)); 
	symlink_oi->oi_symlink[strlen(symname)] = '\0';
	memcpy (sym_dentry->od_name, dentry->d_name.name, dentry->d_name.len);
	sym_dentry->od_name[dentry->d_name.len] = '\0';
	sym_dentry->od_ino = entry_ino;

	 //Execute this code after your function has successfully created the
	   //file.  Set entry_ino to the created file's inode number before
	   //getting here. 
	{
		struct inode *i = ospfs_mk_linux_inode(dir->i_sb, entry_ino);
		if (!i)
			return -ENOMEM;
		d_instantiate(dentry, i);
		return 0;
	}
}
开发者ID:qinyiyan,项目名称:CS111,代码行数:56,代码来源:ospfsmod.c

示例13: remove_block

static int
remove_block(ospfs_inode_t *oi)
{
	// current number of blocks in file
	uint32_t n = ospfs_size2nblocks(oi->oi_size);		
	/* EXERCISE: Your code here */
	uint32_t blockno = n - 1;
	if (blockno >= OSPFS_NDIRECT + OSPFS_NINDIRECT) {
		uint32_t blockoff = blockno - (OSPFS_NDIRECT + OSPFS_NINDIRECT);
		uint32_t *indirect2_block;
		uint32_t *indirect_block;
		if (oi->oi_indirect2 == 0)
			return -EIO;
		indirect2_block = ospfs_block(oi->oi_indirect2);
		if (indirect2_block[blockoff / OSPFS_NINDIRECT] == 0)
			return -EIO;
		indirect_block = ospfs_block(indirect2_block[blockoff / OSPFS_NINDIRECT]);

		free_block(indirect_block[blockoff % OSPFS_NINDIRECT]);
		indirect_block[blockoff % OSPFS_NINDIRECT] = 0;
		if (blockoff % OSPFS_NINDIRECT == 0) {
			free_block(indirect2_block[blockoff / OSPFS_NINDIRECT]);
			indirect2_block[blockoff / OSPFS_NINDIRECT] = 0;
			if (blockno == OSPFS_NDIRECT + OSPFS_NINDIRECT) {
				free_block(oi->oi_indirect2);
				oi->oi_indirect2 = 0;
			}
		}
	} else if (blockno >= OSPFS_NDIRECT) {
		uint32_t *indirect_block = ospfs_block(oi->oi_indirect);
		if (oi->oi_indirect == 0)
			return -EIO;

		free_block(indirect_block[blockno - OSPFS_NINDIRECT]);
		if (blockno - OSPFS_NDIRECT == 0)
			free_block(oi->oi_indirect);
	} else {
		free_block(oi->oi_direct[blockno]);
		oi->oi_direct[blockno] = 0;
	}
	oi->oi_size -= OSPFS_BLKSIZE;
	return 0; 
}
开发者ID:bngo92,项目名称:CS-111,代码行数:43,代码来源:ospfsmod.c

示例14: ospfs_read

static ssize_t
ospfs_read(struct file *filp, char __user *buffer, size_t count, loff_t *f_pos)
{
	ospfs_inode_t *oi = ospfs_inode(filp->f_dentry->d_inode->i_ino);
	int retval = 0;
	size_t amount = 0;

	// Make sure we don't read past the end of the file!
	// Change 'count' so we never read past the end of the file.
	/* DONE: Your code here */
	if (count > oi->oi_size - *f_pos) {
		count = oi->oi_size - *f_pos;
	}
	// Copy the data to user block by block
	while (amount < count && retval >= 0) {
		uint32_t blockno = ospfs_inode_blockno(oi, *f_pos);
		uint32_t n;
		char *data;

		// ospfs_inode_blockno returns 0 on error
		if (blockno == 0) {
			retval = -EIO;
			goto done;
		}

		data = ospfs_block(blockno);

		// Figure out how much data is left in this block to read.
		// Copy data into user space. Return -EFAULT if unable to write
		// into user space.
		// Use variable 'n' to track number of bytes moved.

		//goto done;

		long block_pos = *f_pos % OSPFS_BLKSIZE;
		if (count - amount > OSPFS_BLKSIZE - block_pos) {
			n = OSPFS_BLKSIZE - block_pos;
		}
		else {
			n = count - amount;
		}
		retval = copy_to_user(buffer, data + block_pos, n);
		if (retval != 0) {
			return -EFAULT;
		}

		buffer += n;
		amount += n;
		*f_pos += n;
	}

    done:
	return (retval >= 0 ? amount : retval);
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:54,代码来源:ospfsmod.c

示例15: _add_block

/* Return Newly allocated block number */
static uint32_t
_add_block(int *ptr)
{
	uint32_t block_no = allocate_block();

	if (block_no) {
		*ptr = block_no;
		memset(ospfs_block(block_no), 0, OSPFS_BLKSIZE);
	}
	return block_no;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:12,代码来源:ospfs-fsckmod.c


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