Daisuke HATAYAMA | 088e7af | 2010-03-05 13:44:06 -0800 | [diff] [blame] | 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 | { |
André Goddard Rosa | 6e3e37a | 2010-03-10 15:21:22 -0800 | [diff] [blame] | 19 | int ret = 1; |
| 20 | |
Daisuke HATAYAMA | 088e7af | 2010-03-05 13:44:06 -0800 | [diff] [blame] | 21 | if (file->f_op->llseek && file->f_op->llseek != no_llseek) { |
| 22 | if (file->f_op->llseek(file, off, SEEK_CUR) < 0) |
| 23 | return 0; |
| 24 | } else { |
| 25 | char *buf = (char *)get_zeroed_page(GFP_KERNEL); |
| 26 | |
| 27 | if (!buf) |
| 28 | return 0; |
| 29 | while (off > 0) { |
| 30 | unsigned long n = off; |
| 31 | |
| 32 | if (n > PAGE_SIZE) |
| 33 | n = PAGE_SIZE; |
André Goddard Rosa | 6e3e37a | 2010-03-10 15:21:22 -0800 | [diff] [blame] | 34 | if (!dump_write(file, buf, n)) { |
| 35 | ret = 0; |
| 36 | break; |
| 37 | } |
Daisuke HATAYAMA | 088e7af | 2010-03-05 13:44:06 -0800 | [diff] [blame] | 38 | off -= n; |
| 39 | } |
| 40 | free_page((unsigned long)buf); |
| 41 | } |
André Goddard Rosa | 6e3e37a | 2010-03-10 15:21:22 -0800 | [diff] [blame] | 42 | return ret; |
Daisuke HATAYAMA | 088e7af | 2010-03-05 13:44:06 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | #endif /* _LINUX_COREDUMP_H */ |