• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ospfs_inode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ospfs_unlink

static int
ospfs_unlink(struct inode *dirino, struct dentry *dentry)
{
	ospfs_inode_t *oi = ospfs_inode(dentry->d_inode->i_ino);
	ospfs_inode_t *dir_oi = ospfs_inode(dentry->d_parent->d_inode->i_ino);
	int entry_off;
	ospfs_direntry_t *od;

	od = NULL; // silence compiler warning; entry_off indicates when !od
	for (entry_off = 0; entry_off < dir_oi->oi_size;
	     entry_off += OSPFS_DIRENTRY_SIZE) {
		od = ospfs_inode_data(dir_oi, entry_off);
		if (od->od_ino > 0
		    && strlen(od->od_name) == dentry->d_name.len
		    && memcmp(od->od_name, dentry->d_name.name, dentry->d_name.len) == 0)
			break;
	}

	if (entry_off == dir_oi->oi_size) {
		printk("<1>ospfs_unlink should not fail!\n");
		return -ENOENT;
	}

	od->od_ino = 0;
	oi->oi_nlink--;

	// if not a symlink, delete file data when all links are gone
	if (oi->oi_ftype != OSPFS_FTYPE_SYMLINK && oi->oi_nlink == 0)
		return change_size(oi, 0);

	return 0;
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:32,代码来源:ospfsmod_freeblock.c


示例2: ospfs_link

static int
ospfs_link(struct dentry *src_dentry, struct inode *dir, struct dentry *dst_dentry) {
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	ospfs_inode_t *src_oi = ospfs_inode(src_dentry->d_inode->i_ino);
	ospfs_direntry_t *entry;


	if (dst_dentry->d_name.len > OSPFS_MAXSYMLINKLEN) {
		return -ENAMETOOLONG;
	}
	
	if (find_direntry(dir_oi, dst_dentry->d_name.name, dst_dentry->d_name.len) != NULL) {
		return -EEXIST;
	}
	
	if (dir_oi == NULL || dir_oi->oi_nlink + 1 == 0) {
		return -EIO;
	}
	
	entry = create_blank_direntry(dir_oi);
	if (IS_ERR(entry)) {
		return PTR_ERR(entry);
	} else if(entry == NULL) {
		return -EIO;
	}
	
	entry->od_ino = src_dentry->d_inode->i_ino;
	memcpy(entry->od_name, dst_dentry->d_name.name, dst_dentry->d_name.len);
	entry->od_name[dst_dentry->d_name.len] = 0;
	
	src_oi->oi_nlink++;
	dir_oi->oi_nlink++;
	return 0;
}
开发者ID:Davidy22,项目名称:111Project3,代码行数:34,代码来源:ospfsmod.c


示例3: copy_inode

int32_t
copy_inode(uint32_t i_ino, uint8_t *bitmap, ospfs_inode_t *inodeTable)
{
	memcpy(&inodeTable[i_ino], ospfs_inode(i_ino), sizeof(*inodeTable));

	mark_inode_bitmap(ospfs_inode(i_ino), bitmap);
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:7,代码来源:ospfs-fsckmod.c


示例4: ospfs_link

static int
ospfs_link(struct dentry *src_dentry, struct inode *dir, struct dentry *dst_dentry) {
	ospfs_direntry_t* link;

	// check if name too long
	if (dst_dentry->d_name.len > OSPFS_MAXNAMELEN)
        return -ENAMETOOLONG;
	// check if directory entry already exists
	if (find_direntry(ospfs_inode(dir->i_ino),
		dst_dentry->d_name.name, dst_dentry->d_name.len))
		return -EEXIST;

	// create new hardlinked file
	link = create_blank_direntry(ospfs_inode(dir->i_ino));
	if (IS_ERR(link))
		return PTR_ERR(link);

	// copy file information
	link->od_ino = src_dentry->d_inode->i_ino;
	memcpy(link->od_name, dst_dentry->d_name.name, dst_dentry->d_name.len);
	link->od_name[dst_dentry->d_name.len] = '\0';

	// increment source file link count
	ospfs_inode(src_dentry->d_inode->i_ino)->oi_nlink++;

	return 0;
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:27,代码来源:ospfsmod_freeblock.c


示例5: ospfs_unlink

static int
ospfs_unlink(uint32_t i_ino, char *d_name)
{
	ospfs_inode_t *oi = ospfs_inode(i_ino); // figure this out???
	ospfs_inode_t *dir_oi = ospfs_inode(i_ino);
	int entry_off;
	ospfs_direntry_t *od;

	od = NULL; // silence compiler warning; entry_off indicates when !od
	for (entry_off = 0; entry_off < dir_oi->oi_size;
	     entry_off += OSPFS_DIRENTRY_SIZE) {
		od = ospfs_inode_data(dir_oi, entry_off);
		if (od->od_ino > 0
		    && strlen(od->od_name) == strlen(d_name)
		    && memcmp(od->od_name, d_name, strlen(d_name)) == 0)
			break;
	}

	if (entry_off == dir_oi->oi_size) {
		return -ENOENT;
	}

	od->od_ino = 0;
	oi->oi_nlink--;
	return 0;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:26,代码来源:ospfs-fsckmod.c


示例6: ospfs_link

static int
ospfs_link(struct dentry *src_dentry, struct inode *dir, struct dentry *dst_dentry) {
	/* EXERCISE: Your code here. */
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	ospfs_direntry_t *od;
	ospfs_inode_t *oi;
	uint32_t entry_ino = 0;
	if (dst_dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;
	if (find_direntry(dir_oi, dst_dentry->d_name.name, dst_dentry->d_name.len))
		return -EEXIST;

	od = create_blank_direntry(dir_oi);

	if (IS_ERR(od))
		return -ENOSPC;
	for (entry_ino = 2; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		oi = ospfs_inode(entry_ino);
		if (oi->oi_nlink == 0)
			break;
	}
	if (entry_ino == ospfs_super->os_ninodes)
		return -EIO;
	od->od_ino = src_dentry->d_inode->i_ino;
	strcpy(od->od_name, dst_dentry->d_name.name);
	oi = ospfs_inode(od->od_ino);
	oi->oi_nlink++;

	return 0;
}
开发者ID:bngo92,项目名称:CS-111,代码行数:30,代码来源:ospfsmod.c


示例7: ospfs_unlink

static int
ospfs_unlink(struct inode *dirino, struct dentry *dentry)
{
	ospfs_inode_t *oi = ospfs_inode(dentry->d_inode->i_ino);
	ospfs_inode_t *dir_oi = ospfs_inode(dentry->d_parent->d_inode->i_ino);
	int entry_off;
	ospfs_direntry_t *od;

	od = NULL; // silence compiler warning; entry_off indicates when !od
	for (entry_off = 0; entry_off < dir_oi->oi_size;
     	entry_off += OSPFS_DIRENTRY_SIZE) {
    	od = ospfs_inode_data(dir_oi, entry_off);
    	if (od->od_ino > 0
        	&& strlen(od->od_name) == dentry->d_name.len
        	&& memcmp(od->od_name, dentry->d_name.name, dentry->d_name.len) == 0)
        	break;
	}

	if (entry_off == dir_oi->oi_size) {
    	printk("<1>ospfs_unlink should not fail!\n");
    	return -ENOENT;
	}

	od->od_ino = 0;
	oi->oi_nlink--;

	//after unlinking, decrement number of links
	dir_oi->oi_nlink--;
	//if a file doesn't have any more links, we can delete it by giving it 0 size  
	if (oi->oi_ftype != OSPFS_FTYPE_SYMLINK && oi->oi_nlink == 0)
    	change_size(oi,0);
    
    
	return 0;
}
开发者ID:rzeng95,项目名称:CS111Lab3,代码行数:35,代码来源:ospfsmod.c


示例8: ospfs_symlink

static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	ospfs_symlink_inode_t *symlink_inode;

	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	if (strlen(symname) > OSPFS_MAXSYMLINKLEN || dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;

	// create a blank direntry, and return error if bad things happen
	ospfs_direntry_t* od = create_blank_direntry(dir_oi);
	if (IS_ERR(od)) {
		return PTR_ERR(od);
	}

	// find empty inode by linear searching the inodes
	for (entry_ino = 0; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		if (!ospfs_inode(entry_ino)->oi_nlink)
			break;
	}

	// entry_ino is now either a ptr to an empty inode we can use or ninodes (no space)

	if (entry_ino == ospfs_super->os_ninodes)
		return -ENOSPC;

	// write directory entry (inode number and the name)
	od->od_ino = entry_ino;
	memcpy(od->od_name, dentry->d_name.name, dentry->d_name.len);
	od->od_name[dentry->d_name.len] = '\0';

	symlink_inode = ospfs_inode(entry_ino);

	// set values in inode
	symlink_inode->oi_nlink = 1;
	symlink_inode->oi_size = strlen(symname);
	symlink_inode->oi_ftype = OSPFS_FTYPE_SYMLINK;
	memcpy(symlink_inode->oi_symlink, symname, strlen(symname));
	symlink_inode->oi_symlink[strlen(symname)] = '\0';
	

	/* 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:wenlongx,项目名称:UCLA_CS,代码行数:57,代码来源:ospfsmod.c


示例9: ospfs_create

static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;

	// if the entry is found, it already exists
	if (find_direntry(dir, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	// if entry name is too long
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
		return -ENAMETOOLONG;
	
	// create a blank direntry, and return error if bad things happen
	ospfs_direntry_t* od = create_blank_direntry(dir_oi);
	if (IS_ERR(od)) {
		return PTR_ERR(od);
	}

	// find empty inode by linear searching the inodes
	for (entry_ino = 0; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		if (!ospfs_inode(entry_ino)->oi_nlink)
			break;
	}

	// entry_ino is now either a ptr to an empty inode we can use or ninodes (no space)

	if (entry_ino == ospfs_super->os_ninodes)
		return -ENOSPC;

	od->od_ino = entry_ino;
	memcpy(od->od_name, dentry->d_name.name, dentry->d_name.len);
	od->od_name[dentry->d_name.len] = '\0';

	ospfs_inode_t* inode = ospfs_inode(entry_ino);

	// set values in inode
	inode->oi_mode = mode;
	inode->oi_nlink = 1;
	inode->oi_size = 0;
	inode->oi_ftype = OSPFS_FTYPE_REG;
	memset(inode->oi_direct, 0, sizeof(inode->oi_direct[0]) * OSPFS_NDIRECT);
	inode->oi_indirect = 0;
	inode->oi_indirect2 = 0;

	/* 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:wenlongx,项目名称:UCLA_CS,代码行数:57,代码来源:ospfsmod.c


示例10: ospfs_create

static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	ospfs_direntry_t *entry = NULL;
	ospfs_inode_t *temp = NULL;
	/* EXERCISE: Your code here. */
	
	if (dentry->d_name.len > OSPFS_MAXNAMELEN) {
		return -ENAMETOOLONG;
	}
	
	if (find_direntry(ospfs_inode(dir->i_ino), dentry->d_name.name, dentry->d_name.len) != NULL) {
		return -EEXIST;
	}
	
	entry = create_blank_direntry(dir_oi);
	if (IS_ERR(entry)) {
		return PTR_ERR(entry);
	}
	
	while(entry_ino < ospfs_super->os_ninodes) {
		temp = ospfs_inode(entry_ino);
		if(temp != NULL && temp->oi_nlink == 0) {
			break;
		}
		entry_ino++;
	}
	
	if (entry_ino == ospfs_super->os_ninodes) {
		return -ENOSPC;
	}
	
	temp->oi_size = 0;
	temp->oi_ftype = OSPFS_FTYPE_REG;
	temp->oi_nlink = 1;
	temp->oi_mode = mode;
	temp->oi_direct[0] = 0;
	dir_oi->oi_nlink++;
	
	entry->od_ino = entry_ino;
	memcpy(entry->od_name, dentry->d_name.name, dentry->d_name.len);
	entry->od_name[dentry->d_name.len] = 0;

	/* 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:Davidy22,项目名称:111Project3,代码行数:56,代码来源:ospfsmod.c


示例11: 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


示例12: ospfs_symlink

static int
ospfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	uint32_t entry_ino = 0;
	ospfs_direntry_t *entry = NULL;
	ospfs_symlink_inode_t *symlink = NULL;
	/* EXERCISE: Your code here. */
	
	if(dentry->d_name.len > OSPFS_MAXNAMELEN || strlen(symname) > OSPFS_MAXNAMELEN) {
		return -ENAMETOOLONG;
	}
	if(find_direntry(dir_oi,dentry->d_name.name,dentry->d_name.len)) {
		return -EEXIST; 
	}
	
	entry = create_blank_direntry(dir_oi);
	if (IS_ERR(entry)) {
		return PTR_ERR(entry);
	}
	
	while(entry_ino < ospfs_super->os_ninodes) {
		symlink = ospfs_inode(entry_ino);
		if(symlink != NULL && symlink->oi_nlink == 0) {
			break;
		}
		entry_ino++;
	}
	
	if (entry_ino == ospfs_super->os_ninodes) {
		return -ENOSPC;
	}
	
	symlink->oi_size = strlen(symname);
	symlink->oi_ftype = OSPFS_FTYPE_SYMLINK;
	symlink->oi_nlink = 1;
	strncpy(symlink->oi_symlink,symname,symlink->oi_size);
	symlink->oi_symlink[symlink->oi_size] = 0;
	dir_oi->oi_nlink++;
	
	entry->od_ino = entry_ino;
	strncpy(entry->od_name,dentry->d_name.name, dentry->d_name.len);
	entry->od_name[dentry->d_name.len] = 0; 
	
	
	/* 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:Davidy22,项目名称:111Project3,代码行数:56,代码来源:ospfsmod.c


示例13: ospfs_create

static int
ospfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd)
{
	ospfs_inode_t *dir_oi = ospfs_inode(dir->i_ino);
	ospfs_direntry_t *dir_entry;
	ospfs_inode_t *inode;
	uint32_t entry_ino = 0;

	// check if name too long
	if (dentry->d_name.len > OSPFS_MAXNAMELEN)
        return -ENAMETOOLONG;
	// check if directory entry already exists
	if (find_direntry(dir_oi, dentry->d_name.name, dentry->d_name.len))
		return -EEXIST;

	// create new directory entry
	dir_entry = create_blank_direntry(dir_oi);
	if (IS_ERR(dir_entry))
		return PTR_ERR(dir_entry);

	// find empty inode
	for (entry_ino = 0; entry_ino < ospfs_super->os_ninodes; entry_ino++) {
		inode = ospfs_inode(entry_ino);
		if (inode->oi_nlink == 0)
			break; // empty inode
	}
	if (entry_ino == ospfs_super->os_ninodes)
		return -ENOSPC;

	// initialize directory entry
	dir_entry->od_ino = entry_ino;
	memcpy(dir_entry->od_name, dentry->d_name.name, dentry->d_name.len);
	dir_entry->od_name[dentry->d_name.len] = '\0';
	// initialize file
	inode->oi_size = 0;
	inode->oi_ftype = OSPFS_FTYPE_REG;
	inode->oi_mode = mode;
	inode->oi_nlink = 1;

	/* 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:wenlongx,项目名称:UCLA_CS,代码行数:50,代码来源:ospfsmod_freeblock.c


示例14: is_dir

int
is_dir(uint32_t i_ino)
{
	ospfs_inode_t *oi = ospfs_inode(i_ino);

	return oi->oi_ftype == OSPFS_FTYPE_DIR ? 1 : 0;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:7,代码来源:ospfs-fsckmod.c


示例15: ospfs_dir_readdir

int
ospfs_dir_readdir(uint32_t i_ino, int *pos, ospfs_direntry_t **_od)
{
	ospfs_inode_t *dir_oi = ospfs_inode(i_ino);
	uint32_t f_pos = *pos;
	int r = -1;
	int entry_off;

	entry_off = f_pos * OSPFS_DIRENTRY_SIZE;
	if (f_pos >= 0 && entry_off < dir_oi->oi_size) {
		ospfs_direntry_t *od = ospfs_inode_data(dir_oi, entry_off);
		ospfs_inode_t *oi;

		/* If at the end of the directory, set 'r' to 1 and exit
		 * the loop.  For now we do this all the time.
		 */
		if (od->od_ino <= 0) {
			r = -1;
			*_od = NULL;
		} else {
			r = 0;
			f_pos++;
			*_od = od;
		}
	}

	// Save the file position and return!
	*pos = f_pos;
	return r;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:30,代码来源:ospfs-fsckmod.c


示例16: is_reg

int
is_reg(uint32_t i_ino)
{
	ospfs_inode_t *oi = ospfs_inode(i_ino);

	return oi->oi_ftype == OSPFS_FTYPE_REG ? 1 : 0;
}
开发者ID:robertabbott,项目名称:CS_111,代码行数:7,代码来源:ospfs-fsckmod.c


示例17: ospfs_follow_link

static void *
ospfs_follow_link(struct dentry *dentry, struct nameidata *nd)
{
	ospfs_symlink_inode_t *oi =
		(ospfs_symlink_inode_t *) ospfs_inode(dentry->d_inode->i_ino);

	// check for conditional symlink
	if (strncmp(oi->oi_symlink, "root?", 5) == 0) {
		// find the pivot between first and second paths
		int pivot = strchr(oi->oi_symlink, ':') - oi->oi_symlink;

		// root user
		if (current->uid == 0) {
			// use null-terminator to indicate ending
			oi->oi_symlink[pivot] = '\0';
			nd_set_link(nd, oi->oi_symlink + 5 + 1); // use first path
		}
		// normal user
		else
			nd_set_link(nd, oi->oi_symlink + pivot + 1); // use second path
	}
	else
		nd_set_link(nd, oi->oi_symlink);

	return (void *) 0;
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:26,代码来源:ospfsmod_freeblock.c


示例18: ospfs_notify_change

static int
ospfs_notify_change(struct dentry *dentry, struct iattr *attr)
{
	struct inode *inode = dentry->d_inode;
	ospfs_inode_t *oi = ospfs_inode(inode->i_ino);
	int retval = 0;

	if (attr->ia_valid & ATTR_SIZE) {
		// We should not be able to change directory size
		if (oi->oi_ftype == OSPFS_FTYPE_DIR)
			return -EPERM;
		if ((retval = change_size(oi, attr->ia_size)) < 0)
			goto out;
	}

	if (attr->ia_valid & ATTR_MODE)
		// Set this inode's mode to the value 'attr->ia_mode'.
		oi->oi_mode = attr->ia_mode;

	if ((retval = inode_change_ok(inode, attr)) < 0
	    || (retval = inode_setattr(inode, attr)) < 0)
		goto out;

    out:
	return retval;
}
开发者ID:wenlongx,项目名称:UCLA_CS,代码行数:26,代码来源:ospfsmod_freeblock.c


示例19: 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


示例20: ospfs_follow_link

static void *
ospfs_follow_link(struct dentry *dentry, struct nameidata *nd)
{
	ospfs_symlink_inode_t *oi =
		(ospfs_symlink_inode_t *) ospfs_inode(dentry->d_inode->i_ino);
	// Exercise: Your code here.

	nd_set_link(nd, oi->oi_symlink);
	return (void *) 0;
}
开发者ID:Saqib117,项目名称:Lab-3,代码行数:10,代码来源:ospfsmod.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ oss函数代码示例发布时间:2022-05-30
下一篇:
C++ ospfs_block函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap