Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/sysinfo.c 3 * 4 * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/kernel.h> 9 #include <fiwix/fs.h> 10 #include <fiwix/system.h> 11 #include <fiwix/sched.h> 12 #include <fiwix/mm.h> 13 #include <fiwix/string.h> 14 15 #ifdef __DEBUG__ 16 #include <fiwix/stdio.h> 17 #include <fiwix/process.h> 18 #endif /*__DEBUG__ */ 19 20 int sys_sysinfo(struct sysinfo *info) 21 { 22 struct sysinfo tmp_info; 23 struct proc *p; 24 int errno; 25 26 #ifdef __DEBUG__ 27 printk("(pid %d) sys_sysinfo(0x%08x)\n ", current->pid, (unsigned int)info); 28 #endif /*__DEBUG__ */ 29 30 if((errno = check_user_area(VERIFY_WRITE, info, sizeof(struct sysinfo)))) { 31 return errno; 32 } 33 memset_b(&tmp_info, NULL, sizeof(struct sysinfo)); 34 tmp_info.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT); 35 tmp_info.loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT); 36 tmp_info.loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT); 37 tmp_info.uptime = kstat.uptime; 38 tmp_info.totalram = kstat.total_mem_pages << PAGE_SHIFT; 39 tmp_info.freeram = kstat.free_pages << PAGE_SHIFT; 40 tmp_info.sharedram = 0; 41 tmp_info.bufferram = kstat.buffers * 1024; 42 tmp_info.totalswap = 0; 43 tmp_info.freeswap = 0; 44 FOR_EACH_PROCESS(p) { 45 tmp_info.procs++; 46 p = p->next; 47 } 48 49 memcpy_b(info, &tmp_info, sizeof(struct sysinfo)); 50 return 0; 51 }