00001 /* 00002 * BEEN: Benchmarking Environment 00003 * ============================== 00004 * 00005 * File author: Branislav Repcek 00006 * 00007 * GNU Lesser General Public License Version 2.1 00008 * --------------------------------------------- 00009 * Copyright (C) 2004-2006 Distributed Systems Research Group, 00010 * Faculty of Mathematics and Physics, Charles University in Prague 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public 00014 * License version 2.1, as published by the Free Software Foundation. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00024 * MA 02111-1307 USA 00025 */ 00026 00058 #ifndef LINUX_DETECTOR_INCLUDED 00059 #define LINUX_DETECTOR_INCLUDED 00060 00061 #include <vector> 00062 #include <string> 00063 #include <mntent.h> 00064 #include "../common/UnicodeString.h" 00065 #include "../common/Detector.h" 00066 #include "../common/XMLFileOutput.h" 00067 #include "../common/DiskDrive.h" 00068 #include "../common/DiskPartition.h" 00069 #include "../common/NetworkAdapter.h" 00070 #include "DistributionRegistry.h" 00071 00072 namespace hwdet 00073 { 00078 class LinuxDetector : public Detector 00079 { 00080 public: 00082 LinuxDetector(void); 00083 00085 ~LinuxDetector(void); 00086 00088 bool Initialize(void); 00089 00091 bool Detect(void); 00092 00094 bool Destroy(void); 00095 00097 String GetOutputString(void) const; 00098 00100 bool WriteToStream(OStream &stream) const; 00101 00102 private: 00108 class DriveInfo 00109 { 00110 public: 00112 DriveInfo(const char *dev_name); 00113 00115 static const unsigned long long SECTOR_SIZE = 512; 00116 00118 static const size_t DEVICE_NAME_LENGTH = 16; 00119 00121 char device_name[DEVICE_NAME_LENGTH]; 00122 00124 unsigned long long size; 00125 00127 String media; 00128 00130 String model; 00131 00133 String GetFullDeviceName(void) const; 00134 00136 DiskDrive *GetDiskDrive(void) const; 00137 00138 private: 00140 void ReadSize(void); 00141 00143 void ReadMedia(void); 00144 00146 void ReadModel(void); 00147 00149 std::string base_path; 00150 }; 00151 00154 class FstabEntry 00155 { 00156 public: 00158 FstabEntry(const mntent *entry); 00159 00161 String device_name; 00162 00164 String file_system; 00165 00167 String mount_point; 00168 00175 class MountPointEquals 00176 { 00177 public: 00182 MountPointEquals(const String &mp) : 00183 mount_point(mp) 00184 { 00185 } 00186 00194 bool operator() (const FstabEntry &entry) const 00195 { 00196 return entry.mount_point == mount_point; 00197 } 00198 00199 private: 00201 String mount_point; 00202 }; 00203 00210 class DeviceNameEquals 00211 { 00212 public: 00217 DeviceNameEquals(const String &dn) : 00218 device_name(dn) 00219 { 00220 } 00221 00229 bool operator() (const FstabEntry &entry) const 00230 { 00231 return entry.device_name == device_name; 00232 } 00233 00234 private: 00236 String device_name; 00237 }; 00238 }; 00239 00242 class PartitionInfo 00243 { 00244 public: 00246 PartitionInfo(const String &name, const std::vector< FstabEntry > &fstab_entries); 00247 00249 String device_name; 00250 00252 String device_path; 00253 00255 unsigned long long size; 00256 00258 unsigned long long free_space; 00259 00261 String file_system; 00262 00264 String mount_point; 00265 00267 DiskPartition *GetDiskPartition(void) const; 00268 }; 00269 00272 class InterfaceInfo 00273 { 00274 public: 00276 InterfaceInfo(const char *name, int socket_fd); 00277 00279 String iface_name; 00280 00282 String vendor_name; 00283 00285 String hw_address; 00286 00288 String iface_type; 00289 00291 static const size_t HW_ADDRESS_LENGTH = 6; 00292 00294 unsigned char hw_addr_bytes[HW_ADDRESS_LENGTH]; 00295 00297 NetworkAdapter *GetNetworkAdapter(void) const; 00298 00299 private: 00301 void HwAddressString(void); 00302 }; 00303 00305 bool DetectOS(void); 00306 00308 bool DetectCPU(void); 00309 00311 bool DetectMemory(void); 00312 00314 bool DetectDrives(void); 00315 00317 std::vector< String > ReadDriveNames(void); 00318 00320 std::vector< String > ReadPartitionNames(const String &drive_prefix); 00321 00323 std::vector< FstabEntry > ReadMounts(void); 00324 00326 bool DetectBeenDisk(void); 00327 00329 bool DetectNetwork(void); 00330 00332 bool DetectProducts(void); 00333 00335 DistributionRegistry registry; 00336 }; 00337 } 00338 00339 #endif