Kernel FAQ 3 (2001.05.16 ~ 2001.05.26)

zhaozj2021-02-11  256

Kernel FAQ (2001.05.16 ~ 2001.05.26) http://linuxAid.com.cn Axing 〖Back〗 Function〗

1. Question within compilation 2, core data: About firewall flow statistics? 3, ask the specific operation of the Unresolved Symbol problem step 4, Linux network card driver problem 5. How to get the User Manual of the Kernel Function 1, compile the problem, save! ! When I compile the kernel during make bzimage, I always have an error. Make [2]: *** [ksyms.o] error 1make [2]: leaving directory '/usr/src/linux-2.4.4/kernel'make [ 1]: *** [first_rule] error 2make [1]: Leaving Directory '/usR/src/linux-2.4.4/kernel'make:***[_dir_kernel] error 2 What do you mean? How to see? Also, when compiling, there is no declared (for example, SMP_NUM_CPUS, in /usr/src/linux-2.4.4/include/linux/kernel_stat.h), but I check it is defined. ,How is this going? Thank you, pointing #Try this Simple Way: #make mrproperty / * Clean Old config info * / # make clean / * clean old object file * / # make menuconfig / * do not Nothing, Just Exit and save config, all us default * / #make dep / * binding the configuration info * / # make bzimage / * it Should work. * / # cp arch / i386 / boot / bzimage / boot / bzimage_00 # vi /etc/lilo.conf / * add the new bzimage_00 To Lilo * / # lilo # reboot high, it is high! It's really it. Why is this? What did the two orders have been played? Please expert guidance. Hello, I first compiled the core, only note the support of the sound card, other according to the system default, compiling smoothly, and reboot everything is normal. When a FAT16 partition is partitioned, FS vfat can not be supported is found. I suspect that MSDOS and VFAT did not choose to compile the kernel. I also pay special attention to these two options. Other photos, the results make Dep; make clean; make zimage has passed, Make Mook : *** [Dummy.o] error 1 *** [MODSUBDIR_NET] error 2 *** [mod_drivers] error 2 What should I do? If there is a problem with the kernel source code, I didn't have an error in compilation.

My kernel version: kernel-2.4.2-2 Source code: kernel-source-2.4.2-2 kernel-headers-2.4.2-2 f u've confige edues, Dunt forget to: #make modules # make modules_install and # Make Install Will Auto Install The New Kernel, But ... I'd Rather Install IT by Myself.2, Core Data: About firewall flow statistics? At the core 2.0, there is / proc / net / ip_acct file to store firewall traffic statistics; at the core 2.2, there is no this file. Only / proc / net / ip_fwchains and / proc / net / ip_fwnames files. Excuse me, how do I access the data in the previous IP_ACCT file? Is there a related or corresponding file? What is their format? You can access traffic statistics for each rule through FireWall Library.

3, ask the specific steps to solve the Unresolved Symbol problem # below is the source code of a character device driver example: / * Chardev.c * Copyright (c) 1998-1999 by Ori Pomerantz * * Create a character Device (Read Only) * // * The nextard in kernel modules * / # include / * We're doing kernel work * / # include / * specification, A Module * // * DEAL with config_modversions * / # if config_modversions == 1 # define modversions # include #ENDIF / * for character deflices * / # include / * the Character Device * Definitions Are Here * / # include / * a Wrapper Which Does * Next To Nothing At * At Present, But May * Help for Compatibility * with Future Versions * of Linux * // * in 2.2.3 /usr/include/linux/Version.h Includes * a macro for this, but 2.0.35 doesn't - SO i add * it here F Necessary. * / # iFNDef kernel_version # define kernel_version (A, B, C) ((a) * 65536 (b) * 256 (c)) # Endif / * Conditional compiration. Linux_version_code is * the code (as per Kernel_version) of this version. * / # If linux_version_code> kernel_version (2, 0) #include / * for put_user * / # endif #define success 0 / * device declarations ***** *********************** * / / * THE NAME for Our Device, AS IT WILL APPEAR * IN / Proc / Devices * / # define device_name "char_dev "/ * The maximum length @ / * is The device open right now? Used to prevent * concurent access into the design * / static int device_open =

0; / * The message the device will give when asked * / static char Message [BUF_LEN]; / * How far did the process reading the message * get Useful if the message is larger than the size * of the buffer we get to? . fill in device_read * / static char * Message_Ptr; / * This function is called whenever a process * attempts to open the device file * / static int device_open (struct inode * inode, struct file * file) {static int counter = 0; #ifdef debug printk ("Device_open (% p,% p)", inode, file); # endif / * this is how you get the minor device number in * Case You have more Than One Physical Device use * the driver. * / Printk ("Device:% D.% D", Inode-> i_rdev >> 8, Inode-> i_rdev & 0xff); / * We don't want to talk to two time * / if ( Device_Open) return -EBUSY; / * If this was a process, we would have had to be * more careful here * * In the case of processes, the danger would be * that one process might have check Device_Open * and then be repla. ced by the schedualer by another * process which runs this function. Then, when the * first process was back on the CPU, it would assume * the device is still not open. * * However, Linux guarantees that a process will not be * replaced while it is running in kernel context. * * in the case of SMP, one CPU might increment * Device_Open while another CPU is here, right after * the check. However, in version 2.0 of the * kernel this is not a problem BECAUSE THERE'S A LOCK * TO Guarantee Only One CPU Will Be Kernel Module At * The Same Time. this is Bad in Terms of * Performance, So Version 2.2 Changed It. * Unfortunately, I DON '

T Have Access To An SMP Box * To Check How IT Works with SMP. * / Device_open ; / * Initialize The Message. * / Sprintf (Message, "IF I TOLD You Once, I Told You% D Times -% S", counter , "Hello, world"); / * The only reason we're allowed to do this sprintf * is because the maximum length of the message * (assuming 32 bit integers - up to 10 digits * with the minus sign) is less than BUF_LEN, which * is 80. BE CAREFUL nOT TO OVERFLOW BUFFERS, * ESPECIALLY IN THE KERNEL !!! * / Message_Ptr = Message; / * Make sure that the module is not removed while * the file is open by incrementing the usage count * (the number of opened references to the module, if * it's not zero rmmod will fail) * / MOD_INC_USE_COUNT; return SUCCESS;.} / * This function is called when a process closes the * device file It does not have a Return Value In * Version 2.0.x Because IT can't Fail (You Must Always * Be Aable To Close A Device). in Version 2.2.x It is * allowed T o fail -. but we will not let it * / # if LINUX_VERSION_CODE> = KERNEL_VERSION (2,2,0) static int device_release (struct inode * inode, struct file * file) #else static void device_release (struct inode * inode Struct File * file) #ENDIF {#ifdef debug printk ("Device_Release (% P,% P)", inode, file); # Endif / * We're now ready for out caller * / device_open -; / * Decrement the usage count, otherwise overce you * Opened the file you'll never get rid of the module. * / Mod_dec_use_count; #if Linux_version_code> = kernel_version (2, 2, 0) Return 0;

#endif} / * This function is called whenever a process which * have already opened the device file attempts to * read from it. * / # if LINUX_VERSION_CODE> = KERNEL_VERSION (2,2,0) static ssize_t device_read (struct file * file , char * buffer, / * The buffer to fill with data * / size_t length, / * The length of the buffer * / loff_t * offset) / * Our offset in the file * / # elsestatic int device_read (struct inode * inode, Struct File * file, char * buffer, / * the buffer to fill with * the data * / int length) / * The length of the buffer * (Mustn't Write Beyond That!) * / # Endif {/ * Number of BYTES ACTUALLY WRITTEN to the Buffer * / INT BYTES_READ = 0; / * ife * Actually put the data info the buffer * / while (length ") {/ * because the buffer is in the user data segment, * NOTTA segment, assignment would not * work Instead, we have to use put_user which * copies data from the kernel data segment to the * user data segment * / put_user (* (Message_Ptr ), buffer ); length -;.. bytes_read ;} #ifdef DEBUG printk ( "Read% d bytes,% d left", bytes_read, length); # endif / * Read functions are supposed to return the number * of bytes actually inserted into the buffer * / return bytes_read;} / * This function is caled whenbody Tries to write * insto our device file - unsupported in this example. * / # If linux_version_code> =

Kernel_Version (2,2,0) static ssize_t device_write (struct file * file, const char * buffer, / * the buffer * / size_t length, / * the length of the buffer * / loff_t * offset) / * Our Offset in The File * / # ElseStatic int device_write (Struct Inode * Inode, Struct File * File, Const Char * Buffer, Int Length) #ENDIF {Return-EinVal;} / * module declarations *************** ***************** * // * The Major Device Number for the Device. This is * Global (Well, Static, Which in this context is global * within this file) Because . it has to be accessible * both for registration and for release * / static int Major; / * This structure will hold the functions to be * called when a process does something to the device * we created Since a pointer to this structure is. * Kept in the devices table, it can't be local to * init_module. Null is for unmeplement functions. * / Struct file_operations FOPS = {null, / * seek * / device_r EAD, Device_Write, Null, / * ReadDir * / Null, / * select * / null, / * ioctl * / null, / * mmap * / device_open, # if Linux_version_code> = kernel_version (2, 2, 0) NULL, / * flush * / # endif device_release / * aka close * /}; / * Initialize the module - Register the character device * / int init_module () {/ * Register the character device (atleast try) * / Major = module_register_chrdev (0, Device_name, & fops); / * Negative Values ​​Signify An Error * / if (Major <0) {Printk ("% s Device Failed with% D", "Sorry, Registering The Character", Major); Return Major;} Printk "% s the major device number is% d."

, "Registeration IS A Success.", Major); Printk ("if you want to talk to the device driver,"); Printk ("You'll Have to Create a Device File."); Printk ("We suggest you Use: "); Printk (" MKNOD C% D ", Major); Printk (" You CAN Try DiffERNOR NUMBERS% S "," and see what happens. "); return 0;} / * Cleanup - unregister the appropriate file from / proc * / void cleanup_module () {int ret; / * Unregister the device * / ret = module_unregister_chrdev (Major, DEVICE_NAME); / * If there's an error, report it * / if (ret <0) Printk ("ERROR in Unregister_chrdev:% D", RET);} # Makefile is written in this: cc = gccmodcflags: = -wall -dmodule -d__kernel__dlinuxchardev.o: charDev.c / usr / include / Linux /Version.h$ (CC) $ (MODCFLAGS) -C CharDev.c # InSmod error: unreSolved Symbol __put_user_x Execrested the reason why heroes are not included in the library containing the PUT_USER function? Or is the kernel version problem? #Makefile is written like this: cc = gccmodcflags: = -wall -dmodule -d__kernel__ -dlinuxchardev.o: charDev.c /usr/include/linux/Version.h$ (CHARDEV.C compilation When "O" parameter $ (cc) -O $ (modcflags) -c charDev.c This is because kernel programming uses many inline functions (INLINE), which requires this parameter why the inline function needs -O option inline The function needs to be copied to the target file during the compiler, and the compilation of the hand is like processing the macro. INSMOD has no problem. I tested it.

转载请注明原文地址:https://www.9cbs.com/read-3489.html

New Post(0)