Hello there, anyone here knows what is the function or library in Linux that corresponds to the win32 functions/library given bellow.

- #include <Windows.h>

- GetDiskFreeSpaceEx()、GetFileAttribute()、GetModuleFileName()、GetFileVersionInfoSize()、GetFileVersion( )

Thank you!

9 Years
Discussion Span
Last Post by jaepi

See man fstat
fstat gives you struct stat for a given file. This struct has following info abt your file:

mode_t   st_mode;                /* File mode (see mknod(2)) */
     ino_t    st_ino;                 /* Inode number */
     dev_t    st_dev;                 /* ID of device containing */
                                      /* a directory entry for this file */
     dev_t    st_rdev;                /* ID of device */
                                      /* This entry is defined only for */
                                      /* char special or block special files */
     nlink_t  st_nlink;               /* Number of links */
     uid_t    st_uid;                 /* User ID of the file's owner */
     gid_t    st_gid;                 /* Group ID of the file's group */
     off_t    st_size;                /* File size in bytes */
     time_t   st_atime;               /* Time of last access */
     time_t   st_mtime;               /* Time of last data modification */
     time_t   st_ctime;               /* Time of last file status change */
                                      /* Times measured in seconds since */
                                      /* 00:00:00 UTC, Jan. 1, 1970 */
     long     st_blksize;             /* Preferred I/O block size */
     blkcnt_t st_blocks;              /* Number of 512 byte blocks allocated*/
     char     st_fstype[_ST_FSTYPSZ]; /* Null-terminated type of filesystem */

It's a system call.


I tried to used the function to my hard drive but it's giving me a -1 return. I checked the mode it's both readable and writable for the root and ordinary users. T_T. *sigh*. What do you think is the problem? Here's my code.

//#include <sys/vfs.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <iostream>

using namespace std;

struct stat buffer;
int status;
off_t size;
blkcnt_t fblock;

int main(){
    size = buffer.st_size;
    fblock = buffer.st_blocks;

    int fildes = open("/dev/hda", O_RDWR);
    status = fstat(fildes, &buffer);
    cout << "size: " << size << endl;
    cout << "free blocks: " << fblock << endl;    
    cout << status << endl;
    return 0;

In addition, I'm getting a 0 in both the size and the free blocks. T_T


>> int fildes = open("/dev/hda", O_RDWR);
Seems like you're trying to access a special file (device)
I donno abt those. Check is the man page says anything abt it.
There are at least 2 attributes that indicate this:
1. dev_t st_rdev; /* ID of device */
2. char st_fstype[_ST_FSTYPSZ]; /* Null-terminated type of filesystem */
But they only seem to indicate that it's a special file.


> GetDiskFreeSpaceEx()
Dunno, but the 'df' command line program provides this information. If you could locate the Linux source for that program, perhaps you'll find out how it's done.

> GetFileAttribute()
Use the stat() API as described already. Should be good for regular files and directories.
Remember, if it returns -1, then look at the 'errno' variable to find out why it failed.

> GetModuleFileName()
The nearest equivalent is argv[0], as passed to your main()

> GetFileVersionInfoSize()
> GetFileVersion( )
AFAIK, there is no consistent way of putting version information into a file. Shared libraries in particular encode the version into the filename, but that's about it.


@thekashyap - Oh, I see. I'm actually dealing with the cd/dvd-rw drive and the media inside it. As what I have read, the function GetDiskFreeSpaceEx( ) has a parameter that deals with the free space in the cd/dvd media, but I'm not quite sure of that. I saw a function which is,I think, quite similar to fstat(), it's statvfs and fstatvfs. I tried both but they still give the same 0 value on the size and the free blocks. *sigh*.

@Salem - I'll try these one dude.

@thekashyap and Salem - Thanks! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.