i want to call open,write system calls from kernel space.
�
[oops, didn't hit reply-to-all at first, sorry rahul!]
For reads:
�� � � �struct file *file = fget(fd)
�� � � �if (file) {
�� � � � � � � �loff_t pos = file_pos_read(file);
�� � � � � � � �ret = vfs_read(file, buf, count, &pos);
�� � � � � � � �file_pos_write(file, pos);
�� � � � � � � �fput(file);
�� � � �}
For writes:
�� � � �struct file *file = fget(fd)
�� � � �if (file) {
�� � � � � � � �loff_t pos = file_pos_read(file);
�� � � � � � � �ret = vfs_write(file, buf, count, &pos);
�� � � � � � � �file_pos_write(file, pos);
�� � � � � � � �fput(file);
�� � � �}
Its a better idea to call�file->f_op->read and�file->f_op->write directly instead of vfs_write in the above code, skips a lot of checks and stuff. See how loop driver does this in drivers/block/loop.c in function �__do_lo_send_write.
You could even call write_begin and write_end directly if your backs fs supports address space ops. Again good examples in loop driver.
HTH,
-Joel