Hi dhiman, I want to know that you mean i can use sys_open in my kernel module to open a file through myfile_open function call? can a character file be act as a normal file to store and update that file periodically? --- "Dhiman, Gaurav" <Gaurav.Dhiman@xxxxxx> wrote: > > > Hi, > > > > You said that you want to create a file at loading > time and want to > remove that file forom file system at unloading > time, but the code you > have pasted is actually opening a file at loading > time, assuming that > you already have a file in file system. > > > > For reading or wrting a simple file, do following > things: > > - Create a chracter file (using mknode) > either dynamically (at > loading time) or statically by mknode. > > - Do not open it at loading time, as you > are doing right now. > > - Open it through your open function > (myfile_open), which will > be called from sys_open system call. > > - Do not close the file at unloading time, > as you are doing > right now. > > - Close the file in your function > (myfile_release), which will > be called form close system call. > > - Do not use filp_open() and filp_close() > functions at all, > they are called by open and close system calls > before the control comes > to your driver. > > > > Regards. > > Gaurav > > > > _____ > > From: kernelnewbies-bounce@xxxxxxxxxxxx > [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf > Of linux lover > Sent: Saturday, September 11, 2004 8:32 PM > To: kernelnewbies@xxxxxxxxxxxx > Subject: Device driver query > > > > i know how to write a character device driver but > the same will not > work for > simple file why? that mean if i create a file > /root/myfile and want to > write > and read to it periodically from a kernel module it > is not working cause > i am doing > > .....fragment of my code......... > static struct file_operations myfile_file_operations > = { > open: myfile_open, > release: myfile_release, > read: myfile_read, > write: myfile_write, > }; > > int init_module(void) > { > > printk("Loading myfile Module\n"); > > ent = filp_open("/root/myfile", O_RDWR,S_IRUSR | > S_IWUSR); > if ( ent == NULL) > printk(KERN_DEBUG, "Error > opening file...\n"); > return 0; > } > > void cleanup_module(void) > { > printk("Unloading myfile Module\n"); > > filp_close(ent,NULL); > } > > int myfile_open(struct inode *inodep, struct file > *filp) > { > printk("Opening a file....\n"); > MOD_INC_USE_COUNT; > > return 0; > } > > int myfile_release(struct inode *inodep, struct file > *filp) > { > MOD_DEC_USE_COUNT; > return 0; > } > > I want whenever module is loaded it should create a > file and when it > unloaded should > remove file. but above code is fail to create a file > and also causing > problem in unloading > a module with warning for arg 1 parameter of > flip_close. > > help to write a module to read/write a normal file > from kernel module. > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam > protection around > http://mail.yahoo.com > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/