Add support to mkdir & rmdir in hostfs
This commit is contained in:
parent
7d31cb743c
commit
70d7d10eeb
@ -127,8 +127,11 @@ impl INode for HNode {
|
|||||||
FileType::File => {
|
FileType::File => {
|
||||||
try_std!(fs::File::create(&new_path));
|
try_std!(fs::File::create(&new_path));
|
||||||
}
|
}
|
||||||
|
FileType::Dir => {
|
||||||
|
try_std!(fs::create_dir(&new_path));
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!("only support creating regular files in HostFS");
|
warn!("only support creating regular file or directory in HostFS");
|
||||||
return Err(FsError::PermError);
|
return Err(FsError::PermError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,8 +153,7 @@ impl INode for HNode {
|
|||||||
if new_path.is_file() {
|
if new_path.is_file() {
|
||||||
try_std!(fs::remove_file(new_path));
|
try_std!(fs::remove_file(new_path));
|
||||||
} else if new_path.is_dir() {
|
} else if new_path.is_dir() {
|
||||||
unimplemented!("no remove_dir in sgx_std?")
|
try_std!(fs::remove_dir(new_path));
|
||||||
// fs::remove_dir(new_path)?;
|
|
||||||
} else {
|
} else {
|
||||||
return Err(FsError::EntryNotFound);
|
return Err(FsError::EntryNotFound);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,26 @@ static int test_readdir() {
|
|||||||
return test_hostfs_framework(__test_readdir);
|
return test_hostfs_framework(__test_readdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_mkdir_then_rmdir() {
|
||||||
|
const char *dir_path = "/host/hostfs_dir";
|
||||||
|
struct stat stat_buf;
|
||||||
|
|
||||||
|
if (mkdir(dir_path, 00775) < 0) {
|
||||||
|
THROW_ERROR("failed to create the dir");
|
||||||
|
}
|
||||||
|
if (stat(dir_path, &stat_buf) < 0) {
|
||||||
|
THROW_ERROR("failed to stat dir");
|
||||||
|
}
|
||||||
|
if (!S_ISDIR(stat_buf.st_mode)) {
|
||||||
|
THROW_ERROR("failed to check if it is dir");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rmdir(dir_path) < 0) {
|
||||||
|
THROW_ERROR("failed to remove the created dir");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Test suite main
|
// Test suite main
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -163,6 +183,7 @@ static test_case_t test_cases[] = {
|
|||||||
TEST_CASE(test_write_read),
|
TEST_CASE(test_write_read),
|
||||||
TEST_CASE(test_rename),
|
TEST_CASE(test_rename),
|
||||||
TEST_CASE(test_readdir),
|
TEST_CASE(test_readdir),
|
||||||
|
TEST_CASE(test_mkdir_then_rmdir),
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user