Coressponding Linux function/library out of Win32...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Coressponding Linux function/library out of Win32...

 
0
  #1
Jun 18th, 2007
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!
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

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

 
0
  #2
Jun 18th, 2007
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.
Are you Agile.. ?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

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

 
0
  #3
Jun 18th, 2007
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.

  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. }
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

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

 
0
  #4
Jun 18th, 2007
In addition, I'm getting a 0 in both the size and the free blocks. T_T
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

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

 
1
  #5
Jun 18th, 2007
>> 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.
Are you Agile.. ?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
1
  #6
Jun 18th, 2007
> 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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

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

 
0
  #7
Jun 18th, 2007
@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.
Retreat!!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC