1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
/*
* MBUFF kernel virtual memory driver for Linux,
* Proc filesystem interface
*
* Copyright (C) 1999, David Edwards <wavefrnt@tampabay.rr.com>
*
*
* Much of this code is based on linux/drivers/block/ide-proc.c
*
* Copyright (C) 1997-1998, Mark Lord
*
*/
#include <linux/proc_fs.h>
#include "mbuff.h"
#include "kernel_compat.h"
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
static struct proc_dir_entry *root, *regions;
/*
* Helper function to compute buffer pointers and sizes
*/
static int proc_mbuff_read_return(char *page, char **start, off_t off,
int count, int *eof, int len)
{
len -= off;
if (len < count)
{
*eof = 1;
if (len <= 0)
return 0;
}
else
len = count;
*start = page + off;
return len;
}
/*
* Read proc to display mbuff version
*/
static int proc_mbuff_read_version(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
char *out = page;
int len;
out += sprintf(out, "%s\n", MBUFF_VERSION);
len = out - page;
return proc_mbuff_read_return(page, start, off, count, eof, len);
}
/*
* Read proc to display size for a region
*/
static int proc_mbuff_read_size(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
char *out = page;
int len;
struct mbuff *mbuff = (struct mbuff *) data;
out += sprintf(out, "%ld\n", mbuff->size);
len = out - page;
return proc_mbuff_read_return(page, start, off, count, eof, len);
}
/*
* Read proc to display user space allocation count for a region
*/
static int proc_mbuff_read_count(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
char *out = page;
int len;
struct mbuff *mbuff = (struct mbuff *) data;
out += sprintf(out, "%d\n", mbuff->count);
len = out - page;
return proc_mbuff_read_return(page, start, off, count, eof, len);
}
/*
* Read proc to display kernal space allocation count for a region
*/
static int proc_mbuff_read_kcount(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
char *out = page;
int len;
struct mbuff *mbuff = (struct mbuff *) data;
out += sprintf(out, "%d\n", mbuff->kcount);
len = out - page;
return proc_mbuff_read_return(page, start, off, count, eof, len);
}
/*
* Read proc to display open count for a region
*/
static int proc_mbuff_read_opencnt(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
char *out = page;
int len;
struct mbuff *mbuff = (struct mbuff *) data;
out += sprintf(out, "%d\n", mbuff->open_cnt);
len = out - page;
return proc_mbuff_read_return(page, start, off, count, eof, len);
}
/*
* Read proc to display open mode for a region
*/
static int proc_mbuff_read_openmode(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
char *out = page;
int len;
struct mbuff *mbuff = (struct mbuff *) data;
out += sprintf(out, "%d\n", mbuff->open_mode);
len = out - page;
return proc_mbuff_read_return(page, start, off, count, eof, len);
}
/*
* Create an mbuff region's proc entry, called from mbuff_list_add
*/
void proc_mbuff_add_mbuff(struct mbuff *mbuff)
{
struct proc_dir_entry *region, *ent;
region = create_proc_entry(mbuff->name, S_IFDIR, regions);
ent = create_proc_entry("size", 0, region);
if (!ent)
return;
ent->read_proc = proc_mbuff_read_size;
ent->data = mbuff;
ent = create_proc_entry("count", 0, region);
if (!ent)
return;
ent->read_proc = proc_mbuff_read_count;
ent->data = mbuff;
ent = create_proc_entry("kcount", 0, region);
if (!ent)
return;
ent->read_proc = proc_mbuff_read_kcount;
ent->data = mbuff;
ent = create_proc_entry("open_cnt", 0, region);
if (!ent)
return;
ent->read_proc = proc_mbuff_read_opencnt;
ent->data = mbuff;
ent = create_proc_entry("open_mode", 0, region);
if (!ent)
return;
ent->read_proc = proc_mbuff_read_openmode;
ent->data = mbuff;
}
/*
* Remove an mbuff region's proc entry, called from mbuff_list_remove
*/
void proc_mbuff_remove_mbuff(struct mbuff *mbuff)
{
remove_proc_entry(mbuff->name, regions);
}
/*
* Create a "directory" in the /proc file system for mbuff
*/
void proc_mbuff_create(void)
{
struct proc_dir_entry *ent;
root = create_proc_entry("mbuff", S_IFDIR, 0);
if (!root)
return;
/* regions is a directory containing a directory for each region */
regions = create_proc_entry("regions", S_IFDIR, root);
/* regions is a directory containing a directory for each region */
ent = create_proc_entry("version", 0, root);
if (!ent)
return;
ent->read_proc = proc_mbuff_read_version;
}
/*
* Remove the mbuff hierarchy from the /proc file system for mbuff
*/
void proc_mbuff_destroy(void)
{
remove_proc_entry("mbuff/regions", 0);
remove_proc_entry("mbuff/version", 0);
remove_proc_entry("mbuff", 0);
}
#else
void proc_mbuff_create(void)
{
}
void proc_mbuff_destroy(void)
{
}
void proc_mbuff_add_mbuff(struct mbuff *mbuff)
{
}
void proc_mbuff_remove_mbuff(struct mbuff *mbuff)
{
}
#endif
|