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


C++ ospfs_inode函数代码示例

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


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


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