-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVolume.cpp
62 lines (56 loc) · 1.77 KB
/
Volume.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
CHƯƠNG TRÌNH TẠO, ĐỊNH DẠNG VOLUME MyFS.dat
*/
#include "Volume.h"
void createVolume(char* file_name,VOLUME& MyFS){
//open volume file_name (MyFS.dat)
FILE* fp = fopen(file_name, "wb");
//initialize info for volume
strcpy(MyFS.file_name, file_name);
cout << "-----CREATE YOUR VOLUME-----" << endl;
cout << "Enter your volume size: ";
cin >> MyFS.size_volume;
MyFS.size_sector = SECTOR_SIZE;
cout << "SET PASSWORD FOR VOLUME" << endl;
cout << "Enter your password: ";
cin.ignore();
cin.getline(MyFS.password, 24);
fwrite(&MyFS, sizeof(MyFS), 1, fp);
fclose(fp);
cout << "COMPLETE!!!!" << endl;
}
void readVolume(char* file_name) {
VOLUME MyFS;
FILE* fp = fopen(file_name, "rb");
fread(&MyFS, sizeof(VOLUME), 1, fp);
fclose(fp);
cout << "-----VOLUME MyFS.dat-----" << endl;
char pass[25];
do
{
cout << "Enter password for volume MyFS.dat: ";
cin.getline(pass, 24);
cin.ignore();
} while (strcmp(MyFS.password,pass) != 0);
cout << "-----INFO OF VOLUME-----" << endl;
cout << "Volume name: " << MyFS.file_name << endl;
cout << "Size of volume: " << MyFS.size_volume << " GB" << endl;
cout << "Size of sector: " << MyFS.size_sector << " byte" << endl;
cout << "Your password for this volume: " << MyFS.password << endl;
}
void resetPassword(char* file_name, VOLUME& MyFS) {
char current_password[25];
do
{
cout << "Enter your current password: ";
cin.getline(current_password, 24);
} while (strcmp(MyFS.password,current_password) != 0);
cout << "Enter your new password: ";
cin.getline(current_password, 24);
cin.ignore();
strcpy(MyFS.password, current_password);
FILE* fp = fopen(file_name, "r+");
fseek(fp, 0l, SEEK_SET);
fwrite(&MyFS, sizeof(VOLUME), 1, fp);
fclose(fp);
}