Re: Deleting a file from within the kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Thu, 21 Apr 2005 Tony.Asleson@xxxxxxxxxxxxxxxx wrote:

> How do you delete a file while in the kernel?
>
> I can find numerous examples of how to open/create/close a file within
> the kernel like http://uqconnect.net/~zzoklan/lkd/using_files.html , but
> I have been unable to find a resource on how to delete a file. I would
> really
> like a filp_unlink to go along with the filp_open, filp_close etc.
>
> I know doing any of these things is discouraged, but please don't respond
> with don't do it :-)
>
> Thanks!
> Tony

Hi,

i don't know very much about this, but i have recently developed a kernel
module that opens, reads, writes, closes files and i didn't use kernel
structures; i used system calls, and i think that might be the answer to
your question.

what i did was this: i created a kernel thread so that i could work with
the process' file descriptor; i called set_fs (KERNEL_DS) - this way i
could get the system call (read, write, open, lseek, close) parameters
from kernel space; after that everything is like in user space:
	fd = open (filename, O_RDWR);
and so on;
unlink should work the same way, i guess (not sure though - so don't hate
if it doesn't ;-) )

i don't know if this is of any help (i mean you have to have a kernel
thread), but you might give it a shot.

happy hacking,
Razvan


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux