b3c91d7cede4e764cb5a62700e5900987aa3e0eb
[safe/jmp/linux-2.6] / include / linux / coredump.h
1 #ifndef _LINUX_COREDUMP_H
2 #define _LINUX_COREDUMP_H
3
4 #include <linux/types.h>
5 #include <linux/mm.h>
6 #include <linux/fs.h>
7
8 /*
9  * These are the only things you should do on a core-file: use only these
10  * functions to write out all the necessary info.
11  */
12 static inline int dump_write(struct file *file, const void *addr, int nr)
13 {
14         return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
15 }
16
17 static inline int dump_seek(struct file *file, loff_t off)
18 {
19         if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
20                 if (file->f_op->llseek(file, off, SEEK_CUR) < 0)
21                         return 0;
22         } else {
23                 char *buf = (char *)get_zeroed_page(GFP_KERNEL);
24
25                 if (!buf)
26                         return 0;
27                 while (off > 0) {
28                         unsigned long n = off;
29
30                         if (n > PAGE_SIZE)
31                                 n = PAGE_SIZE;
32                         if (!dump_write(file, buf, n))
33                                 return 0;
34                         off -= n;
35                 }
36                 free_page((unsigned long)buf);
37         }
38         return 1;
39 }
40
41 #endif /* _LINUX_COREDUMP_H */