Press "Enter" to skip to content

Linux的patch原理

通过一个简单的小例子,讲述一下Linux的patch原理。

假设有个系统源码,位于mm/slab.c

[root@os1 tmp]# ls mm
slab.c
[root@os1 tmp]# cp -r mm newmm
[root@os1 tmp]# vim newmm/slab.c    #手动更新一下系统源码,随便作点改动,作为新版本
ZXXXXXX            /*手动添加这一行*/
/*
 * linux/mm/slab.c
 * Written by Mark Hemment, 1996/97.
 * ([email protected])
 *
 * kmem_cache_destroy() + some cleanup - 1999 Andrea Arcangeli
 *
 * Major cleanup, different bufctl logic, per-cpu arrays
 *      (c) 2000 Manfred Spraul
……

提取patch

[root@os1 tmp]# diff -u mm/slab.c newmm/slab.c  > t.patch

看看patch里都有什么

[root@os1 tmp]# more t.patch
--- mm/slab.c	2013-11-04 23:28:25.646753453 +0800
+++ newmm/slab.c	2013-11-04 23:38:50.355752475 +0800
@@ -1,3 +1,4 @@
+ZXXXXXX
 /*
  * linux/mm/slab.c
  * Written by Mark Hemment, 1996/97.

更新一下patch吧

[root@os1 mm]# cd mm
[root@os1 mm]# patch -p1 < ../t.patch
patching file slab.c
[root@os1 mm]# more slab.c   #看看原始文件发生了什么变化
ZXXXXXX
/*
 * linux/mm/slab.c
 * Written by Mark Hemment, 1996/97.
 * ([email protected])
 *
 * kmem_cache_destroy() + some cleanup - 1999 Andrea Arcangeli
 *
 * Major cleanup, different bufctl logic, per-cpu arrays
 *	(c) 2000 Manfred Spraul

原文件竟然被更新了耶!

Leave a Reply

Your email address will not be published. Required fields are marked *