namei_1.c

来自「阿基米德操作系统的源代码」· C语言 代码 · 共 69 行

C
69
字号

/////////////////////////////////////////////////////////////////////
#include "general.h"
#include "s_isdirreg.h"

#include "hd_info_struct.h"
#include "dir_entry.h"
#include "msdos_dir_entry.h"
#include "d_inode.h"
#include "m_inode.h"
#include "buffer_head.h"
#include "fat_cache.h"
#include "file.h"
#include "hd_request_struct.h"
#include "super_block.h"

#include "common_head.h"
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
int sys_delete(const char * name){	struct m_inode     * dir, * inode;	struct buffer_head * bh;	struct dir_entry   * de;
	const char         * basename;
	int                  namelen;
	if (!(dir = dir_namei(name,&namelen,&basename)))		return -1;	if (!namelen) {		iput(dir);		return -1;	}	bh = find_entry(dir,basename,namelen,&de);	if (!bh) {		iput(dir);		return -1;	}	inode = iget(dir->i_dev, de->inode);	if (!inode) {		brelse(bh);
		iput(dir);		return -1;	}	if (!S_ISREG(inode->i_mode)) {		iput(inode);
		brelse(bh);		iput(dir);		return -1;	}	inode->i_nlinks--;	inode->i_mtime	= file_datetime;
	inode->i_dirt	= 1;
	iput(inode);

	de->inode		= 0;
	bh->b_dirt		= 1;
	brelse(bh);

	dir->i_mtime	= file_datetime;
	dir->i_dirt		= 1;	iput(dir);
	return 0;}

⌨️ 快捷键说明

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