How to get inode count of a filesystem on Solaris/Unix?
I was invoking the following command and reading the outpup df -F ufs -o i
. It worked fine initially but then star开发者_运维问答ted to fail for the reason reported and explained here http://wesunsolve.net/bugid/id/6795242.
Although the solution suggested on the above link might work but it is ugly and I want a permanent solution. So, really looking for c api on Solaris/Unix that would give me the total and available number of inodes given a filesystem.
Sample/Example is much appreciated.
The statvfs system call can be used to retrieve file system statistics including the number of total inodes and the number of free inodes. Use the system call to retrieve a statvfs structure and then inspect the f_files
and f_ffree
fields to determine the number of inodes and the number of free inodes, respectively.
Example:
#include <statvfs.h>
struct statvfs buffer;
int status;
fsfilcnt_t total_inodes;
fsfilcnt_t free_inodes;
...
status = statvfs("/home/betaylor/file_in_filesystem", &buffer);
total_inodes = buffer.f_files;
free_inodes = buffer.f_ffree;
...
What you want is statvfs
-- see the man page on the Solaris web site.
精彩评论