`
lobin
  • 浏览: 425965 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

linux

阅读更多

linux的一些有关DevOps的东西

地址:https://www.iteye.com/blog/lobin-2040270

 

 

linux: Guide

地址:https://www.iteye.com/blog/lobin-2512870

 

C部分和汇编部分

汇编部分如bootloader等采用GNU AS实现,老版本ru linux 1.0, 1.x, 2.0 采用的是as86,ld86实现。

 

gnulib

参考资料:http://www.gnu.org/software/gnulib/manual/html_node/index.html

>git clone git://git.savannah.gnu.org/gnulib.git gnulib

 

$ gnulib-tool --create-testdir --source-base=lib --dir=/tmp/posixlib `posix-modules`

 

一张有关io的图片

 

一张有关io的图片

 


 

 

 

 

主引导程序

# dd if=/dev/sda of=mbr.bin bs=512 count=1

# od -xa mbr.bin

# od -A x -t x1 mbr.bin

写道
000000 eb 48 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0
000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00
000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75
000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 03 02
000040 80 00 00 80 ee 49 08 00 00 08 fa 90 90 f6 c2 80
000050 75 02 b2 80 ea 59 7c 00 00 31 c0 8e d8 8e d0 bc
000060 00 20 fb a0 40 7c 3c ff 74 02 88 c2 52 f6 c2 80
000070 74 54 b4 41 bb aa 55 cd 13 5a 52 72 49 81 fb 55
000080 aa 75 43 a0 41 7c 84 c0 75 05 83 e1 01 74 37 66
000090 8b 4c 10 be 05 7c c6 44 ff 01 66 8b 1e 44 7c c7
0000a0 04 10 00 c7 44 02 01 00 66 89 5c 08 c7 44 06 00
0000b0 70 66 31 c0 89 44 04 66 89 44 0c b4 42 cd 13 72
0000c0 05 bb 00 70 eb 7d b4 08 cd 13 73 0a f6 c2 80 0f
0000d0 84 f0 00 e9 8d 00 be 05 7c c6 44 ff 00 66 31 c0
0000e0 88 f0 40 66 89 44 04 31 d2 88 ca c1 e2 02 88 e8
0000f0 88 f4 40 89 44 08 31 c0 88 d0 c0 e8 02 66 89 04
000100 66 a1 44 7c 66 31 d2 66 f7 34 88 54 0a 66 31 d2
000110 66 f7 74 04 88 54 0b 89 44 0c 3b 44 08 7d 3c 8a
000120 54 0d c0 e2 06 8a 4c 0a fe c1 08 d1 8a 6c 0c 5a
000130 8a 74 0b bb 00 70 8e c3 31 db b8 01 02 cd 13 72
000140 2a 8c c3 8e 06 48 7c 60 1e b9 00 01 8e db 31 f6
000150 31 ff fc f3 a5 1f 61 ff 26 42 7c be 7f 7d e8 40
000160 00 eb 0e be 84 7d e8 38 00 eb 06 be 8e 7d e8 30
000170 00 be 93 7d e8 2a 00 eb fe 47 52 55 42 20 00 47
000180 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 65
000190 61 64 00 20 45 72 72 6f 72 00 bb 01 00 b4 0e cd
0001a0 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 00 00 00
0001b0 00 00 00 00 00 00 00 00 c4 15 0a 00 00 00 80 20
0001c0 21 00 83 dd 1e 3f 00 08 00 00 00 a0 0f 00 00 dd
0001d0 1f 3f 8e fe ff ff 00 a8 0f 00 00 58 70 02 00 00
0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

 

 

OS如果有多重引导,还有个多重引导程序的概念。

linux 1.0 主引导程序

引导段(BOOTSEG)

初始段(INITSEG)

装载段(SETUPSEG)

系统段(SYSSEG)

 

bootsect.S

setup.S

head.S

 

linux 1.3.0 主引导程序

bootsect.S

 

编译链接

gcc -D__KERNEL__ -I/cygdrive/d/home/admin/workstation/linux/linux-1.3.0/linux/include -E -traditional -DSVGA_MODE=NORMAL_VGA  -DRAMDISK=512 bootsect.S -o bootsect.asm

as86 -0 -a -o bootsect.o bootsect.asm

ld86 -0 -s -o bootsect bootsect.o

 

在linux下编译链接是没问题的。

 

我找到as86,ld86的源代码在cygwin下安装,安装没问题,编译链接都能通过,但生成的bootsect文件大小为544字节,不是512字节,这就有问题了。

 

 

linux 2.6.0 主引导程序

SETUPSECTS	= 4			/* default nr of setup-sectors */
BOOTSEG		= 0x07C0		/* original address of boot-sector */
INITSEG		= 0x9000		/* we move boot here - out of the way */
SETUPSEG	= 0x9020		/* setup starts here */
SYSSEG		= 0x1000		/* system loaded at 0x10000 (65536) */
SYSSIZE		= 0x7F00		/* system size: # of 16-byte clicks */
					/* to be loaded */
ROOT_DEV	= 0 			/* ROOT_DEV is now written by "build" */
SWAP_DEV	= 0			/* SWAP_DEV is now written by "build" */



	.code16

.text

	.global _start
_start:

	# Normalize the start address
	jmpl	$BOOTSEG, $start2

start2:
	movw	%cs, %ax
	movw	%ax, %ds
	movw	%ax, %es
	movw	%ax, %ss
	movw	$0x7c00, %sp
	sti
	cld

	movw	$bugger_off_msg, %si

msg_loop:
	lodsb
	andb	%al, %al
	jz	die
	movb	$0xe, %ah
	movw	$7, %bx
	int	$0x10
	jmp	msg_loop

die:
	# Allow the user to press a key, then reboot
	xorw	%ax, %ax
	int	$0x16
	int	$0x19

	# int 0x19 should never return.  In case it does anyway,
	# invoke the BIOS reset code...
	ljmp	$0xf000,$0xfff0


bugger_off_msg:
	.ascii	"Direct booting from floppy is no longer supported.\r\n"
	.ascii	"Please use a boot loader program instead.\r\n"
	.ascii	"\n"
	.ascii	"Remove disk and press any key to reboot . . .\r\n"
	.byte	0
	

	# Kernel attributes; used by setup

	.org 497

setup_sects:	.byte SETUPSECTS
root_flags:	.word 1
syssize:	.word SYSSIZE
swap_dev:	.word SWAP_DEV
ram_size:	.word 0
vid_mode:	.word 0xfffd
root_dev:	.word ROOT_DEV
boot_flag:	.word 0xAA55

>as boot_test.asm -o boot_test.o

>objcopy -O binary boot_test.o boot_test.bin

>bximage

Please choose one [0] 1

Please type hd or fd. [hd] fd

Please type 160k, 180k, 320k, 360k, 720k, 1.2M, 1.44M, 1.68M, 1.72M, or 2.88M.

[1.44M] 1.44M

What should be the name of the image?

[a.img] boot_test.asm.img

 

>dd if=boot_test.bin of=boot_test.asm.img bs=512 count=1 conv=notrunc


 

 

 

 

内存管理

 

 

进程管理

 

 

进程管理

linux 当前进程(current)

static inline struct task_struct * get_current(void)
{
	return current_thread_info()->task;
}
 
#define current get_current()

 

/* how to get the thread information struct from C */
static inline struct thread_info *current_thread_info(void)
{
	struct thread_info *ti;
	__asm__("andl %%esp,%0; ":"=r" (ti) : "0" (~8191UL));
	return ti;
}

 

struct thread_info {
	struct task_struct	*task;		/* main task structure */
	struct exec_domain	*exec_domain;	/* execution domain */
	unsigned long		flags;		/* low level flags */
	unsigned long		status;		/* thread-synchronous flags */
	__u32			cpu;		/* current CPU */
	__s32			preempt_count; /* 0 => preemptable, <0 => BUG */

	mm_segment_t		addr_limit;	/* thread address space:
					 	   0-0xBFFFFFFF for user-thead
						   0-0xFFFFFFFF for kernel-thread
						*/
	struct restart_block    restart_block;

	__u8			supervisor_stack[0];
};

task_struct结构

\include\linux\sched.h

struct task_struct {
	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
	struct thread_info *thread_info;
	atomic_t usage;
	unsigned long flags;	/* per process flags, defined below */
	unsigned long ptrace;

	int lock_depth;		/* Lock depth */

	int prio, static_prio;
	struct list_head run_list;
	prio_array_t *array;

	unsigned long sleep_avg;
	long interactive_credit;
	unsigned long long timestamp;
	int activated;

	unsigned long policy;
	cpumask_t cpus_allowed;
	unsigned int time_slice, first_time_slice;

	struct list_head tasks;
	struct list_head ptrace_children;
	struct list_head ptrace_list;

	struct mm_struct *mm, *active_mm;

/* task state */
	struct linux_binfmt *binfmt;
	int exit_code, exit_signal;
	int pdeath_signal;  /*  The signal sent when the parent dies  */
	/* ??? */
	unsigned long personality;
	int did_exec:1;
	pid_t pid;
	pid_t __pgrp;		/* Accessed via process_group() */
	pid_t tty_old_pgrp;
	pid_t session;
	pid_t tgid;
	/* boolean value for session group leader */
	int leader;
	/* 
	 * pointers to (original) parent process, youngest child, younger sibling,
	 * older sibling, respectively.  (p->father can be replaced with 
	 * p->parent->pid)
	 */
	struct task_struct *real_parent; /* real parent process (when being debugged) */
	struct task_struct *parent;	/* parent process */
	struct list_head children;	/* list of my children */
	struct list_head sibling;	/* linkage in my parent's children list */
	struct task_struct *group_leader;	/* threadgroup leader */

	/* PID/PID hash table linkage. */
	struct pid_link pids[PIDTYPE_MAX];

	wait_queue_head_t wait_chldexit;	/* for wait4() */
	struct completion *vfork_done;		/* for vfork() */
	int __user *set_child_tid;		/* CLONE_CHILD_SETTID */
	int __user *clear_child_tid;		/* CLONE_CHILD_CLEARTID */

	unsigned long rt_priority;
	unsigned long it_real_value, it_prof_value, it_virt_value;
	unsigned long it_real_incr, it_prof_incr, it_virt_incr;
	struct timer_list real_timer;
	struct list_head posix_timers; /* POSIX.1b Interval Timers */
	unsigned long utime, stime, cutime, cstime;
	unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; /* context switch counts */
	u64 start_time;
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
	unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
/* process credentials */
	uid_t uid,euid,suid,fsuid;
	gid_t gid,egid,sgid,fsgid;
	int ngroups;
	gid_t	groups[NGROUPS];
	kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
	int keep_capabilities:1;
	struct user_struct *user;
/* limits */
	struct rlimit rlim[RLIM_NLIMITS];
	unsigned short used_math;
	char comm[16];
/* file system info */
	int link_count, total_link_count;
	struct tty_struct *tty; /* NULL if no tty */
/* ipc stuff */
	struct sysv_sem sysvsem;
/* CPU-specific state of this task */
	struct thread_struct thread;
/* filesystem information */
	struct fs_struct *fs;
/* open file information */
	struct files_struct *files;
/* namespace */
	struct namespace *namespace;
/* signal handlers */
	struct signal_struct *signal;
	struct sighand_struct *sighand;

	sigset_t blocked, real_blocked;
	struct sigpending pending;

	unsigned long sas_ss_sp;
	size_t sas_ss_size;
	int (*notifier)(void *priv);
	void *notifier_data;
	sigset_t *notifier_mask;
	
	void *security;

/* Thread group tracking */
   	u32 parent_exec_id;
   	u32 self_exec_id;
/* Protection of (de-)allocation: mm, files, fs, tty */
	spinlock_t alloc_lock;
/* Protection of proc_dentry: nesting proc_lock, dcache_lock, write_lock_irq(&tasklist_lock); */
	spinlock_t proc_lock;
/* context-switch lock */
	spinlock_t switch_lock;

/* journalling filesystem info */
	void *journal_info;

/* VM state */
	struct reclaim_state *reclaim_state;

	struct dentry *proc_dentry;
	struct backing_dev_info *backing_dev_info;

	struct io_context *io_context;

	unsigned long ptrace_message;
	siginfo_t *last_siginfo; /* For ptrace use.  */
};

初始化

\arch\x86_64\kernel\init_task.c

 

/*
 * Initial task structure.
 *
 * All other task structs will be allocated on slabs in fork.c
 */
struct task_struct init_task = INIT_TASK(init_task);
INIT_TASK(init_task):
\include\linux\init_task.h

 

/*
 *  INIT_TASK is used to set up the first task table, touch at
 * your own risk!. Base=0, limit=0x1fffff (=2MB)
 */
#define INIT_TASK(tsk)	\
{									\
	.state		= 0,						\
	.thread_info	= &init_thread_info,				\
	.usage		= ATOMIC_INIT(2),				\
	.flags		= 0,						\
	.lock_depth	= -1,						\
	.prio		= MAX_PRIO-20,					\
	.static_prio	= MAX_PRIO-20,					\
	.policy		= SCHED_NORMAL,					\
	.cpus_allowed	= CPU_MASK_ALL,					\
	.mm		= NULL,						\
	.active_mm	= &init_mm,					\
	.run_list	= LIST_HEAD_INIT(tsk.run_list),			\
	.time_slice	= HZ,						\
	.tasks		= LIST_HEAD_INIT(tsk.tasks),			\
	.ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children),		\
	.ptrace_list	= LIST_HEAD_INIT(tsk.ptrace_list),		\
	.real_parent	= &tsk,						\
	.parent		= &tsk,						\
	.children	= LIST_HEAD_INIT(tsk.children),			\
	.sibling	= LIST_HEAD_INIT(tsk.sibling),			\
	.group_leader	= &tsk,						\
	.wait_chldexit	= __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
	.real_timer	= {						\
		.function	= it_real_fn				\
	},								\
	.cap_effective	= CAP_INIT_EFF_SET,				\
	.cap_inheritable = CAP_INIT_INH_SET,				\
	.cap_permitted	= CAP_FULL_SET,					\
	.keep_capabilities = 0,						\
	.rlim		= INIT_RLIMITS,					\
	.user		= INIT_USER,					\
	.comm		= "swapper",					\
	.thread		= INIT_THREAD,					\
	.fs		= &init_fs,					\
	.files		= &init_files,					\
	.signal		= &init_signals,				\
	.sighand	= &init_sighand,				\
	.pending	= {						\
		.list = LIST_HEAD_INIT(tsk.pending.list),		\
		.signal = {{0}}},					\
	.blocked	= {{0}},					\
	.posix_timers	 = LIST_HEAD_INIT(tsk.posix_timers),		\
	.alloc_lock	= SPIN_LOCK_UNLOCKED,				\
	.proc_lock	= SPIN_LOCK_UNLOCKED,				\
	.switch_lock	= SPIN_LOCK_UNLOCKED,				\
	.journal_info	= NULL,						\
}

 

 

 

 

 

pthread

http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

 

文件系统

linux使用的是ext文件系统。ext文件系统现在已经有好几个版本,包括ext2,ext3以及ext4。实际上还存在ext 0.x,1.x,2.x,3.x,4.x等版本。

 

linux同时支持其他很多文件系统格式,如fat,fat32,vfx,xfx等。

 

关于ext文件系统

参考另一篇文章:https://www.iteye.com/blog/lobin-2311779

 

linux提供了一些工具来格式化生成ext格式的文件系统

后面在通过源代码来分析ext文件系统之前,可以先通过这些工具来格式化生成ext文件系统进行分析。

 

ext2

 

ext2超级块

\include\linux\ext2_fs.h

 

/*
 * Structure of the super block
 */
struct ext2_super_block {
	__u32	s_inodes_count;		/* Inodes count */
	__u32	s_blocks_count;		/* Blocks count */
	__u32	s_r_blocks_count;	/* Reserved blocks count */
	__u32	s_free_blocks_count;	/* Free blocks count */
	__u32	s_free_inodes_count;	/* Free inodes count */
	__u32	s_first_data_block;	/* First Data Block */
	__u32	s_log_block_size;	/* Block size */
	__s32	s_log_frag_size;	/* Fragment size */
	__u32	s_blocks_per_group;	/* # Blocks per group */
	__u32	s_frags_per_group;	/* # Fragments per group */
	__u32	s_inodes_per_group;	/* # Inodes per group */
	__u32	s_mtime;		/* Mount time */
	__u32	s_wtime;		/* Write time */
	__u16	s_mnt_count;		/* Mount count */
	__s16	s_max_mnt_count;	/* Maximal mount count */
	__u16	s_magic;		/* Magic signature */
	__u16	s_state;		/* File system state */
	__u16	s_errors;		/* Behaviour when detecting errors */
	__u16	s_minor_rev_level; 	/* minor revision level */
	__u32	s_lastcheck;		/* time of last check */
	__u32	s_checkinterval;	/* max. time between checks */
	__u32	s_creator_os;		/* OS */
	__u32	s_rev_level;		/* Revision level */
	__u16	s_def_resuid;		/* Default uid for reserved blocks */
	__u16	s_def_resgid;		/* Default gid for reserved blocks */
	/*
	 * These fields are for EXT2_DYNAMIC_REV superblocks only.
	 *
	 * Note: the difference between the compatible feature set and
	 * the incompatible feature set is that if there is a bit set
	 * in the incompatible feature set that the kernel doesn't
	 * know about, it should refuse to mount the filesystem.
	 * 
	 * e2fsck's requirements are more strict; if it doesn't know
	 * about a feature in either the compatible or incompatible
	 * feature set, it must abort and not try to meddle with
	 * things it doesn't understand...
	 */
	__u32	s_first_ino; 		/* First non-reserved inode */
	__u16   s_inode_size; 		/* size of inode structure */
	__u16	s_block_group_nr; 	/* block group # of this superblock */
	__u32	s_feature_compat; 	/* compatible feature set */
	__u32	s_feature_incompat; 	/* incompatible feature set */
	__u32	s_feature_ro_compat; 	/* readonly-compatible feature set */
	__u8	s_uuid[16];		/* 128-bit uuid for volume */
	char	s_volume_name[16]; 	/* volume name */
	char	s_last_mounted[64]; 	/* directory where last mounted */
	__u32	s_algorithm_usage_bitmap; /* For compression */
	/*
	 * Performance hints.  Directory preallocation should only
	 * happen if the EXT2_COMPAT_PREALLOC flag is on.
	 */
	__u8	s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
	__u8	s_prealloc_dir_blocks;	/* Nr to preallocate for dirs */
	__u16	s_padding1;
	/*
	 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
	 */
	__u8	s_journal_uuid[16];	/* uuid of journal superblock */
	__u32	s_journal_inum;		/* inode number of journal file */
	__u32	s_journal_dev;		/* device number of journal file */
	__u32	s_last_orphan;		/* start of list of inodes to delete */
	__u32	s_hash_seed[4];		/* HTREE hash seed */
	__u8	s_def_hash_version;	/* Default hash version to use */
	__u8	s_reserved_char_pad;
	__u16	s_reserved_word_pad;
	__u32	s_default_mount_opts;
 	__u32	s_first_meta_bg; 	/* First metablock block group */
	__u32	s_reserved[190];	/* Padding to the end of the block */
};
include\linux\ext2_fs_sb.h

 

/*
 * second extended-fs super-block data in memory
 */
struct ext2_sb_info {
	unsigned long s_frag_size;	/* Size of a fragment in bytes */
	unsigned long s_frags_per_block;/* Number of fragments per block */
	unsigned long s_inodes_per_block;/* Number of inodes per block */
	unsigned long s_frags_per_group;/* Number of fragments in a group */
	unsigned long s_blocks_per_group;/* Number of blocks in a group */
	unsigned long s_inodes_per_group;/* Number of inodes in a group */
	unsigned long s_itb_per_group;	/* Number of inode table blocks per group */
	unsigned long s_gdb_count;	/* Number of group descriptor blocks */
	unsigned long s_desc_per_block;	/* Number of group descriptors per block */
	unsigned long s_groups_count;	/* Number of groups in the fs */
	struct buffer_head * s_sbh;	/* Buffer containing the super block */
	struct ext2_super_block * s_es;	/* Pointer to the super block in the buffer */
	struct buffer_head ** s_group_desc;
	unsigned long  s_mount_opt;
	uid_t s_resuid;
	gid_t s_resgid;
	unsigned short s_mount_state;
	unsigned short s_pad;
	int s_addr_per_block_bits;
	int s_desc_per_block_bits;
	int s_inode_size;
	int s_first_ino;
	u32 s_next_generation;
	unsigned long s_dir_count;
	u8 *s_debts;
	struct percpu_counter s_freeblocks_counter;
	struct percpu_counter s_freeinodes_counter;
	struct percpu_counter s_dirs_counter;
	struct blockgroup_lock s_blockgroup_lock;
};

ext3

 

ext4

 

超级块

include\linux\fs.h

 

struct super_block {
	struct list_head	s_list;		/* Keep this first */
	dev_t			s_dev;		/* search index; _not_ kdev_t */
	unsigned long		s_blocksize;
	unsigned long		s_old_blocksize;
	unsigned char		s_blocksize_bits;
	unsigned char		s_dirt;
	unsigned long long	s_maxbytes;	/* Max file size */
	struct file_system_type	*s_type;
	struct super_operations	*s_op;
	struct dquot_operations	*dq_op;
 	struct quotactl_ops	*s_qcop;
	struct export_operations *s_export_op;
	unsigned long		s_flags;
	unsigned long		s_magic;
	struct dentry		*s_root;
	struct rw_semaphore	s_umount;
	struct semaphore	s_lock;
	int			s_count;
	int			s_syncing;
	int			s_need_sync_fs;
	atomic_t		s_active;
	void                    *s_security;

	struct list_head	s_dirty;	/* dirty inodes */
	struct list_head	s_io;		/* parked for writeback */
	struct hlist_head	s_anon;		/* anonymous dentries for (nfs) exporting */
	struct list_head	s_files;

	struct block_device	*s_bdev;
	struct list_head	s_instances;
	struct quota_info	s_dquot;	/* Diskquota specific options */

	char s_id[32];				/* Informational name */

	struct kobject           kobj;          /* anchor for sysfs */
	void 			*s_fs_info;	/* Filesystem private info */

	/*
	 * The next field is for VFS *only*. No filesystems have any business
	 * even looking at it. You had been warned.
	 */
	struct semaphore s_vfs_rename_sem;	/* Kludge */
};
 

 

 

文件

文件结构在\include\linux\fs.h中定义如下:

struct file {
	struct list_head	f_list;
	struct dentry		*f_dentry;
	struct vfsmount         *f_vfsmnt;
	struct file_operations	*f_op;
	atomic_t		f_count;
	unsigned int 		f_flags;
	mode_t			f_mode;
	loff_t			f_pos;
	struct fown_struct	f_owner;
	unsigned int		f_uid, f_gid;
	int			f_error;
	struct file_ra_state	f_ra;

	unsigned long		f_version;
	void			*f_security;

	/* needed for tty driver, and maybe others */
	void			*private_data;

	/* Used by fs/eventpoll.c to link all the hooks to this file */
	struct list_head	f_ep_links;
	spinlock_t		f_ep_lock;
};

inode

inode结构在\include\linux\fs.h中定义如下:

struct inode {
	struct hlist_node	i_hash;
	struct list_head	i_list;
	struct list_head	i_dentry;
	unsigned long		i_ino;
	atomic_t		i_count;
	umode_t			i_mode;
	unsigned int		i_nlink;
	uid_t			i_uid;
	gid_t			i_gid;
	dev_t			i_rdev;
	loff_t			i_size;
	struct timespec		i_atime;
	struct timespec		i_mtime;
	struct timespec		i_ctime;
	unsigned int		i_blkbits;
	unsigned long		i_blksize;
	unsigned long		i_version;
	unsigned long		i_blocks;
	unsigned short          i_bytes;
	spinlock_t		i_lock;	/* i_blocks, i_bytes, maybe i_size */
	struct semaphore	i_sem;
	struct inode_operations	*i_op;
	struct file_operations	*i_fop;	/* former ->i_op->default_file_ops */
	struct super_block	*i_sb;
	struct file_lock	*i_flock;
	struct address_space	*i_mapping;
	struct address_space	i_data;
	struct dquot		*i_dquot[MAXQUOTAS];
	/* These three should probably be a union */
	struct list_head	i_devices;
	struct pipe_inode_info	*i_pipe;
	struct block_device	*i_bdev;
	struct cdev		*i_cdev;
	int			i_cindex;

	unsigned long		i_dnotify_mask; /* Directory notify events */
	struct dnotify_struct	*i_dnotify; /* for directory notifications */

	unsigned long		i_state;

	unsigned int		i_flags;
	unsigned char		i_sock;

	atomic_t		i_writecount;
	void			*i_security;
	__u32			i_generation;
	union {
		void		*generic_ip;
	} u;
#ifdef __NEED_I_SIZE_ORDERED
	seqcount_t		i_size_seqcount;
#endif
};

 



 

有关传统机械硬盘可参考另一篇文章:

 https://cloud.tencent.com/developer/article/1018511

system-call level & thread-specific variables

 

 

linux epoll_ctl函数对应系统调用sys_epoll_ctl

 

asmlinkage long
sys_epoll_ctl(int epfd, int op, int fd, struct epoll_event __user *event)
{
	int error;
	struct file *file, *tfile;
	struct eventpoll *ep;
	struct epitem *epi;
	struct epoll_event epds;

	DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_ctl(%d, %d, %d, %p)\n",
		     current, epfd, op, fd, event));

	error = -EFAULT;
	if (copy_from_user(&epds, event, sizeof(struct epoll_event)))
		goto eexit_1;

	/* Get the "struct file *" for the eventpoll file */
	error = -EBADF;
	file = fget(epfd);
	if (!file)
		goto eexit_1;

	/* Get the "struct file *" for the target file */
	tfile = fget(fd);
	if (!tfile)
		goto eexit_2;

	/* The target file descriptor must support poll */
	error = -EPERM;
	if (!tfile->f_op || !tfile->f_op->poll)
		goto eexit_3;

	/*
	 * We have to check that the file structure underneath the file descriptor
	 * the user passed to us _is_ an eventpoll file. And also we do not permit
	 * adding an epoll file descriptor inside itself.
	 */
	error = -EINVAL;
	if (file == tfile || !IS_FILE_EPOLL(file))
		goto eexit_3;

	/*
	 * At this point it is safe to assume that the "private_data" contains
	 * our own data structure.
	 */
	ep = file->private_data;

	down_write(&ep->sem);

	/* Try to lookup the file inside our hash table */
	epi = ep_find(ep, tfile, fd);

	error = -EINVAL;
	switch (op) {
	case EPOLL_CTL_ADD:
		if (!epi) {
			epds.events |= POLLERR | POLLHUP;

			error = ep_insert(ep, &epds, tfile, fd);
		} else
			error = -EEXIST;
		break;
	case EPOLL_CTL_DEL:
		if (epi)
			error = ep_remove(ep, epi);
		else
			error = -ENOENT;
		break;
	case EPOLL_CTL_MOD:
		if (epi) {
			epds.events |= POLLERR | POLLHUP;
			error = ep_modify(ep, epi, &epds);
		} else
			error = -ENOENT;
		break;
	}

	/*
	 * The function ep_find() increments the usage count of the structure
	 * so, if this is not NULL, we need to release it.
	 */
	if (epi)
		ep_release_epitem(epi);

	up_write(&ep->sem);

eexit_3:
	fput(tfile);
eexit_2:
	fput(file);
eexit_1:
	DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_ctl(%d, %d, %d, %p) = %d\n",
		     current, epfd, op, fd, event, error));

	return error;
}

 

static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
		     struct file *tfile, int fd)
{
	int error, revents, pwake = 0;
	unsigned long flags;
	struct epitem *epi;
	struct ep_pqueue epq;

	error = -ENOMEM;
	if (!(epi = EPI_MEM_ALLOC()))
		goto eexit_1;

	/* Item initialization follow here ... */
	INIT_LIST_HEAD(&epi->llink);
	INIT_LIST_HEAD(&epi->rdllink);
	INIT_LIST_HEAD(&epi->fllink);
	INIT_LIST_HEAD(&epi->txlink);
	INIT_LIST_HEAD(&epi->pwqlist);
	epi->ep = ep;
	epi->file = tfile;
	epi->fd = fd;
	epi->event = *event;
	atomic_set(&epi->usecnt, 1);
	epi->nwait = 0;

	/* Initialize the poll table using the queue callback */
	epq.epi = epi;
	init_poll_funcptr(&epq.pt, ep_ptable_queue_proc);

	/*
	 * Attach the item to the poll hooks and get current event bits.
	 * We can safely use the file* here because its usage count has
	 * been increased by the caller of this function.
	 */
	revents = tfile->f_op->poll(tfile, &epq.pt);

	/*
	 * We have to check if something went wrong during the poll wait queue
	 * install process. Namely an allocation for a wait queue failed due
	 * high memory pressure.
	 */
	if (epi->nwait < 0)
		goto eexit_2;

	/* Add the current item to the list of active epoll hook for this file */
	spin_lock(&tfile->f_ep_lock);
	list_add_tail(&epi->fllink, &tfile->f_ep_links);
	spin_unlock(&tfile->f_ep_lock);

	/* We have to drop the new item inside our item list to keep track of it */
	write_lock_irqsave(&ep->lock, flags);

	/* Add the current item to the hash table */
	list_add(&epi->llink, ep_hash_entry(ep, ep_hash_index(ep, tfile, fd)));

	/* If the file is already "ready" we drop it inside the ready list */
	if ((revents & event->events) && !EP_IS_LINKED(&epi->rdllink)) {
		list_add_tail(&epi->rdllink, &ep->rdllist);

		/* Notify waiting tasks that events are available */
		if (waitqueue_active(&ep->wq))
			wake_up(&ep->wq);
		if (waitqueue_active(&ep->poll_wait))
			pwake++;
	}

	write_unlock_irqrestore(&ep->lock, flags);

	/* We have to call this outside the lock */
	if (pwake)
		ep_poll_safewake(&psw, &ep->poll_wait);

	DNPRINTK(3, (KERN_INFO "[%p] eventpoll: ep_insert(%p, %p, %d)\n",
		     current, ep, tfile, fd));

	return 0;

eexit_2:
	ep_unregister_pollwait(ep, epi);

	/*
	 * We need to do this because an event could have been arrived on some
	 * allocated wait queue.
	 */
	write_lock_irqsave(&ep->lock, flags);
	if (EP_IS_LINKED(&epi->rdllink))
		EP_LIST_DEL(&epi->rdllink);
	write_unlock_irqrestore(&ep->lock, flags);

	EPI_MEM_FREE(epi);
eexit_1:
	return error;
}

 

 

 

查看显卡驱动

有多种方法可以查看显卡驱动。以我这台笔记本为例,我这是一台老笔记本,还是XP老系统。显卡配置还不是独立显卡,而是一种处理器上的集成显卡。

方法1:

右键选择“我的电脑”,选择“管理”,打开“计算机管理”,选择“设备管理器”,在“设备管理器”中可以查看到“显卡“,然后右键选择“显卡“设备,选择属性,查看显卡设备属性信息,在“驱动程序”选项卡中可以看到显卡驱动程序的版本。如:6.14.10.5420。

方法2:

右键选择“我的电脑”,选择“属性”,打开“系统属性”,选择“硬件”选项卡,在点击“设备管理器”,在设备管理器中可以像方法1中那样查看显卡驱动程序的版本。

方法3:

选择”开始”,再选择“控制面板”,再选择“管理工具”,再选择“计算机管理”,打开“计算机管理”,选择“设备管理器”,在设备管理器中可以像方法1中那样查看显卡驱动程序的版本。

方法4:msinfo32

选择”开始”,再选择“运行”,输入“dxdiag”,或者在命令行下运行dxdiag命令,打开“DirectX诊断工具”,选择“显示”选项卡,可以看到显卡驱动程序的版本。如:6.14.10.5420。

方法5:选择”开始”,再选择“运行”,输入“msinfo32”,或者在命令行下运行msinfo32命令,打开“系统信息”,选择“组件”,再选择“显示”,可以看到显卡驱动程序的版本。如:6.14.10.5420。

更多方法查看显卡驱动信息可参考:https://www.intel.cn/content/www/cn/zh/support/articles/000005589/graphics-drivers.html

 

 

 

 

 

 

https://www.intel.com/content/www/us/en/support/articles/000005612/network-and-i-o/ethernet-products.html

List of Supported Retail Intel® Ethernet Adapters

 

写道
PCI vendor ID 8086 identifies Intel as the manufacturer of the device.

 

Intel 的厂商id:8086

 

http://pci-ids.ucw.cz/read/PC?restrict=0

PCI Devices-Vendors

 

查看网卡信息

包括网卡厂商,网卡设备id,驱动信息,如驱动版本

如我这里的一台电脑,在设备管理器中找到网络适配器看到是Broadcom NetLink (TM) Fast Ethernet,如果对Broadcom了解的话,我们就可以看出这个是来自博通(Broadcom)的网卡。右键选择“属性”后查看“详细信息”,选择“设备范例 Id”




 

前面的那个表是厂商Id,后面那个表示网卡设备Id。

 

从上面给的查询地址可看到:

14e4Broadcom Inc. and subsidiaries

1713NetLink BCM5906M Fast Ethernet PCI Express

 

右键选择“属性”后查看“驱动程序”可查看驱动版本:10.62.1.2。还可以看出该驱动程序也是由博通(Broadcom)提供的驱动程序。

 

X11

# ./configure --prefix=/usr/local/xtrans-1.3.0

# make

# make install

 

# ./configure --prefix=/usr/local/libX11-1.5.0 PKG_CONFIG_PATH="/usr/local/share/pkgconfig"

X11 will be built with the following settings:

 Loadable i18n module support:            no

 Loadable xcursor library support:        yes

 Threading support:                       yes

 Use Threads safe API:                    yes

 Threads stubs in libX11:                 no

 XCMS:                                    yes

 Internationalization support:            yes

 XF86BigFont support:                     yes

 XKB support:                             yes

 XLOCALEDIR environment variable support: yes

 Compose table cache enabled:             yes

 Functional specs building enabled:       yes

 

# make

# make install

 

portmap: 所有跟portmap service服务相关的函数调用都失败,什么原因?

 

 

pmap_unset函数调用失败, 返回0.

 

所有跟portmap service服务相关的函数调用都失败,什么原因?

 

	if (! pmap_unset (TESTPROG, VERSION))
	{
		fprintf (stderr, "%s", "pmap_unset error.");
		exit(1);
	}

 

	if (!svc_register(transp, TESTPROG, VERSION, testprog_1, IPPROTO_UDP)) {
		fprintf (stderr, "%s", "unable to register (TESTPROG, VERSION, udp).");
		exit(1);
	}

 

	result = svc_register(transp, TESTPROG, VERSION, testprog_1, IPPROTO_TCP);
	if (! result) {
		fprintf (stderr, "%s", "unable to register (TESTPROG, VERSION, tcp).");
		exit(1);
	}

 

但是我portmap服务已经启动了:

 

./portmap -d

 

./rpcinfo.exe  -p

   program vers proto   port

    100000    2   tcp    111

    100000    2   udp    111

 

 

 

QEMU下安装&运行linux系统

参考另一篇文章:https://www.iteye.com/blog/lobin-2047130

 

 

 

The POSIX Standard: The posix standard - The Open Group Base Specifications

http://pubs.opengroup.org/onlinepubs/9699919799/

http://pubs.opengroup.org/onlinepubs/9699919799/nframe.html

 

  • 大小: 23.8 KB
  • 大小: 30.9 KB
  • 大小: 22.3 KB
0
0
分享到:
评论

相关推荐

    util-linux-ng-2.17源码(含fdisk)

    util-linux-ng-2.17源码(含fdisk) Here is a list of all documented files with brief descriptions: util-linux-ng-2.17.2/disk-utils/blockdev.c [code] util-linux-ng-2.17.2/disk-utils/cramfs.h [code] ...

    linux2.6.1内核源码注释

    Linux 2.6.11.12内核源码注释是一份极其珍贵的资料,它涵盖了Linux内核的多个关键组件,包括同步机制、信号处理、内存管理、进程调度、文件系统以及网络系统。这些是Linux内核运行的核心组成部分,对于理解Linux操作...

    jdk1.7_linux Linux版零积分免费下载

    jdk1.7_linux Linux版零积分jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk...

    Linux网络调试助手

    Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络...

    LINUX操作系统(电子教案,参考答案)

    主要包括Linux的基本概念和操作,Linux的树型结构,Linux的文本编辑,Linux的安装和启动,用户管理,Shell编程技术,进程管理,C编译器,系统扩充,维护与监视,Linux的图形界面,网络的基本概念与设置,Linux在网络...

    Linux内核源代码情景分析 (上下册 高清非扫描 )

    ### Linux内核源代码情景分析知识点总结 #### 第1章 预备知识 - **1.1 Linux内核简介** - Linux是由Linus Torvalds在1991年开始开发的操作系统内核,其设计思想受到Unix的影响,但并不直接继承Unix的任何代码。 -...

    大学生攻克Linux系统教程

    【大学生攻克Linux系统教程】 本教程专为对Linux操作系统感兴趣的初学者设计,旨在提供一个从零开始学习Linux的全面指南。教程内容涵盖了Linux系统的安装、基本操作、文本编辑器VI的使用、调试工具GDB的基础知识,...

    linux内核源码.zip

    linux

    Linux设备驱动开发详解4.0内核(非扫描版)_Linux驱动_linuxkernel_linux内核_Linux/Unix编

    Linux设备驱动开发详解4.0内核(非扫描版).pdf 技术日新月异,产业斗转星移,滚滚红尘,消逝的事物太多,新事物的诞生也更迅猛。众多新生事物如灿烂烟 花,转瞬即逝。当我们仰望星空时,在浩如烟海的专业名词中寻找,...

    Linux vmtools的Linux.iso下载

    首先启动虚拟机软件VM(虚拟Linux系统 rhel4 已经安装完毕) 1.设置VMware的cd-rom→ Use ISO image → 本文件(linux.iso) 2.启动虚拟机 3.用超级用户root登录 4.登录成功后,Ctrl+Alt ,取出鼠标,点选菜单栏,vm → ...

    Linux2.6.24内核注释

    这是半年来,在看ULA的过程中,针对Linux 2.6.24内核顺手做的一点注释。内容不多,个人觉得文件系统和USB这两个模块的注释还有一点意思。 所有注释都是中文,您可以与标准2.6.24内核进行比较,看看具体的注释内容。 ...

    LINUX设备驱动程序

    在Linux系统中,设备驱动程序是操作系统与硬件设备之间的桥梁,它们使得操作系统能够高效地管理和控制硬件资源。这里我们主要探讨的是与嵌入式开发相关的Linux设备驱动程序,特别是针对ARM架构,如6410处理器的开发...

    基于Linux 下qt改版的聊天室

    基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版...

    linux 0.11 内核源码 - 免费下载

    linux 0.11 源码下载 本代码是目前能够找到的最早的Linux的内核版本,Linux 0.11内核是Linux内核的早期版本,于1991年由Linus Torvalds编写并发布。作为一个基于UNIX的操作系统内核,它的源代码包含了核心代码和一些...

    《Linux从入门到精通》

    Linux操作系统入门书,比较全面 目录 0 前言 0.1 什么是Linux? 0.2 本手册概述 0.3 速查信息 0.4 从以前版本的Red Hat Linux升级 0.5 开发者的话 0.6 编者的话 1 Red Hat Linux 5.1新特性 1.1 安装性能的...

    Linux C函数库参考手册完整版 含Linux C函数使用手册chm 中文pdf格式

    Linux C函数库参考手册是一套Linux C函数使用手册,这里还提供了LinuxC函数手册chm,帮助大家查找。在Linux下,使用到的C语言函数中文手册,全都有实例,如果你是大神,完全不需要,如果你对英文的手册感到头疼,...

    linux 系统下安装IE必备的三个包wine cabextract ies4linux

    在Linux系统中,由于默认不支持Microsoft Internet Explorer(简称IE),因此如果需要在Linux环境下运行IE,就需要借助一些工具来实现。本篇文章将详细介绍在Linux系统下安装IE所需的三个关键包:Wine、CabExtract和...

    linux基础教程资源合集(精华)PDF版

    Linux,在今天的广大电脑爱好者心中已经不再是那个遥不可及的新东西了,如果说几年前的 Linux 是星星之火的话,如今 Linux 不仅在服务器领域的应用取得较大进展,而且在桌面应用领域也有越来越多的人选择使用。Linux...

    PL2303 linux驱动

    标题中的“PL2303 Linux驱动”指的是用于Linux操作系统中的PL2303 USB转串口芯片的驱动程序。PL2303是Prolific Technology公司生产的一款广泛使用的USB到UART桥接器,它允许计算机通过USB接口与各种串行设备进行通信...

Global site tag (gtag.js) - Google Analytics