Re: KERNEL_DS ?

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

 





On Thu, 22 Nov 2001, Daniel Marian wrote:

> Hello,
>    Before File I/O( read or write using f_op->read or f_op->write ) in
> kernel space, why is it that
> the following is done
> oldfs = get_fs();
> set_fs(KERNEL_DS);
> read /write
> set_fs(oldfs);

Normally, read/write transfers data to/from user space, using a pointer to
a buffer living in user space. A check is made to ensure the address
supplied by the user is valid, and an address residing in kernel space
isn't valid for a call done in user space.
But when you're doing this call from kernel space, all addresses that you
supply will be in kernel space. To avoid the call to fail, the code above
temporally sets the address limit to the kernel space (via set_fs()),
after saving the original limit. When the call has complete, the old limit
is restored.

> What is KERNEL_DS ? and what is the functionality of get_fs() and set_fs().
>
KERNEL_DS is the address limit for the kernel (4GB, normally).

get/set_fs() will return/sets the address limit for the current process.

Take a look at http://www.linux-mag.com/2000-11/gear_03.html for a (much)
better explanation.

regards,
Roberto

--
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