Skip to content

Commit f2873a4

Browse files
committed
vfs: a bit of cleanup
1 parent 224274b commit f2873a4

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

kernel/source/system/syscall/vfs.cpp

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,24 @@ namespace syscall::vfs
8282
if (!parent.has_value())
8383
return std::nullopt;
8484

85-
const auto res = vfs::resolve(parent, path);
85+
auto res = resolve(parent, path);
8686
if (!res)
8787
return (errno = map_error(res.error()), std::nullopt);
8888

89-
return res.value();
89+
return std::move(res.value());
9090
}
9191

9292
std::optional<lib::path> get_path(const char __user *pathname)
9393
{
9494
if (pathname == nullptr)
9595
return (errno = EFAULT, std::nullopt);
9696

97-
const auto pathname_len = lib::strnlen_user(pathname, vfs::path_max);
97+
const auto pathname_len = lib::strnlen_user(pathname, path_max);
9898
if (pathname_len < 0)
9999
return (errno = EFAULT, std::nullopt);
100100
if (pathname_len == 0)
101101
return (errno = EINVAL, std::nullopt);
102-
if (pathname_len == vfs::path_max)
102+
if (pathname_len == path_max)
103103
return (errno = ENAMETOOLONG, std::nullopt);
104104

105105
lib::path path { static_cast<std::size_t>(pathname_len), 0 };
@@ -112,7 +112,7 @@ namespace syscall::vfs
112112
return std::move(path);
113113
}
114114

115-
std::optional<vfs::path> get_target(sched::process *proc, int dirfd, const char __user *pathname, bool follow_links, bool empty_path)
115+
std::optional<path> get_target(sched::process *proc, int dirfd, const char __user *pathname, bool follow_links, bool empty_path)
116116
{
117117
if (empty_path)
118118
{
@@ -130,22 +130,19 @@ namespace syscall::vfs
130130
if (!val.has_value())
131131
return std::nullopt;
132132

133-
const auto path = val.value();
134-
135-
vfs::path target { };
136-
const auto res = resolve_from(proc, dirfd, path);
133+
auto res = resolve_from(proc, dirfd, val.value());
137134
if (!res.has_value())
138135
return std::nullopt;
139136

140-
target = res->target;
137+
auto target = std::move(res->target);
141138
lib::bug_on(!target.dentry || !target.dentry->inode);
142139

143140
if (follow_links)
144141
{
145-
const auto reduced = vfs::reduce(res->parent, target);
142+
auto reduced = reduce(res->parent, target);
146143
if (!reduced.has_value())
147144
return (errno = map_error(reduced.error()), std::nullopt);
148-
target = reduced.value();
145+
target = std::move(reduced.value());
149146
}
150147
return target;
151148
}
@@ -172,23 +169,23 @@ namespace syscall::vfs
172169
if (!val.has_value())
173170
return -1;
174171

175-
const auto path = val.value();
172+
const auto pathstr = val.value();
176173

177-
vfs::path target { };
178-
const auto res = resolve_from(proc, dirfd, path);
174+
path target { };
175+
auto res = resolve_from(proc, dirfd, pathstr);
179176
if (!res.has_value())
180177
{
181178
if ((flags & o_creat) == 0)
182179
return -1;
183180

184-
const auto parent = resolve_from(proc, dirfd, path.dirname());
181+
const auto parent = resolve_from(proc, dirfd, pathstr.dirname());
185182
if (!parent.has_value())
186183
return -1;
187184

188185
if (parent->target.dentry->inode->stat.type() != stat::type::s_ifdir)
189186
return (errno = ENOTDIR, -1);
190187

191-
const auto created = vfs::create(parent->target, path.basename(), (mode & ~proc->umask));
188+
auto created = create(parent->target, pathstr.basename(), (mode & ~proc->umask));
192189
if (!created.has_value())
193190
return (errno = map_error(created.error()), -1);
194191

@@ -203,7 +200,7 @@ namespace syscall::vfs
203200
else
204201
stat.st_gid = proc->egid;
205202

206-
target = created.value();
203+
target = std::move(created.value());
207204
}
208205
else if ((flags & o_excl) && (flags & o_creat))
209206
{
@@ -212,15 +209,15 @@ namespace syscall::vfs
212209
}
213210
else
214211
{
215-
target = res->target;
212+
target = std::move(res->target);
216213
lib::bug_on(!target.dentry || !target.dentry->inode);
217214

218215
if (follow_links)
219216
{
220-
const auto reduced = vfs::reduce(res->parent, target);
217+
auto reduced = reduce(res->parent, target);
221218
if (!reduced.has_value())
222219
return (errno = map_error(reduced.error()), -1);
223-
target = reduced.value();
220+
target = std::move(reduced.value());
224221
}
225222
}
226223

@@ -664,7 +661,7 @@ namespace syscall::vfs
664661
return (errno = EINVAL, -1);
665662

666663
const auto supgids = proc->supplementary_gids.read_lock();
667-
if (!vfs::check_access(uid, gid, *supgids, target->dentry->inode->stat, mode))
664+
if (!check_access(uid, gid, *supgids, target->dentry->inode->stat, mode))
668665
return (errno = EACCES, -1);
669666

670667
return 0;
@@ -752,7 +749,7 @@ namespace syscall::vfs
752749
{
753750
const auto proc = sched::this_thread()->parent;
754751

755-
const auto path_str = vfs::pathname_from(proc->cwd);
752+
const auto path_str = pathname_from(proc->cwd);
756753
if (path_str.size() + 1 > size)
757754
return (errno = ERANGE, nullptr);
758755

@@ -769,14 +766,14 @@ namespace syscall::vfs
769766
if (flags & ~(o_closexec | o_direct | o_nonblock))
770767
return (errno = EINVAL, -1);
771768

772-
const auto inode = std::make_shared<vfs::inode>(pipe::get_ops());
769+
auto shared_inode = std::make_shared<inode>(pipe::get_ops());
773770
{
774-
inode->stat.st_blksize = 0x1000;
775-
inode->stat.st_mode = std::to_underlying(stat::s_ififo) | s_irwxu | s_irwxg | s_irwxo;
776-
inode->stat.st_uid = proc->euid;
777-
inode->stat.st_gid = proc->egid;
771+
shared_inode->stat.st_blksize = 0x1000;
772+
shared_inode->stat.st_mode = std::to_underlying(stat::s_ififo) | s_irwxu | s_irwxg | s_irwxo;
773+
shared_inode->stat.st_uid = proc->euid;
774+
shared_inode->stat.st_gid = proc->egid;
778775

779-
inode->stat.update_time(
776+
shared_inode->stat.update_time(
780777
stat::time::access |
781778
stat::time::modify |
782779
stat::time::status
@@ -785,9 +782,9 @@ namespace syscall::vfs
785782

786783
std::array<int, 2> fds;
787784

788-
const auto rdentry = std::make_shared<vfs::dentry>();
785+
const auto rdentry = std::make_shared<dentry>();
789786
rdentry->name = "<[PIPE READ]>";
790-
rdentry->inode = inode;
787+
rdentry->inode = shared_inode;
791788

792789
const auto rfdesc = filedesc::create({
793790
.dentry = rdentry,
@@ -806,9 +803,9 @@ namespace syscall::vfs
806803
return (errno = EIO, -1);
807804
}
808805

809-
const auto wdentry = std::make_shared<vfs::dentry>();
806+
const auto wdentry = std::make_shared<dentry>();
810807
wdentry->name = "<[PIPE WRITE]>";
811-
wdentry->inode = inode;
808+
wdentry->inode = std::move(shared_inode);
812809

813810
const auto wfdesc = filedesc::create({
814811
.dentry = wdentry,

0 commit comments

Comments
 (0)