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

📄 trunc.cc

📁 南京航空航天大学开发的一个类Unix和Linux的操作系统,好不好看看就知道了,
💻 CC
字号:
#include <lib/root.h>#include <lib/errno.h>#include "inode.h"#include "fs.h"#include "buf.h"/* need not mark the indirect block buffer dirty */int inode_t::truncate(int nindirect, minixzone_t * index){	int e;	buf_t * b;	assert(nindirect > 0);	if (*index == MINIXFREEBNO)		return 0;	if (e = readb(dev, *index, &b))		return EIO;	minixzone_t * z = (minixzone_t*) b->data, * end = z + MINIXPTRPERBLOCK;	for (; z < end; z++) {		if (nindirect == 1) {			if (*z == MINIXFREEBNO)				continue;			fs->freeb(*z);		} else {			if (e = truncate(nindirect-1, z)) {				b->lose();				return e;			}		}		*z = MINIXFREEBNO;	}	b->lose();	fs->freeb(*index);	*index = MINIXFREEBNO;	return 0;}int inode_t::truncate(){	int e = 0;	/* bno_t end = bnodiv(size + MINIXBSIZE - 1); */	if (!isreg() && !isdir())		return EINVAL;	rwlock.wlock();	for (int i = 0; i < MINIXEND0; i++) {		if (daddr[i] != MINIXFREEBNO) {			fs->freeb(daddr[i]);			daddr[i] = MINIXFREEBNO;		}	}	if (e = truncate(1, daddr + 7))		goto exit;	if (e = truncate(2, daddr + 8))		goto exit;	if (e = truncate(3, daddr + 9))		goto exit;	size = 0;	setdirty();exit:	rwlock.unlock();	return e;}

⌨️ 快捷键说明

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