mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-14 06:56:51 -04:00
Search for an empty entry in the cluster
This commit is contained in:
parent
ce86d48d6b
commit
ef38a9a260
@ -223,7 +223,7 @@ void k_printf(const char* fmt, ...){
|
||||
|
||||
auto prev = current_column;
|
||||
|
||||
//Decimal
|
||||
//Unsigned Decimal
|
||||
if(ch == 'd'){
|
||||
auto arg = va_arg(va, uint64_t);
|
||||
|
||||
|
@ -277,22 +277,6 @@ std::pair<bool, uint32_t> find_cluster_number(fat32::dd disk, const std::vector<
|
||||
return std::make_pair(false, 0);
|
||||
}
|
||||
|
||||
std::pair<bool, std::unique_heap_array<cluster_entry>> find_directory_cluster(fat32::dd disk, const std::vector<std::string>& path){
|
||||
auto cluster_number = find_cluster_number(disk, path);
|
||||
|
||||
if(cluster_number.first){
|
||||
std::unique_heap_array<cluster_entry> cluster(16 * fat_bs->sectors_per_cluster);
|
||||
|
||||
if(read_sectors(disk, cluster_lba(cluster_number.second), fat_bs->sectors_per_cluster, cluster.get())){
|
||||
return std::make_pair(true, std::move(cluster));
|
||||
} else {
|
||||
return std::make_pair(false, std::unique_heap_array<cluster_entry>());
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(false, std::unique_heap_array<cluster_entry>());
|
||||
}
|
||||
|
||||
std::vector<disks::file> files(fat32::dd disk, const std::vector<std::string>& path){
|
||||
auto cluster_number_search = find_cluster_number(disk, path);
|
||||
if(!cluster_number_search.first){
|
||||
@ -462,5 +446,33 @@ bool fat32::mkdir(dd disk, const disks::partition_descriptor& partition, const s
|
||||
return false;
|
||||
}
|
||||
|
||||
auto cluster_number = find_cluster_number(disk, path);
|
||||
if(!cluster_number.first){
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_heap_array<cluster_entry> directory_cluster(16 * fat_bs->sectors_per_cluster);
|
||||
|
||||
if(read_sectors(disk, cluster_lba(cluster_number.second), fat_bs->sectors_per_cluster, directory_cluster.get())){
|
||||
auto end = -1;
|
||||
auto free = -1;
|
||||
for(size_t i = 0; i < directory_cluster.size(); ++i){
|
||||
auto& entry = directory_cluster[i];
|
||||
|
||||
if(end_of_directory(entry)){
|
||||
end = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!entry_used(entry)){
|
||||
free = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
k_printf("end=%d\n", end);
|
||||
k_printf("free=%d\n", free);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user