核心FAQ 3 (2001.05.16~2001.05.26) (轉)
核心FAQ(2001.05.16~2001.05.26)
">axing〖〗〖轉發〗
1、 編譯核心出問題
2、 核心資料:關於流量統計資料?
3、 請問解決unresolved symbol 問題的具體操作步驟
4、 linux的問題
5、 如何得到核心的使用手冊
1、編譯核心出問題,求救!!
我編譯核心在make bzImage的時候老是出現錯誤,
make[2]:***[ksyms.o] Error 1
make[2]:Leaving directory '/usr/src/linux-2.4.4/kernel'
make[1]:***[first_rule]Error 2
make[1]:Leaving directory '/usr/src/linux-2.4.4/kernel'
make:***[_dir_kernel] Error 2
這些表示什麼意思?怎麼看?
還有,編譯的時候說有好些變數沒declared(比如說,smp_num_s,在/usr/src/linux-2.4.4/include/linux/kernel_stat.h)中,可是我查了它是給定義了啊,這是怎麼回事?多謝各位指點
#Try this simple way:
#make mrproper /* clean old config info */
#make clean /* clean old file */
#make menuconfig /* do nothing,just exit and save config,all use 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
高,實在是高!真可以了.為什麼會這樣?前面兩條命令起了什麼作用?請高手指點.
你好,我第一次編譯核心時,只注意了音效卡支援,其他的按預設,編譯順利透過,重新引導也一切正常。在mount一個16分割槽時,發現fs vfat can not be supported。我懷疑編譯核心時MSDOS和VFAT是不是沒有選上,就重新編譯核心,特別的注意了這兩個選項,其他照舊,結果make dep; make clean; make zImage都透過了,make modules時出了問題:
*** [dummy.o] error 1
*** [modsubdir] error 2
*** [mod_s] error 2
我該怎麼辦呢?如果說核心原始碼有問題,我第一次編譯怎麼沒有出錯呢。
我的核心版本:kernel-2.4.2-2
原始碼:kernel--2.4.2-2
kernel-headers-2.4.2-2
if u've configed modules,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、核心資料:關於防火牆流量統計資料?
在核心2.0時,有/proc/net/ip_acct用於存放防火牆流量統計資料;在核心2.2時,沒有了此檔案。只有/proc/net/ip_fwchains和 /proc/net/ip_fwnames 檔案。請問,我如何訪問以前的ip_acct檔案中的資料呢?有相關的或是相對應的檔案嗎?它們的格式是什麼?
你可以透過 library來訪問每一條規則的流量統計資訊。
3、請問解決unresolved symbol 問題的具體操作步驟
#以下是一個字元裝置驅動程式例子的:
/* chardev.c
* Copyright (C) 1998-1999 by Ori Pomerantz
*
* Create a character device (read only)
*/
/* The necessary header files */
/* Standard in kernel modules */
#include
#include
/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include
#endif
/* For character devices */
#include
* definitions are here */
#include
* 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 if necessary. */
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif
/* Conditional compilation. LINUX_VERSION_CODE is
* the code (as per KERNEL_VERSION) of this version. */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)
#include
#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 of the message from the device */
#define BUF_LEN 80
/* Is the device open right now? Used to prevent
* concurent access into the same device */
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 DE
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 using
* the driver. */
printk("Device: %d.%d
",
inode->i_rdev >> 8, inode->i_rdev & 0xFF);
/* We don't want to talk to two processes at the
* same 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 replaced 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 won't 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 isn't 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 doesn't have a return value in
* version 2.0.x because it can't fail (you must ALWAYS
* be able to close a device). In version 2.2.x it is
* allowed to fail - but we won't 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 our next caller */
Device_Open --;
/* Decrement the usage count, otherwise once 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 */
#else
static 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;
/* If we're at the end of the message, return 0
* (which signifies end of file) */
if (*Message_Ptr == 0)
return 0;
/* Actually put the data into the buffer */
while (length && *Message_Ptr) {
/* Because the buffer is in the user data segment,
* not the kernel data segment, assignment wouldn't
* 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 called when somebody tries to write
* into 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 */
#else
static 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 unimplemented functions. */
struct file_operations Fops = {
NULL, /* seek */
device_read,
device_write,
NULL, /* readdir */
NULL, /* */
NULL, /* ioctl */
NULL, /* mmap */
device_open,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
NULL, /* flush */
#endif
device_release /* a.k.a. 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 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
", Major);
printk ("You can try different minor 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 printk("Error in unregister_chrdev: %d
", ret);
}
#Makefile是這樣寫的:
CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
chardev.o: chardev.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c chardev.c
#insmod時出現錯誤:
unresolved symbol __put_user_X
請問大俠究竟是什麼原因
是沒有包含put_user函式所在的庫嗎?
還是核心版本問題?
#Makefile是這樣寫的:
CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
chardev.o: chardev.c /usr/include/linux/version.h
$(CC) $(MODCFLAGS) -c chardev.c
編譯時加“O”引數
$(CC) -O $(MODCFLAGS) -c chardev.c
這是由於核心會用到很多行內函數(inline),需要此引數
為什麼行內函數需要-O選項
行內函數需在編譯期間被整塊複製到目標檔案,就象處理宏一樣
編譯透過了, insmod也沒有問題, 我測試了一下, 出了問題。
我的操作步驟(用的都是):
1 mknod /dev/mychar c 254 0 /*insmod時主裝置號為254*/
2 test.c
#include
#include
#include
int main()
{
int fd;
char buf[80];
fd = open("mychar", O_RDONLY, 0);
if(fd == -1)
printf("error: open mychar");
else
{
if(read(fd, buf, 80) == -1)
printf("read error!");
else
printf("the read result is : %s", buf);
}
}
3 gcc test.c -o test
4 ./test
提示: error: open mychar
請問斑竹, 這是為何?
檔案路徑錯:
改為:mknod mychar c 254 0
或者:
fd=open("/dev/mychar",O_RDWR);
4、linux網路卡驅動程式的問題
我編了一個linux網路卡驅動程式,我的網路卡是NE2000的,其實我並沒有使用NE2000的資料,因為我不知道,我只把網路卡設為IRQ=3, I/O=OX300,編譯透過, 自己可以,但PING 別人就不行了,甚至馬上重啟機器,問扎回事?
在下,程式訪問到無效地枝是(一般是陣列越界)一般是將程式的記憶體對映寫成名為core 的檔案,然後退出,而在核心模式下linux就無能為力啦,只好馬上重起,linux 源帶碼中有ne2000的驅動原始碼(/usr/src/linux/drivers/net/ne2k-pci.c),你可參考一下。
5、如何得到核心函式的使用手冊
編驅動程式時,常回用到比如“printk,kfree,request_irq...."等等一系列核心函式,用man又不行,請問該怎麼拌,謝謝!
/proc/kysms中既是
實在是對不起,我已看了kysms檔案,裡面只有函式名,後面跟一串以R開頭的字串,我還是不知道具體函式的用法,請賜教,謝謝。
在核心原始碼理查一下函式實現,不就知道用法了嗎 。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-989568/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 核心FAQ(2001.05.06~2001.05.16) (轉)
- 核心FAQ 2 (2001.05.26~2001.06.06) (轉)
- 核心FAQ 舉例說明 (轉)
- RedHatPostfix中文FAQ(轉)Redhat
- Microsoft .NET 框架 FAQ (轉)ROS框架
- SMTH Java FAQ (3) 檔案與磁碟操作(菜鳥必看) (轉)Java
- 轉載:有關SQL server connection Keep Alive 的FAQ(3)SQLServer
- 資料結構FAQ (轉)資料結構
- REDHAT 7.1 sendmail配置FAQ (轉)RedhatAI
- 轉載:Oracle iLearning FAQOracle
- UTF-8 and Unicode FAQ(轉)Unicode
- Unity3D熱更新全書FAQUnity3D
- C++11FAQ中文版–轉C++
- Linux命令FAQ:系統配置(轉)Linux
- lilo--實踐篇(FAQ) (轉)
- gcc編譯器小知識FAQ(轉)GC編譯
- SMTH Java FAQ (2) 資料轉換(菜鳥必看) (轉)Java
- 【FAQ】HarmonyOS SDK 閉源開放能力 —Map Kit(3)
- 【FAQ】HarmonyOS SDK 閉源開放能力 —IAP Kit(3)
- C#搶鮮快報之FAQ20 (轉)C#
- Linux_FAQ:程式設計問題(轉)Linux程式設計
- Docker FAQDocker
- Oracle FaqOracle
- itpub上的ORACLE之常用FAQ V1.0(轉)Oracle
- 再從核心談3DEngine的設計架構(轉)3D架構
- Volatility FAQ
- autoit《FAQ大全》
- Windows Phone FAQWindows
- Android FAQAndroid
- 轉載:有關SQL server connection KeepAlive 的FAQSQLServer
- 【FAQ】RPM軟體包使用常見問題(轉)
- Win32開發知識庫(分類FAQ) (轉)Win32
- 初學者。aspx學習日記第1天---faq (轉)
- Linux核心分析。3Linux
- Linux系統可解除安裝核心模組完全指南(3)(轉)Linux
- 基於Fedora Core 3的核心編譯的準備工作(轉)編譯
- 核心引數(轉)
- BREW常見檔案解答(FAQ 6)-記憶體管理 (轉)記憶體