Compare commits
No commits in common. "4f4b8ada8cd4e42ede9a1a65529fe1ec4d59a0e9" and "e8890062d68fa3dfcccf5b8b243cf5a554349d43" have entirely different histories.
4f4b8ada8c
...
e8890062d6
|
@ -37,7 +37,6 @@ namespace Kernel
|
|||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
|
||||
virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
|
||||
|
||||
private:
|
||||
uint32_t fs_block_of_data_block_index(uint32_t data_block_index);
|
||||
|
|
|
@ -99,7 +99,6 @@ namespace Kernel
|
|||
BAN::ErrorOr<size_t> read(off_t, BAN::ByteSpan buffer);
|
||||
BAN::ErrorOr<size_t> write(off_t, BAN::ConstByteSpan buffer);
|
||||
BAN::ErrorOr<void> truncate(size_t);
|
||||
BAN::ErrorOr<void> chmod(mode_t);
|
||||
bool has_data() const;
|
||||
|
||||
protected:
|
||||
|
@ -116,7 +115,6 @@ namespace Kernel
|
|||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
virtual BAN::ErrorOr<void> truncate_impl(size_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
virtual BAN::ErrorOr<void> chmod_impl(mode_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
virtual bool has_data_impl() const { dwarnln("nonblock not supported"); return true; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -56,8 +56,6 @@ namespace Kernel
|
|||
ASSERT((inode_info.mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
}
|
||||
|
||||
virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
|
||||
|
||||
protected:
|
||||
RamFileSystem& m_fs;
|
||||
FullInodeInfo m_inode_info;
|
||||
|
|
|
@ -97,8 +97,6 @@ namespace Kernel
|
|||
BAN::ErrorOr<long> sys_read(int fd, void* buffer, size_t count);
|
||||
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
|
||||
|
||||
BAN::ErrorOr<long> sys_chmod(const char*, mode_t);
|
||||
|
||||
BAN::ErrorOr<long> sys_pipe(int fildes[2]);
|
||||
BAN::ErrorOr<long> sys_dup(int fildes);
|
||||
BAN::ErrorOr<long> sys_dup2(int fildes, int fildes2);
|
||||
|
|
|
@ -242,16 +242,6 @@ namespace Kernel
|
|||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Ext2Inode::chmod_impl(mode_t mode)
|
||||
{
|
||||
ASSERT((mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
if (m_inode.mode == mode)
|
||||
return {};
|
||||
m_inode.mode = (m_inode.mode & Inode::Mode::TYPE_MASK) | mode;
|
||||
TRY(sync());
|
||||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Ext2Inode::list_next_inodes_impl(off_t offset, DirectoryEntryList* list, size_t list_size)
|
||||
{
|
||||
ASSERT(mode().ifdir());
|
||||
|
|
|
@ -129,14 +129,6 @@ namespace Kernel
|
|||
return truncate_impl(size);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Inode::chmod(mode_t mode)
|
||||
{
|
||||
ASSERT((mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
LockGuard _(m_lock);
|
||||
Thread::TerminateBlocker blocker(Thread::current());
|
||||
return chmod_impl(mode);
|
||||
}
|
||||
|
||||
bool Inode::has_data() const
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
|
|
@ -26,14 +26,6 @@ namespace Kernel
|
|||
this->rdev = 0;
|
||||
}
|
||||
|
||||
|
||||
BAN::ErrorOr<void> RamInode::chmod_impl(mode_t mode)
|
||||
{
|
||||
ASSERT((mode & Inode::Mode::TYPE_MASK) == 0);
|
||||
m_inode_info.mode = (m_inode_info.mode & Inode::Mode::TYPE_MASK) | mode;
|
||||
return {};
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
RAM FILE INODE
|
||||
|
@ -62,7 +54,7 @@ namespace Kernel
|
|||
if (offset >= size())
|
||||
return 0;
|
||||
size_t to_copy = BAN::Math::min<size_t>(m_inode_info.size - offset, buffer.size());
|
||||
memcpy(buffer.data(), m_data.data() + offset, to_copy);
|
||||
memcpy(buffer.data(), m_data.data(), to_copy);
|
||||
return to_copy;
|
||||
}
|
||||
|
||||
|
@ -201,9 +193,9 @@ namespace Kernel
|
|||
{
|
||||
BAN::RefPtr<RamInode> inode;
|
||||
if (Mode(mode).ifreg())
|
||||
inode = TRY(RamFileInode::create(m_fs, mode & ~Inode::Mode::TYPE_MASK, uid, gid));
|
||||
inode = TRY(RamFileInode::create(m_fs, mode, uid, gid));
|
||||
else if (Mode(mode).ifdir())
|
||||
inode = TRY(RamDirectoryInode::create(m_fs, ino(), mode & ~Inode::Mode::TYPE_MASK, uid, gid));
|
||||
inode = TRY(RamDirectoryInode::create(m_fs, ino(), mode, uid, gid));
|
||||
else
|
||||
ASSERT_NOT_REACHED();
|
||||
|
||||
|
|
|
@ -733,21 +733,6 @@ namespace Kernel
|
|||
return TRY(m_open_file_descriptors.write(fd, BAN::ByteSpan((uint8_t*)buffer, count)));
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_chmod(const char* path, mode_t mode)
|
||||
{
|
||||
if (mode & S_IFMASK)
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
|
||||
LockGuard _(m_lock);
|
||||
validate_string_access(path);
|
||||
|
||||
auto absolute_path = TRY(absolute_path_of(path));
|
||||
auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, O_WRONLY));
|
||||
TRY(file.inode->chmod(mode));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<long> Process::sys_pipe(int fildes[2])
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
|
|
@ -199,9 +199,6 @@ namespace Kernel
|
|||
case SYS_POWEROFF:
|
||||
ret = Process::current().sys_poweroff((int)arg1);
|
||||
break;
|
||||
case SYS_CHMOD:
|
||||
ret = Process::current().sys_chmod((const char*)arg1, (mode_t)arg2);
|
||||
break;
|
||||
default:
|
||||
dwarnln("Unknown syscall {}", syscall);
|
||||
break;
|
||||
|
|
|
@ -55,7 +55,6 @@ __BEGIN_DECLS
|
|||
#define SYS_MUNMAP 52
|
||||
#define SYS_TTY_CTRL 53
|
||||
#define SYS_POWEROFF 54
|
||||
#define SYS_CHMOD 55
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int chmod(const char* path, mode_t mode)
|
||||
{
|
||||
return syscall(SYS_CHMOD, path, mode);
|
||||
}
|
||||
|
||||
int fstat(int fildes, struct stat* buf)
|
||||
{
|
||||
return syscall(SYS_FSTAT, fildes, buf);
|
||||
|
|
|
@ -5,7 +5,6 @@ project(userspace CXX)
|
|||
set(USERSPACE_PROJECTS
|
||||
cat
|
||||
cat-mmap
|
||||
chmod
|
||||
cp
|
||||
dd
|
||||
echo
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(chmod CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(chmod ${SOURCES})
|
||||
target_compile_options(chmod PUBLIC -O2 -g)
|
||||
target_link_libraries(chmod PUBLIC libc)
|
||||
|
||||
add_custom_target(chmod-install
|
||||
COMMAND sudo cp ${CMAKE_CURRENT_BINARY_DIR}/chmod ${BANAN_BIN}/
|
||||
DEPENDS chmod
|
||||
USES_TERMINAL
|
||||
)
|
|
@ -1,43 +0,0 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
void usage(const char* argv0, int ret)
|
||||
{
|
||||
FILE* out = (ret == 0) ? stdout : stderr;
|
||||
fprintf(out, "usage: %s MODE FILE...\n", argv0);
|
||||
fprintf(out, " Change the mode of each FILE to MODE.\n");
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc <= 2)
|
||||
usage(argv[0], 1);
|
||||
|
||||
int base = (argv[1][0] == '0') ? 8 : 10;
|
||||
|
||||
mode_t mode = 0;
|
||||
for (const char* ptr = argv[1]; *ptr; ptr++)
|
||||
{
|
||||
if (!isdigit(*ptr))
|
||||
{
|
||||
fprintf(stderr, "Invalid MODE %s\n", argv[1]);
|
||||
usage(argv[0], 1);
|
||||
}
|
||||
mode = (mode * base) + (*ptr - '0');
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
for (int i = 2; i < argc; i++)
|
||||
{
|
||||
if (chmod(argv[i], mode) == -1)
|
||||
{
|
||||
perror("chmod");
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -69,7 +69,7 @@ bool copy_file(const BAN::String& source, BAN::String destination)
|
|||
perror("write");
|
||||
ret = false;
|
||||
}
|
||||
if (nwrite <= 0)
|
||||
if (nwrite == 0)
|
||||
break;
|
||||
written += nwrite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue