[Win32utils-devel] [ANN] win32-driveinfo in CVS

Park Heesob phasis at nownuri.net
Mon Feb 7 01:07:44 EST 2005


Hi all,

I committed win32-driveinfo 0.1.0 to CVS.

What is it?
===========
 A class for  getting information of drives
  
Synopsis
========
  include Win32::DriveInfo

    (sectorsPerCluster,
     bytesPerSector,
     numberOfFreeClusters,
     totalNumberOfClusters,
     freeBytesAvailableToCaller,
     totalNumberOfBytes,
     totalNumberOfFreeBytes) = getDriveSpace('c').to_a
     
     totalNumberOfFreeBytes = getDriveSpace('c').TotalNumberOfFreeBytes

     totalNumberOfBytes = getDriveSpace("\\\\serv\\share").TotalNumberOfBytes

     drives = getDrivesInUse()

     freelet = getFreeDriveLetters()

     drivetype = getDriveType('a')
     

     (volumeName,
      volumeSerialNumber,
      maximumComponentLength,
      fileSystemName, attr) = getVolumeInfo('g').to_a
      

     (majorVersion, minorVersion, buildNumber,
      platformId, buildStr) = getVersionEx().to_a
   
     # check is your CD-ROM loaded
     aCDROM = getDrivesInUse().select {|x| getDriveType(x) == "CDROM" }[0]
     
     aCD_inside = isReady(aCDROM)
 
Constants
=========
DriveInfo::VERSION
 The current version of this package.
DriveInfo::FS_CASE_IS_PRESERVED       
DriveInfo::FS_CASE_SENSITIVE         
DriveInfo::FS_UNICODE_STORED_ON_DISK 
DriveInfo::FS_PERSISTENT_ACLS         
DriveInfo::FS_VOL_IS_COMPRESSED       
DriveInfo::FS_FILE_COMPRESSION       
 
Module Methods
=====
DriveInfo#getDriveSpace( drive )
 Returns a structure that contains drivespace information such as SectorsPerCluster, BytesPerSector, NumberOfFreeClusters,TotalNumberOfClusters 
   and FreeBytesAvailable, :TotalNumberOfBytes, :TotalNumberOfFreeBytes
  drive is drive-letter in either 'c' or 'c:' or 'c:\\' form or UNC path
           in either "\\\\server\\share" or "\\\\server\\share\\" form.

DriveInfo#getDrivesInUse()
 Returns sorted array of all drive-letters in use.

DriveInfo#getFreeDriveLetters()
 Returns sorted array of all drive-letters that are available for allocation.

DriveInfo#getDriveType(drive)
 Returns string value:
     "unknown"       - the drive type cannot be determined.                 
     "no root dir"   - the root directory does not exist.                   
     "Removable"     - the drive can be removed from the drive (removable). 
     "Fixed"         - the disk cannot be removed from the drive (fixed).   
     "Remote"        - the drive is a remote (network) drive.               
     "CDROM"         - the drive is a CD-ROM drive.                         
     "RAM"         - the drive is a RAM disk.                             
     
  drive is drive-letter in either 'c' or 'c:' or 'c:\\' form or UNC path
           in either "\\\\server\\share" or "\\\\server\\share\\" form.

DriveInfo#isReady(drive)
 Returns TRUE if root of the drive is accessible, otherwise FALSE.
 This one isn't really something cool - the function just tries to
 chdir to the drive's root. This takes time and produces unpleasant
 sound in case the removable drive is not loaded. If somebody knows
 some better way to determine is there something inside your CD-ROM
 or FDD - please let me know (in fact CD-ROMs, RAM drives and network
 drives return their status fast,
 may be some other devices make problem, dunno).

  drive is drive-letter in either 'c' or 'c:' or 'c:\\' form or UNC path
           in either "\\\\server\\share" or "\\\\server\\share\\" form.

DriveInfo#getVolumeInfo(drive)
 Returns a structure that contains Volume information such as

   VolumeName             - name of the specified volume.
   VolumeSerialNumber     - volume serial number.
   MaximumComponentLength -
        filename component supported by the specified file system.
        A filename component is that portion of a filename between backslashes.
        Indicate that long names are supported by the specified file system.
        For a FAT file system supporting long names, the function stores
        the value 255, rather than the previous 8.3 indicator. Long names can
        also be supported on systems that use the New Technology file system
        (NTFS).
   FileSystemName         - name of the file system (such as FAT, FAT32, CDFS or NTFS).
   attr                   - array of constants
     FS_CASE_IS_PRESERVED - file system preserves the case of filenames
     FS_CASE_SENSITIVE - file system supports case-sensitive filenames
     FS_UNICODE_STORED_ON_DISK - file system supports Unicode in filenames as they appear on disk
     FS_PERSISTENT_ACLS - file system preserves and enforces ACLs (access-control lists).
         For example, NTFS preserves and enforces ACLs, and FAT does not.
     FS_VOL_IS_COMPRESSED - file system supports file-based compression
     FS_FILE_COMPRESSION - specified volume is a compressed volume; for ex., a DoubleSpace volume
  drive is drive-letter in either 'c' or 'c:' or 'c:\\' form.

DriveInfo#getVersionEx(drive)
  Returns a structure that contains Version information such as     
   MajorVersion - major version number of the operating system. For Windows NT
                   version 3.51, it's 3; for Windows NT version 4.0, it's 4; for Windows XP, Windows 2000 and 
                   Windows 2003, it's 5.

   MinorVersion - minor version number of the operating system. For Windows NT
                   version 3.51, it's 51; for Windows NT version 4.0, it's 0.
   BuildNumber  - build number of the operating system.
   PlatformId   - 0 for Win32s, 1 for Win95/98, 2 for Win NT
   BuildStr     - Windows NT: Contains string, such as "Service Pack 3".
                   Indicates the latest Service Pack installed on the system.
                   If no Service Pack has been installed, the string is empty.
                   Windows 95: Contains a null-terminated string that provides
                   arbitrary additional information about the operating system.

It is pure ruby implementation using Ruby/dl.
 
Regards,

Park Heesob



More information about the win32utils-devel mailing list