Jump to content

Linux to Windows port help


Recommended Posts

I haven't had much luck concerning programming questions in this forum and definately don't get answers related to windows in the linux forum but I'll try again. Im looking for or perhaps my call is supported, that returns information about a mounted file system. Basically in other word I could return how much information is available on C:\

The first bit determines a mount point for a given directory name while the second refreshes this mountpoint.

Thanks in advance guys

static char *
find_mount_point (const char *file)
{
 char saved_cwd[MAXFILEPATH];
 static char mp[MAXFILEPATH];
 struct stat last_stat;

 getcwd (saved_cwd, MAXFILEPATH);

 if (chdir (file) < 0){
   log_message(LOG_ERROR, "Unable to change to dir/file %s\n", file);
   return NULL;
 }
 
 if (stat (".", &last_stat) < 0){
   log_message(LOG_ERROR, "Unable to get stat for dir/file %s\n", file);
   goto done;
 }

 /* Now walk up FILE's parents until we find another filesystem or /,
    chdiring as we go.  LAST_STAT holds stat information for the last place
    we visited.  */
 for (;;)
   {
     struct stat st;
     if (stat ("..", &st) < 0)
 goto done;
     if (st.st_dev != last_stat.st_dev || st.st_ino == last_stat.st_ino)
 /* cwd is the mount point.  */
 break;
     if (chdir ("..") < 0)
 goto done;
     last_stat = st;
   }

 /* Finally reached a mount point, see what it's called.  */
 getcwd (mp, MAXFILEPATH);

done:
 /* Restore the original cwd.  */
 {
   int save_errno = errno;
   chdir(saved_cwd);
   errno = save_errno;
 }

 return mp;
}

void refreshMount(struct userMount *mount){
 struct statfs s;

 if (statfs(mount->mountPoint, &s) != 0) {    
   log_message(LOG_ERROR, "Unable to get stats on mount %s : %s\n", mount->mountPoint, strerror(errno));
   return;
 }
 
 mount->usedSize = (long long)((((long long)s.f_blocks) - s.f_bfree)* s.f_bsize);
 mount->freeSize = (long long)(((long long)s.f_bavail) * s.f_bsize);
     
 log_message(LOG_DEBUG, "Mount %s : used=%llu free=%llu\n", mount->mountPoint,
   mount->usedSize, mount->freeSize);
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy