Use and create a patch file
Posting time: Author: superuser Source: confused
Font family: small, medium, and large | print
Original article http://www.linuxsir.org/bbs/showthread.php? T = 240802
When I went to QQ today, I found that Eva could not be used. Later I saw a solution, so I wanted to make a patch, but it would not be :-). Later, I checked and clarified, wrote a summary, shared it, and did not know whether there was any such thing. I hope this is not unnecessary.
Create a patch file:
Code:
Diff-Naur old folder new folder> patch file
Or
Diff-Naur old file new File> patch file
Some limitations on folder Layers
When creating a patch, the folder layers should be the same, for example
Code:
--- Old/modules/pcitablemon Sep 27 11:03:56 1999
++ New/modules/pcitabletue Dec 19 20:05:41 2000
This can be done.
While
Code:
--- Old/try1/other/modules/pcitablemon Sep 27 11:03:56 1999
++ New/modules/pcitabletue Dec 19 20:05:41 2000
This may cause some problems.
How to Use patch
There are two common usage methods for a patch file:
1.
Code:
cat new-patch | patch -p02.
2,
Code:
patch -p0 < new-patch
The number of layers in the patch command (-P0? -P1 ?)
Begin number-P to specify the starting ratio from the nth layer. For example, the patch header of a patch file is like this:
Code:
--- old/modules/pcitableMon Sep 27 11:03:56 1999
+++ new/modules/pcitableTue Dec 19 20:05:41 2000
If the number of modules-P0 is used, a folder named new is found from the current folder, and a folder named modules is found below it, find a folder named pcitablemon under it.
If the number of modules-P1 is used, the first layer is ignored. Find a folder named modules from the current folder and find a folder named modules below it. This will ignore the new folder mentioned in the patch header.
And so on.
Patch file structure
Patch Header
The patch header contains two lines starting with ---/++ to indicate the files to be patched.
Multiple patches in a patch file
A patch file may contain many sections starting with ---/++. Each section is used for a patch. Therefore, a patch file can contain many patches.
Block
The block is the part to be changed in the patch. It usually starts and ends with a part of things that do not need to be changed. They are only used to indicate the location to be modified. They usually start with @ and end with a block or a new patch header.
Block indent
Blocks will be reduced into one column, and this column is used to indicate that this row is to be added? You still need to delete it.
First column of the block
+ Indicates that this line is to be added.
-Indicates that this row is to be deleted.
There is no plus sign or minus sign, which means that this is just referenced and does not need to be changed.
Example of a patch
Code:
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"
Analysis
In this example
Code:
diff -u old/modules/pcitable new/modules/pcitable
Created. It is better to replace diff-u with diff-Naur.
It changes two files, new/modules/pcitable and new/usr/share/kudzu/pcitable.
The first patch header contains two parts: add? Two rows and one row.
This is why I have taken this article http://www.cpqlinux.com/patch.html. Because I have just been in touch with these things, translation may be inappropriate in many places, especially some terms. If any problem is found, please leave a message to explain it so that I can correct it. Thank you.
I also want to view all comments in two sentences.
Related Comments
- Superuser (2007-2-13 21:12:26) Patching (very) mini howto
Introduction
This very short document is a slightly lengthened version of an email I wrote in 2003 on the subject of patches, I 've put it here in case it cocould be useful to anyone else.
The howto
CD into the directory containing the sources you want to patch:Code:
$ cd madwifi
Then you need to pipe the patch file into the program 'patch ', like this:Code:
$ cat /path/to/patch/patch.diff | patch -p1
The processs for applying gzipped or bzipped patches is almost identical, only you use a modified version of 'cat' which can handle the compression thats been used e. g:Code:
$ bzcat /path/to/patch/patch.bz2 | patch -p1
For bzips, orCode:
$ zcat /path/to/patch/patch.gz2 | patch -p1
For the (more common) gzips.
Another way which might interest some people (which I 've just descovered) is to do things the other way around, in this way you can do it without running Cat:Code:
$ patch -p1 < patch
I'm not exactly sure how to do this with zipped patches just yet however, my experiments wowould lead me to belive that its more complex than most of what's above.
The option-P1 tells the patch program to remove 1 layer of all the filenames from the input, you do this because normally the person who made the patch is one directory closer to/than you. the best way to explain this is too look at the content of a patch (this is part of the wireless extensions patch ):Code:
diff -u -p linux/include/linux/wireless.15.h linux/include/linux/wireless.h
--- linux/include/linux/wireless.15.h Fri Jan 10 16:55:07 2003
+++ linux/include/linux/wireless.h Wed Apr 2 16:33:31 2003
The lines mention "Linux/include/[...] ", now if you have more than one set of kernel sources on your system, then the one you want to patch will not necessarily be in as Directory called 'linux ', the-P1 option wocould strip the Linux from the filename and just leave:Code:
diff -u -p include/linux/wireless.15.h include/linux/wireless.h
--- include/linux/wireless.15.h Fri Jan 10 16:55:07 2003
+++ include/linux/wireless.h Wed Apr 2 16:33:31 2003
From the above discussion, it shocould be fairly easy to see that patch strips from the left hand side, and removes n slashes. where N is the number the 'p' option.
There are a couple of other things which I thinks its handy to know about patch, first is that not all patches will go on 'cleanly ', sometimes you will get messages like 'hunk suceeded at offset 32', this means that part of the patch applied, but not in the exact same place as the original author intended. this happens all the time with the madwifi driver from CVS.
Second is the-r swich for 'patch ', this:Code:
$ cat /path/to/patch/patch.diff | patch -p1 -R
Wocould remove the patch from your current directory tree.
And finally
One last thing to remember: I am no expert, And some of this may be a bit wrong, missing something or whatever. Drop me a line if it is.
Use and create a patch file