[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Cloning filedescriptor
Hi all,
I'm trying to port some kernel code from OpenBSD to Linux and need an
advice ;-) The intent is to "clone" a filedescriptor but let the result
have different "file_operations" (f_op). With the BSD semantics it is
done in a ioctl() on a given device:
fd = open("/dev/something", ...);
ioctl(fd, CRIOGET, &cfd);
Now 'fd' uses the original f_op and 'cfd' the new ones.
So I did an ioctl handler for the device and let it handle CRIOGET:
case CRIOGET:
fd = get_unused_fd();
new_file = get_empty_filp();
memcpy(new_file, file, sizeof(struct file));
new_file->f_op = &new_fops;
fd_install(fd, new_file);
put_user(fd, (int*)arg);
return 0;
This works but I bet it is not very clean. Especially the memcpy()
copying (possible) locks, refcounts, ...
Is there a better way to "cleanly" duplicate "struct file" and attach it
to a new filedescriptor?
Thanks!
Michal Ludvig
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/