You are not logged in.

#1 2012-03-18 03:50:27

kdar
Member
From: Sweet home Alabama!
Registered: 2009-06-27
Posts: 356

How /dev/null is implemented? How it works in background?

How does /dev/null works on hardware level? or kernel level?

If you send something to /dev/null, what happens to those output bits? Are they still written somewhere? or a buffer or anywhere on the drive?

Offline

#2 2012-03-18 03:55:47

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: How /dev/null is implemented? How it works in background?

It's all implemented via file_operations (drivers/char/mem.c if you're curious to look yourself):

static const struct file_operations null_fops = {
	.llseek		= null_lseek,
	.read		= read_null,
	.write		= write_null,
	.splice_write	= splice_write_null,
};

write_null is what's called when you write to /dev/null. It always returns the same number of bytes that you write to it:

static ssize_t write_null(struct file *file, const char __user *buf,
			  size_t count, loff_t *ppos)
{
	return count;
}

That's it. The buffer is just ignored.

Last edited by falconindy (2012-03-18 03:56:38)

Offline

Board footer

Powered by FluxBB