blob: 1a299ea9ee1601208154526fbfe29349e746b09c [file] [log] [blame]
srs5694e7b4ff92009-08-18 13:16:10 -04001// attributes.cc
2// Class to manage partition attribute codes. These are binary bit fields,
3// of which only three are currently (2/2009) documented on Wikipedia.
4
5#define __STDC_LIMIT_MACROS
6#define __STDC_CONSTANT_MACROS
7
8#include <string.h>
9#include <stdint.h>
10#include <stdio.h>
11#include "attributes.h"
12
13using namespace std;
14
15// Constructor. Its main task is to initialize the attribute name
16// data.
17Attributes::Attributes(void) {
18 int i;
19 char temp[ATR_NAME_SIZE];
20
21 // Most bits are undefined, so start by giving them an
22 // appropriate name
23 for (i = 1; i < NUM_ATR; i++) {
24 sprintf(temp, "Undefined bit #%d", i);
25 strcpy(atNames[i], temp);
26 } // for
27
28 // Now reset those names that are defined....
29 strcpy(atNames[0], "system partition");
30 strcpy(atNames[60], "read-only");
31 strcpy(atNames[62], "hidden");
32 strcpy(atNames[63], "do not automount");
33} // Attributes constructor
34
35// Destructor.
36Attributes::~Attributes(void) {
37} // Attributes destructor
38
39// Display current attributes to user
40void Attributes::DisplayAttributes(void) {
41 int i;
42
43 printf("Attribute value is %llX. Set fields are:\n",
44 (unsigned long long) attributes);
45 for (i = 0; i < NUM_ATR; i++) {
46 if (((attributes >> i) % 2) == 1) { // bit is set
47/* if (strncmp("Undefined", atNames[i], 9) != 0)
48 printf("%s\n", atNames[i]); */
49 if (strncmp("Undefined", atNames[NUM_ATR - i - 1], 9) != 0)
50 printf("%s\n", atNames[NUM_ATR - i - 1]);
51 } // if
52 } // for
53} // Attributes::DisplayAttributes()
54
55// Prompt user for attribute changes
56void Attributes::ChangeAttributes(void) {
57 int response, i;
58 uint64_t bitValue;
59
60 printf("Known attributes are:\n");
61 for (i = 0; i < NUM_ATR; i++) {
62 if (strncmp("Undefined", atNames[i], 9) != 0)
63 printf("%d - %s\n", i, atNames[i]);
64 } // for
65
66 do {
67 response = GetNumber(0, 64, -1, "Toggle which attribute field (0-63, 64 to exit): ");
68 if (response != 64) {
69 bitValue = PowerOf2(NUM_ATR - response - 1); // Find the integer value of the bit
70// bitValue = PowerOf2(response); // Find the integer value of the bit
71 if ((bitValue & attributes) == bitValue) { // bit is set
72 attributes -= bitValue; // so unset it
73 printf("Have disabled the '%s' attribute.\n", atNames[response]);
74 } else { // bit is not set
75 attributes += bitValue; // so set it
76 printf("Have enabled the '%s' attribute.\n", atNames[response]);
77 } // if/else
78 } // if
79 } while (response != 64);
80} // Attributes::ChangeAttributes()
81