File: proc.c

package info (click to toggle)
mol 0.9.61-6
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 6,140 kB
  • ctags: 8,491
  • sloc: ansic: 50,560; asm: 2,826; sh: 458; makefile: 373; perl: 165; lex: 135; yacc: 131
file content (147 lines) | stat: -rw-r--r-- 3,855 bytes parent folder | download
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
/* 
 *   Creation Date: <1999/10/16 20:04:37 samuel>
 *   Time-stamp: <1999/10/16 20:07:49 samuel>
 *   
 *	<proc.c>
 *	
 *	/proc/mol/ interface
 *   
 *   Copyright (C) 1999 Samuel Rydh (samuel@ibrium.se)
 *   
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation
 *   
 */

/* THIS FILE IS CURRENTLY UNUSED */

static void build_mol_proc_entry( void );
static void destroy_mol_proc_entry();

static int property_read_proc(char *, char **, off_t, int, int *, void *);

static struct proc_dir_entry *mol_dir_entry=0;

static int 
property_read_proc(char *page, char **start, off_t off,
                              int count, int *eof, void *data)
{
	ulong num = 0x12345678;
        int n;

        if (off >= 4) {
                *eof = 1;
                return 0;
        }
        n = 4 - off;
        if (n > count)
                n = count;
	else
		*eof = 1;
	memcpy(page, (char*)&num + off, n);
	*start = page;
	return n;
}

static int 
mmap_page(struct file * file, struct vm_area_struct * vma)
{
#if 0
        unsigned long offset = vma->vm_offset;
        if (offset & ~PAGE_MASK)
                return -ENXIO;
#endif
	
	vma->vm_flags = VM_IO | VM_SHM;
	
	if( remap_page_range(vma->vm_start,  virt_to_phys(kvars) /*offset*/, 
			     vma->vm_end-vma->vm_start,
                             vma->vm_page_prot))
                return -EAGAIN;
	return 0;
}


static struct file_operations page_fops = {
        NULL,		/* lseek */
        NULL,		/* read */
        NULL,		/* write */
        NULL,           /* mem_readdir */
        NULL,           /* mem_poll */
        NULL,           /* mem_ioctl */
        mmap_page,
        NULL,           /* no special open code */
        NULL,           /* flush */
        NULL,           /* no special release code */
        NULL            /* fsync */
};

static struct inode_operations page_inode_ops = {
        &page_fops,   /* default base directory file-ops */
        NULL,                   /* create */
        NULL,                   /* lookup */
        NULL,                   /* link */
        NULL,                   /* unlink */
        NULL,                   /* symlink */
        NULL,                   /* mkdir */
        NULL,                   /* rmdir */
        NULL,                   /* mknod */
        NULL,                   /* rename */
        NULL,                   /* readlink */
        NULL,                   /* follow_link */
        NULL,                   /* readpage */
        NULL,                   /* writepage */
        NULL,                   /* bmap */
        NULL,                   /* truncate */
	NULL,		        /* permission */
};

static void
build_mol_proc_entry( void )
{
	struct proc_dir_entry *ent;

        mol_dir_entry = create_proc_entry("mol", S_IFDIR, 0);
        if( mol_dir_entry == 0 )
                return;

	ent = kmalloc(sizeof(struct proc_dir_entry), GFP_KERNEL);
	if( ent == NULL )
		return;
	memset(ent, 0, sizeof(struct proc_dir_entry));
	ent->name = "testing";
	ent->namelen = strlen("testing");
	ent->mode = S_IFREG | S_IRUGO;
	ent->nlink = 1;
	ent->data = NULL;
	ent->read_proc = property_read_proc;
	ent->size = 4;

	proc_register( mol_dir_entry, ent);

	/* B */

	ent = kmalloc(sizeof(struct proc_dir_entry), GFP_KERNEL);
	if( ent == NULL )
		return;
	memset(ent, 0, sizeof(struct proc_dir_entry));
	ent->name = "page";
	ent->namelen = strlen("page");
	ent->mode = S_IFREG | S_IRUGO;
	ent->nlink = 1;
	ent->data = NULL;
	ent->read_proc = property_read_proc;
	ent->ops = &page_inode_ops;

	proc_register( mol_dir_entry, ent);
}

static void
destroy_mol_proc_entry( void )
{
	remove_proc_entry( "mol/testing", 0 );
	remove_proc_entry( "mol/page", 0 );
	remove_proc_entry( "mol", 0 );
}