F Yaqoob
F Yaqoob

Reputation: 2661

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 started 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.

Upvotes: 2

Views: 6982

Answers (2)

Callie J
Callie J

Reputation: 31316

What you want is statvfs -- see the man page on the Solaris web site.

Upvotes: 1

Brandon E Taylor
Brandon E Taylor

Reputation: 25369

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;
...

Upvotes: 3

Related Questions