1 |
/* |
2 |
* fs/proc/ccs_proc.c |
3 |
* |
4 |
* /proc interface for SAKURA and TOMOYO. |
5 |
* |
6 |
* Copyright (C) 2005-2008 NTT DATA CORPORATION |
7 |
* |
8 |
* Version: 1.5.3-pre 2008/01/03 |
9 |
* |
10 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
11 |
* See README.ccs for ChangeLog. |
12 |
* |
13 |
*/ |
14 |
|
15 |
#include <linux/types.h> |
16 |
#include <linux/kernel.h> |
17 |
#include <asm/io.h> |
18 |
#include <linux/proc_fs.h> |
19 |
#include <linux/module.h> |
20 |
#include <linux/version.h> |
21 |
#include <linux/ccs_proc.h> |
22 |
#include <linux/ccs_common.h> |
23 |
|
24 |
#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO) |
25 |
|
26 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23) |
27 |
static inline struct proc_dir_entry *PDE(const struct inode *inode) |
28 |
{ |
29 |
return (struct proc_dir_entry *) inode->u.generic_ip; |
30 |
} |
31 |
#endif |
32 |
|
33 |
static int ccs_open(struct inode *inode, struct file *file) |
34 |
{ |
35 |
return CCS_OpenControl(((u8 *) PDE(inode)->data) - ((u8 *) NULL), file); |
36 |
} |
37 |
|
38 |
static int ccs_release(struct inode *inode, struct file *file) |
39 |
{ |
40 |
return CCS_CloseControl(file); |
41 |
} |
42 |
|
43 |
static unsigned int ccs_poll(struct file *file, poll_table *wait) |
44 |
{ |
45 |
return CCS_PollControl(file, wait); |
46 |
} |
47 |
|
48 |
static ssize_t ccs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
49 |
{ |
50 |
return CCS_ReadControl(file, buf, count); |
51 |
} |
52 |
|
53 |
static ssize_t ccs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
54 |
{ |
55 |
return CCS_WriteControl(file, buf, count); |
56 |
} |
57 |
|
58 |
static struct file_operations ccs_operations = { |
59 |
open: ccs_open, |
60 |
release: ccs_release, |
61 |
poll: ccs_poll, |
62 |
read: ccs_read, |
63 |
write: ccs_write |
64 |
}; |
65 |
|
66 |
static __init void CreateEntry(const char *name, const mode_t mode, struct proc_dir_entry *parent, const u8 key) |
67 |
{ |
68 |
struct proc_dir_entry *entry = create_proc_entry(name, mode, parent); |
69 |
if (entry) { |
70 |
entry->proc_fops = &ccs_operations; |
71 |
entry->data = ((u8 *) NULL) + key; |
72 |
} |
73 |
} |
74 |
|
75 |
void __init CCSProc_Init(void) |
76 |
{ |
77 |
struct proc_dir_entry *ccs_dir = proc_mkdir("ccs", NULL); |
78 |
extern void __init realpath_Init(void); |
79 |
realpath_Init(); |
80 |
CreateEntry("query", 0600, ccs_dir, CCS_QUERY); |
81 |
#ifdef CONFIG_SAKURA |
82 |
CreateEntry("system_policy", 0600, ccs_dir, CCS_SYSTEMPOLICY); |
83 |
#endif |
84 |
#ifdef CONFIG_TOMOYO |
85 |
CreateEntry("domain_policy", 0600, ccs_dir, CCS_DOMAINPOLICY); |
86 |
CreateEntry("exception_policy", 0600, ccs_dir, CCS_EXCEPTIONPOLICY); |
87 |
CreateEntry("grant_log", 0400, ccs_dir, CCS_GRANTLOG); |
88 |
CreateEntry("reject_log", 0400, ccs_dir, CCS_REJECTLOG); |
89 |
#endif |
90 |
CreateEntry("self_domain", 0400, ccs_dir, CCS_SELFDOMAIN); |
91 |
CreateEntry(".domain_status", 0600, ccs_dir, CCS_DOMAIN_STATUS); |
92 |
CreateEntry(".process_status", 0400, ccs_dir, CCS_PROCESS_STATUS); |
93 |
CreateEntry("meminfo", 0400, ccs_dir, CCS_MEMINFO); |
94 |
CreateEntry("profile", 0600, ccs_dir, CCS_PROFILE); |
95 |
CreateEntry("manager", 0600, ccs_dir, CCS_MANAGER); |
96 |
CreateEntry(".updates_counter", 0400, ccs_dir, CCS_UPDATESCOUNTER); |
97 |
CreateEntry("version", 0400, ccs_dir, CCS_VERSION); |
98 |
} |
99 |
|
100 |
#else |
101 |
void __init CCSProc_Init(void) {} |
102 |
#endif |