Fix procfs inability to set st_mode properly
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
// Setup the logging for this file (do this before any other include).
|
||||
#include "sys/kernel_levels.h" // Include kernel log levels.
|
||||
#define __DEBUG_HEADER__ "[EXT2 ]" ///< Change header.
|
||||
#define __DEBUG_LEVEL__ LOGLEVEL_DEBUG ///< Set log level.
|
||||
#define __DEBUG_LEVEL__ LOGLEVEL_INFO ///< Set log level.
|
||||
#include "io/debug.h" // Include debugging functions.
|
||||
|
||||
#include "assert.h"
|
||||
@@ -2659,6 +2659,14 @@ static int __ext2_stat(ext2_inode_t *inode, stat_t *stat)
|
||||
/// @return 0 if success.
|
||||
static int ext2_fstat(vfs_file_t *file, stat_t *stat)
|
||||
{
|
||||
if (!file) {
|
||||
pr_err("We received a NULL file pointer.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
if (!stat) {
|
||||
pr_err("We received a NULL stat pointer.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
// Get the filesystem.
|
||||
ext2_filesystem_t *fs = (ext2_filesystem_t *)file->device;
|
||||
if (fs == NULL) {
|
||||
|
||||
+17
-1
@@ -654,11 +654,27 @@ off_t procfs_lseek(vfs_file_t *file, off_t offset, int whence)
|
||||
/// @return 0 if success.
|
||||
static int __procfs_stat(procfs_file_t *file, stat_t *stat)
|
||||
{
|
||||
if (!file) {
|
||||
pr_err("We received a NULL file pointer.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
if (!stat) {
|
||||
pr_err("We received a NULL stat pointer.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
if ((file->flags & DT_DIR)) {
|
||||
stat->st_mode = 0040000;
|
||||
} else if ((file->flags & DT_REG)) {
|
||||
stat->st_mode = 0100000;
|
||||
} else if ((file->flags & DT_LNK)) {
|
||||
stat->st_mode = 0120000;
|
||||
} else {
|
||||
return -ENOENT;
|
||||
}
|
||||
stat->st_uid = file->uid;
|
||||
stat->st_gid = file->gid;
|
||||
stat->st_dev = 0;
|
||||
stat->st_ino = file->inode;
|
||||
stat->st_mode = file->flags;
|
||||
stat->st_size = 0;
|
||||
stat->st_atime = file->atime;
|
||||
stat->st_mtime = file->mtime;
|
||||
|
||||
@@ -24,13 +24,15 @@ static ssize_t procs_do_meminfo(char *buffer, size_t bufsize);
|
||||
|
||||
static ssize_t procs_do_stat(char *buffer, size_t bufsize);
|
||||
|
||||
static ssize_t procs_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte)
|
||||
static ssize_t __procs_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyte)
|
||||
{
|
||||
if (file == NULL) {
|
||||
if (!file) {
|
||||
pr_err("We received a NULL file pointer.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
proc_dir_entry_t *entry = (proc_dir_entry_t *)file->device;
|
||||
if (entry == NULL) {
|
||||
pr_err("The file is not a valid proc entry.\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
// Prepare a buffer.
|
||||
@@ -81,7 +83,7 @@ static vfs_file_operations_t procs_fs_operations = {
|
||||
.open_f = NULL,
|
||||
.unlink_f = NULL,
|
||||
.close_f = NULL,
|
||||
.read_f = procs_read,
|
||||
.read_f = __procs_read,
|
||||
.write_f = NULL,
|
||||
.lseek_f = NULL,
|
||||
.stat_f = NULL,
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
static inline void print_content(const char *path, char *buffer, unsigned buflen)
|
||||
{
|
||||
pr_warning("Printing content of %s\n", path);
|
||||
// Open the file.
|
||||
int fd = open(path, O_RDONLY, 42);
|
||||
if (fd >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user