Re: Creating a file in kernel Module -- working fine

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

 



On Mon, Feb 21, 2005 at 21:14:03 -0800, linux lover wrote:
> Hello Srinivas,
>            I am using RedHat 9 with its kernel
> 2.4.20-8 . When i make your program it compiled
> successfully but i am getting following errors while i
> insmod
>  insmod cf.o
> cf.o: unresolved symbol sys_open
> cf.o: unresolved symbol sys_write

RedHat kernel, unfortunately, does not have much in common with Linus'
kernels. In this respect they are right though, the code is bogus and
should not compile.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

The (bogus) code follows.

> > cre_fil.c
> >
> ------------------------------------------------------------------
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <asm/fcntl.h>		/* for O_WRONLY */
> > #include <linux/syscall.h>	/* for sys_ functions */
> > #include <asm/uaccess.h>	/* for set_fs(), get_fs()
> > etc. */
> > #include <linux/string.h>	/* for string length */
> > #include <linux/slab.h>		/* for kmalloc */
> > 
> > MODULE_LICENSE("GPL");
> > 
> > typedef struct tagWRITE_TEST
> > {
> > 	unsigned long fd;
> > 	unsigned long x;
> > 	
> > }WRITE_TEST, *PWRITE_TEST;
> > 
> > PWRITE_TEST ptest;
> > 
> > void SysPrint(char * pString, ...)
> > {
> > 	static char buff[1024];
> > 	va_list ap;
> > 
> > 	va_start(ap,pString);
> > 	vsprintf((char *)buff, pString, ap);
> > 	va_end(ap);
> > 	
> > 	sys_write(ptest->fd,(char *)buff,strlen(buff));
> > }
> > 
> > int init_module(void)
> > {
> > 	
> > 	printk("<%s> invoked!\n",__FUNCTION__);
> > 	printk("File Creation Testing in Kernel
> > Module!\n");
> > 
> > 	set_fs(get_ds());
> > 	
> > 	/* allocate the memory for structre */
> > 	ptest =
> > (PWRITE_TEST)kmalloc(sizeof(WRITE_TEST),GFP_KERNEL);
> > 	if(ptest == NULL)
> > 	{
> > 		printk("Structure Memory Allocation Fails!\n");
> > 		return -ENOMEM;
> > 	}
> > 	
> > 	ptest->fd = sys_open("srcdebug.txt", O_CREAT |
> > O_WRONLY, 644);
> > 	if (ptest->fd == 0)
> > 	{
> > 		printk("File Creation Error!!!\n");
> > 		return 1;
> > 	}
> > 	
> > 	SysPrint("File Creation Testing in Kernel
> > Module!\n");
> > 	SysPrint("Srinivas Testing the File Creation\n");
> > 
> > 	/* close the file here */
> > 	sys_close(ptest->fd);
> > 	
> > 	return 0;
> > }
> > 
> > void cleanup_module(void)
> > {
> > 	printk("Good bye!\n");
> > 
> > 	/* free the allocated memory */
> > 	kfree(ptest);
> > 	
> > }
> > 
> > Makefile
> > ------------------------------------------------
> > INCDIR=/usr/src/linux-2.4/include
> > 
> > CFLAGS=-DMODULE -D__KERNEL__ -I$(INCDIR) -O2 -Wall
> > 
> > OBJS=cre_fil.o
> > TARGET=cf.o
> > 
> > $(TARGET): $(OBJS)
> > 	$(LD) -r -o $(TARGET) $(OBJS)
> > 
> > clean:
> > 	$(RM) -f $(TARGET) $(OBJS)
> > 	
> >
> ------------------------------------------------------------------------

Attachment: signature.asc
Description: Digital signature


[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