1
00:00:00,002 --> 00:00:05,002
(upbeat music begins)

2
00:00:05,002 --> 00:00:07,000
- [Instructor] Some fun with Dev Null,

3
00:00:07,000 --> 00:00:10,002
everybody's favorite device file, I think.

4
00:00:10,002 --> 00:00:14,006
Let's start out by looking at the file dev null

5
00:00:14,006 --> 00:00:18,006
and finding the major number, and it's number one.

6
00:00:18,006 --> 00:00:21,003
All righty, it's also minor number three,

7
00:00:21,003 --> 00:00:26,006
but let's see all the other device files, major number one.

8
00:00:26,006 --> 00:00:31,009
So let's look in Dev

9
00:00:31,009 --> 00:00:39,003
and we're going to grep space one comma space.

10
00:00:39,003 --> 00:00:41,004
And we check to make sure we're looking at

11
00:00:41,004 --> 00:00:44,003
only character device files.

12
00:00:44,003 --> 00:00:47,001
There's any B's in there, they could also be a one,

13
00:00:47,001 --> 00:00:48,009
but they would be a block driver,

14
00:00:48,009 --> 00:00:49,009
not a character driver.

15
00:00:49,009 --> 00:00:51,005
So that'd be a different device driver.

16
00:00:51,005 --> 00:00:54,003
But all these are C, they're all one.

17
00:00:54,003 --> 00:00:56,008
So these are all implemented,

18
00:00:56,008 --> 00:01:00,002
turns out, by the same driver.

19
00:01:00,002 --> 00:01:03,001
Now, for other sorts of major minor numbers,

20
00:01:03,001 --> 00:01:05,009
it might be possible that different minor numbers

21
00:01:05,009 --> 00:01:07,003
are implemented by different drivers,

22
00:01:07,003 --> 00:01:09,003
but for number one, it's the same driver.

23
00:01:09,003 --> 00:01:11,009
It's the memory driver.

24
00:01:11,009 --> 00:01:15,001
And notice that dev null

25
00:01:15,001 --> 00:01:16,009
everybody has write access to.

26
00:01:16,009 --> 00:01:18,009
Makes sense, right?

27
00:01:18,009 --> 00:01:20,003
Because you're always doing greater than dev null

28
00:01:20,003 --> 00:01:21,006
to throw away output.

29
00:01:21,006 --> 00:01:25,000
Some others have write access.

30
00:01:25,000 --> 00:01:28,006
Dev full, dev zero.

31
00:01:28,006 --> 00:01:32,005
Dev zero is very common to read binary zeros,

32
00:01:32,005 --> 00:01:34,002
as many as you want.

33
00:01:34,002 --> 00:01:35,009
It's interesting, you're going to write into dev zero.

34
00:01:35,009 --> 00:01:38,004
What happens when you write into dev zero?

35
00:01:38,004 --> 00:01:40,007
I'll let you figure that out.

36
00:01:40,007 --> 00:01:45,003
Now we want to look at what happens

37
00:01:45,003 --> 00:01:48,003
if we try to read from Dev Null.

38
00:01:48,003 --> 00:01:57,005
So let's strace catting Dev Null.

39
00:01:57,005 --> 00:02:00,009
And let's look at the trace file.

40
00:02:00,009 --> 00:02:08,003
Let's look for the open for Dev Null.

41
00:02:08,003 --> 00:02:11,001
So we see the open right there.

42
00:02:11,001 --> 00:02:12,005
That works.

43
00:02:12,005 --> 00:02:14,002
We get back file descriptor number three.

44
00:02:14,002 --> 00:02:15,005
That's what that three is.

45
00:02:15,005 --> 00:02:17,009
So when we read, we read from three,

46
00:02:17,009 --> 00:02:19,002
we go down just a few lines.

47
00:02:19,002 --> 00:02:22,003
There's where we try to read from three,

48
00:02:22,003 --> 00:02:24,008
that would be a buffer of where to put it.

49
00:02:24,008 --> 00:02:27,009
It actually tries to read 131,000 characters,

50
00:02:27,009 --> 00:02:31,000
says, "Gimme 131,000 characters if you have 'em."

51
00:02:31,000 --> 00:02:34,001
And the driver says you get zero,

52
00:02:34,001 --> 00:02:37,000
I have no characters for you.

53
00:02:37,000 --> 00:02:38,006
That means end of file.

54
00:02:38,006 --> 00:02:41,000
It's fine to try to read from Dev Null.

55
00:02:41,000 --> 00:02:42,008
You just get end of file.

56
00:02:42,008 --> 00:02:44,009
It never gives you any characters.

57
00:02:44,009 --> 00:02:47,000
Kind of interesting, I think.

