0

The C fsize function returns 4096 for special/device files, but is there an integrated function to know the real size of a device file if it is finite ?
I would also like to know if there is a way to know whether a file is a regular file or a device file ?

Thank you !

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

0

Your question is still rather unspecific and broad, and you'll get unspecific answers to unspecific questions, which may be helpful or not. Still here's a try to point you into the right direction.

I would also like to know if there is a way to know whether a file is a regular file or a device file ?

Of course. The most common is the output of ls -l:

$ ls -l /dev
total 0
crw-rw----+ 1 root   audio      14,   4 Jan  5 00:44 audio
crw-------  1 root   root       10, 235 Jan  5 00:44 autofs
drwxr-xr-x  2 root   root           480 Jan 17 01:20 block
drwxr-xr-x  2 root   root           140 Jan 17 01:20 bsg
drwxr-xr-x  3 root   root            60 Jan  5 00:44 bus
lrwxrwxrwx  1 root   root             3 Jan 17 22:14 cdrom -> sr0
[...]

The first character of each entry line reveals the file type; you can find a list of valid types in the ls manual.

As you're asking about the entries in /dev, the most common types there, besides directories and links, are character devices and block devices.

is there an integrated function to know the real size of a device file

As I already pointed out, what you mean with "real size" is the size of the content that's available "in" a device, of which the special files in /dev are just a representation to make access to them available to the system.

The answer to "how to get the size" is "depends on the content". E. g. for a disk partition, which is a block device, you usually mount it and can get the sizes (total, occupied, free space) using df. On the other hand not every block device can be mounted.

And without knowing what exactly you want to achieve that's all you'll get so far. It's now up to you to think about it, search the web (it's all there) and create a new question if you can't figure it out yourself.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Murphy
  • 2,649