Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

linux 0.11 ÄÚºËѧϰ file_dev.c


/*
 *  linux/fs/file_dev.c
 *
 *  (C) 1991  Linus Torvalds
 */
#include <errno.h>
#include <fcntl.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <asm/segment.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
/* ¸ù¾Ýi ½ÚµãºÍÎļþ½á¹¹£¬¶ÁÉ豸Êý¾Ý£¬ÎªÉϲãµÄreadº¯ÊýÌṩº¯Êý */
int file_read(struct m_inode * inode, struct file * filp, char * buf, int count)
{
// ÓÉi ½Úµã¿ÉÒÔÖªµÀÉ豸ºÅ£¬ÓÉfilp ½á¹¹¿ÉÒÔÖªµÀÎļþÖе±Ç°¶ÁдָÕëλÖá£buf Ö¸¶¨Óû§Ì¬ÖÐ
// »º³åÇøµÄλÖã¬count ΪÐèÒª¶ÁÈ¡µÄ×Ö½ÚÊý¡£·µ»ØÖµÊÇʵ¼Ê¶ÁÈ¡µÄ×Ö½ÚÊý£¬»ò³ö´íºÅ(СÓÚ0)
int left,chars,nr;
struct buffer_head * bh;
// ÈôÐèÒª¶ÁÈ¡µÄ×Ö½Ú¼ÆÊýֵСÓÚµÈÓÚÁ㣬Ôò·µ»Ø
if ((left=count)<=0)
return 0;

while (left) 
{
// ¸ù¾Ýi ½ÚµãºÍÎļþ±í½á¹¹ÐÅÏ¢£¬È¡Êý¾Ý¿éÎļþµ±Ç°¶ÁдλÖÃÔÚÉ豸É϶ÔÓ¦µÄÂß¼­¿éºÅnr¡£Èônr ²»
// Ϊ0£¬Ôò´Ói ½ÚµãÖ¸¶¨µÄÉ豸É϶ÁÈ¡¸ÃÂß¼­¿é
if (nr = bmap(inode,(filp->f_pos)/BLOCK_SIZE)) // µÃµ½Âß¼­¿éºÅ
{
if (!(bh=bread(inode->i_dev,nr)))
break;
} else
bh = NULL;
// ¼ÆËãÎļþ¶ÁдָÕëÔÚÊý¾Ý¿éÖеÄÆ«ÒÆÖµnr
nr = filp->f_pos % BLOCK_SIZE;
// È»ºóÓ뻹Ðè¶ÁÈ¡µÄ×Ö½ÚÊýleft ×÷±È½Ï£¬ÆäÖÐСֵ¼´Îª±¾´ÎÐè¶ÁµÄ×Ö½ÚÊýchars
chars = MIN( BLOCK_SIZE-nr , left );
// µ÷Õû¶ÁдÎļþÖ¸Õë
filp->f_pos += chars;
// Ê£Óà×Ö½Ú¼ÆÊýÏàÓ¦¼õÈ¥chars
left -= chars;
if (bh) // Èç¹û¶Á³öÁËÊý¾Ý
{
char * p = nr + bh->b_data; // ½«p Ö¸Ïò¶Á³öÊý¾Ý¿é»º³åÇøÖпªÊ¼¶ÁÈ¡µÄλÖÃ
// ¸´ÖÆchars×Ö½Úµ½Óû§µÄ»º³åÇø
while (chars-->0)
put_fs_byte(*(p++),buf++);
brelse(bh);

// ·ñÔò½«Óû§µÄ»º³åÇøÈ«²¿ÉèÖóÉ0
else
{
/*************************************/
while (chars-->0)
put_fs_byte(0,buf++);
/**************************************/
}
}
// Ð޸ĸÃi ½ÚµãµÄ·ÃÎÊʱ¼äΪµ±Ç°Ê±¼ä¡£·µ»Ø¶ÁÈ¡µÄ×Ö½ÚÊý
inode->i_atime = CURRENT_TIME;
return (count-left)?(count-left):-ERROR;
/*
* ¸Ãº¯ÊýʵÏÖµÄÊǸ


Ïà¹ØÎĵµ£º

Linuxϳ£ÓÃCÓïÑÔ×Ö·û´®²Ù×÷º¯Êý

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)  ......

¡¶LINUXÉ豸Çý¶¯³ÌÐò¡·Ñ§Ï°Ôý¼Ç£¨Ò»£©

×ܽáÕ½ڣºµÚÒ»Õ É豸Çý¶¯³ÌÐò¼ò½é
          µÚ¶þÕ ¹¹ÔìºÍÔËÐÐÄ£¿é
Ìáµ½Çý¶¯³ÌÐò¾Í²»µÃ²»ÏÈ˵ÏÂÁ½¸öÃû´Ê£ºÄں˿ռäºÍÓû§¿Õ¼ä¡£Óû§¿Õ¼ä¼´Óû§Ó¦ÓÃËùÔËÐеĿռ䣬Äں˿ռäÖµµÃÊDzÙ×÷ϵͳÄÚºËÔËÐеĿռ䡣Óû§¿Õ¼ä²»ÄÜÖ±½ÓÒýÓûòÕß²Ù×÷Äں˿ռäµÄÊý¾Ý£¬Äں˿ռäÒ²²»ÄÜÖ±½ ......

Linux ÄÚºËÅäÖÃ

LinuxÄÚºËÅäÖð취£º
1. make config
ÕâÖÖ°ì·¨»á±éÀúËùÓÐÅäÖÃÏҪÇóÓû§Öð¸öÑ¡ÔñY/N/M
2. make menuconfig
Õâ¸ö°ì·¨ÊÇ»ùÓÚncurse¿â±àÖƵÄͼÐνçÃ湤¾ß¡£³£ÓÃ
3. make xconfig
ÓÃÓÚ»ùÓÚX11µÄͼÐι¤¾ß
4. make gconfig
ÓÃÓÚ»ùÓÚgtk+ͼÐι¤¾ß
5. make defconfig
´´½¨Ò»¸öĬÈϵÄÅäÖã¬Éú³Éµ±Ç°µÄ.config
6. make x ......

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 < ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ