2 * linux/fs/proc/sysvipc.c
4 * Copyright (c) 1999 Dragos Acostachioaie
6 * This code is derived from linux/fs/proc/generic.c,
7 * which is Copyright (C) 1991, 1992 Linus Torvalds.
9 * /proc/sysvipc directory handling functions
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/proc_fs.h>
14 #include <linux/stat.h>
17 #include <asm/uaccess.h>
20 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
23 /* 4K page size but our output routines use some slack for overruns */
24 #define PROC_BLOCK_SIZE (3*1024)
27 proc_sysvipc_read(struct file
* file
, char * buf
, size_t nbytes
, loff_t
*ppos
)
29 struct inode
* inode
= file
->f_dentry
->d_inode
;
35 struct proc_dir_entry
* dp
;
37 dp
= (struct proc_dir_entry
*) inode
->u
.generic_ip
;
38 if (!(page
= (char*) __get_free_page(GFP_KERNEL
)))
41 while ((nbytes
> 0) && !eof
)
43 count
= MIN(PROC_BLOCK_SIZE
, nbytes
);
48 * Handle backwards compatibility with the old net
51 * XXX What gives with the file->f_flags & O_ACCMODE
52 * test? Seems stupid to me....
54 n
= dp
->get_info(page
, &start
, *ppos
, count
,
55 (file
->f_flags
& O_ACCMODE
) == O_RDWR
);
58 } else if (dp
->read_proc
) {
59 n
= dp
->read_proc(page
, &start
, *ppos
,
60 count
, &eof
, dp
->data
);
66 * For proc files that are less than 4k
76 break; /* End of file */
83 /* This is a hack to allow mangling of file pos independent
84 * of actual bytes read. Simply place the data at page,
85 * return the bytes, and set `start' to the desired offset
86 * as an unsigned int. - Paul.Russell@rustcorp.com.au
88 n
-= copy_to_user(buf
, start
< page
? page
: start
, n
);
95 *ppos
+= start
< page
? (long)start
: n
; /* Move down the file */
100 free_page((unsigned long) page
);
104 static struct file_operations proc_sysvipc_operations
= {
106 proc_sysvipc_read
, /* read */
112 NULL
, /* no special open code */
113 NULL
, /* no special release code */
114 NULL
/* can't fsync */
118 * proc directories can do almost nothing..
120 struct inode_operations proc_sysvipc_inode_operations
= {
121 &proc_sysvipc_operations
, /* default net file-ops */
132 NULL
, /* follow_link */
133 NULL
, /* get_block */
135 NULL
, /* writepage */
136 NULL
, /* flushpage */
138 NULL
, /* permission */
140 NULL
/* revalidate */