Skip to content

Commit

Permalink
procfs: added /proc/cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 6, 2024
1 parent 83b726d commit 55be75a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fs/procfs/src/include/procfs/procfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define RESOLVE_MEMUSAGE 3
#define RESOLVE_PAGESIZE 4
#define RESOLVE_UPTIME 5
#define RESOLVE_SYS 6
#define RESOLVE_CPU 6

/* for /proc/pid/X*/
#define RESOLVE_PID 0x8000
Expand Down
5 changes: 5 additions & 0 deletions fs/procfs/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void procfsStat(StatCommand *scmd) {
if(res & RESOLVE_DIRECTORY) scmd->buffer.st_mode |= S_IFDIR;

if(res == RESOLVE_KERNEL) scmd->buffer.st_size = strlen(sysinfo->kernel);
else if(res == RESOLVE_CPU) scmd->buffer.st_size = strlen(sysinfo->cpu);
else scmd->buffer.st_size = 8;

luxSendDependency(scmd);
Expand Down Expand Up @@ -95,6 +96,10 @@ void procfsRead(RWCommand *rcmd) {
ptr = sysinfo->kernel;
size = strlen(sysinfo->kernel);
break;
case RESOLVE_CPU:
ptr = sysinfo->cpu;
size = strlen(sysinfo->cpu);
break;
case RESOLVE_MEMSIZE:
luxSysinfo(sysinfo);
data = sysinfo->memorySize;
Expand Down
2 changes: 1 addition & 1 deletion fs/procfs/src/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

int resolve(const char *path, pid_t *pid) {
if(!path) return -1;
if(!strcmp(path, "/sys")) return RESOLVE_SYS;
if(!strcmp(path, "/cpu")) return RESOLVE_CPU;
if(!strcmp(path, "/kernel")) return RESOLVE_KERNEL;
if(!strcmp(path, "/memsize")) return RESOLVE_MEMSIZE;
if(!strcmp(path, "/memusage")) return RESOLVE_MEMUSAGE;
Expand Down

0 comments on commit 55be75a

Please sign in to comment.