Re: How to access a regular file from within a module ?

From: Jon Masters
Date: Sun Jan 11 2009 - 00:37:38 EST


On Sat, 2009-01-10 at 19:44 -0800, Jose Luis Marchetti wrote:

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

No, you probably wouldn't :) Generally, this is recommended against
because there are many better ways to do it:

* Create an interface and have userspace set the parameter (ethtool,
ifconfig - the latter can already set MAC addresses)

* Create entries in sysfs and have uevents cause various activities,
including having the response being some file gets loaded (firmware).

Since it looks like you just want to set the MAC address, I suggest
looking at how this is already done, then rely upon users using ifconfig
correctly to set the desired address. There should be no reason to have
a kernel-side network driver reading from a file.

[NOTE: If you're doing embedded development and you don't have an EEPROM
on your board, and you're asking this because someone told you to find
the cheapest and nastiest solution in software, then look at passing in
the desired MAC via the firmware, as many embedded boards already do. ]

Jon.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/