linux 0.11 内核学习 read_write.c
/*
* 该文件实现系统调用read,write和lseek。
*/
/*
* linux/fs/read_write.c
*
* (C) 1991 Linus Torvalds
*/
#include <sys/stat.h>
#include <errno.h>
#include <sys/types.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <asm/segment.h>
/* 字符设备读写函数 */
extern int rw_char(int rw,int dev, char * buf, int count, off_t * pos);
/* 读管道操作函数 */
extern int read_pipe(struct m_inode * inode, char * buf, int count);
/* 写管道操作函数 */
extern int write_pipe(struct m_inode * inode, char * buf, int count);
/* 块设备读操作函数 */
extern int block_read(int dev, off_t * pos, char * buf, int count);
/* 块设备写操作函数 */
extern int block_write(int dev, off_t * pos, char * buf, int count);
/* 读文件操作函数 */
extern int file_read(struct m_inode * inode, struct file * filp,
char * buf, int count);
/* 写文件操作函数 */
extern int file_write(struct m_inode * inode, struct file * filp,
char * buf, int count);
/* 重定位文件读写指针系统调用函数,参数fd是文件句柄,offset是新的文件 */
/* 读写偏移量,origin是偏移的起始地址,可能是下面的三个值:SEEK_SET */
/* 文件的开始处,SEEK_CUR当前的读写位置,SEEK_END文件结尾处 */
int sys_lseek(unsigned int fd,off_t offset, int origin)
{
struct file * file;
int tmp;
// 如果文件句柄值大于程序最多打开文件数NR_OPEN(20),或者该句柄的文件结构指针为空,或者
// 对应文件结构的i 节点字段为空,或者指定设备文件指针是不可定位的,则返回出错码并退出
if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode)
|| !IS_SEEKABLE(MAJOR(file->f_inode->i_dev)))
return -EBADF;
// 如果文件对应的i 节点是管道节点,则返回出错码,退出
if (file->f_inode->i_pipe)
return -ESPIPE;
switch (origin) {
case 0: // SEEK_SET
// 若偏移值小于零,则出错
if (offset<0) return -EINVAL;
// 设置文件读写指针等于offset
file->f_
相关文档:
前言:这一章我们讨论一下Linux下的信号处理函数.
Linux下的信号处理函数:
1.信号的产生
2.信号的处理
3.其它信号函数
--------------------------------------------------------------------------------
一个实例
1。信号的产生 ......
本文并非解释什么是非阻塞socket,也不是介绍socket API的用法, 取而代替的是让你感受实际工作中的代码编写。虽然很简陋,但你可以通过man手册与其它资源非富你的代码。请注意本教程所说的主题,如果细说,内容可以达到一本书内容,你会发现本教程很有用。
本教程内容如下:
......
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH&nbs ......
stroul,
strdup
snprintf()
atio
C中常用字符串操作函数
#include <string.h>
size_t strlen(const char *s) 测量字符串长度s的实际长度。
例如s[20]="abc",那么strlen(s)的结果是3,而不是20.这就是实际长度
char *strcat(const char *s1, const *s2) ......
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/Neverland2012
我们经常会去下载别 ......