title: How to get the filesystem name and size in C?
body: <p>I'm passing a file or a directory to my Unix C program and I want to determine to what file system it belongs to and what is the size of that system. I've tried using <code>getmntent()</code> from <code>mntent.h</code> and some functions from <code>fstab.h</code> but to no luck. Is there any way to do at all?</p>
  
  <p>Edit:
  What I meant by no luck is that for example when using <code>getmntent()</code> the mnt_type field was empty. I used it like this:</p>
  
  <pre><code>struct mntent* storage = getmntent(fopen(argv[1], "r"));
  if(storage) printf("File system type: %s\n", storage-&gt;mnt_type);
  </code></pre>
  
  <p>and using <code>fstab.h</code> always returned NULL.</p>
  
  <p>EDIT 2:</p>
  
  <pre><code>struct statvfs* statisticVfs = malloc(sizeof(struct statvfs));
  rtrn = statvfs(argv[1], statisticVfs);
  if(rtrn != -1)
  {
      printf("Block size: %lu\n", statisticVfs-&gt;f_bsize);
      FILE* myFile = fopen(argv[1], "r");
      if(myFile) puts("Opened!");
      struct mntent* storage = getmntent(myFile);
      if(storage) printf("Type: %s\n", storage-&gt;mnt_type);
  }
  else puts("Error when using statvfs!");
  </code></pre>