Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the file system type that a file is stored on

Tags:

c

bash

unix

How can I determine the type of file-system that a file is stored on? I might have the filename, or later, just a descriptor.

I would happily use a script at first, but would like also to know how to do it with syscalls from C.

like image 796
Will Avatar asked Oct 16 '25 02:10

Will


1 Answers

On the command line/script, You can use stat:

$ stat -f -c "%T" someFileOnExt2Ext3
ext2/ext3

$ stat -f -c "%T" someFileOnNFS
nfs

This eventually leads to the statfs(2) system call:

int statfs(const char *path, struct statfs *buf);

The function statfs() returns information about a mounted file system. path is the pathname of any file within the mounted file system, buf is a pointer to a statfs structure.

like image 133
Andreas Fester Avatar answered Oct 17 '25 16:10

Andreas Fester