Commit 417935b0 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: create file snmp_mmap with create_map function

This function was in file wrsCurrentTimeGroup.c, but memory maping is also
needed for other groups.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 21c39f78
......@@ -27,6 +27,7 @@ SHLIB = wrsSnmp.so
SOURCES = \
init.c \
snmp_shmem.c \
snmp_mmap.c \
wrsScalar.c \
wrsStartCntGroup.c \
wrsPstatsTable.c \
......
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include "snmp_mmap.h"
/* FIXME: this is copied from wr_date, should be librarized */
void *create_map(unsigned long address, unsigned long size)
{
unsigned long ps = getpagesize();
unsigned long offset, fragment, len;
void *mapaddr;
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0)
return NULL;
offset = address & ~(ps - 1);
fragment = address & (ps - 1);
len = address + size - offset;
mapaddr = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, offset);
close(fd);
if (mapaddr == MAP_FAILED)
return NULL;
return mapaddr + fragment;
}
void *create_map(unsigned long address, unsigned long size);
#include "wrsSnmp.h"
#include "wrsCurrentTimeGroup.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "snmp_mmap.h"
/* defines for nic-hardware.h */
#define WR_SWITCH
......@@ -23,30 +18,6 @@ static struct pickinfo wrsCurrentTime_pickinfo[] = {
struct wrsCurrentTime_s wrsCurrentTime_s;
/* FIXME: this is copied from wr_date, should be librarized */
static void *create_map(unsigned long address, unsigned long size)
{
unsigned long ps = getpagesize();
unsigned long offset, fragment, len;
void *mapaddr;
int fd;
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0)
return NULL;
offset = address & ~(ps - 1);
fragment = address & (ps - 1);
len = address + size - offset;
mapaddr = mmap(0, len, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, offset);
close(fd);
if (mapaddr == MAP_FAILED)
return NULL;
return mapaddr + fragment;
}
time_t wrsCurrentTime_data_fill(void)
{
static time_t time_update;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment