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

📄 pipe.c

📁 用于motorala 68K系列处理器的小实时多任务操作系统 The OMU Kernel was written to provide a cut-down Unix-like O/S for a
💻 C
字号:
/****************************************************************************** *	Pipe.c		Pipe system call 	T.Barnaby, Made 9/6/85 ****************************************************************************** * *	Will create a pipe with two file descriptors */# include	"../include/param.h"# include	"../include/inode.h"# include	"../include/signal.h"# include	<errno.h># include	"../include/procs.h"# include	"../include/file.h"# include	"../include/dev.h"# include	"../include/state.h"extern struct file uft[];/* *	Pipe()		System call for opening a pipe */pipe(){	int	fw, fr, err;	# ifdef TPIPESprintf("Pipe open %d\n\r",cur_proc->pid);# endif	/* Opens the pipe */	if(err = pipeopen(&fw, &fr)) return err;# ifdef TPIPESprintf("Opened %d %d\n\r",fw, fr);# endif	/* Returns correct file descriptors */	cur_proc->reg->d1 = fw;	return fr;}/* *	Pipeopen()	Creates a pipe *			Gets two empty slots in the system file table *			linked the the curent processes file slot table. *			Gets a free inode to allocate to the pipe and *			locks it, creates the correct entries in the *			system file table and returns file descritors *			for both read and write files. */pipeopen(fw, fr)int *fw, *fr;{	struct file *wfile, *rfile;	struct inode *inode;	int	(*fnc)();# ifdef TPIPESprintf("Get slots\n");# endif	/* Check if pipe device exists */	if(!(fnc = bdevsw[PDEV_MAJ].openfnc)){		if(state.warning) printf("PIPE: No pipe device\n");		return error(-1);	}	/* File open - open device it's using */	if((*fnc)(PDEV_MIN)){		if(state.warning) printf("PIPE: Unable to open pipe device\n"); 		return error(-1);	}	/* Gets device close function */	fnc = bdevsw[PDEV_MAJ].closefnc;	/* Get slots for files */	if((*fw = getslot()) == -1) return -1;	if((*fr = getslot()) == -1){		freslot(*fw);		/* Close pipe device */		(*fnc)(PDEV_MIN);		return error(-1);	}# ifdef TPIPESprintf("Get inode\n\r");# endif	/* Gets a free inode from the devices inode free list */	if(!(inode = lockfree(&bdevsw[PDEV_MAJ], PDEV_MIN))){		freslot(*fw);		freslot(*fr);		/* Close pipe device */		(*fnc)(PDEV_MIN);		return error(-1);	}	/* Inode is in use */	inode->i_nlink++;	/* Relocks the inode (both read and write file descriptors) */	relock(inode);	wfile = cur_proc->slots[*fw];	rfile = cur_proc->slots[*fr];# ifdef TPIPESprintf("create file entries\n\r");# endif	/* Sets up the uft entries */	f_creat(wfile, inode, WRITEABLE | PIPE, 0777);	f_creat(rfile, inode, READABLE | PIPE, 0777);	/* Sets up the cross pipe links */	wfile->f_pipelink = rfile;	rfile->f_pipelink = wfile;	/* Close pipe device note f_creat opened device as well */	(*fnc)(PDEV_MIN);	return 0;}

⌨️ 快捷键说明

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