summaryrefslogtreecommitdiff
path: root/attributes.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-10-07 13:00:45 -0400
committersrs5694 <srs5694@users.sourceforge.net>2010-10-07 13:00:45 -0400
commit0873e9d0e9345a2c4418b4718db525c9f1111c83 (patch)
tree4c6b2adf5d20e0bce392eb2cf0ebc47801d9495b /attributes.cc
parentab4b0438394df4ae6bdea86194e254d7d35fdea0 (diff)
downloadsgdisk-0873e9d0e9345a2c4418b4718db525c9f1111c83.tar.gz
Version 0.6.12 release; mostly changes in support for disks with other
than 512-byte sectors.
Diffstat (limited to 'attributes.cc')
-rw-r--r--attributes.cc91
1 files changed, 62 insertions, 29 deletions
diff --git a/attributes.cc b/attributes.cc
index f068e6d..07f909a 100644
--- a/attributes.cc
+++ b/attributes.cc
@@ -19,11 +19,33 @@
using namespace std;
string Attributes::atNames[NUM_ATR];
-Attributes::staticInit Attributes::staticInitializer;
+int Attributes::numAttrs = 0;
+//Attributes::staticInit Attributes::staticInitializer;
+
+// Default constructor
+Attributes::Attributes(void) {
+ numAttrs++;
+ if (numAttrs == 1)
+ Setup();
+ attributes = 0;
+} // constructor
+
+// Alternate constructor
+Attributes::Attributes(const uint64_t a) {
+ numAttrs++;
+ if (numAttrs == 1)
+ Setup();
+ attributes = a;
+} // alternate constructor
-Attributes::staticInit::staticInit (void) {
+// Destructor.
+Attributes::~Attributes(void) {
+ numAttrs--;
+} // Attributes destructor
+
+void Attributes::Setup(void) {
ostringstream temp;
-
+
// Most bits are undefined, so start by giving them an
// appropriate name
for (int i = 0; i < NUM_ATR; i++) {
@@ -33,17 +55,13 @@ Attributes::staticInit::staticInit (void) {
} // for
// Now reset those names that are defined....
- Attributes::atNames[0] = "system partition"; // required for computer to operate
- Attributes::atNames[1] = "hide from EFI";
- Attributes::atNames[2] = "legacy BIOS bootable";
- Attributes::atNames[60] = "read-only";
- Attributes::atNames[62] = "hidden";
- Attributes::atNames[63] = "do not automount";
-} // Attributes::staticInit::staticInit
-
-// Destructor.
-Attributes::~Attributes(void) {
-} // Attributes destructor
+ atNames[0] = "system partition"; // required for computer to operate
+ atNames[1] = "hide from EFI";
+ atNames[2] = "legacy BIOS bootable";
+ atNames[60] = "read-only";
+ atNames[62] = "hidden";
+ atNames[63] = "do not automount";
+} // Attributes::Setup()
// Display current attributes to user
void Attributes::DisplayAttributes(void) {
@@ -57,7 +75,7 @@ void Attributes::DisplayAttributes(void) {
cout << hex << attributes << dec << ". Set fields are:\n";
for (i = 0; i < NUM_ATR; i++) {
if ((UINT64_C(1) << i) & attributes) {
- cout << i << " (" << Attributes::GetAttributeName(i) << ")" << "\n";
+ cout << i << " (" << GetAttributeName(i) << ")" << "\n";
numSet++;
} // if
} // for
@@ -67,6 +85,21 @@ void Attributes::DisplayAttributes(void) {
cout << "\n";
} // Attributes::DisplayAttributes()
+// Display attributes for a partition. Note that partNum is just passed for
+// immediate display; it's not used to access a particular partition.
+void Attributes::ShowAttributes(const uint32_t partNum) {
+ uint32_t bitNum;
+ bool bitset;
+
+ for (bitNum = 0; bitNum < 64; bitNum++) {
+ bitset = (UINT64_C(1) << bitNum) & attributes;
+ if (bitset) {
+ cout << partNum+1 << ":" << bitNum << ":" << bitset
+ << " (" << GetAttributeName(bitNum) << ")" << endl;
+ } // if
+ } // for
+} // Attributes::ShowAttributes
+
// Prompt user for attribute changes
void Attributes::ChangeAttributes(void) {
int response;
@@ -78,7 +111,8 @@ void Attributes::ChangeAttributes(void) {
do {
DisplayAttributes();
- response = GetNumber(0, NUM_ATR, -1, "Toggle which attribute field (0-63, 64 to exit): ");
+ response = GetNumber(0, NUM_ATR, 64,
+ "Toggle which attribute field (0-63, 64 or <Enter> to exit): ");
if (response != 64) {
bitValue = UINT64_C(1) << response; // Find the integer value of the bit
if (bitValue & attributes) { // bit is set
@@ -104,19 +138,6 @@ void Attributes::ListAttributes(void) {
} // for
} // Attributes::ListAttributes
-void Attributes::ShowAttributes(const uint32_t partNum) {
- uint32_t bitNum;
- bool bitset;
-
- for (bitNum = 0; bitNum < 64; bitNum++) {
- bitset = (UINT64_C(1) << bitNum) & attributes;
- if (bitset) {
- cout << partNum+1 << ":" << bitNum << ":" << bitset
- << " (" << Attributes::GetAttributeName(bitNum) << ")" << endl;
- } // if
- } // for
-} // Attributes::ShowAttributes
-
// multifaceted attributes access
// returns true upon success, false upon failure
bool Attributes::OperateOnAttributes(const uint32_t partNum, const string& attributeOperator, const string& attributeBits) {
@@ -190,3 +211,15 @@ bool Attributes::OperateOnAttributes(const uint32_t partNum, const string& attri
return true;
} // Attributes::OperateOnAttributes()
+
+/*******************************
+* *
+* Non-class support functions *
+* *
+*******************************/
+
+// Display attributes
+ostream & operator<<(ostream & os, const Attributes & data) {
+ os << data.GetAttributes();
+ return os;
+} // operator<<() \ No newline at end of file