linux 0.11 内核学习 ioctl.c
/*
* ioctl.c 文件实现了输入/输出控制系统调用ioctl(),该函数
* 主要是调用函数tty_ioctl()对终端的IO进行控制
*/
/*
* linux/fs/ioctl.c
*
* (C) 1991 Linus Torvalds
*/
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <linux/sched.h>
extern int tty_ioctl(int dev, int cmd, int arg);
typedef int (*ioctl_ptr)(int dev,int cmd,int arg);
/* 定义系统中设备种数 */
#define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr)))
/* ioctl 操作函数指针表 */
static ioctl_ptr ioctl_table[]={
NULL, /* nodev */
NULL, /* /dev/mem */
NULL, /* /dev/fd */
NULL, /* /dev/hd */
tty_ioctl, /* /dev/ttyx */
tty_ioctl, /* /dev/tty */
NULL, /* /dev/lp */
NULL}; /* named pipes */
/* 输入输出控制函数 */
int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
{
struct file * filp;
int dev,mode;
// 如果文件描述符超出可打开的文件数,或者对应描述符的文件结构指针为空,则返回出错码
if (fd >= NR_OPEN || !(filp = current->filp[fd]))
return -EBADF;
// 取对应文件的属性
mode=filp->f_inode->i_mode;
// 如果该文件不是字符文件,也不是块设备文件,则返回出错码
if (!S_ISCHR(mode) && !S_ISBLK(mode))
return -EINVAL;
// 从字符或块设备文件的i 节点中取设备号。如果设备号大于系统现有的设备数,则返回出错号
dev = filp->f_inode->i_zone[0];
if (MAJOR(dev) >= NRDEVS)
return -ENODEV;
// 如果该设备在ioctl 函数指针表中没有对应函数
if (!ioctl_table[MAJOR(dev)])
return -ENOTTY;
// 否则返回实际ioctl 函数返回码
return ioctl_table[MAJOR(dev)](dev,cmd,arg);
}
参考《linux内核完全注释》和网上相关文章
相关文档:
-、概念
1、DHCP:动态主机配置协议
作用:用于简化IP配管理的TCP/IP标准。
2、DHCP工作流程:
&nb ......
1101 linux中刻录iso的方法(hutuworm)
方法一:使用xcdroast,选择制作光碟,选择ISO文件,刻录!
参见[url]http://www.xcdroast.org/xcdr098/faq-a15.html#17[/url]
方法二:找刻录机的命令:
cdrecord --scanbus
输出结果为:
0,0,0 0) 'ATAPI ' 'CD-R/RW 8X4X32 ' '5.EZ' Removable CD-ROM
刻录的命令:
cdrecord ......
下载 SDK
系统和软件需求
用Android sdk的代码和工具开发Android应用程序,你需要下面列出来的合适开发电脑和开发环境.
所需操作系统:
•Windows XP 或 Vista
•Mac OS X 10.4.8 或更高版本 (仅支持x86)
•Linux ( Linux Ubuntu Dapper Drake 版本已测试)
所需开发环境:
•Eclipse IDE
◦Ecli ......
/*
* linux/fs/bitmap.c
*
* (C) 1991 Linus Torvalds
*/
/* bitmap.c contains the code that handles the inode and block bitmaps */
#include <string.h>
#include <linux/sched.h>
#include <linux/kernel.h> // 一些内核常用函数的原形定义
......