1、源碼官網
可以直接下載,也可以使用git下載,git下載的好處是可以隨時切換版本,查看提交歷史,方便學習。
2、git下載配置
1)下載安裝git
[root@VM_0_11_centos home]# yum -y install git
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.aliyun.com
* elrepo: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
2)配置
[root@VM_0_11_centos home]# git config --global user.name "xxxx"
[root@VM_0_11_centos home]# git config --global user.email "XXXXXXX"
[root@VM_0_11_centos home]# git config --list
user.name=xxx
user.email=xxxxxxxxxxxxxxx
3)下載源碼
[root@VM_0_11_centos home]# cd kernel_source/
[root@VM_0_11_centos kernel_source]# git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Cloning into 'linux'...
remote: Enumerating objects: 7233058, done.
Receiving objects: 0% (3917/7233058), 2.11 MiB | 2.00 KiB/s
3、查看源碼更改信息
1)查看內核版本
make kernelversion #在根目錄下使用
[root@VM_0_11_centos linux]# make kernelversion
5.6.0-rc7
[root@VM_0_11_centos linux]#
2) 查看提交記錄
git log
[root@VM_0_11_centos linux]# git log
commit f3e69428b5e26b0851d7ef4c15859cffebf2b9de
Merge: 9efcc4a 4134252
Author: Linus Torvalds <[email protected]>
Date: Thu Mar 26 20:49:44 2020 -0700
Merge branch
3)查詢commitID
git blame 文件名 #查看該文件的修改歷史
[root@VM_0_11_centos fs]# git blame ./open.c
457c89965 (Thomas Gleixner 2019-05-19 13:08:55 +0100 1) // SPDX-License-Identifier: GPL-2.0-only
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 2) /*
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 3) * linux/fs/open.c
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) *
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5) * Copyright (C) 1991, 1992 Linus Torvalds
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 6) */
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 7)
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 8) #include <linux/string.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 9) #include <linux/mm.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 10) #include <linux/file.h>
9f3acc314 (Al Viro 2008-04-24 07:44:08 -0400 11) #include <linux/fdtable.h>
0eeca2830 (Robert Love 2005-07-12 17:06:03 -0400 12) #include <linux/fsnotify.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) #include <linux/module.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14) #include <linux/tty.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) #include <linux/namei.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 16) #include <linux/backing-dev.h>
16f7e0fe2 (Randy Dunlap 2006-01-11 12:17:46 -0800 17) #include <linux/capability.h>
086f7316f (Andrew G. Morgan 2008-07-04 09:59:58 -0700 18) #include <linux/securebits.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) #include <linux/security.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) #include <linux/mount.h>
5590ff0d5 (Ulrich Drepper 2006-01-18 17:43:53 -0800 21) #include <linux/fcntl.h>
5a0e3ad6a (Tejun Heo 2010-03-24 17:04:11 +0900 22) #include <linux/slab.h>
7c0f6ba68 (Linus Torvalds 2016-12-24 11:46:01 -0800 23) #include <linux/uaccess.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 24) #include <linux/fs.h>
ef3daeda7 (Yoav Zach 2005-06-23 00:09:58 -0700 25) #include <linux/personality.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:36 -0700 26) #include <linux/pagemap.h>
^1da177e4 (Linus Torvalds 2005-04-16 15:20:3
查找對應行代碼的commitID
cc4e69dee (Miklos Szeredi 2005-11-07 00:59:49 -0800 50) if (filp) {
cc4e69dee (Miklos Szeredi 2005-11-07 00:59:49 -0800 51) newattrs.ia_file = filp;
cc4e69dee (Miklos Szeredi 2005-11-07 00:59:49 -0800 52) newattrs.ia_valid |= ATTR_FILE;
cc4e69dee (Miklos Szeredi 2005-11-07 00:59:49 -0800 53) }
git show commitID #查看commit信息
[root@VM_0_11_centos fs]# git show cc4e69dee
commit cc4e69dee4a080f6eae3f410daec2593f4fa6f00
Author: Miklos Szeredi <[email protected]>
Date: Mon Nov 7 00:59:49 2005 -0800
[PATCH] VFS: pass file pointer to filesystem from ftruncate()
This patch extends the iattr structure with a file pointer memeber, and adds
an ATTR_FILE validity flag for this member.
This is set if do_truncate() is invoked from ftruncate() or from
do_coredump().
The change is source and binary compatible.
Signed-off-by: Miklos Szeredi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
diff --git a/fs/exec.c b/fs/exec.c
index ce76b33..cd6c574 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1511,7 +1511,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
goto close_fail;
if (!file->f_op->write)
goto close_fail;
- if (do_truncate(file->f_dentry, 0) != 0)
+ if (do_truncate(file->f_dentry, 0, file) != 0)
goto close_fail;
retval = binfmt->core_dump(signr, regs, file);
diff --git a/fs/namei.c b/fs/namei.c
index c5769c4..b3f8a19 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1459,7 +1459,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
if (!error) {
DQUOT_INIT(inode);
- error = do_truncate(dentry, 0);
+ error = do_truncate(dentry, 0, NULL);
}
put_write_access(inode);
if (error)
diff --git a/fs/open.c b/fs/open.c
index 2835f09..6e81367 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -194,7 +194,7 @@ asmlinkage long sys_fstatfs64(unsigned int fd, size_t sz, struct statfs64 __user
return error;
}
-int do_truncate(struct dentry *dentry, loff_t length)
: