Fix tmpfs
This commit is contained in:
parent
3451d50a37
commit
046065c533
@ -1,61 +1,9 @@
|
||||
mkdir /tmp/folder0
|
||||
mkdir /tmp/1
|
||||
sleep 1
|
||||
mkdir /tmp/folder1
|
||||
mkdir /tmp/1/2
|
||||
sleep 1
|
||||
mkdir /tmp/folder2
|
||||
mkdir /tmp/1/2/3
|
||||
sleep 1
|
||||
mkdir /tmp/folder3
|
||||
mkdir /tmp/1/2/3/4
|
||||
sleep 1
|
||||
mkdir /tmp/folder4
|
||||
sleep 1
|
||||
mkdir /tmp/folder5
|
||||
sleep 1
|
||||
mkdir /tmp/folder6
|
||||
sleep 1
|
||||
mkdir /tmp/folder7
|
||||
sleep 1
|
||||
mkdir /tmp/folder8
|
||||
sleep 1
|
||||
mkdir /tmp/folder9
|
||||
sleep 1
|
||||
mkdir /tmp/folder10
|
||||
sleep 1
|
||||
mkdir /tmp/folder11
|
||||
sleep 1
|
||||
mkdir /tmp/folder12
|
||||
sleep 1
|
||||
mkdir /tmp/folder13
|
||||
sleep 1
|
||||
mkdir /tmp/folder14
|
||||
sleep 1
|
||||
mkdir /tmp/folder15
|
||||
sleep 1
|
||||
mkdir /tmp/folder16
|
||||
sleep 1
|
||||
mkdir /tmp/folder17
|
||||
sleep 1
|
||||
mkdir /tmp/folder18
|
||||
sleep 1
|
||||
mkdir /tmp/folder19
|
||||
sleep 1
|
||||
mkdir /tmp/folder20
|
||||
sleep 1
|
||||
mkdir /tmp/folder21
|
||||
sleep 1
|
||||
mkdir /tmp/folder22
|
||||
sleep 1
|
||||
mkdir /tmp/folder23
|
||||
sleep 1
|
||||
mkdir /tmp/folder24
|
||||
sleep 1
|
||||
mkdir /tmp/folder25
|
||||
sleep 1
|
||||
mkdir /tmp/folder26
|
||||
sleep 1
|
||||
mkdir /tmp/folder27
|
||||
sleep 1
|
||||
mkdir /tmp/folder28
|
||||
sleep 1
|
||||
mkdir /tmp/folder29
|
||||
sleep 1
|
||||
mkdir /tmp/folder30
|
||||
mkdir /tmp/1/2/3/4/5
|
@ -36,7 +36,7 @@ VFS::Node* TmpFS::get()
|
||||
tmpfs_root->find_func = TmpFS::finddir;
|
||||
tmpfs_root->readdir_func = TmpFS::readdir;
|
||||
tmpfs_root->mkdir_func = TmpFS::mkdir;
|
||||
tmpfs_root->mode = 0755;
|
||||
tmpfs_root->mode = 0777;
|
||||
tmpfs_root->uid = tmpfs_root->gid = 0;
|
||||
tmpfs_root->atime = tmpfs_root->ctime = tmpfs_root->mtime = clock_now();
|
||||
strncpy(tmpfs_root->name, "tmpfs", sizeof(tmpfs_root->name));
|
||||
@ -75,9 +75,8 @@ int TmpFS::mkdir(VFS::Node* node, const char* name, mode_t mode)
|
||||
if (node->inode >= tmpfs_dirs.size()) return -EINVAL;
|
||||
if (!(node->type & VFS_DIRECTORY)) return -ENOTDIR;
|
||||
auto& parent = tmpfs_dirs[node->inode];
|
||||
uint64_t inode = tmpfs_dirs.size();
|
||||
VFS::Node* new_node = new VFS::Node;
|
||||
new_node->inode = inode;
|
||||
new_node->inode = tmpfs_dirs.size();
|
||||
new_node->find_func = TmpFS::finddir;
|
||||
new_node->readdir_func = TmpFS::readdir;
|
||||
new_node->mkdir_func = TmpFS::mkdir;
|
||||
@ -87,8 +86,12 @@ int TmpFS::mkdir(VFS::Node* node, const char* name, mode_t mode)
|
||||
new_node->uid = new_node->gid = 0;
|
||||
new_node->atime = new_node->ctime = new_node->mtime = clock_now();
|
||||
strncpy(new_node->name, name, sizeof(new_node->name));
|
||||
ensure(tmpfs_dirs.push({{}}));
|
||||
ensure(parent.files.push(
|
||||
new_node)); // We have to push the new node to the parent BEFORE we push the directory object to the list of
|
||||
// tmpfs directories. This is crucial, since pushing to the list of tmpfs directories could relocate
|
||||
// said list, where the parent object is stored, while we would still be using the old parent
|
||||
// object. Thus our changes to the parent would be erased as soon as we exit this function.
|
||||
ensure(tmpfs_dirs.push({{}})); // FIXME: Handle OOM instead of panicking
|
||||
node->length++;
|
||||
ensure(parent.files.push(new_node));
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user