1. Mekanisme:
a. Alokasi file pada metode Chained Allocation:
File yang akan dialokasikan mulai pada blok yang ditentukan dan lengthnya
menentukan jumlah blok yang akan dikunjungi oleh file. Pada disk, blok-bloknya
tersebar dimana saja, misalnya dari blok 1 bisa loncat ke blok 10, 11, dst hingga
sesuai dengan jumlah blok.
// File Class
class File {
public:
// Name of File
string filename;
// Size of file
size_t size;
public:
void set_file(File file)
{
this->file = file;
occupied = true;
}
string get_file_name()
{
return file.filename;
}
int get_file_partition_no()
{
return file.partition;
}
bool is_empty()
{
return !occupied;
}
void set_empty()
{
occupied = false;
}
};
return sum;
}
if ((*memory).at(*slot).get_file_name()
== file) {
index = i;
main_index = (*slot);
break;
}
i++;
}
i = main_index;
(*index_page).erase((*index_page).begin() + index);
cout << "File " << file
<< " has been successfully deleted"
<< endl;
}
}
vector<Block>::iterator slot;
string fname;
for (i = 0; i < index_page.size();
i++) {
if (memory.at(index_page.at(i)).get_file_name().length()> max) {
max = memory.at(index_page.at(i)).get_file_name().length();
// Iterate index_pages
for (i = 0; i < index_page.size();
i++) {
cout << "|"
<< string(max / 2 + max % 2
- memory
.at(index_page
.at(i))
.get_file_name()
.length()
/2
- memory
.at(index_page
.at(i))
.get_file_name()
.length()
%2
+ 1,
' ')
<< memory.at(index_page.at(i))
.get_file_name()
<< string(max / 2
- memory
.at(index_page
.at(i))
.get_file_name()
.length()
/2
+ 1,
' ')
<< "|"
<< string(8
- to_string(index_page
.at(i))
.length()
/2
- to_string(index_page
.at(i))
.length()
% 2,
' ')
<< index_page.at(i)
<< string(7
- to_string(index_page
.at(i))
.length()
/ 2,
' ')
<< "|";
j = index_page
.at(i);
fname = memory
.at(j)
.get_file_name();
// Iterator
vector<int>::iterator slot;
<< string(9
- to_string(memory
.at(ind
ex)
.get
_file
_partition
_no())
.length()
/2
- to_string(memory
.at(ind
ex)
.get_fil
e
_partition
_no())
.length()
% 2,
' ')
<< memory
.at(index)
.get_file_partition_no()
<< string(9
- to_string(memory
.at(ind
ex)
.get_fil
e_partition_no())
.length()
/ 2,
' ')
<< "|"
<< endl;
index++;
}
cout << "+------------------+"
<< "------------------+"
<< endl;
}
else
cout << "File does not exist "
<< "in given memory"
<< endl;
}
// Driver Code
int main()
{
// Declare memory of size 16 Blocks
vector<Block> memory(16);
temp.filename = "Report.docx";
temp.size = 6;
set_contiguous_memory(&memory,
&index_page,
temp);
temp.filename = "new_img.png";
temp.size = 3;
set_contiguous_memory(&memory,
&index_page,
temp);
temp.filename = "test.cpp";
temp.size = 2;
set_contiguous_memory(&memory,
&index_page,
temp);
show_contiguous_index(memory, index_page);
cout << "deleting them to see" << " which locations ";
cout << "are going to be set free" << " as our slots"<< endl;
show_contiguous_index(memory, index_page);
temp.filename = "hello.jpeg";
temp.size = 8;
set_contiguous_memory(&memory, &index_page, temp);