mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-09 04:22:04 -04:00
Finalize cd in multi level
This commit is contained in:
parent
99228505b6
commit
f291dd0023
@ -69,8 +69,8 @@ uint64_t free_size();
|
|||||||
const disk_descriptor* mounted_disk();
|
const disk_descriptor* mounted_disk();
|
||||||
const partition_descriptor* mounted_partition();
|
const partition_descriptor* mounted_partition();
|
||||||
|
|
||||||
const string& current_directory();
|
//TODO It is not a really good practice to directly expose the vector
|
||||||
void set_current_directory(const string& directory = string());
|
vector<string>& current_directory();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ namespace fat32 {
|
|||||||
|
|
||||||
typedef const disks::disk_descriptor& dd;
|
typedef const disks::disk_descriptor& dd;
|
||||||
|
|
||||||
vector<disks::file> ls(dd disk, const disks::partition_descriptor& partition, const string& path);
|
vector<disks::file> ls(dd disk, const disks::partition_descriptor& partition, const vector<string>& path);
|
||||||
uint64_t free_size(dd disk, const disks::partition_descriptor& partition);
|
uint64_t free_size(dd disk, const disks::partition_descriptor& partition);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,10 @@ public:
|
|||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool empty() const {
|
||||||
|
return _size;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr size_type capacity() const {
|
constexpr size_type capacity() const {
|
||||||
return _capacity;
|
return _capacity;
|
||||||
}
|
}
|
||||||
@ -70,7 +74,7 @@ public:
|
|||||||
|
|
||||||
//Modifiers
|
//Modifiers
|
||||||
|
|
||||||
void push_back(value_type& element){
|
void push_back(const value_type& element){
|
||||||
if(_capacity == 0){
|
if(_capacity == 0){
|
||||||
_capacity = 1;
|
_capacity = 1;
|
||||||
data = new T[_capacity];
|
data = new T[_capacity];
|
||||||
@ -89,6 +93,10 @@ public:
|
|||||||
data[_size++] = element;
|
data[_size++] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear(){
|
||||||
|
_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//Iterators
|
//Iterators
|
||||||
|
|
||||||
iterator begin(){
|
iterator begin(){
|
||||||
|
@ -45,7 +45,7 @@ const disks::disk_descriptor* _mounted_disk;
|
|||||||
const disks::partition_descriptor* _mounted_partition;
|
const disks::partition_descriptor* _mounted_partition;
|
||||||
|
|
||||||
//TODO This should be improved to suppport multi level
|
//TODO This should be improved to suppport multi level
|
||||||
string pwd;
|
vector<string> pwd;
|
||||||
|
|
||||||
} //end of anonymous namespace
|
} //end of anonymous namespace
|
||||||
|
|
||||||
@ -228,10 +228,6 @@ uint64_t disks::free_size(){
|
|||||||
return fat32::free_size(*_mounted_disk, *_mounted_partition);
|
return fat32::free_size(*_mounted_disk, *_mounted_partition);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& disks::current_directory(){
|
const vector<string>& disks::current_directory(){
|
||||||
return pwd;
|
return pwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void disks::set_current_directory(const string& directory){
|
|
||||||
pwd = directory;
|
|
||||||
}
|
|
||||||
|
@ -186,7 +186,7 @@ bool filename_equals(char* name, const string& path){
|
|||||||
|
|
||||||
} //end of anonymous namespace
|
} //end of anonymous namespace
|
||||||
|
|
||||||
vector<disks::file> fat32::ls(dd disk, const disks::partition_descriptor& partition, const string& path){
|
vector<disks::file> fat32::ls(dd disk, const disks::partition_descriptor& partition, const vector<string>& path){
|
||||||
if(cached_disk != disk.uuid || cached_partition != partition.uuid){
|
if(cached_disk != disk.uuid || cached_partition != partition.uuid){
|
||||||
partition_start = partition.start;
|
partition_start = partition.start;
|
||||||
|
|
||||||
@ -204,22 +204,38 @@ vector<disks::file> fat32::ls(dd disk, const disks::partition_descriptor& partit
|
|||||||
|
|
||||||
auto cluster_addr = cluster_lba(fat_bs->root_directory_cluster_start);
|
auto cluster_addr = cluster_lba(fat_bs->root_directory_cluster_start);
|
||||||
|
|
||||||
unique_heap_array<cluster_entry> root_cluster(16 * fat_bs->sectors_per_cluster);
|
unique_heap_array<cluster_entry> current_cluster(16 * fat_bs->sectors_per_cluster);
|
||||||
|
|
||||||
if(read_sectors(disk, cluster_addr, fat_bs->sectors_per_cluster, root_cluster.get())){
|
k_print_line(path.size());
|
||||||
if(path.empty()){
|
|
||||||
return files(root_cluster);
|
if(read_sectors(disk, cluster_addr, fat_bs->sectors_per_cluster, current_cluster.get())){
|
||||||
} else {
|
for(auto& p : path){
|
||||||
for(auto& entry : root_cluster){
|
bool found = false;
|
||||||
|
|
||||||
|
for(auto& entry : current_cluster){
|
||||||
if(entry_exists(entry) && !is_long_name(entry) && entry.attrib & 0x10){
|
if(entry_exists(entry) && !is_long_name(entry) && entry.attrib & 0x10){
|
||||||
//entry.name is not a real c_string, cannot be compared
|
//entry.name is not a real c_string, cannot be compared
|
||||||
//directly
|
//directly
|
||||||
if(filename_equals(entry.name, path)){
|
if(filename_equals(entry.name, p)){
|
||||||
return files(disk, entry.cluster_low + (entry.cluster_high << 16));
|
unique_heap_array<cluster_entry> cluster(16 * fat_bs->sectors_per_cluster);
|
||||||
|
|
||||||
|
if(read_sectors(disk, cluster_lba(entry.cluster_low + (entry.cluster_high << 16)),
|
||||||
|
fat_bs->sectors_per_cluster, cluster.get())){
|
||||||
|
current_cluster = move(cluster);
|
||||||
|
found = true;
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!found){
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return files(current_cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -475,18 +475,22 @@ void free_command(const vector<string>&){
|
|||||||
void pwd_command(const vector<string>&){
|
void pwd_command(const vector<string>&){
|
||||||
auto& cd = disks::current_directory();
|
auto& cd = disks::current_directory();
|
||||||
|
|
||||||
if(cd.empty()){
|
k_print('/');
|
||||||
k_print_line("/");
|
|
||||||
} else {
|
for(auto& p : cd){
|
||||||
k_printf("/%s\n", cd.c_str());
|
k_print(p);
|
||||||
|
k_print('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
k_print_line();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cd_command(const vector<string>& params){
|
void cd_command(const vector<string>& params){
|
||||||
|
//If there are no params, go to /
|
||||||
if(params.size() == 1){
|
if(params.size() == 1){
|
||||||
disks::set_current_directory();
|
disks::current_directory().clear();
|
||||||
} else {
|
} else {
|
||||||
disks::set_current_directory(params[1]);
|
disks::current_directory().push_back(params[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user