loulou
loulou

Reputation: 331

Difference between character and block files

I'm studying about Drivers programming for Linux kernel. I found out that there are 2 types of of Device files, character file and block file.

For this moment, I don't really want to know what a device file is exactly about, but I would like to know if there is an abstract concept of character (non-buffered) and block (buffered) files in C language (I mean if it is a concept relative to the Operating System or to C language);

Upvotes: 0

Views: 2499

Answers (2)

Devolus
Devolus

Reputation: 22094

In C there is no concept of a character file. You have streams, which you can read ony byte after the other, but that is independent of the underlying hardware. And the C library may or may not buffer it.

On the other hand, on the driver level, a character device is a device which can provide only ony value after the other (serial port would be such an example), as opposed to a block device, which can provide a defined buffer (like a hard disc, CD drive, etc.).

Upvotes: 1

nouney
nouney

Reputation: 4411

to know if there is an abstract concept of character (non-buffered) and block (buffered) files in C language (I mean if it is a concept relative to the Operating System or to C language);

It's relative to the Operating System yes.

to get some sample codes to show the difference between them in language C (independently than if it's about a device file).

You will see no difference. I mean that there's no special C features for a character device or a block one. Of course the code will be different but only the logic, not the language.

This tutorial is pretty awesome if you need more informations.

Upvotes: 1

Related Questions