# Porting sys/sysinfo.h and asm/fcntl.h from Linux



## axiomcrs (Jul 1, 2010)

I'm sure this has been asked before, but I've been looking at all the documentation, i.e. porting handbook, faqs, searching the forums for keywords and have turned up nothing.  Is there an equivalent set of header files in FreeBSD?  This code executes on several of the popular versions of Linux.


----------



## expl (Jul 2, 2010)

```
struct sysinfo {
        long uptime;             /* Seconds since boot */
        unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
        unsigned long totalram;  /* Total usable main memory size */
        unsigned long freeram;   /* Available memory size */
        unsigned long sharedram; /* Amount of shared memory */
        unsigned long bufferram; /* Memory used by buffers */
        unsigned long totalswap; /* Total swap space size */
        unsigned long freeswap;  /* swap space still available */
        unsigned short procs;    /* Number of current processes */
        unsigned long totalhigh; /* Total high memory size */
        unsigned long freehigh;  /* Available high memory size */
        unsigned int mem_unit;   /* Memory unit size in bytes */
        char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
}
```

How are you suppose to calculate 1, 5 and 15 minute "load" average? Does FreeBSD kernel even log such things by default, cause no service ran by default caches such data.


----------



## crsd (Jul 2, 2010)

expl said:
			
		

> ```
> struct sysinfo {
> long uptime;             /* Seconds since boot */
> unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
> ...



getloadavg(3)


----------



## expl (Jul 3, 2010)

Quick port of it:

https://code.google.com/p/sysinfo-bsd/source/browse/

Data on structure and header file should be compatible with linux applications.

To download the source install devel/mercurial and type
`hg clone [url]https://sysinfo-bsd.googlecode.com/hg/[/url] sysinfo-bsd`
Will be fetched to ./sysinfo-bsd/

I am only lost with what exactly is "high memory" in the structure (HMA? kernel reserved ram? ..?)

If anyone is interested in actual FreeBSD port for this lib let me know.


----------



## stast (Jul 5, 2010)

Library sysinfo-bsd could be really speed up of porting linux-applications to FreeBSD.


----------



## expl (Jul 5, 2010)

Anyone knows any such apps that use this function?


----------



## axiomcrs (Jul 5, 2010)

The application that I am trying to port is called sys_basher

http://www.polybus.com/sys_basher_web/


----------



## expl (Jul 5, 2010)

Regarding asm/fcntl.h, it has linux kernel specific definitions so there is no reason to port it. After looking at sys_basher source code it does not look like it even needs it included. Ill try to build it when I have some free time.


----------



## expl (Jul 6, 2010)

Turns out it also needs libsensors that runs only with linux kernel. And it would be a big task to port it. It would be easer to write a big patch for sysbasher.


----------



## expl (Jul 6, 2010)

Ok I compiled it without sensor support and it seems to run (dont have linux box to see if it runs the same).

You need to change all

```
#include <asm/fcntl.h>
```
to

```
#include <fcntl.h>
```

Comment out "open()" declaration in sys_disk.h

And I attached the Makefile patch. Just run "gmake" and ignore all the warnings. (might want to clean up it more, I just changed it enough to compile the application)

It also depends on libsysinfo, just install it from my google code repo. (make & make install)


----------



## axiomcrs (Jul 14, 2010)

Thanks for all your help!  It compiles and runs successfully.  Will that sysinfo library remain at that link?


----------



## expl (Jul 16, 2010)

Yes, I also submitted port for it. 
http://www.freebsd.org/cgi/query-pr.cgi?pr=148415


----------

