在做usb-2.6.12LE06.patch.tar.gz補丁時候出現錯誤,所以找patch的方法,看到了關于參數的解釋,學習了
blog.chinaunix.net/u1/48180/showart_1868730.html
下面是我出現的錯誤備份一下,//原因是patch的目錄不對,應該在kernel同級的drivers/usb/目錄下進行的哦
[root@localhost usb]# tar zxvf usb-2.6.12LE06.patch.tar.gz
usb-2.6.12.patch
[root@localhost usb]# ls
usb-2.6.12LE06.patch.tar.gz usb-2.6.12.patch
[root@localhost usb]# patch -p1 < usb-2.6.12.patch
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -ruN usb_old/Makefile usb/Makefile
|--- usb_old/Makefile 2005-06-19 19:09:13.000000000 +0200
|+++ usb/Makefile 2005-11-06 00:44:46.000000000 +0100
--------------------------
File to patch:
Skip this patch? [y] y
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 15
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -ruN usb_old/media/Kconfig usb/media/Kconfig
|--- usb_old/media/Kconfig 2005-06-19 17:49:07.000000000 +0200
|+++ usb/media/Kconfig 2005-11-25 21:14:39.000000000 +0100
--------------------------
File to patch:
Skip this patch? [y] y
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 38
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -ruN usb_old/media/Makefile usb/media/Makefile
|--- usb_old/media/Makefile 2005-06-19 17:49:07.000000000 +0200
|+++ usb/media/Makefile 2005-11-05 23:05:56.000000000 +0100
--------------------------
File to patch:
Skip this patch? [y] y
Skipping patch.
1 out of 1 hunk ignored
patching file media/spca5xx/cs2102.h
patching file media/spca5xx/hdcs2020.h
patching file media/spca5xx/hv7131b.h
patching file media/spca5xx/hv7131c.h
patching file media/spca5xx/icm105a.h
patching file media/spca5xx/Makefile
patching file media/spca5xx/Makefile.2.4
patching file media/spca5xx/Makefile.org
patching file media/spca5xx/pas106b.h
patching file media/spca5xx/pb0330.h
patching file media/spca5xx/sn9cxxx.h
patching file media/spca5xx/sp5xxfw2.dat
patching file media/spca5xx/sp5xxfw2.h
patching file media/spca5xx/spca5xx.h
patching file media/spca5xx/spcaCompat.h
patching file media/spca5xx/spca_core.c
patching file media/spca5xx/spcadecoder.c
patching file media/spca5xx/spcadecoder.h
patching file media/spca5xx/spcausb.h
patching file media/spca5xx/tas5130c.h
patching file media/spca5xx/zc3xx.h
[root@localhost usb]#
創建補丁文件:
代碼:diff -Naur 舊的目錄 新的目錄 > patch文件
或者
diff -Naur 舊的文件 新的文件 > patch文件對于目錄層數的一些限制
在創建patch的時候文件夾的層數應當是一樣的,比如
代碼:--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000這樣是可以的。
而
代碼:--- old/try1/other/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000這樣做可能會有一些問題。
如何使用patch
對于一個patch文件,有兩種常用使用方法:
1.代碼:cat new-patch | patch -p02.代碼:patch -p0 < new-patchpatch命令里面的層數(-p0?-p1?)
參數-p來指定從第幾層開始比較。比如有一個patch文件的補丁頭是這樣的:
代碼:--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000如果使用參數-p0,就表示從當前目錄,找一個叫作new的目錄,在它下面找一個叫modules的目錄,再在它下面找一個叫pcitableMon的目錄。
如果使用參數-p1,就表示忽略第一層,從當前目錄找一個叫modules的目錄,在它下面找一個叫modules的目錄。這樣會忽略掉補丁頭提到的new目錄。
依此類推。
patch文件的結構
補丁頭
補丁頭是分別由---/+++開頭的兩行,用來表示要打補丁的文件。
一個補丁文件中的多個補丁
一個補丁文件中可能包含以---/+++開頭的很多節,每一節用來打一個補丁。所以在一個補丁文件中可以包含好多個補丁。
塊
塊是補丁中要修改的地方。它通常由一部分不用修改的東西開始和結束。他們只是用來表示要修改的位置。他們通常以@@開始,結束于另一個塊的開始或者一個新的補丁頭。
塊的縮進
塊會縮進一列,而這一列是用來表示這一行是要增加還是要刪除的。
塊的第一列
+號表示這一行是要加上的。
-號表示這一行是要刪除的。
沒有加號也沒有減號表示這里只是引用的而不需要修改。
一個patch的例子
代碼:diff -u old/modules/pcitable new/modules/pcitable
--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
@@ -1,4 +1,6 @@
0x0e110xae10"cpqarray""Compaq|Smart-2/P RAID Controller"
+0x10000x0010"cpqarray""Compaq|Integrated Array Controller"
+0x10110x0046"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae32"tlan""Compaq|Netelligent 10/100"
0x0e110xae34"tlan""Compaq|Netelligent 10"
0x0e110xae35"tlan""Compaq|Integrated NetFlex-3/P"
@@ -21,6 +23,7 @@
0x10000x000f"ncr53c8xx""Symbios|53c875"
0x10000x0012"ncr53c8xx""Symbios|53c895a"
0x10000x008f"ncr53c8xx""Symbios|53c875J"
+0x10000x000a"sym53c8xx""Symbios|53c1510"
0x10000x0701"yellowfin""Symbios|83C885 gigabit ethernet"
0x10000x0702"yellowfin""Symbios|Yellowfin G-NIC gigabit ethernet"
0x10110x0001"tulip""DEC|DECchip 21050"
--- old/usr/share/kudzu/pcitableSun Sep 26 17:11:23 1999
+++ new/usr/share/kudzu/pcitableTue Dec 19 20:05:41 2000
@@ -15,6 +15,8 @@
0x0e110x3034"unknown""Compaq|QVision 1280/p"
0x0e110x4000"unknown""Compaq|4000 [Triflex]"
0x0e110xa0f3"ignore""Compaq|Triflex PCI to ISA Bridge"
+0x10000x0010"cpqarray""Compaq|Integrated Array Controller"
+0x10110x0046"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae10"cpqarray""Compaq|Smart-2/P RAID Controller"
0x0e110xae29"unknown""Compaq|MIS-L"
0x0e110xae2a"unknown""Compaq|MPC"
@@ -46,6 +48,7 @@
0x10000x000f"ncr53c8xx""Symbios|53c875"
0x10000x0012"ncr53c8xx""Symbios|53c895a"
0x10000x008f"ncr53c8xx""Symbios|53c875J"
+0x10000x000a"sym53c8xx""Symbios|53c1510"
0x10000x0701"yellowfin""Symbios|83C885 gigabit ethernet"
0x10000x0702"yellowfin""Symbios|Yellowfin G-NIC gigabit ethernet"
0x10000x0901"unknown""Symbios|61C102"分析
這個例子是由命令
代碼:diff -u old/modules/pcitable new/modules/pcitable創建的。不過最好是用命令diff -Naur來代替diff -u。
它修改了兩個文件,new/modules/pcitable和new/usr/share/kudzu/pcitable。
第一個補丁頭包含兩個塊,分別增加了兩行和一行。