1 #include <linux/init.h>
2 #include <linux/debugfs.h>
3 #include <linux/module.h>
7 static struct dentry
*d_xen_debug
;
9 struct dentry
* __init
xen_init_debugfs(void)
12 d_xen_debug
= debugfs_create_dir("xen", NULL
);
15 pr_warning("Could not create 'xen' debugfs directory\n");
27 static int u32_array_open(struct inode
*inode
, struct file
*file
)
29 file
->private_data
= NULL
;
30 return nonseekable_open(inode
, file
);
33 static size_t format_array(char *buf
, size_t bufsize
, const char *fmt
,
34 u32
*array
, unsigned array_size
)
39 for(i
= 0; i
< array_size
; i
++) {
42 len
= snprintf(buf
, bufsize
, fmt
, array
[i
]);
43 len
++; /* ' ' or '\n' */
49 buf
[-1] = (i
== array_size
-1) ? '\n' : ' ';
60 static char *format_array_alloc(const char *fmt
, u32
*array
, unsigned array_size
)
62 size_t len
= format_array(NULL
, 0, fmt
, array
, array_size
);
65 ret
= kmalloc(len
, GFP_KERNEL
);
69 format_array(ret
, len
, fmt
, array
, array_size
);
73 static ssize_t
u32_array_read(struct file
*file
, char __user
*buf
, size_t len
,
76 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
77 struct array_data
*data
= inode
->i_private
;
81 if (file
->private_data
) {
82 kfree(file
->private_data
);
83 file
->private_data
= NULL
;
86 file
->private_data
= format_array_alloc("%u", data
->array
, data
->elements
);
90 if (file
->private_data
)
91 size
= strlen(file
->private_data
);
93 return simple_read_from_buffer(buf
, len
, ppos
, file
->private_data
, size
);
96 static int xen_array_release(struct inode
*inode
, struct file
*file
)
98 kfree(file
->private_data
);
103 static struct file_operations u32_array_fops
= {
104 .owner
= THIS_MODULE
,
105 .open
= u32_array_open
,
106 .release
= xen_array_release
,
107 .read
= u32_array_read
,
110 struct dentry
*xen_debugfs_create_u32_array(const char *name
, mode_t mode
,
111 struct dentry
*parent
,
112 u32
*array
, unsigned elements
)
114 struct array_data
*data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
120 data
->elements
= elements
;
122 return debugfs_create_file(name
, mode
, parent
, data
, &u32_array_fops
);