2
// Class to manage partition attribute codes. These are binary bit fields,
3
// of which only three are currently (2/2009) documented on Wikipedia.
5
/* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed
6
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
8
#define __STDC_LIMIT_MACROS
9
#define __STDC_CONSTANT_MACROS
14
#include "attributes.h"
18
// Constructor. Its main task is to initialize the attribute name
20
Attributes::Attributes(void) {
22
char temp[ATR_NAME_SIZE];
24
// Most bits are undefined, so start by giving them an
26
for (i = 1; i < NUM_ATR; i++) {
27
sprintf(temp, "Undefined bit #%d", i);
28
strcpy(atNames[i], temp);
31
// Now reset those names that are defined....
32
strcpy(atNames[0], "system partition");
33
strcpy(atNames[60], "read-only");
34
strcpy(atNames[62], "hidden");
35
strcpy(atNames[63], "do not automount");
36
} // Attributes constructor
39
Attributes::~Attributes(void) {
40
} // Attributes destructor
42
// Display current attributes to user
43
void Attributes::DisplayAttributes(void) {
46
printf("Attribute value is %llX. Set fields are:\n",
47
(unsigned long long) attributes);
48
for (i = 0; i < NUM_ATR; i++) {
49
if (((attributes >> i) % 2) == 1) { // bit is set
50
/* if (strncmp("Undefined", atNames[i], 9) != 0)
51
printf("%s\n", atNames[i]); */
52
if (strncmp("Undefined", atNames[NUM_ATR - i - 1], 9) != 0)
53
printf("%s\n", atNames[NUM_ATR - i - 1]);
56
} // Attributes::DisplayAttributes()
58
// Prompt user for attribute changes
59
void Attributes::ChangeAttributes(void) {
63
printf("Known attributes are:\n");
64
for (i = 0; i < NUM_ATR; i++) {
65
if (strncmp("Undefined", atNames[i], 9) != 0)
66
printf("%d - %s\n", i, atNames[i]);
70
response = GetNumber(0, 64, -1, "Toggle which attribute field (0-63, 64 to exit): ");
72
bitValue = PowerOf2(NUM_ATR - response - 1); // Find the integer value of the bit
73
// bitValue = PowerOf2(response); // Find the integer value of the bit
74
if ((bitValue & attributes) == bitValue) { // bit is set
75
attributes -= bitValue; // so unset it
76
printf("Have disabled the '%s' attribute.\n", atNames[response]);
77
} else { // bit is not set
78
attributes += bitValue; // so set it
79
printf("Have enabled the '%s' attribute.\n", atNames[response]);
82
} while (response != 64);
83
} // Attributes::ChangeAttributes()