Re: accessing files, devices, in kernel modules



thanks for all the replies. I tried using sys_open, and "aparently" I
could open the file, but I couldn't write or read it using sys_write or
sys_read. Linux complains it can't find the sys_read and sys_write
symbols.
I also tried using filp_open and filp_open, but got a segmentation
fault :(.
here's my code, and what I want to do first:

int init_module(void)
{
int fd;
printk(KERN_ALERT "module loaded\n");
fd = open("/home/alisson/texte.txt", 02);
if(fd ==-1)
printk(KERN_ALERT "error opening file");
/* write something here */
close(fd);
return 0;
}

but what I'd like to know is: can I use the sound card the same way I
use it in user space programs? like reading and opening a file? my
final goal is record some sound from the microphone for 3 seconds, and
then play it.

thanks


miline wrote:
Yellow wrote:

hi there!

I have just started studying the linux kernel, version 2.6. i read some
manuals, howtos, have already made some really simple modules, but when
I tried to do a little more complex work, I stumbled across some
dificulties.
well, what I want to is a kernel module that opens a regular file,
writes something to it, and closes it. easy, isn't it? I also thought
that ;)

but then I tried making a simple open over the file, but the module
complains it can't find the symbols open, close and write. Is there
Are you doing OPEN(filename, flags)?
anything unusual I must do to work with files in the kernel? none of
the manuals I read mentioned how to open and do some I/O over it.

now, to my real problem: I must record some sound, and then play it!
since in LInux everything is a file, I'm able to do it by means of
/dev/dsp. that's why I asked abou t how to work with regular files. but
I don't know if this way of accessing devices hold for modules. and I
can't open that file!

I looked at /proc/kallsyms, and open is there. I don't have a clue why
the module complains it couldn't find the open.
Kernel opens the files with sys_open, similary sys_close, sys_read,
sys_write and so on.

thanks for any help you could provide, and sorry for such noob question

.



Relevant Pages

  • Re: Future of IT in Lebanon
    ... working knowledge of Indian programmers DNA, nor of their intuitive Java ... > So Longhorn is not an experiment and Linux is an experiment? ... another chapter in the Windows story, and the Microsoft marketing machine is ... > application opens, Check the about, it says Microsoft Visual Basic 6.3. ...
    (soc.culture.lebanon)
  • Re: Bastard spammers
    ... >>The reason I initially chose Linux for my servers was because I ... intimate knowlege of the system and all the potential vulnerabilities ... >>replacing it with a Windoze system that does the same thing, ... >>opens and web pages accessed etc.), ...
    (uk.legal)
  • Linux UI vs Mac?
    ... idea of using Linux for it. ... Mac at work. ... Saving the attachment from Mozilla opens up the dreaded file/directory ...
    (alt.os.linux)
  • Re: broken linuxulator in -current as of Jan 8 17:51:45 CET
    ... the open trace shows REAL path ie. after possible prefixing with /compat/linux ... ie. it opens the right library but IGNORES it and the iterates through the rest ... This may not be a _new_ bug in the kernel. ... It may be the case that the introduction of a new linux syscall ...
    (freebsd-current)
  • Re: Mystery Folders and Files
    ... This pasted in Start | Run opens the desktop.ini file.... ... I know nothing about Linux. ... MS-MVP Windows Shell/User ... I have enabled viewing hidden folders and system folders, ...
    (microsoft.public.windowsxp.general)