Skip to content
Advertisement

Which system call does the Linux file command use?

Do you know which system call the Linux file command uses to determine the type of file?

On the command line, if you use the file command it will reply with something like:

dev-1:~/$ file download.png

download.png: PNG image data, 724x 724, 8-bit/color RGBA, non-interlaced

Is this an entire routine that does that? Or is there a system call that maps to that functionality?

Advertisement

Answer

On the suggestion of @stark I ran the Linux strace command like the following:

$ strace file download.png

A lot of info is returned (many system calls) but I picked through it and found the core item I was looking for:

fstat(3, {st_mode=

I searched and found a man page for fstat:

These functions [lstat, fstatat] return information about a file, in the buffer pointed to by statbuf.

There is also a call (or calls) to pread64() which reads from the file descriptor.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement