filp_open not working with O_RDWR or O_WRONLY

1.9k views Asked by At

I'm trying to use filp_open() within the kernel to open the file "/proc/.../mynode". The file opens issue-free when it is opened using the O_RDONLY flag, however; when I attempt to open the same file, using the same function, but change the flag to O_RDWR or O_WRONLY, my device's boot sequence breaks.

Does anyone know how to solve this issue?


My Code:

struct file* file_open(const char* path, int flags, int rights) {
    struct file* filp = NULL;
    mm_segment_t oldfs;
    int err = 0;
    oldfs = get_fs();
    set_fs(get_ds());

    filp = filp_open(path, flags, rights);

    set_fs(oldfs);
    if(IS_ERR(filp)) {
        err = PTR_ERR(filp);
        return NULL;
    }
    return filp;
}

The following method is called:

struct file *fp = NULL;
fp = file_open("/proc/.../mynode", O_WRONLY,0);
1

There are 1 answers

0
Vishal Sahu On

I could not understand why're you turning on address conversion before error checking. You've called filp_open in kernel address space(i assume get_ds takes you there) and hence it's practice to do error checks in same space. This might be the reason filp gets translated to some random address and why device boot sequence is breaking. If issue persists even after this has been looked into, target file-sys might not be having write permission on this file.