Re:

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

 



Hi,

Dinesh Gandhewar wrote:

> Hello,
> Can you explain this code segment?
>
> oldfs = get_fs(); set_fs(KERNEL_DS);
> err = file.f_op->read(&file, buf, *count, &file.f_pos);
> set_fs(oldfs);
>
> What is the functionality of get_fs() and set_fs().
>
> Thanking you,
> Dinesh

See http://www.linux.it/kerneldocs/ksys/ksys.html, section 'doing it in kernel space', which gives a similar example, and explains the code (especially the use of get_fs()
and set_fs()).

Summarizing, what happens is that set_fs(KERNEL_DS) sets some 'memory access information' such, that the validation of the addresses in the subsequent
file.f_op->read(&file, buf, *count, &file.f_pos) succeeds, even though (some of) the arguments refer to kernel space addresses. get_fs() saves the old 'memory access
information' in oldfs, in order to restore the memory access information to the old value after invoking file.f_op->read(&file, buf, *count, &file.f_pos.

regards
Martin
--
Supercomputing System AG          email: maletinsky@scs.ch
Martin Maletinsky                 phone: +41 (0)1 445 16 05
Technoparkstrasse 1               fax:   +41 (0)1 445 16 10
CH-8005 Zurich


-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[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