Hi all,

I developed an LKM and loaded it into android emulator. At first, I
called filp_open("/data/", O_RDONLY, 0) from kernel module init
function (called during insmod). The function filp_open() ran
successfully. Then, I wrote ioctl(), to command kernel module from
usermode, but filp_open("/data/", O_RDONLY, 0) here is failing on
directory "/data/", and returned -13 (permission denied) error.
However, flip_open() on full filepath, say "/data/data/
com.android.music/shared_prefs/Music.xml" ran successfully.

I am not able to understand why this error came when filp_open() is
called inside dev_ioctl(), but ran successfully when called inside
kernel module init function. Please go through the code attached
below, and help me resolve this error.

test.c (user-mode code)
^^^^^^^^^^^^^^^^^^^^^^^
void Java_com_example_test_TestingJNI( JNIEnv* env, jobject thiz )
{
        char buf[256];
        fd = open ("/dev/mydev", O_RDONLY);
        if (fd > 0 ) {

                strcpy (buf, "/data/");

                ioctl (fd, IOCTL_CMD, buf);

                close (fd);
        }
}

driver.c (Kernel-mode code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
int dev_ioctl(struct inode *Inode, struct file *filp,  unsigned int
cmd, char* ubuffer )
{
        char dirname[250];

        switch (cmd) {

         case IOCTL_CMD:

                mm_segment_t old_fs = get_fs();
                set_fs(KERNEL_DS);

                memset (dirname, 0, 250);
                if(copy_from_user(dirname, ubuffer, 250))
                        return -EFAULT;

                struct file *filp = filp_open(dirname, O_RDONLY, 0);

                if (IS_ERR(filp) || (filp==NULL)) {

                       printk("filp_open returned error %ld\n",
PTR_ERR(filp));

                } else {
                        printk ("flip_open success\n");
                        filp_close(filp);
                }

                set_fs(old_fs);
                break;

         default:
                return -ENOTTY;
        };
        return 0;
}

Thanks & Regards

-- 
unsubscribe: [email protected]
website: http://groups.google.com/group/android-kernel

Reply via email to