Skip to contentSkip to conversation

DISCUSSION Jose Luis Marchetti 4 participants 5 messages Jan 11, 2009 – Jan 12, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I would like to open/read/write/close a regular file from my device driver.
I think it would be possible, but I am confused, the "The Linux Kernel Module Programming Guide" states that I can not use standard libraries from within a module, I know the standard library ends up calling system calls, but which calls should I use to deal with regular files ?
I am developing a Ethernet driver and the Mac address configuration

Thanks in advance!

José Luís Marchetti

Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com

#1 lore raw

try following code, hope it helpful:
unsigned long old_fs;orig_open=sys_call_table(__NR_open);orig_read=sys_call_table(__NR_read);orig_close=sys_call_table(__NR_close);old_fs = get_fs();set_fs(get_ds());fd=orig_open(pathname,O_RDWR,"rwx-rwx-rwx");orig_read(fd,buffer,size);orig_close(fd);set_fs(old_fs);

On Sun, Jan 11, 2009 at 11:41 AM, Jose Luis Marchetti<[email protected]> wrote:> Hi,>> I would like to open/read/write/close a regular file from my device> driver.> I think it would be possible, but I am confused, the "The Linux Kernel> Module Programming Guide" states that I can not use standard libraries> from within a module, I know the standard library ends up calling> system calls, but which calls should I use to deal with regular> files ?> I am developing a Ethernet driver and the Mac address configuration>> Thanks in advance!>> José Luís Marchetti>>> Veja quais são os assuntos do momento no Yahoo! +Buscados> http://br.maisbuscados.yahoo.com> --> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in> the body of a message to [email protected]> More majordomo info at http://vger.kernel.org/majordomo-info.html> Please read the FAQ at http://www.tux.org/lkml/>���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#2 lore raw

Re: your mail

In reply to Jose Luis Marchetti
Quoted 4 lines · Jose Luis Marchetti

Hi,

I would like to open/read/write/close a regular file from my device driver.

That's probably a bad idea and what you really want to do is use procfs, sysfs, debugfs, relayfs, module parameters or similar.

Take a look here:
http://kernelnewbies.org/FAQ/WhyWritingFilesFromKernelIsBad

Signature · 3 lines
Jesper Juhl <[email protected]>        http://personal.chaosbits.net/
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#3 lore raw

MAC address runtime configuration in new driver (was Re: ...no subject)

In reply to Jose Luis Marchetti
Quoted 9 lines · Jose Luis Marchetti

Hi,

I would like to open/read/write/close a regular file from my device driver.
I think it would be possible, but I am confused, the "The Linux Kernel Module Programming Guide" states that I can not use standard libraries from within a module, I know the standard library ends up calling system calls, but which calls should I use to deal with regular files ?

http://kernelnewbies.org/FAQ/WhyWritingFilesFromKernelIsBad discusses this.

Quoted 5 lines

I am developing a Ethernet driver and the Mac address configuration

Thanks in advance!

José Luís Marchetti

Userspace could write the necessary configuration data into the kernel, for example a sysfs attribute. Of course the attribute could also be readable. But perhaps there are already established mechanisms for exactly this purpose. I added Cc: netdev, maybe somebody there can give advice.

Signature · 3 lines
Stefan Richter
-=====-==--= ---= -=-==
http://arcgraph.de/sr/
#4 lore raw

Re: MAC address runtime configuration in new driver (was Re: ...no subject)

Quoted 2 lines

http://kernelnewbies.org/FAQ/WhyWritingFilesFromKernelIsBad
discusses this.

Thanks, I have missed this faq.

Quoted 9 lines

Userspace could write the necessary configuration data into the kernel,
for example a sysfs attribute. Of course the attribute could also be
readable. But perhaps there are already established mechanisms for
exactly this purpose. I added Cc: netdev, maybe somebody there can give
advice.

Thanks for the advice, I have another scenario where it should be nice to access files from inside the kernel, I am going to describe it on another email, but know I am not sure I should keep pursuint it.

Thanks again.

Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com