943,879 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4255
  • C++ RSS
Jun 18th, 2007
0

Coressponding Linux function/library out of Win32...

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

library
- #include <Windows.h>

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

Thank you!
Similar Threads
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006
Jun 18th, 2007
0

Re: Coressponding Linux function/library out of Win32...

See man fstat
fstat gives you struct stat for a given file. This struct has following info abt your file:
  1. mode_t st_mode; /* File mode (see mknod(2)) */
  2. ino_t st_ino; /* Inode number */
  3. dev_t st_dev; /* ID of device containing */
  4. /* a directory entry for this file */
  5. dev_t st_rdev; /* ID of device */
  6. /* This entry is defined only for */
  7. /* char special or block special files */
  8. nlink_t st_nlink; /* Number of links */
  9. uid_t st_uid; /* User ID of the file's owner */
  10. gid_t st_gid; /* Group ID of the file's group */
  11. off_t st_size; /* File size in bytes */
  12. time_t st_atime; /* Time of last access */
  13. time_t st_mtime; /* Time of last data modification */
  14. time_t st_ctime; /* Time of last file status change */
  15. /* Times measured in seconds since */
  16. /* 00:00:00 UTC, Jan. 1, 1970 */
  17. long st_blksize; /* Preferred I/O block size */
  18. blkcnt_t st_blocks; /* Number of 512 byte blocks allocated*/
  19. char st_fstype[_ST_FSTYPSZ]; /* Null-terminated type of filesystem */
It's a system call.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Jun 18th, 2007
0

Re: Coressponding Linux function/library out of Win32...

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.

c++ Syntax (Toggle Plain Text)
  1. //#include <sys/vfs.h>
  2. #include <sys/types.h>
  3. #include <fcntl.h>
  4. #include <sys/stat.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. struct stat buffer;
  10. int status;
  11. off_t size;
  12. blkcnt_t fblock;
  13.  
  14. int main(){
  15. size = buffer.st_size;
  16. fblock = buffer.st_blocks;
  17.  
  18. int fildes = open("/dev/hda", O_RDWR);
  19.  
  20. status = fstat(fildes, &buffer);
  21.  
  22. cout << "size: " << size << endl;
  23. cout << "free blocks: " << fblock << endl;
  24.  
  25. cout << status << endl;
  26. return 0;
  27. }
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006
Jun 18th, 2007
0

Re: Coressponding Linux function/library out of Win32...

In addition, I'm getting a 0 in both the size and the free blocks. T_T
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006
Jun 18th, 2007
1

Re: Coressponding Linux function/library out of Win32...

>> 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.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Jun 18th, 2007
1

Re: Coressponding Linux function/library out of Win32...

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 18th, 2007
0

Re: Coressponding Linux function/library out of Win32...

@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!
Last edited by jaepi; Jun 18th, 2007 at 10:23 pm.
Reputation Points: 32
Solved Threads: 4
Practically a Master Poster
jaepi is offline Offline
647 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ filesystem operations??
Next Thread in C++ Forum Timeline: Please help with assignment





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC