mirror of
https://github.com/ish-app/ish.git
synced 2026-01-25 14:06:40 +00:00
Also a bunch of somewhat related changes, I was too lazy to break this into more than one commit
52 lines
1.5 KiB
C
52 lines
1.5 KiB
C
#include <sys/stat.h>
|
|
#include <string.h>
|
|
#include "fs/stat.h"
|
|
#include "fs/proc.h"
|
|
|
|
mode_t_ proc_entry_mode(struct proc_entry *entry) {
|
|
mode_t_ mode = entry->meta->mode;
|
|
if ((mode & S_IFMT) == 0)
|
|
mode |= S_IFREG;
|
|
if ((mode & 0777) == 0) {
|
|
if (S_ISREG(mode))
|
|
mode |= 0444;
|
|
else if (S_ISDIR(mode))
|
|
mode |= 0555;
|
|
else if (S_ISLNK(mode))
|
|
mode |= 0777;
|
|
}
|
|
return mode;
|
|
}
|
|
|
|
int proc_entry_stat(struct proc_entry *entry, struct statbuf *stat) {
|
|
memset(stat, 0, sizeof(*stat));
|
|
stat->mode = proc_entry_mode(entry);
|
|
stat->inode = entry->meta->inode | entry->pid << 16 | (uint64_t) entry->fd << 48;
|
|
return 0;
|
|
}
|
|
|
|
void proc_entry_getname(struct proc_entry *entry, char *buf) {
|
|
if (entry->meta->getname)
|
|
entry->meta->getname(entry, buf);
|
|
else if (entry->meta->name)
|
|
strcpy(buf, entry->meta->name);
|
|
else
|
|
assert(!"missing name in proc entry");
|
|
}
|
|
|
|
bool proc_dir_read(struct proc_entry *entry, unsigned long *index, struct proc_entry *next_entry) {
|
|
if (entry->meta->readdir)
|
|
return entry->meta->readdir(entry, index, next_entry);
|
|
|
|
if (entry->meta->children) {
|
|
if (*index >= entry->meta->children_sizeof/sizeof(entry->meta->children[0]))
|
|
return false;
|
|
next_entry->meta = &entry->meta->children[*index];
|
|
next_entry->pid = entry->pid;
|
|
(*index)++;
|
|
return true;
|
|
}
|
|
assert(!"read from invalid proc directory");
|
|
}
|
|
|