00001 /* 00002 * Copyright (c) [2004-2010] Novell, Inc. 00003 * 00004 * All Rights Reserved. 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of version 2 of the GNU General Public License as published 00008 * by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 * more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may 00019 * find current contact information at www.novell.com. 00020 */ 00021 00022 00023 #ifndef DEVICE_H 00024 #define DEVICE_H 00025 00026 00027 #include <string> 00028 #include <list> 00029 00030 #include "storage/StorageTypes.h" 00031 #include "storage/XmlFile.h" 00032 00033 00034 namespace storage 00035 { 00036 using std::string; 00037 using std::list; 00038 00039 00040 class SystemInfo; 00041 00042 00043 class Device 00044 { 00045 public: 00046 00047 Device(const string& nm, const string& dev); 00048 Device(const string& nm, const string& dev, SystemInfo& systeminfo); 00049 Device(const xmlNode* node); 00050 Device(const Device&); 00051 virtual ~Device(); 00052 00053 void saveData(xmlNode* node) const; 00054 00055 const string& name() const { return nm; } 00056 const string& device() const { return dev; } 00057 void setNameDevice(const string& nm, const string& dev); 00058 00059 bool created() const { return create; } 00060 bool deleted() const { return del; } 00061 void setCreated(bool val = true) { create = val; } 00062 void setDeleted(bool val = true) { del = val; } 00063 00064 bool isSilent() const { return silent; } 00065 void setSilent(bool val = true) { silent = val; } 00066 00067 unsigned long long sizeK() const { return size_k; } 00068 string sizeString() const; 00069 00070 bool getMajorMinor(); 00071 unsigned long majorNr() const { return mjr; } 00072 unsigned long minorNr() const { return mnr; } 00073 00074 const std::list<string>& altNames() const { return( alt_names ); } 00075 void setAltNames( std::list<string>& li ) { alt_names=li; } 00076 bool sameDevice( const string& device ) const; 00077 00078 // udev path and ids (without leading "/dev/disk/by-*/") 00079 virtual string udevPath() const; 00080 virtual list<string> udevId() const; 00081 00082 // name for device in /proc/partitions 00083 virtual string procName() const { return ""; } 00084 00085 // full path for device in /sys/block 00086 virtual string sysfsPath() const { return ""; } 00087 00088 void clearUsedBy() { uby.clear(); } 00089 void setUsedBy(UsedByType type, const string& device); 00090 void addUsedBy(UsedByType type, const string& device); 00091 void removeUsedBy(UsedByType type, const string& device); 00092 bool isUsedBy() const { return !uby.empty(); } 00093 bool isUsedBy(UsedByType type) const; 00094 const list<UsedBy>& getUsedBy() const { return uby; } 00095 00096 virtual list<string> getUsing() const { return list<string>(); } 00097 00098 void logDifference(std::ostream& log, const Device& rhs) const; 00099 00100 friend std::ostream& operator<<(std::ostream& s, const Device& d); 00101 00102 protected: 00103 00104 string nm; 00105 string dev; 00106 00107 bool create; 00108 bool del; 00109 00110 bool silent; 00111 00112 unsigned long long size_k; 00113 00114 unsigned long mjr; 00115 unsigned long mnr; 00116 00117 list<UsedBy> uby; 00118 list<string> alt_names; 00119 00120 private: 00121 00122 Device& operator=(const Device&); // disallow 00123 00124 }; 00125 00126 } 00127 00128 00129 #endif
1.5.6