⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namei.c

📁 《嵌入式系统设计与实例开发实验教材二源码》Linux内核移植与编译实验
💻 C
📖 第 1 页 / 共 3 页
字号:
	UDF_I_UCTIME(inode) = UDF_I_UCTIME(dir) = UDF_I_UMTIME(dir) = CURRENT_UTIME;	mark_inode_dirty(dir);end_rmdir:	if (fibh.sbh != fibh.ebh)		udf_release_data(fibh.ebh);	udf_release_data(fibh.sbh);out:	return retval;}static int udf_unlink(struct inode * dir, struct dentry * dentry){	int retval;	struct inode * inode = dentry->d_inode;	struct udf_fileident_bh fibh;	struct FileIdentDesc *fi;	struct FileIdentDesc cfi;	retval = -ENOENT;	fi = udf_find_entry(dir, dentry, &fibh, &cfi);	if (!fi)		goto out;	retval = -EIO;	if (udf_get_lb_pblock(dir->i_sb, lelb_to_cpu(cfi.icb.extLocation), 0) !=		inode->i_ino)	{		goto end_unlink;	}	if (!inode->i_nlink)	{		udf_debug("Deleting nonexistent file (%lu), %d\n",			inode->i_ino, inode->i_nlink);		inode->i_nlink = 1;	}	retval = udf_delete_entry(dir, fi, &fibh, &cfi);	if (retval)		goto end_unlink;	dir->i_ctime = dir->i_mtime = CURRENT_TIME;	UDF_I_UCTIME(dir) = UDF_I_UMTIME(dir) = CURRENT_UTIME;	mark_inode_dirty(dir);	inode->i_nlink--;	mark_inode_dirty(inode);	inode->i_ctime = dir->i_ctime;	retval = 0;end_unlink:	if (fibh.sbh != fibh.ebh)		udf_release_data(fibh.ebh);	udf_release_data(fibh.sbh);out:	return retval;}static int udf_symlink(struct inode * dir, struct dentry * dentry, const char * symname){	struct inode * inode;	struct PathComponent *pc;	char *compstart;	struct udf_fileident_bh fibh;	struct buffer_head *bh = NULL;	int eoffset, elen = 0;	struct FileIdentDesc *fi;	struct FileIdentDesc cfi;	char *ea;	int err;	int block;	if (!(inode = udf_new_inode(dir, S_IFLNK, &err)))		goto out;	inode->i_mode = S_IFLNK | S_IRWXUGO;	inode->i_data.a_ops = &udf_symlink_aops;	inode->i_op = &page_symlink_inode_operations;	if (UDF_I_ALLOCTYPE(inode) != ICB_FLAG_AD_IN_ICB)	{		struct buffer_head *bh = NULL;		lb_addr bloc, eloc;		Uint32 elen, extoffset;		block = udf_new_block(inode->i_sb, inode,			UDF_I_LOCATION(inode).partitionReferenceNum,			UDF_I_LOCATION(inode).logicalBlockNum, &err);		if (!block)			goto out_no_entry;		bloc = UDF_I_LOCATION(inode);		eloc.logicalBlockNum = block;		eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;		elen = inode->i_sb->s_blocksize;		UDF_I_LENEXTENTS(inode) = elen;		extoffset = udf_file_entry_alloc_offset(inode);		udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 0);		udf_release_data(bh);		block = udf_get_pblock(inode->i_sb, block,			UDF_I_LOCATION(inode).partitionReferenceNum, 0);		bh = udf_tread(inode->i_sb, block);		lock_buffer(bh);		memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);		mark_buffer_uptodate(bh, 1);		unlock_buffer(bh);		mark_buffer_dirty_inode(bh, inode);	}	else	{		block = udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0);		bh = udf_tread(inode->i_sb, block);	}	ea = bh->b_data + udf_ext0_offset(inode);	eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode);	pc = (struct PathComponent *)ea;	if (*symname == '/')	{		do		{			symname++;		} while (*symname == '/');		pc->componentType = 1;		pc->lengthComponentIdent = 0;		pc->componentFileVersionNum = 0;		pc += sizeof(struct PathComponent);		elen += sizeof(struct PathComponent);	}	err = -ENAMETOOLONG;	while (*symname)	{		if (elen + sizeof(struct PathComponent) > eoffset)			goto out_no_entry;		pc = (struct PathComponent *)(ea + elen);		compstart = (char *)symname;		do		{			symname++;		} while (*symname && *symname != '/');		pc->componentType = 5;		pc->lengthComponentIdent = 0;		pc->componentFileVersionNum = 0;		if (pc->componentIdent[0] == '.')		{			if (pc->lengthComponentIdent == 1)				pc->componentType = 4;			else if (pc->lengthComponentIdent == 2 && pc->componentIdent[1] == '.')				pc->componentType = 3;		}		if (pc->componentType == 5)		{			if (elen + sizeof(struct PathComponent) + symname - compstart > eoffset)				goto out_no_entry;			else				pc->lengthComponentIdent = symname - compstart;			memcpy(pc->componentIdent, compstart, pc->lengthComponentIdent);		}		elen += sizeof(struct PathComponent) + pc->lengthComponentIdent;		if (*symname)		{			do			{				symname++;			} while (*symname == '/');		}	}	udf_release_data(bh);	inode->i_size = elen;	if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)		UDF_I_LENALLOC(inode) = inode->i_size;	mark_inode_dirty(inode);	if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err)))		goto out_no_entry;	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);	cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));	if (UDF_SB_LVIDBH(inode->i_sb))	{		struct LogicalVolHeaderDesc *lvhd;		Uint64 uniqueID;		lvhd = (struct LogicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse);		uniqueID = le64_to_cpu(lvhd->uniqueID);		*(Uint32 *)((struct ADImpUse *)cfi.icb.impUse)->impUse =			cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);		if (!(++uniqueID & 0x00000000FFFFFFFFUL))			uniqueID += 16;		lvhd->uniqueID = cpu_to_le64(uniqueID);		mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));	}	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);	if (UDF_I_ALLOCTYPE(dir) == ICB_FLAG_AD_IN_ICB)	{		mark_inode_dirty(dir);		dir->i_version = ++event;	}	if (fibh.sbh != fibh.ebh)		udf_release_data(fibh.ebh);	udf_release_data(fibh.sbh);	d_instantiate(dentry, inode);	err = 0;out:	return err;out_no_entry:	inode->i_nlink--;	mark_inode_dirty(inode);	iput(inode);	goto out;}static int udf_link(struct dentry * old_dentry, struct inode * dir,	 struct dentry *dentry){	struct inode *inode = old_dentry->d_inode;	struct udf_fileident_bh fibh;	int err;	struct FileIdentDesc cfi, *fi;	if (S_ISDIR(inode->i_mode))		return -EPERM;	if (inode->i_nlink >= (256<<sizeof(inode->i_nlink))-1)		return -EMLINK;	if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err)))		return err;	cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);	cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));	if (UDF_SB_LVIDBH(inode->i_sb))	{		struct LogicalVolHeaderDesc *lvhd;		Uint64 uniqueID;		lvhd = (struct LogicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse);		uniqueID = le64_to_cpu(lvhd->uniqueID);		*(Uint32 *)((struct ADImpUse *)cfi.icb.impUse)->impUse =			cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);		if (!(++uniqueID & 0x00000000FFFFFFFFUL))			uniqueID += 16;		lvhd->uniqueID = cpu_to_le64(uniqueID);		mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));	}	udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);	if (UDF_I_ALLOCTYPE(dir) == ICB_FLAG_AD_IN_ICB)	{		mark_inode_dirty(dir);		dir->i_version = ++event;	}	if (fibh.sbh != fibh.ebh)		udf_release_data(fibh.ebh);	udf_release_data(fibh.sbh);	inode->i_nlink ++;	inode->i_ctime = CURRENT_TIME;	UDF_I_UCTIME(inode) = CURRENT_UTIME;	mark_inode_dirty(inode);	atomic_inc(&inode->i_count);	d_instantiate(dentry, inode);	return 0;}/* Anybody can rename anything with this: the permission checks are left to the * higher-level routines. */static int udf_rename (struct inode * old_dir, struct dentry * old_dentry,	struct inode * new_dir, struct dentry * new_dentry){	struct inode * old_inode = old_dentry->d_inode;	struct inode * new_inode = new_dentry->d_inode;	struct udf_fileident_bh ofibh, nfibh;	struct FileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi;	struct buffer_head *dir_bh = NULL;	int retval = -ENOENT;	if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi)))	{		if (ofibh.sbh != ofibh.ebh)			udf_release_data(ofibh.ebh);		udf_release_data(ofibh.sbh);	}	if (!ofi || udf_get_lb_pblock(old_dir->i_sb, lelb_to_cpu(ocfi.icb.extLocation), 0) !=		old_inode->i_ino)	{		goto end_rename;	}	nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi);	if (nfi)	{		if (!new_inode)		{			if (nfibh.sbh != nfibh.ebh)				udf_release_data(nfibh.ebh);			udf_release_data(nfibh.sbh);			nfi = NULL;		}	}	if (S_ISDIR(old_inode->i_mode))	{		Uint32 offset = udf_ext0_offset(old_inode);		if (new_inode)		{			retval = -ENOTEMPTY;			if (!empty_dir(new_inode))				goto end_rename;		}		retval = -EIO;		dir_bh = udf_bread(old_inode, 0, 0, &retval);		if (!dir_bh)			goto end_rename;		dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset);		if (!dir_fi)			goto end_rename;		if (udf_get_lb_pblock(old_inode->i_sb, cpu_to_lelb(dir_fi->icb.extLocation), 0) !=			old_dir->i_ino)		{			goto end_rename;		}		retval = -EMLINK;		if (!new_inode && new_dir->i_nlink >= (256<<sizeof(new_dir->i_nlink))-1)			goto end_rename;	}	if (!nfi)	{		nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval);		if (!nfi)			goto end_rename;	}	new_dir->i_version = ++event;	/*	 * Like most other Unix systems, set the ctime for inodes on a	 * rename.	 */	old_inode->i_ctime = CURRENT_TIME;	UDF_I_UCTIME(old_inode) = CURRENT_UTIME;	mark_inode_dirty(old_inode);	/*	 * ok, that's it	 */	ncfi.fileVersionNum = ocfi.fileVersionNum;	ncfi.fileCharacteristics = ocfi.fileCharacteristics;	memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(long_ad));	udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL);	/* The old fid may have moved - find it again */	ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi);	udf_delete_entry(old_dir, ofi, &ofibh, &ocfi);	old_dir->i_version = ++event;	if (new_inode)	{		new_inode->i_nlink--;		new_inode->i_ctime = CURRENT_TIME;		UDF_I_UCTIME(new_inode) = CURRENT_UTIME;		mark_inode_dirty(new_inode);	}	old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;	UDF_I_UCTIME(old_dir) = UDF_I_UMTIME(old_dir) = CURRENT_UTIME;	mark_inode_dirty(old_dir);	if (dir_bh)	{		dir_fi->icb.extLocation = lelb_to_cpu(UDF_I_LOCATION(new_dir));		udf_update_tag((char *)dir_fi, (sizeof(struct FileIdentDesc) +			cpu_to_le16(dir_fi->lengthOfImpUse) + 3) & ~3);		if (UDF_I_ALLOCTYPE(old_inode) == ICB_FLAG_AD_IN_ICB)		{			mark_inode_dirty(old_inode);			old_inode->i_version = ++event;		}		else			mark_buffer_dirty_inode(dir_bh, old_inode);		old_dir->i_nlink --;		mark_inode_dirty(old_dir);		if (new_inode)		{			new_inode->i_nlink --;			mark_inode_dirty(new_inode);		}		else		{			new_dir->i_nlink ++;			mark_inode_dirty(new_dir);		}	}	if (ofi)	{		if (ofibh.sbh != ofibh.ebh)			udf_release_data(ofibh.ebh);		udf_release_data(ofibh.sbh);	}	retval = 0;end_rename:	udf_release_data(dir_bh);	if (nfi)	{		if (nfibh.sbh != nfibh.ebh)			udf_release_data(nfibh.ebh);		udf_release_data(nfibh.sbh);	}	return retval;}struct inode_operations udf_dir_inode_operations = {	lookup:				udf_lookup,	create:				udf_create,	link:				udf_link,	unlink:				udf_unlink,	symlink:			udf_symlink,	mkdir:				udf_mkdir,	rmdir:				udf_rmdir,	mknod:				udf_mknod,	rename:				udf_rename,};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -