1

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?

Hao
  • 163
  • 2
  • 11

2 Answers2

1

Why not see the kernel code which fills /proc/mounts

mountstats_open() in base.c

refer get filesystem mount point in kernel module

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