Back to index

lshw  02.16
Classes | Defines | Typedefs | Enumerations | Functions | Variables
volumes.cc File Reference
#include "version.h"
#include "config.h"
#include "volumes.h"
#include "blockio.h"
#include "lvm.h"
#include "osutils.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <time.h>

Go to the source code of this file.

Classes

struct  fstypes
struct  ext2_super_block
struct  HFSPlusExtentDescriptor
struct  HFSPlusForkData
struct  HFSPlusVolumeHeader
struct  HFSMasterDirectoryBlock
struct  mft_entry
struct  attr_entry
struct  volinfo
struct  stdinfo
struct  attr_entry.__unnamed__

Defines

#define _LARGEFILE_SOURCE
#define _FILE_OFFSET_BITS   64
#define EXT2_SUPER_MAGIC   0xEF53
#define EXT2_DEFAULT_BLOCK_SIZE   1024
#define EXT2_VALID_FS   0x0001 /* Unmounted cleanly */
#define EXT2_ERROR_FS   0x0002 /* Errors detected */
#define EXT2_OS_LINUX   0
#define EXT2_OS_HURD   1
#define EXT2_OS_MASIX   2
#define EXT2_OS_FREEBSD   3
#define EXT2_OS_LITES   4
#define EXT2_FEATURE_COMPAT_DIR_PREALLOC   0x0001
#define EXT2_FEATURE_COMPAT_IMAGIC_INODES   0x0002
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL   0x0004
#define EXT2_FEATURE_COMPAT_EXT_ATTR   0x0008
#define EXT2_FEATURE_COMPAT_RESIZE_INODE   0x0010
#define EXT2_FEATURE_COMPAT_DIR_INDEX   0x0020
#define EXT2_FEATURE_COMPAT_LAZY_BG   0x0040
#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER   0x0001
#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE   0x0002
#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE   0x0008
#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM   0x0010
#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK   0x0020
#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE   0x0040
#define EXT2_FEATURE_INCOMPAT_COMPRESSION   0x0001
#define EXT2_FEATURE_INCOMPAT_FILETYPE   0x0002
#define EXT3_FEATURE_INCOMPAT_RECOVER   0x0004 /* Needs recovery */
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV   0x0008 /* Journal device */
#define EXT2_FEATURE_INCOMPAT_META_BG   0x0010
#define EXT3_FEATURE_INCOMPAT_EXTENTS   0x0040
#define EXT4_FEATURE_INCOMPAT_EXTENTS   0x0040
#define EXT4_FEATURE_INCOMPAT_64BIT   0x0080
#define EXT4_FEATURE_INCOMPAT_MMP   0x0100
#define REISERFSBLOCKSIZE   0x1000
#define HFSBLOCKSIZE   1024
#define HFSTIMEOFFSET   2082844800UL
#define HFS_ATTR_HW_LOCKED   (1 << 7)
#define HFS_ATTR_CLEAN   (1 << 8)
#define HFS_ATTR_BAD_BLOCKS_SPARED   (1 << 9)
#define HFS_ATTR_LOCKED   (1 << 15)
#define MFT_RECORD_IN_USE   1
#define MFT_RECORD_IS_DIRECTORY   2
#define MFT_RECORD_SIZE   1024
#define MFT_MFT   0
#define MFT_MFTMirr   1
#define MFT_LogFile   2
#define MFT_VOLUME   3
#define NTFSTIMEOFFSET   ((int64_t)(369 * 365 + 89) * 24 * 3600 * 10000000)
#define SWAPBLOCKSIZE   1024

Typedefs

typedef uint32_t HFSCatalogNodeID
typedef HFSPlusExtentDescriptor HFSPlusExtentRecord [8]

Enumerations

enum  {
  kHFSVolumeHardwareLockBit = 7, kHFSVolumeUnmountedBit = 8, kHFSVolumeSparedBlocksBit = 9, kHFSVolumeNoCacheRequiredBit = 10,
  kHFSBootVolumeInconsistentBit = 11, kHFSCatalogNodeIDsReusedBit = 12, kHFSVolumeJournaledBit = 13, kHFSVolumeSoftwareLockBit = 15
}
enum  ATTR_TYPES {
  AT_UNUSED = 0, AT_STANDARD_INFORMATION = 0x10, AT_ATTRIBUTE_LIST = 0x20, AT_FILE_NAME = 0x30,
  AT_OBJECT_ID = 0x40, AT_VOLUME_NAME = 0x60, AT_VOLUME_INFORMATION = 0x70, AT_END = 0xffffffff
}
enum  VOLUME_FLAGS {
  VOLUME_IS_DIRTY = 0x0001, VOLUME_RESIZE_LOG_FILE = 0x0002, VOLUME_UPGRADE_ON_MOUNT = 0x0004, VOLUME_MOUNTED_ON_NT4 = 0x0008,
  VOLUME_DELETE_USN_UNDERWAY = 0x0010, VOLUME_REPAIR_OBJECT_ID = 0x0020, VOLUME_MODIFIED_BY_CHKDSK = 0x8000, VOLUME_FLAGS_MASK = 0x803f
}

Functions

 __ID ("@(#) $Id: volumes.cc 2433 2012-01-10 22:01:30Z lyonel $")
static bool detect_luks (hwNode &n, source &s)
static bool detect_ext2 (hwNode &n, source &s)
static bool detect_reiserfs (hwNode &n, source &s)
static bool detect_fat (hwNode &n, source &s)
static bool detect_hfsx (hwNode &n, source &s)
static bool detect_hfs (hwNode &n, source &s)
static bool detect_ntfs (hwNode &n, source &s)
static bool detect_swap (hwNode &n, source &s)
static string uuid (const uint8_t s_uuid[16])
static string datetime (time_t timestamp, bool utc=true)
static string dos_serial (unsigned long serial)
static time_t ntfs2utc (int64_t ntfs_time)
bool scan_volume (hwNode &n, source &s)

Variables

static struct fstypes []

Class Documentation

struct ext2_super_block

Definition at line 75 of file volumes.cc.

Class Members
uint32_t s_algorithm_usage_bitmap
uint16_t s_block_group_nr
uint32_t s_blocks_count
uint32_t s_blocks_count_hi
uint32_t s_blocks_per_group
uint32_t s_checkinterval
uint32_t s_creator_os
uint8_t s_def_hash_version
uint16_t s_def_resgid
uint16_t s_def_resuid
uint32_t s_default_mount_opts
uint16_t s_desc_size
uint16_t s_errors
uint32_t s_feature_compat
uint32_t s_feature_incompat
uint32_t s_feature_ro_compat
uint32_t s_first_data_block
uint32_t s_first_ino
uint32_t s_first_meta_bg
uint32_t s_flags
uint32_t s_frags_per_group
uint32_t s_free_blocks_count
uint32_t s_free_blocks_hi
uint32_t s_free_inodes_count
uint32_t s_hash_seed
uint16_t s_inode_size
uint32_t s_inodes_count
uint32_t s_inodes_per_group
uint8_t s_jnl_backup_type
uint32_t s_jnl_blocks
uint32_t s_journal_dev
uint32_t s_journal_inum
uint8_t s_journal_uuid
char s_last_mounted
uint32_t s_last_orphan
uint32_t s_lastcheck
uint32_t s_log_block_size
int32_t s_log_frag_size
uint16_t s_magic
int16_t s_max_mnt_count
uint16_t s_min_extra_isize
uint16_t s_minor_rev_level
uint32_t s_mkfs_time
uint64_t s_mmp_block
uint16_t s_mmp_interval
uint16_t s_mnt_count
uint32_t s_mtime
uint8_t s_prealloc_blocks
uint8_t s_prealloc_dir_blocks
uint32_t s_r_blocks_count
uint32_t s_r_blocks_count_hi
uint16_t s_raid_stride
uint32_t s_raid_stripe_width
uint32_t s_reserved
uint16_t s_reserved_gdt_blocks
uint32_t s_rev_level
uint16_t s_state
uint8_t s_uuid
char s_volume_name
uint16_t s_want_extra_isize
uint32_t s_wtime
struct HFSPlusExtentDescriptor

Definition at line 512 of file volumes.cc.

Class Members
uint32_t blockCount
uint32_t startBlock
struct HFSPlusForkData

Definition at line 518 of file volumes.cc.

Collaboration diagram for HFSPlusForkData:
Class Members
uint32_t clumpSize
HFSPlusExtentRecord extents
uint64_t logicalSize
uint32_t totalBlocks
struct HFSPlusVolumeHeader

Definition at line 525 of file volumes.cc.

Collaboration diagram for HFSPlusVolumeHeader:
Class Members
HFSPlusForkData allocationFile
uint32_t attributes
HFSPlusForkData attributesFile
uint32_t backupDate
uint32_t blockSize
HFSPlusForkData catalogFile
uint32_t checkedDate
uint32_t createDate
uint32_t dataClumpSize
uint64_t encodingsBitmap
HFSPlusForkData extentsFile
uint32_t fileCount
uint32_t finderInfo
uint32_t folderCount
uint32_t freeBlocks
uint32_t journalInfoBlock
uint32_t lastMountedVersion
uint32_t modifyDate
uint32_t nextAllocation
HFSCatalogNodeID nextCatalogID
uint32_t rsrcClumpSize
uint16_t signature
HFSPlusForkData startupFile
uint32_t totalBlocks
uint16_t version
uint32_t writeCount
struct HFSMasterDirectoryBlock

Definition at line 656 of file volumes.cc.

Class Members
int32_t drAlBlkSiz
int16_t drAlBlSt
uint16_t drAllocPtr
uint16_t drAtrb
int32_t drClpSiz
uint32_t drCrDate
uint32_t drCTClpSiz
uint8_t drCTExtRec
uint32_t drCTFlSize
uint32_t drDirCnt
uint32_t drEmbedExtent
uint16_t drEmbedSigWord
uint32_t drFilCnt
uint32_t drFndrInfo
int16_t drFreeBks
uint32_t drLsMod
uint16_t drNmAlBlks
int16_t drNmFls
uint16_t drNmRtDirs
uint32_t drNxtCNID
uint16_t drSigWord
uint16_t drVBMSt
char drVN
uint32_t drVolBkUp
uint16_t drVSeqNum
uint32_t drWrCnt
uint32_t drXTClpSiz
uint8_t drXTExtRec
uint32_t drXTFlSize
struct mft_entry

Definition at line 744 of file volumes.cc.

Class Members
uint16_t attr_ofs
uint32_t bytes_allocated
uint32_t bytes_used
uint16_t flags
uint16_t links
uint64_t logseqnumber
char magic
uint16_t seq
uint16_t usa_count
uint16_t usa_ofs
struct attr_entry

Definition at line 765 of file volumes.cc.

Class Members
struct attr_entry __unnamed__
uint16_t flags
uint16_t instance
uint32_t length
uint8_t name_length
uint16_t name_offset
uint8_t non_resident
uint32_t type
struct volinfo

Definition at line 829 of file volumes.cc.

Class Members
uint16_t flags
uint8_t major_ver
uint8_t minor_ver
uint64_t reserved
struct stdinfo

Definition at line 836 of file volumes.cc.

Class Members
int64_t creation_time
uint32_t file_attributes
int64_t last_access_time
int64_t last_data_change_time
int64_t last_mft_change_time
struct attr_entry.__unnamed__

Definition at line 791 of file volumes.cc.

Class Members
int8_t reservedR
uint8_t resident_flags
uint32_t value_length
uint16_t value_offset

Define Documentation

#define _FILE_OFFSET_BITS   64

Definition at line 7 of file volumes.cc.

Definition at line 6 of file volumes.cc.

#define EXT2_DEFAULT_BLOCK_SIZE   1024

Definition at line 164 of file volumes.cc.

#define EXT2_ERROR_FS   0x0002 /* Errors detected */

Definition at line 170 of file volumes.cc.

#define EXT2_FEATURE_COMPAT_DIR_INDEX   0x0020

Definition at line 186 of file volumes.cc.

#define EXT2_FEATURE_COMPAT_DIR_PREALLOC   0x0001

Definition at line 181 of file volumes.cc.

#define EXT2_FEATURE_COMPAT_EXT_ATTR   0x0008

Definition at line 184 of file volumes.cc.

#define EXT2_FEATURE_COMPAT_IMAGIC_INODES   0x0002

Definition at line 182 of file volumes.cc.

#define EXT2_FEATURE_COMPAT_LAZY_BG   0x0040

Definition at line 187 of file volumes.cc.

#define EXT2_FEATURE_COMPAT_RESIZE_INODE   0x0010

Definition at line 185 of file volumes.cc.

#define EXT2_FEATURE_INCOMPAT_COMPRESSION   0x0001

Definition at line 197 of file volumes.cc.

#define EXT2_FEATURE_INCOMPAT_FILETYPE   0x0002

Definition at line 198 of file volumes.cc.

#define EXT2_FEATURE_INCOMPAT_META_BG   0x0010

Definition at line 201 of file volumes.cc.

#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE   0x0002

Definition at line 190 of file volumes.cc.

Definition at line 189 of file volumes.cc.

#define EXT2_OS_FREEBSD   3

Definition at line 178 of file volumes.cc.

#define EXT2_OS_HURD   1

Definition at line 176 of file volumes.cc.

#define EXT2_OS_LINUX   0

Definition at line 175 of file volumes.cc.

#define EXT2_OS_LITES   4

Definition at line 179 of file volumes.cc.

#define EXT2_OS_MASIX   2

Definition at line 177 of file volumes.cc.

#define EXT2_SUPER_MAGIC   0xEF53

Definition at line 162 of file volumes.cc.

#define EXT2_VALID_FS   0x0001 /* Unmounted cleanly */

Definition at line 169 of file volumes.cc.

#define EXT3_FEATURE_COMPAT_HAS_JOURNAL   0x0004

Definition at line 183 of file volumes.cc.

#define EXT3_FEATURE_INCOMPAT_EXTENTS   0x0040

Definition at line 202 of file volumes.cc.

#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV   0x0008 /* Journal device */

Definition at line 200 of file volumes.cc.

#define EXT3_FEATURE_INCOMPAT_RECOVER   0x0004 /* Needs recovery */

Definition at line 199 of file volumes.cc.

#define EXT4_FEATURE_INCOMPAT_64BIT   0x0080

Definition at line 204 of file volumes.cc.

#define EXT4_FEATURE_INCOMPAT_EXTENTS   0x0040

Definition at line 203 of file volumes.cc.

#define EXT4_FEATURE_INCOMPAT_MMP   0x0100

Definition at line 205 of file volumes.cc.

#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK   0x0020

Definition at line 194 of file volumes.cc.

Definition at line 195 of file volumes.cc.

#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM   0x0010

Definition at line 193 of file volumes.cc.

#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE   0x0008

Definition at line 192 of file volumes.cc.

#define HFS_ATTR_BAD_BLOCKS_SPARED   (1 << 9)

Definition at line 695 of file volumes.cc.

#define HFS_ATTR_CLEAN   (1 << 8)

Definition at line 694 of file volumes.cc.

#define HFS_ATTR_HW_LOCKED   (1 << 7)

Definition at line 693 of file volumes.cc.

#define HFS_ATTR_LOCKED   (1 << 15)

Definition at line 696 of file volumes.cc.

#define HFSBLOCKSIZE   1024

Definition at line 575 of file volumes.cc.

#define HFSTIMEOFFSET   2082844800UL

Definition at line 577 of file volumes.cc.

#define MFT_LogFile   2

Definition at line 860 of file volumes.cc.

#define MFT_MFT   0

Definition at line 858 of file volumes.cc.

#define MFT_MFTMirr   1

Definition at line 859 of file volumes.cc.

#define MFT_RECORD_IN_USE   1

Definition at line 762 of file volumes.cc.

#define MFT_RECORD_IS_DIRECTORY   2

Definition at line 763 of file volumes.cc.

#define MFT_RECORD_SIZE   1024

Definition at line 857 of file volumes.cc.

#define MFT_VOLUME   3

Definition at line 861 of file volumes.cc.

#define NTFSTIMEOFFSET   ((int64_t)(369 * 365 + 89) * 24 * 3600 * 10000000)

Definition at line 863 of file volumes.cc.

#define REISERFSBLOCKSIZE   0x1000

Definition at line 376 of file volumes.cc.

#define SWAPBLOCKSIZE   1024

Definition at line 1003 of file volumes.cc.


Typedef Documentation

typedef uint32_t HFSCatalogNodeID

Definition at line 510 of file volumes.cc.

Definition at line 516 of file volumes.cc.


Enumeration Type Documentation

anonymous enum
Enumerator:
kHFSVolumeHardwareLockBit 
kHFSVolumeUnmountedBit 
kHFSVolumeSparedBlocksBit 
kHFSVolumeNoCacheRequiredBit 
kHFSBootVolumeInconsistentBit 
kHFSCatalogNodeIDsReusedBit 
kHFSVolumeJournaledBit 
kHFSVolumeSoftwareLockBit 

Definition at line 561 of file volumes.cc.

     {
    /* Bits 0-6 are reserved */
    kHFSVolumeHardwareLockBit       =  7,
    kHFSVolumeUnmountedBit          =  8,
    kHFSVolumeSparedBlocksBit       =  9,
    kHFSVolumeNoCacheRequiredBit    = 10,
    kHFSBootVolumeInconsistentBit   = 11,
    kHFSCatalogNodeIDsReusedBit     = 12,
    kHFSVolumeJournaledBit          = 13,
    /* Bit 14 is reserved */
    kHFSVolumeSoftwareLockBit       = 15
    /* Bits 16-31 are reserved */
};
enum ATTR_TYPES
Enumerator:
AT_UNUSED 
AT_STANDARD_INFORMATION 
AT_ATTRIBUTE_LIST 
AT_FILE_NAME 
AT_OBJECT_ID 
AT_VOLUME_NAME 
AT_VOLUME_INFORMATION 
AT_END 

Definition at line 806 of file volumes.cc.

             {
        AT_UNUSED                       = 0,
        AT_STANDARD_INFORMATION         = 0x10,
        AT_ATTRIBUTE_LIST               = 0x20,
        AT_FILE_NAME                    = 0x30,
        AT_OBJECT_ID                    = 0x40,
        AT_VOLUME_NAME                  = 0x60,
        AT_VOLUME_INFORMATION           = 0x70,
        AT_END                          = 0xffffffff,
       // other values are defined but we don't use them
} ATTR_TYPES;
Enumerator:
VOLUME_IS_DIRTY 
VOLUME_RESIZE_LOG_FILE 
VOLUME_UPGRADE_ON_MOUNT 
VOLUME_MOUNTED_ON_NT4 
VOLUME_DELETE_USN_UNDERWAY 
VOLUME_REPAIR_OBJECT_ID 
VOLUME_MODIFIED_BY_CHKDSK 
VOLUME_FLAGS_MASK 

Definition at line 818 of file volumes.cc.


Function Documentation

__ID ( "@(#) $Id: volumes.cc 2433 2012-01-10 22:01:30Z lyonel $"  )
static string datetime ( time_t  timestamp,
bool  utc = true 
) [static]

Definition at line 215 of file volumes.cc.

{
  char buffer[50];
  tm ltime;

  if(timestamp)
  {
    if(utc)
      localtime_r(&timestamp, &ltime);
    else
      gmtime_r(&timestamp, &ltime);
    strftime(buffer, sizeof(buffer), "%F %T", &ltime);
    return string(buffer);
  }
  else
    return "";
}

Here is the caller graph for this function:

static bool detect_ext2 ( hwNode n,
source s 
) [static]

Definition at line 233 of file volumes.cc.

{
  static char buffer[EXT2_DEFAULT_BLOCK_SIZE];
  source ext2volume;
  ext2_super_block *sb = (ext2_super_block*)buffer;
  uint32_t ext2_version = 0;
  time_t mtime, wtime, mkfstime;
  unsigned long long blocksize = EXT2_DEFAULT_BLOCK_SIZE;

  ext2volume = s;
  ext2volume.blocksize = EXT2_DEFAULT_BLOCK_SIZE;

  if(readlogicalblocks(ext2volume, buffer, 1, 1)!=1) // read the second block
    return false;

  if(le_short(&sb->s_magic) != EXT2_SUPER_MAGIC) // wrong magic number
    return false;

  blocksize = 1024LL*(1 << le_long(&sb->s_log_block_size));
  if(blocksize < EXT2_DEFAULT_BLOCK_SIZE)
    blocksize = EXT2_DEFAULT_BLOCK_SIZE;
  n.setSize(blocksize * le_long(&sb->s_blocks_count));

  switch(le_long(&sb->s_creator_os))
  {
    case EXT2_OS_LINUX:
       n.setVendor("Linux");
       break;
    case EXT2_OS_HURD:
       n.setVendor("GNU Hurd");
       break;
    case EXT2_OS_MASIX:
       n.setVendor("MASIX");
       break;
    case EXT2_OS_FREEBSD:
       n.setVendor("FreeBSD");
       break;
    case EXT2_OS_LITES:
       n.setVendor("LITES");
       break;
  }

  ext2_version = le_short(&sb->s_rev_level);
  n.setVersion(tostring(ext2_version)+"."+tostring(le_short(&sb->s_minor_rev_level)));

  mtime = (time_t)le_long(&sb->s_mtime);
  n.setConfig("mounted", datetime(mtime));
  wtime = (time_t)le_long(&sb->s_wtime);
  n.setConfig("modified", datetime(wtime));

  if(ext2_version >= 1)
  {
    switch(le_short(&sb->s_state))
    {
      case EXT2_VALID_FS:
       n.setConfig("state", "clean");
       break;
      case EXT2_ERROR_FS:
       n.setConfig("state", "unclean");
       break;
      default:
       n.setConfig("state", "unknown");
    }
    n.setConfig("label", hw::strip(string(sb->s_volume_name, sizeof(sb->s_volume_name))));
    n.setConfig("lastmountpoint", hw::strip(string(sb->s_last_mounted, sizeof(sb->s_last_mounted))));
    n.setSerial(hw::strip(uuid(sb->s_uuid)));

    if(le_long(&sb->s_feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL)
    {
      n.addCapability("journaled");
      
      mkfstime = (time_t)le_long(&sb->s_mkfs_time);
      n.setConfig("created", datetime(mkfstime));
    }
    if(le_long(&sb->s_feature_compat) & EXT2_FEATURE_COMPAT_EXT_ATTR)
      n.addCapability("extended_attributes", _("Extended Attributes"));
    if(le_long(&sb->s_feature_ro_compat) & EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
      n.addCapability("large_files", _("4GB+ files"));
    if(le_long(&sb->s_feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
      n.addCapability("huge_files", _("16TB+ files"));
    if(le_long(&sb->s_feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_DIR_NLINK)
      n.addCapability("dir_nlink", _("directories with 65000+ subdirs"));
    if(le_long(&sb->s_feature_incompat) & EXT3_FEATURE_INCOMPAT_RECOVER)
      n.addCapability("recover", _("needs recovery"));
    if(le_long(&sb->s_feature_incompat) & EXT4_FEATURE_INCOMPAT_64BIT)
      n.addCapability("64bit", _("64bit filesystem"));
    if(le_long(&sb->s_feature_incompat) & EXT4_FEATURE_INCOMPAT_EXTENTS)
      n.addCapability("extents", _("extent-based allocation"));
  }

  if(n.isCapable("journaled"))
  {
    if(n.isCapable("huge_files") || n.isCapable("64bit") || n.isCapable("extents") || n.isCapable("dir_nlink"))
    {
      n.addCapability("ext4");
      n.setDescription(_("EXT4 volume"));
      n.setConfig("filesystem", "ext4");
    }
    else
    {
      n.addCapability("ext3");
      n.setDescription(_("EXT3 volume"));
      n.setConfig("filesystem", "ext3");
    }
  }

  return true;
}

Here is the call graph for this function:

static bool detect_fat ( hwNode n,
source s 
) [static]

Definition at line 449 of file volumes.cc.

{
  static char buffer[BLOCKSIZE];
  source fatvolume;
  string magic, label;
  unsigned long long bytes_per_sector = 512;
  unsigned long long reserved_sectors = 0;
  unsigned long long hidden_sectors = 0;
  unsigned long long size = 0;
  unsigned long serial = 0;

  fatvolume = s;
  fatvolume.blocksize = BLOCKSIZE;

                                                  // read the first block
  if(readlogicalblocks(fatvolume, buffer, 0, 1)!=1)
    return false;

  if(be_short(buffer+0x1fe) != 0x55aa)           // no "boot" signature
    return false;

  magic = hw::strip(string(buffer+0x52, 8));
  if(magic != "FAT32")
    magic = hw::strip(string(buffer+0x36, 8));
  if(magic != "FAT12" && magic != "FAT16" && magic != "FAT32")                    // wrong magic
    return false;

  n.setVendor(hw::strip(string(buffer+0x3, 8)));
  n.setVersion(magic);

  bytes_per_sector = le_short(buffer+0xb);
  reserved_sectors = le_short(buffer+0xe);
  hidden_sectors = le_short(buffer+0x1c);
  size = le_long(buffer+0x20);
  size -= reserved_sectors + hidden_sectors;
  size *= bytes_per_sector;
  n.setSize(size);
  n.setCapacity(fatvolume.size);

  n.setConfig("FATs", buffer[0x10]);

  if(magic == "FAT32")
  {
    label = hw::strip(std::string(buffer+0x47, 11));
    serial = le_long(buffer+0x43);
  }
  else
  {
    label = hw::strip(std::string(buffer+0x2b, 11));
    serial = le_long(buffer+0x27);
  }

  if(label != "NO NAME" && label != "")
    n.setConfig("label", label);

  n.setSerial(dos_serial(serial));
  n.setDescription("");

  return true;
}

Here is the call graph for this function:

static bool detect_hfs ( hwNode n,
source s 
) [static]

Definition at line 698 of file volumes.cc.

{
  static char buffer[HFSBLOCKSIZE];
  source hfsvolume;
  string magic;
  HFSMasterDirectoryBlock *vol = (HFSMasterDirectoryBlock*)buffer;
  uint16_t attributes = 0;
  time_t mkfstime, dumptime, wtime;

  hfsvolume = s;
  hfsvolume.blocksize = HFSBLOCKSIZE;

                                                  // read the second block
  if(readlogicalblocks(hfsvolume, buffer, 1, 1)!=1)
    return false;

  magic = hw::strip(string(buffer, 2));
  if((magic != "BD"))              // wrong signature
    return false;

  n.setSize((unsigned long long)be_short(&vol->drNmAlBlks) * (unsigned long long)be_long(&vol->drAlBlkSiz));
  n.setConfig("label", hw::strip(string(vol->drVN, sizeof(vol->drVN))));

  attributes = be_short(&vol->drAtrb);
  if(attributes & (HFS_ATTR_LOCKED | HFS_ATTR_HW_LOCKED))
    n.addCapability("ro");
  if(attributes & HFS_ATTR_CLEAN)
    n.setConfig("state", "clean");
  else
    n.setConfig("state", "unclean");
  if(vol->drFndrInfo[0])
    n.addCapability("bootable");

  mkfstime = (time_t)be_long(&vol->drCrDate);
  dumptime = (time_t)be_long(&vol->drVolBkUp);
  wtime = (time_t)be_long(&vol->drLsMod);
  if(mkfstime)
    n.setConfig("created", datetime(mkfstime - HFSTIMEOFFSET, false));       // all dates use local time
  if(dumptime)
    n.setConfig("backup", datetime(dumptime - HFSTIMEOFFSET, false));
  if(wtime)
    n.setConfig("modified", datetime(wtime - HFSTIMEOFFSET, false));

  return true;
}

Here is the call graph for this function:

static bool detect_hfsx ( hwNode n,
source s 
) [static]

Definition at line 579 of file volumes.cc.

{
  static char buffer[HFSBLOCKSIZE];
  source hfsvolume;
  string magic;
  HFSPlusVolumeHeader *vol = (HFSPlusVolumeHeader*)buffer;
  uint16_t version = 0;
  uint32_t attributes = 0;
  time_t mkfstime, fscktime, wtime;

  hfsvolume = s;
  hfsvolume.blocksize = HFSBLOCKSIZE;

                                                  // read the second block
  if(readlogicalblocks(hfsvolume, buffer, 1, 1)!=1)
    return false;

  magic = hw::strip(string(buffer, 2));
  if((magic != "H+") && (magic != "HX"))         // wrong signature
    return false;

  version = be_short(&vol->version);
  if(version >= 5)
    n.addCapability("hfsx");

  magic = hw::strip(string(buffer+8, 4));
  if(magic == "10.0")
    n.setVendor("Mac OS X");
  if(magic == "8.10")
    n.setVendor("Mac OS");
  if(magic == "HFSJ")
    n.setVendor("Mac OS X (journaled)");
  if(magic == "fsck")
    n.setVendor("Mac OS X (fsck)");
  n.setConfig("lastmountedby", hw::strip(magic));

  n.setSize((unsigned long long)be_long(&vol->blockSize) * (unsigned long long)be_long(&vol->totalBlocks));
  n.setVersion(tostring(version));
 
  attributes = be_long(&vol->attributes);
  if(attributes & (1 << kHFSVolumeJournaledBit))
    n.addCapability("journaled");
  if(attributes & (1 << kHFSVolumeSoftwareLockBit))
    n.addCapability("ro");
  if(attributes & (1 << kHFSBootVolumeInconsistentBit))
    n.addCapability("recover");
  if(attributes & (1 << kHFSVolumeUnmountedBit))
    n.setConfig("state", "clean");
  else
    n.setConfig("state", "unclean");
  
  n.setSerial(uuid((uint8_t*)&vol->finderInfo[6]));     // finderInfo[6] and finderInfo[7] contain uuid

  if(vol->finderInfo[0])
    n.addCapability("bootable");
  if(vol->finderInfo[3])
    n.addCapability("macos", _("Contains a bootable Mac OS installation"));
  if(vol->finderInfo[5])
    n.addCapability("osx", _("Contains a bootable Mac OS X installation"));
  if(vol->finderInfo[0] && (vol->finderInfo[0] == vol->finderInfo[3]))
    n.setConfig("boot", "macos");
  if(vol->finderInfo[0] && (vol->finderInfo[0] == vol->finderInfo[5]))
    n.setConfig("boot", "osx");

  mkfstime = (time_t)(be_long(&vol->createDate) - HFSTIMEOFFSET);
  fscktime = (time_t)(be_long(&vol->checkedDate) - HFSTIMEOFFSET);
  wtime = (time_t)(be_long(&vol->modifyDate) - HFSTIMEOFFSET);
  n.setConfig("created", datetime(mkfstime, false));    // creation time uses local time
  n.setConfig("checked", datetime(fscktime));
  n.setConfig("modified", datetime(wtime));

  return true;
}

Here is the call graph for this function:

static bool detect_luks ( hwNode n,
source s 
) [static]

Definition at line 342 of file volumes.cc.

{
  static char buffer[BLOCKSIZE];
  source luksvolume;
  unsigned luks_version = 0;

  luksvolume = s;
  luksvolume.blocksize = BLOCKSIZE;

                                                  // read the first block
  if(readlogicalblocks(luksvolume, buffer, 0, 1)!=1)
    return false;

  if(memcmp(buffer, "LUKS", 4) != 0)                    // wrong magic number
    return false;
  if(be_short(buffer+4) != 0xbabe)
    return false;

  luks_version = be_short(buffer+6);
  if(luks_version<1) return false;                 // weird LUKS version

  n.addCapability("encrypted", _("Encrypted volume"));
  n.setConfig("version", luks_version);
  n.setConfig("cipher", hw::strip(std::string(buffer+8, 32)));
  n.setConfig("mode", hw::strip(std::string(buffer+40, 32)));
  n.setConfig("hash", hw::strip(std::string(buffer+72, 32)));
  n.setConfig("bits", 8*be_long(buffer+108));
  n.setWidth(8*be_long(buffer+108));
  n.setSerial(hw::strip(std::string(buffer+168, 40)));
  n.setCapacity(luksvolume.size);
  n.setSize(luksvolume.size);
  return true;
}

Here is the call graph for this function:

static bool detect_ntfs ( hwNode n,
source s 
) [static]

Definition at line 870 of file volumes.cc.

{
  static char buffer[BLOCKSIZE];
  source ntfsvolume;
  string magic, serial, name, version;
  unsigned long long bytes_per_sector = 512;
  unsigned long long sectors_per_cluster = 8;
  signed char clusters_per_mft_record = 1;
  signed char clusters_per_index_record = 1;
  unsigned long long reserved_sectors = 0;
  unsigned long long hidden_sectors = 0;
  unsigned long long size = 0;
  unsigned long long mft = 0;
  mft_entry *entry = NULL;
  attr_entry *attr = NULL;
  unsigned long long mft_record_size = MFT_RECORD_SIZE;
  volinfo *vi = NULL;
  stdinfo *info = NULL;
  string guid = "";

  ntfsvolume = s;
  ntfsvolume.blocksize = BLOCKSIZE;

                                                  // read the first block
  if(readlogicalblocks(ntfsvolume, buffer, 0, 1)!=1)
    return false;

  if(be_short(buffer+0x1fe) != 0x55aa)           // no "boot" signature
    return false;

  magic = hw::strip(string(buffer+3, 8));
  if(magic != "NTFS")                            // wrong magic
    return false;

  bytes_per_sector = le_short(buffer+0xb);
  sectors_per_cluster = le_short(buffer+0xd);
  reserved_sectors = le_short(buffer+0xe);
  hidden_sectors = le_short(buffer+0x1c);
  size = le_long(buffer+0x28);
  size -= reserved_sectors + hidden_sectors;
  size *= bytes_per_sector;

  serial = dos_serial(le_long(buffer+0x48));

  mft = le_longlong(buffer+0x30);
  clusters_per_mft_record = (char)buffer[0x40];
  if(clusters_per_mft_record < 0)
    mft_record_size = 1 << -clusters_per_mft_record;
  else
  {
    mft_record_size = clusters_per_mft_record;
    mft_record_size *= bytes_per_sector * sectors_per_cluster;
  }
  clusters_per_index_record = (char)buffer[0x44];

  ntfsvolume = s;
  ntfsvolume.offset += mft * bytes_per_sector * sectors_per_cluster; // point to $MFT
  ntfsvolume.blocksize = mft_record_size;
  // FIXME mft_record_size<=sizeof(buffer)
  if(readlogicalblocks(ntfsvolume, buffer, MFT_VOLUME, 1)!=1)  // read $Volume
    return false;

  entry = (mft_entry*)buffer;
  if(strncmp(entry->magic, "FILE", 4) != 0)
    return false;

  if(le_short(&entry->flags) && MFT_RECORD_IN_USE)      // $Volume is valid
  {
    unsigned offset = le_short(&entry->attr_ofs);

    while(offset < mft_record_size)
    {
       attr = (attr_entry*)(buffer+offset);

       if(attr->type == AT_END)
         break;

       if(!attr->non_resident)            // ignore non-resident attributes
         switch(le_long(&attr->type))
         {
           case AT_STANDARD_INFORMATION:
             info = (stdinfo*)(buffer+offset+le_short(&attr->value_offset));
             break;
           case AT_VOLUME_INFORMATION:
             vi = (volinfo*)(buffer+offset+le_short(&attr->value_offset));
             vi->flags = le_short(&vi->flags);
             version = tostring(vi->major_ver) + "." + tostring(vi->minor_ver);
             break;
           case AT_OBJECT_ID:
             guid = uuid((uint8_t*)buffer+offset+le_short(&attr->value_offset));
             break;
           case AT_VOLUME_NAME:
             name = utf8((uint16_t*)(buffer+offset+le_short(&attr->value_offset)), le_short(&attr->value_length)/2, true);
             break;
           }
       offset += le_short(&attr->length);
    }
  }

  n.setSize(size);
  n.setCapacity(ntfsvolume.size);
  n.setConfig("clustersize", bytes_per_sector * sectors_per_cluster);
  n.setConfig("label", name);
  n.setSerial(serial);
  if(guid != "")
    n.setSerial(guid);
  n.setVersion(version);
  n.setDescription("");
  if(vi)
  {
    if(vi->flags && VOLUME_IS_DIRTY)
      n.setConfig("state", "dirty");
    else
      n.setConfig("state", "clean");

    if(vi->flags && VOLUME_MODIFIED_BY_CHKDSK)
      n.setConfig("modified_by_chkdsk", "true");
    if(vi->flags && VOLUME_MOUNTED_ON_NT4)
      n.setConfig("mounted_on_nt4", "true");
    if(vi->flags && VOLUME_UPGRADE_ON_MOUNT)
      n.setConfig("upgrade_on_mount", "true");
    if(vi->flags && VOLUME_RESIZE_LOG_FILE)
      n.setConfig("resize_log_file", "true");
  }
  if(info)
  {
    n.setConfig("created", datetime(ntfs2utc(le_longlong(&info->creation_time))));
    //n.setConfig("mounted", datetime(ntfs2utc(le_longlong(&info->last_access_time))));
    //n.setConfig("modified", datetime(ntfs2utc(le_longlong(&info->last_mft_change_time))));
  }
  return true;
}

Here is the call graph for this function:

static bool detect_reiserfs ( hwNode n,
source s 
) [static]

Definition at line 378 of file volumes.cc.

{
  static char buffer[REISERFSBLOCKSIZE];
  source reiserfsvolume;
  string magic;
  long long blocksize = 0;

  reiserfsvolume = s;
  reiserfsvolume.blocksize = REISERFSBLOCKSIZE;
                                                  // read the 16th block
  if(readlogicalblocks(reiserfsvolume, buffer, 0x10, 1)!=1)
    return false;

  magic = hw::strip(string(buffer+52, 10));
  if(magic != "ReIsEr2Fs" && magic != "ReIsErFs" && magic != "ReIsEr3Fs")                    // wrong magic
    return false;

  n.setConfig("label", hw::strip(string(buffer + 0x64, 16)));

  blocksize = le_short(buffer+44);
  n.setSize(le_long(buffer)*blocksize);

  if(le_long(buffer+20) != 0)
    n.addCapability("journaled");

  n.setSerial(hw::strip(uuid((uint8_t*)buffer+0x54)));

  switch(le_long(buffer+64))
  {
    case 1:
       n.setConfig("hash", "tea");
       break;
    case 2:
       n.setConfig("hash", "yura");
       break;
    case 3:
       n.setConfig("hash", "r5");
  }

  switch(le_short(buffer+50))
  {
    case 1:
       n.setConfig("state", "clean");
       break;
    case 2:
       n.setConfig("state", "unclean");
       break;
    default:
       n.setConfig("state", "unknown");
  }

  if(magic == "ReIsErFs")
    n.setVersion("3.5");
  if(magic == "ReIsEr2Fs")
    n.setVersion("3.6");
  if(magic == "ReIsEr3Fs")
    n.setVersion("nonstandard " + tostring(le_short(buffer+72)));

  n.setCapacity(reiserfsvolume.size);
  return true;
}

Here is the call graph for this function:

static bool detect_swap ( hwNode n,
source s 
) [static]

Definition at line 1005 of file volumes.cc.

{
  static char buffer[SWAPBLOCKSIZE];
  source swapvolume;
  unsigned long version = 0;
  unsigned long pages = 0;
  unsigned long badpages = 0;
  unsigned long long pagesize = 4096;
  bool bigendian = false;
  string signature = "";

  swapvolume = s;
  swapvolume.blocksize = SWAPBLOCKSIZE;

  if(readlogicalblocks(swapvolume, buffer, 3, 1)!=1) // look for a signature
    return false;
  signature = string(buffer+SWAPBLOCKSIZE-10, 10);
  if(signature != "SWAPSPACE2" && signature != "SWAP-SPACE")
    return false;

  swapvolume = s;
  swapvolume.blocksize = SWAPBLOCKSIZE;
  if(readlogicalblocks(swapvolume, buffer, 1, 1)!=1) // skip the first block
    return false;

  version = le_long(buffer);
  if(version == 0x01000000)
  {
    bigendian = true;
    version = 1;
  }

  if((version < 0) || (version > 1))      // unknown version
    return false;

  if(bigendian)
  {
    pages = be_long(buffer + 4) + 1;
    badpages = be_long(buffer + 8);
  }
  else
  {
    pages = le_long(buffer + 4) + 1;
    badpages = le_long(buffer + 8);
  }
  pagesize = swapvolume.size / (unsigned long long)pages;

  n.setSerial(uuid((uint8_t*)buffer+0xc));
  n.setConfig("label", hw::strip(std::string(buffer+0x1c, 16)));
  n.setConfig("pagesize", pagesize);
  n.setSize((unsigned long long)(pages - badpages) * pagesize);
  n.setCapacity(swapvolume.size);
  n.setVersion(tostring(version));
  n.setDescription("");

  return true;
}

Here is the call graph for this function:

static string dos_serial ( unsigned long  serial) [static]

Definition at line 440 of file volumes.cc.

{
  char buffer[16];

  snprintf(buffer, sizeof(buffer), "%04lx-%04lx", serial >> 16, serial & 0xffff);

  return string(buffer);
}

Here is the caller graph for this function:

static time_t ntfs2utc ( int64_t  ntfs_time) [static]

Definition at line 865 of file volumes.cc.

{
  return (ntfs_time - (NTFSTIMEOFFSET)) / 10000000;
}

Here is the caller graph for this function:

bool scan_volume ( hwNode n,
source s 
)

Definition at line 1063 of file volumes.cc.

{
  int i = 0;

  while(fs_types[i].id)
  {
    if(fs_types[i].detect && fs_types[i].detect(n, s))
    {
      n.addCapability(fs_types[i].id, fs_types[i].description);
      if(n.getConfig("filesystem") == "")
        n.setConfig("filesystem", fs_types[i].id);
      n.addCapability("initialized", _("initialized volume"));
      if(n.getDescription()=="")
        n.setDescription(string(fs_types[i].description) + " "+string(_("volume")));
      return true;
    }
    i++;
  }

  return scan_lvm(n,s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string uuid ( const uint8_t  s_uuid[16]) [static]

Definition at line 207 of file volumes.cc.

{
  char buffer[50];

  snprintf(buffer, sizeof(buffer), "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", s_uuid[0], s_uuid[1], s_uuid[2], s_uuid[3], s_uuid[4], s_uuid[5], s_uuid[6], s_uuid[7], s_uuid[8], s_uuid[9], s_uuid[10], s_uuid[11], s_uuid[12], s_uuid[13], s_uuid[14], s_uuid[15]);
  return string(buffer);
}

Here is the caller graph for this function:


Variable Documentation

struct fstypes[] [static]

Definition at line 43 of file volumes.cc.