mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
Add a simple /bin/df which gathers its info from /proc/df.
This commit is contained in:
parent
7d288aafb2
commit
43075e5878
8 changed files with 119 additions and 0 deletions
|
@ -1359,3 +1359,27 @@ bool Ext2FSInode::chmod(mode_t mode, int& error)
|
|||
set_metadata_dirty(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::total_block_count() const
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return super_block().s_blocks_count;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::free_block_count() const
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return super_block().s_free_blocks_count;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::total_inode_count() const
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return super_block().s_inodes_count;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::free_inode_count() const
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return super_block().s_free_inodes_count;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,11 @@ public:
|
|||
virtual ~Ext2FS() override;
|
||||
virtual bool initialize() override;
|
||||
|
||||
virtual unsigned total_block_count() const override;
|
||||
virtual unsigned free_block_count() const override;
|
||||
virtual unsigned total_inode_count() const override;
|
||||
virtual unsigned free_inode_count() const override;
|
||||
|
||||
private:
|
||||
typedef unsigned BlockIndex;
|
||||
typedef unsigned GroupIndex;
|
||||
|
|
|
@ -37,6 +37,11 @@ public:
|
|||
|
||||
bool is_readonly() const { return m_readonly; }
|
||||
|
||||
virtual unsigned total_block_count() const { return 0; }
|
||||
virtual unsigned free_block_count() const { return 0; }
|
||||
virtual unsigned total_inode_count() const { return 0; }
|
||||
virtual unsigned free_inode_count() const { return 0; }
|
||||
|
||||
struct DirectoryEntry {
|
||||
DirectoryEntry(const char* name, InodeIdentifier, byte file_type);
|
||||
DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte file_type);
|
||||
|
|
|
@ -28,6 +28,7 @@ enum ProcFileType {
|
|||
__FI_Root_Start,
|
||||
FI_Root_mm,
|
||||
FI_Root_mounts,
|
||||
FI_Root_df,
|
||||
FI_Root_kmalloc,
|
||||
FI_Root_all,
|
||||
FI_Root_summary,
|
||||
|
@ -399,6 +400,27 @@ ByteBuffer procfs$mounts(InodeIdentifier)
|
|||
return builder.to_byte_buffer();
|
||||
}
|
||||
|
||||
ByteBuffer procfs$df(InodeIdentifier)
|
||||
{
|
||||
// FIXME: This is obviously racy against the VFS mounts changing.
|
||||
StringBuilder builder;
|
||||
VFS::the().for_each_mount([&builder] (auto& mount) {
|
||||
auto& fs = mount.guest_fs();
|
||||
builder.appendf("%s,", fs.class_name());
|
||||
builder.appendf("%u,", fs.total_block_count());
|
||||
builder.appendf("%u,", fs.free_block_count());
|
||||
builder.appendf("%u,", fs.total_inode_count());
|
||||
builder.appendf("%u,", fs.free_inode_count());
|
||||
if (!mount.host().is_valid())
|
||||
builder.append("/");
|
||||
else {
|
||||
builder.append(VFS::the().absolute_path(mount.host()));
|
||||
}
|
||||
builder.append('\n');
|
||||
});
|
||||
return builder.to_byte_buffer();
|
||||
}
|
||||
|
||||
ByteBuffer procfs$cpuinfo(InodeIdentifier)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
@ -1076,6 +1098,7 @@ ProcFS::ProcFS()
|
|||
m_entries.resize(FI_MaxStaticFileIndex);
|
||||
m_entries[FI_Root_mm] = { "mm", FI_Root_mm, procfs$mm };
|
||||
m_entries[FI_Root_mounts] = { "mounts", FI_Root_mounts, procfs$mounts };
|
||||
m_entries[FI_Root_df] = { "df", FI_Root_df, procfs$df };
|
||||
m_entries[FI_Root_kmalloc] = { "kmalloc", FI_Root_kmalloc, procfs$kmalloc };
|
||||
m_entries[FI_Root_all] = { "all", FI_Root_all, procfs$all };
|
||||
m_entries[FI_Root_summary] = { "summary", FI_Root_summary, procfs$summary };
|
||||
|
|
|
@ -64,6 +64,7 @@ cp -v ../Userland/dmesg mnt/bin/dmesg
|
|||
cp -v ../Userland/chmod mnt/bin/chmod
|
||||
cp -v ../Userland/top mnt/bin/top
|
||||
cp -v ../Userland/ln mnt/bin/ln
|
||||
cp -v ../Userland/df mnt/bin/df
|
||||
cp -v ../Applications/Terminal/Terminal mnt/bin/Terminal
|
||||
cp -v ../Applications/FontEditor/FontEditor mnt/bin/FontEditor
|
||||
cp -v ../Applications/Launcher/Launcher mnt/bin/Launcher
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue