I have to write a linux module and I can't find a proper function to list all mounted file system and their information. I know command "df -T" can achieve this and sadly I can't use that. Is there a kernel function that can do this or other way?
Asked
Active
Viewed 697 times
1
-
Have you look [here](http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob_plain;f=src/df.c;hb=HEAD) ? – Ôrel Mar 01 '15 at 14:39
-
you might use system( "df -T > tempfile;")'; FILE * fp = fopen( tempfile, "r"); fgets(..... – user3629249 Mar 01 '15 at 19:26
2 Answers
1
Why not see the kernel code which fills /proc/mounts
mountstats_open()
in base.c

Community
- 1
- 1

Milind Dumbare
- 3,104
- 2
- 19
- 32
-
I saw the code but can't really understand the usage of "current" in your link that is the macro of "thread_info"? I can't use current->namespace in code. – Hao Mar 01 '15 at 16:43
-
@Hao: You do need to somehow decide which filesystem namespace you will query, because the list of mounted filesystems is different for each namespace. – caf Mar 02 '15 at 04:07
0
Your code could open/read the /proc/mounts
file, line by line. It contains everything that is mounted, including many mount points that you would not expect.
In general, the format is the same as the /etc/fstab
file, but will also include all the mounts that the OS adds.

Dan Getz
- 8,774
- 6
- 30
- 64

user3629249
- 16,402
- 1
- 16
- 17