31 #include <linux/string.h>
32 #include <linux/module.h>
33 #include <linux/virgo_fs.h>
34 #include <linux/string.h>
36 #include <linux/ctype.h>
38 unsigned int virgo_parse_integer(
const char *s,
unsigned int base,
unsigned long long *p);
39 void printBytes(
const char* str);
40 char* toKernelAddress(
const char*);
46 struct virgo_fs_args* parse_virgofs_command_kernelspace(
char* fsFunction);
49 virgo_cloud_fs_kernelspace_init(
void)
51 printk(KERN_INFO
"virgo_cloud_fs_kernelspace_init(): doing init() of virgo cloud kernel space test module\n");
54 EXPORT_SYMBOL(virgo_cloud_fs_kernelspace_init);
58 virgo_cloud_fs_kernelspace_exit(
void)
60 printk(KERN_INFO
"virgo_cloud_fs_kernelspace_exit(): exiting virgo cloud test kernel space module \n");
63 EXPORT_SYMBOL(virgo_cloud_fs_kernelspace_exit);
67 void* virgo_cloud_open_kernelspace(
struct virgo_fs_args* args)
70 printk(KERN_INFO
"virgo_cloud_fs_kernelspace.c:virgo_cloud_open_kernelspace(): file path to open=%s\n",vmargs->fs_args[0]);
74 f=filp_open(vmargs->fs_args[0], O_RDWR|O_APPEND, 0);
77 printk(KERN_INFO
"virgo_cloud_open_kernelspace(): filp_open return value is error code : %p", f);
80 open_VFS_files[no_of_openfiles]=f;
81 printk(KERN_INFO
"virgo_cloud_fs_kernelspace.c:virgo_cloud_open_kernelspace(): f=%p, no_of_openfiles=%d, file struct=%p\n",f,no_of_openfiles, open_VFS_files[no_of_openfiles]);
82 return toVFSString(&no_of_openfiles);
84 EXPORT_SYMBOL(virgo_cloud_open_kernelspace);
88 void* virgo_cloud_read_kernelspace(
struct virgo_fs_args* args)
91 char *buf=kmalloc(
sizeof(
char)*500,GFP_KERNEL);
92 printk(KERN_INFO
"virgo_cloud_fs_kernelspace.c: virgo_cloud_read_kernelspace(): vmargs->fs_cmd=%s, vmargs->fs_args[0] = %s\n, vmargs->fs_args[1]=%s, vmargs->fs_args[2]=%s, vmargs->fs_args[3]=%s \n",vmargs->fs_cmd, vmargs->fs_args[0],vmargs->fs_args[1],vmargs->fs_args[2],vmargs->fs_args[3]);
93 unsigned long long ll;
94 virgo_parse_integer(vmargs->fs_args[0],10,&ll);
95 unsigned long long ll2;
96 virgo_parse_integer(vmargs->fs_args[2],10,&ll2);
97 unsigned long long ll3;
98 virgo_parse_integer(vmargs->fs_args[3],10,&ll3);
100 loff_t pos = (loff_t)ll3;
101 size_t cnt = (size_t)ll2;
102 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): buf=%s\n", buf);
103 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): vfsdesc=%d\n", vfsdesc);
104 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): cnt=%d\n", cnt);
105 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): pos=%d\n", pos);
106 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): open_VFS_files[vfsdesc]=%p\n", open_VFS_files[vfsdesc]);
109 loff_t bytesread=vfs_read(open_VFS_files[vfsdesc], buf, cnt, &pos);
110 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): after vfs_read(): bytesread=%d, buf=%s\n", bytesread, buf);
114 EXPORT_SYMBOL(virgo_cloud_read_kernelspace);
118 void* virgo_cloud_write_kernelspace(
struct virgo_fs_args* args)
121 printk(KERN_INFO
"virgo_cloud_fs_kernelspace.c: virgo_cloud_write_kernelspace(): vmargs->fs_cmd=%s, vmargs->fs_args[0] = %s\n, vmargs->fs_args[1]=%s, vmargs->fs_args[2]=%d, vmargs->fs_args[3]=%d \n",vmargs->fs_cmd, vmargs->fs_args[0],vmargs->fs_args[1],vmargs->fs_args[2],vmargs->fs_args[3]);
122 unsigned long long ll;
123 virgo_parse_integer(vmargs->fs_args[0],10,&ll);
124 unsigned long long ll2;
125 virgo_parse_integer(vmargs->fs_args[2],10,&ll2);
126 unsigned long long ll3;
127 virgo_parse_integer(vmargs->fs_args[3],10,&ll3);
129 loff_t pos = (loff_t)ll3;
130 size_t cnt = (size_t)ll2;
131 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): vmargs->fs_args[1]=%s\n", vmargs->fs_args[1]);
132 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): vfsdesc=%d\n", vfsdesc);
133 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): cnt=%d\n", cnt);
134 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): cnt=%d\n", cnt);
135 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): pos=%d\n", pos);
136 printk(KERN_INFO
"virgo_cloud_read_kernelspace(): open_VFS_files[vfsdesc]=%p\n", open_VFS_files[vfsdesc]);
139 vfs_write(open_VFS_files[(
int)ll], vmargs->fs_args[1], cnt, &pos);
143 EXPORT_SYMBOL(virgo_cloud_write_kernelspace);
147 void* virgo_cloud_close_kernelspace(
struct virgo_fs_args* args)
150 printk(KERN_INFO
"virgo_cloud_fs_kernelspace.c: virgo_cloud_close_kernelspace(): vmargs->fs_args[0]=%s\n",vmargs->fs_args[0]);
151 unsigned long long ll;
152 virgo_parse_integer(vmargs->fs_args[0],10,&ll);
153 filp_close(open_VFS_files[(
int)ll],NULL);
156 EXPORT_SYMBOL(virgo_cloud_close_kernelspace);
160 void printBytes(
const char* str)
165 printk(KERN_INFO
"printBytes(): %c\n",*p);
178 unsigned int virgo_parse_integer(
const char *s,
unsigned int base,
unsigned long long *p)
180 unsigned long long res;
188 printk(KERN_INFO
"virgo_parse_integer(): *s=%c, res=%ld\n",*s, res);
195 if (
'0' <= *s && *s <=
'9')
197 else if (
'a' <= tolower(*s) && tolower(*s) <=
'f')
198 val = tolower(*s) -
'a' + 10;
212 res = res * base + val;
220 char* toVFSString(
int* data)
222 char* VFSString=kmalloc(BUF_SIZE, GFP_KERNEL);
223 sprintf(VFSString,
"%d",*data);
224 printk(KERN_INFO
"toVFSString(): VFSString=%s\n", VFSString);
230 MODULE_LICENSE(
"GPL");
231 module_init(virgo_cloud_fs_kernelspace_init);
232 module_exit(virgo_cloud_fs_kernelspace_exit);