亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? sd.c

?? LINUX1.0源代碼,代碼條理清晰
?? C
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
/*
 *	sd.c Copyright (C) 1992 Drew Eckhardt 
 *	Linux scsi disk driver by
 *		Drew Eckhardt 
 *
 *	<drew@colorado.edu>
 *
 *       Modified by Eric Youngdale eric@tantalus.nrl.navy.mil to
 *       add scatter-gather, multiple outstanding request, and other
 *       enhancements.
 */

#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <asm/system.h>

#define MAJOR_NR SCSI_DISK_MAJOR
#include "../block/blk.h"
#include "scsi.h"
#include "hosts.h"
#include "sd.h"
#include "scsi_ioctl.h"
#include "constants.h"

#include <linux/genhd.h>

/*
static const char RCSid[] = "$Header:";
*/

#define MAX_RETRIES 5

/*
 *	Time out in seconds
 */

#define SD_TIMEOUT 300

struct hd_struct * sd;

int NR_SD=0;
int MAX_SD=0;
Scsi_Disk * rscsi_disks;
static int * sd_sizes;
static int * sd_blocksizes;

extern int sd_ioctl(struct inode *, struct file *, unsigned int, unsigned long);

static sd_init_onedisk(int);

static void requeue_sd_request (Scsi_Cmnd * SCpnt);

static int sd_open(struct inode * inode, struct file * filp)
{
        int target;
	target =  DEVICE_NR(MINOR(inode->i_rdev));

	if(target >= NR_SD || !rscsi_disks[target].device)
	  return -ENODEV;   /* No such device */
	
/* Make sure that only one process can do a check_change_disk at one time.
 This is also used to lock out further access when the partition table is being re-read. */

	while (rscsi_disks[target].device->busy);

	if(rscsi_disks[target].device->removable) {
	  check_disk_change(inode->i_rdev);

	  if(!rscsi_disks[target].device->access_count)
	    sd_ioctl(inode, NULL, SCSI_IOCTL_DOORLOCK, 0);
	};
	rscsi_disks[target].device->access_count++;
	return 0;
}

static void sd_release(struct inode * inode, struct file * file)
{
        int target;
	sync_dev(inode->i_rdev);

	target =  DEVICE_NR(MINOR(inode->i_rdev));

	rscsi_disks[target].device->access_count--;

	if(rscsi_disks[target].device->removable) {
	  if(!rscsi_disks[target].device->access_count)
	    sd_ioctl(inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
	};
}

static void sd_geninit(void);

static struct file_operations sd_fops = {
	NULL,			/* lseek - default */
	block_read,		/* read - general block-dev read */
	block_write,		/* write - general block-dev write */
	NULL,			/* readdir - bad */
	NULL,			/* select */
	sd_ioctl,		/* ioctl */
	NULL,			/* mmap */
	sd_open,		/* open code */
	sd_release,		/* release */
	block_fsync		/* fsync */
};

static struct gendisk sd_gendisk = {
	MAJOR_NR,		/* Major number */
	"sd",		/* Major name */
	4,		/* Bits to shift to get real from partition */
	1 << 4,		/* Number of partitions per real */
	0,		/* maximum number of real */
	sd_geninit,	/* init function */
	NULL,		/* hd struct */
	NULL,	/* block sizes */
	0,		/* number */
	NULL,	/* internal */
	NULL		/* next */
};

static void sd_geninit (void)
{
	int i;

	for (i = 0; i < NR_SD; ++i)
		sd[i << 4].nr_sects = rscsi_disks[i].capacity;
	sd_gendisk.nr_real = NR_SD;
}

/*
	rw_intr is the interrupt routine for the device driver.  It will
	be notified on the end of a SCSI read / write, and
	will take on of several actions based on success or failure.
*/

static void rw_intr (Scsi_Cmnd *SCpnt)
{
  int result = SCpnt->result;
  int this_count = SCpnt->bufflen >> 9;

#ifdef DEBUG
  printk("sd%d : rw_intr(%d, %d)\n", MINOR(SCpnt->request.dev), SCpnt->host->host_no, result);
#endif

/*
  First case : we assume that the command succeeded.  One of two things will
  happen here.  Either we will be finished, or there will be more
  sectors that we were unable to read last time.
*/

  if (!result) {

#ifdef DEBUG
    printk("sd%d : %d sectors remain.\n", MINOR(SCpnt->request.dev), SCpnt->request.nr_sectors);
    printk("use_sg is %d\n ",SCpnt->use_sg);
#endif
    if (SCpnt->use_sg) {
      struct scatterlist * sgpnt;
      int i;
      sgpnt = (struct scatterlist *) SCpnt->buffer;
      for(i=0; i<SCpnt->use_sg; i++) {
#ifdef DEBUG
	printk(":%x %x %d\n",sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
#endif
	if (sgpnt[i].alt_address) {
	  if (SCpnt->request.cmd == READ)
	    memcpy(sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
	  scsi_free(sgpnt[i].address, sgpnt[i].length);
	};
      };
      scsi_free(SCpnt->buffer, SCpnt->sglist_len);  /* Free list of scatter-gather pointers */
    } else {
      if (SCpnt->buffer != SCpnt->request.buffer) {
#ifdef DEBUG
	printk("nosg: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
		   SCpnt->bufflen);
#endif	
	  if (SCpnt->request.cmd == READ)
	    memcpy(SCpnt->request.buffer, SCpnt->buffer,
		   SCpnt->bufflen);
	  scsi_free(SCpnt->buffer, SCpnt->bufflen);
      };
    };
/*
 * 	If multiple sectors are requested in one buffer, then
 *	they will have been finished off by the first command.  If
 *	not, then we have a multi-buffer command.
 */
    if (SCpnt->request.nr_sectors > this_count)
      {
	SCpnt->request.errors = 0;
	
	if (!SCpnt->request.bh)
	  {
#ifdef DEBUG
	    printk("sd%d : handling page request, no buffer\n",
		   MINOR(SCpnt->request.dev));
#endif
/*
  The SCpnt->request.nr_sectors field is always done in 512 byte sectors,
  even if this really isn't the case.
*/
	    panic("sd.c: linked page request (%lx %x)",
		  SCpnt->request.sector, this_count);
	  }
      }
    end_scsi_request(SCpnt, 1, this_count);
    requeue_sd_request(SCpnt);
    return;
  }

/* Free up any indirection buffers we allocated for DMA purposes. */
    if (SCpnt->use_sg) {
      struct scatterlist * sgpnt;
      int i;
      sgpnt = (struct scatterlist *) SCpnt->buffer;
      for(i=0; i<SCpnt->use_sg; i++) {
#ifdef DEBUG
	printk("err: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
		   SCpnt->bufflen);
#endif
	if (sgpnt[i].alt_address) {
	  scsi_free(sgpnt[i].address, sgpnt[i].length);
	};
      };
      scsi_free(SCpnt->buffer, SCpnt->sglist_len);  /* Free list of scatter-gather pointers */
    } else {
#ifdef DEBUG
      printk("nosgerr: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
		   SCpnt->bufflen);
#endif
      if (SCpnt->buffer != SCpnt->request.buffer)
	scsi_free(SCpnt->buffer, SCpnt->bufflen);
    };

/*
	Now, if we were good little boys and girls, Santa left us a request
	sense buffer.  We can extract information from this, so we
	can choose a block to remap, etc.
*/

        if (driver_byte(result) != 0) {
	  if (sugestion(result) == SUGGEST_REMAP) {
#ifdef REMAP
/*
	Not yet implemented.  A read will fail after being remapped,
	a write will call the strategy routine again.
*/
	    if rscsi_disks[DEVICE_NR(SCpnt->request.dev)].remap
	      {
		result = 0;
	      }
	    else
	      
#endif
	    }

	  if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70) {
	    if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
	      if(rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->removable) {
	      /* detected disc change.  set a bit and quietly refuse	*/
	      /* further access.					*/
	      
		rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->changed = 1;
		end_scsi_request(SCpnt, 0, this_count);
		requeue_sd_request(SCpnt);
		return;
	      }
	    }
	  }
	  

/* 	If we had an ILLEGAL REQUEST returned, then we may have
performed an unsupported command.  The only thing this should be would
be a ten byte read where only a six byte read was supportted.  Also,
on a system where READ CAPACITY failed, we mave have read past the end
of the 	disk. 
*/

	  if (SCpnt->sense_buffer[2] == ILLEGAL_REQUEST) {
	    if (rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten) {
	      rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten = 0;
	      requeue_sd_request(SCpnt);
	      result = 0;
	    } else {
	    }
	  }
	}  /* driver byte != 0 */
	if (result) {
		printk("SCSI disk error : host %d id %d lun %d return code = %x\n",
		       rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->host->host_no,
		       rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->id,
		       rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->lun, result);

		if (driver_byte(result) & DRIVER_SENSE)
			print_sense("sd", SCpnt);
		end_scsi_request(SCpnt, 0, SCpnt->request.current_nr_sectors);
		requeue_sd_request(SCpnt);
		return;
	}
}

/*
	requeue_sd_request() is the request handler function for the sd driver.
	Its function in life is to take block device requests, and translate
	them to SCSI commands.
*/

static void do_sd_request (void)
{
  Scsi_Cmnd * SCpnt = NULL;
  struct request * req = NULL;
  int flag = 0;
  while (1==1){
    cli();
    if (CURRENT != NULL && CURRENT->dev == -1) {
      sti();
      return;
    };

    INIT_SCSI_REQUEST;


/* We have to be careful here.  allocate_device will get a free pointer, but
   there is no guarantee that it is queueable.  In normal usage, we want to
   call this, because other types of devices may have the host all tied up,
   and we want to make sure that we have at least one request pending for this
   type of device.   We can also come through here while servicing an
   interrupt, because of the need to start another command.  If we call
   allocate_device more than once, then the system can wedge if the command
   is not queueable.  The request_queueable function is safe because it checks
   to make sure that the host is able to take another command before it returns
   a pointer.  */

    if (flag++ == 0)
      SCpnt = allocate_device(&CURRENT,
			      rscsi_disks[DEVICE_NR(MINOR(CURRENT->dev))].device->index, 0); 
    else SCpnt = NULL;
    sti();

/* This is a performance enhancement.  We dig down into the request list and
   try and find a queueable request (i.e. device not busy, and host able to
   accept another command.  If we find one, then we queue it. This can
   make a big difference on systems with more than one disk drive.  We want
   to have the interrupts off when monkeying with the request list, because
   otherwise the kernel might try and slip in a request inbetween somewhere. */

    if (!SCpnt && NR_SD > 1){
      struct request *req1;
      req1 = NULL;
      cli();
      req = CURRENT;
      while(req){
	SCpnt = request_queueable(req,
				  rscsi_disks[DEVICE_NR(MINOR(req->dev))].device->index);
	if(SCpnt) break;
	req1 = req;
	req = req->next;
      };
      if (SCpnt && req->dev == -1) {
	if (req == CURRENT) 
	  CURRENT = CURRENT->next;
	else
	  req1->next = req->next;
      };
      sti();
    };
    
    if (!SCpnt) return; /* Could not find anything to do */
    
    wake_up(&wait_for_request);
    
    /* Queue command */
    requeue_sd_request(SCpnt);
  };  /* While */
}    

static void requeue_sd_request (Scsi_Cmnd * SCpnt)
{
	int dev, block, this_count;
	unsigned char cmd[10];
	char * buff;

repeat:

	if(SCpnt->request.dev <= 0) {
	  do_sd_request();
	  return;
	}

	dev =  MINOR(SCpnt->request.dev);
	block = SCpnt->request.sector;
	this_count = 0;

#ifdef DEBUG
	printk("Doing sd request, dev = %d, block = %d\n", dev, block);
#endif

	if (dev >= (NR_SD << 4) || block + SCpnt->request.nr_sectors > sd[dev].nr_sects)
		{
		end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
		goto repeat;
		}

	block += sd[dev].start_sect;
	dev = DEVICE_NR(dev);

	if (rscsi_disks[dev].device->changed)
	        {
/*
 * quietly refuse to do anything to a changed disc until the changed bit has been reset
 */
		/* printk("SCSI disk has been changed.  Prohibiting further I/O.\n");	*/
		end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
		goto repeat;
		}

#ifdef DEBUG
	printk("sd%d : real dev = /dev/sd%d, block = %d\n", MINOR(SCpnt->request.dev), dev, block);
#endif

	switch (SCpnt->request.cmd)
		{
		case WRITE :
			if (!rscsi_disks[dev].device->writeable)
				{
				end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
				goto repeat;
				}
			cmd[0] = WRITE_6;
			break;
		case READ :
			cmd[0] = READ_6;
			break;
		default :
			panic ("Unknown sd command %d\n", SCpnt->request.cmd);
		      }

	SCpnt->this_count = 0;

	if (!SCpnt->request.bh || 
	    (SCpnt->request.nr_sectors == SCpnt->request.current_nr_sectors)) {

	  /* case of page request (i.e. raw device), or unlinked buffer */
	  this_count = SCpnt->request.nr_sectors;
	  buff = SCpnt->request.buffer;
	  SCpnt->use_sg = 0;

	} else if (SCpnt->host->sg_tablesize == 0 ||
		   (need_isa_buffer && 
		    dma_free_sectors < 10)) {

	  /* Case of host adapter that cannot scatter-gather.  We also
	   come here if we are running low on DMA buffer memory.  We set
	   a threshold higher than that we would need for this request so
	   we leave room for other requests.  Even though we would not need
	   it all, we need to be conservative, because if we run low enough
	   we have no choice but to panic. */

	  if (SCpnt->host->sg_tablesize != 0 &&
	      need_isa_buffer && 
	      dma_free_sectors < 10)
	    printk("Warning: SCSI DMA buffer space running low.  Using non scatter-gather I/O.\n");

	  this_count = SCpnt->request.current_nr_sectors;
	  buff = SCpnt->request.buffer;
	  SCpnt->use_sg = 0;

	} else {

	  /* Scatter-gather capable host adapter */
	  struct buffer_head * bh;
	  struct scatterlist * sgpnt;
	  int count, this_count_max;
	  bh = SCpnt->request.bh;
	  this_count = 0;
	  this_count_max = (rscsi_disks[dev].ten ? 0xffff : 0xff);
	  count = 0;
	  while(bh && count < SCpnt->host->sg_tablesize) {
	    if ((this_count + (bh->b_size >> 9)) > this_count_max) break;
	    this_count += (bh->b_size >> 9);
	    count++;
	    bh = bh->b_reqnext;
	  };

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99精品久久99久久久久| 日韩欧美国产电影| 91在线视频在线| 99re这里只有精品6| 色综合天天综合狠狠| 色综合天天狠狠| 色婷婷av一区二区| 在线一区二区观看| 欧美性大战久久| 欧美久久久久中文字幕| 欧美日韩电影在线播放| 欧美顶级少妇做爰| 欧美一区二区福利在线| 欧美变态tickling挠脚心| 精品精品国产高清a毛片牛牛 | 99视频精品全部免费在线| 成人三级在线视频| 日本道免费精品一区二区三区| 一本色道久久综合亚洲精品按摩| 色成年激情久久综合| 91超碰这里只有精品国产| 日韩一区二区三区电影在线观看| 欧美v亚洲v综合ⅴ国产v| 国产日韩精品一区二区三区| 日本一区二区三区国色天香| 亚洲欧美日韩国产一区二区三区 | 丝袜美腿成人在线| 久久国产精品99精品国产| 国产成人综合视频| 91猫先生在线| 欧美一区二区三区免费大片 | 午夜精品久久久久久久| 国产精品白丝在线| 亚洲成人免费看| 国产高清不卡一区二区| 91浏览器在线视频| 欧美一区二区在线免费播放| 久久久久国产精品免费免费搜索| 日韩一区欧美一区| 蜜臀99久久精品久久久久久软件| 国产资源在线一区| 色香蕉成人二区免费| 日韩欧美一区在线观看| 国产精品久久久久一区二区三区| 亚洲综合色视频| 国产精品亚洲成人| 91久久线看在观草草青青| 日韩免费看网站| 亚洲精品精品亚洲| 精品一区二区免费在线观看| 91丨九色丨黑人外教| 日韩一级高清毛片| 亚洲欧美色一区| 国模冰冰炮一区二区| 欧美私模裸体表演在线观看| 久久久综合精品| 视频一区免费在线观看| 成人黄页毛片网站| 日韩写真欧美这视频| 亚洲欧美日韩在线| 国产精品456露脸| 在线综合视频播放| 亚洲女与黑人做爰| 大白屁股一区二区视频| 日韩视频中午一区| 亚洲一二三四区不卡| 成人激情文学综合网| 亚洲精品在线免费观看视频| 亚洲一区二三区| proumb性欧美在线观看| 欧美videos中文字幕| 亚洲午夜成aⅴ人片| av一本久道久久综合久久鬼色| 日韩美女一区二区三区四区| 亚洲第一狼人社区| 色偷偷久久人人79超碰人人澡| 久久久三级国产网站| 日韩vs国产vs欧美| 色欧美乱欧美15图片| 国产精品久久久久久久久晋中| 久久疯狂做爰流白浆xx| 欧美乱熟臀69xxxxxx| 亚洲综合色婷婷| 日本丰满少妇一区二区三区| 中文字幕欧美一| 粉嫩一区二区三区在线看| 久久综合狠狠综合久久激情| 男男视频亚洲欧美| 欧美精品久久久久久久多人混战| 亚洲在线成人精品| 在线一区二区三区做爰视频网站| 综合欧美亚洲日本| 波多野结衣一区二区三区| 国产亚洲精品久| 韩国毛片一区二区三区| 欧美大片顶级少妇| 黄网站免费久久| 久久婷婷色综合| 国产乱码精品一区二区三区五月婷 | 国产69精品久久777的优势| 久久久久国产精品厨房| 国产在线精品一区二区不卡了| 亚洲精品一区二区三区在线观看| 免费观看成人鲁鲁鲁鲁鲁视频| 91精品国产91久久综合桃花 | 91电影在线观看| 亚洲一区二区影院| 欧美三区在线视频| 日韩av电影免费观看高清完整版 | 精品国产免费一区二区三区香蕉| 日本不卡的三区四区五区| 91精品国产一区二区三区香蕉| 男男成人高潮片免费网站| 精品乱人伦小说| 国产精品18久久久久久久久久久久 | 国产高清亚洲一区| 国产精品久久久久天堂| 99久久99久久免费精品蜜臀| 国产精品久久一级| 在线中文字幕一区| 人人爽香蕉精品| 久久精品日产第一区二区三区高清版| 国产凹凸在线观看一区二区| 国产精品免费久久久久| 欧美性受xxxx黑人xyx性爽| 青青国产91久久久久久| 久久久久国色av免费看影院| 成人av免费在线| 亚洲二区在线观看| 精品国产一区二区三区不卡| 国产91精品一区二区麻豆网站| 国产精品久久久久影视| 欧美午夜精品一区二区三区| 美女看a上一区| 中文在线一区二区 | 伊人性伊人情综合网| 欧美日韩精品一区二区三区 | 91免费精品国自产拍在线不卡| 亚洲宅男天堂在线观看无病毒| 日韩免费视频线观看| 不卡的电影网站| 日本在线不卡视频| 欧美激情一区在线观看| 欧美精品久久天天躁| 国产高清不卡一区二区| 亚洲成人www| 久久久精品一品道一区| 欧美少妇一区二区| 国产一区二区三区在线看麻豆| 亚洲人吸女人奶水| 日韩欧美国产一区在线观看| 99国产精品99久久久久久| 美美哒免费高清在线观看视频一区二区| 欧美激情中文不卡| 欧美精品少妇一区二区三区| 处破女av一区二区| 天天综合网 天天综合色| 国产精品免费看片| 欧美电视剧免费全集观看| 色哟哟日韩精品| 国产成人午夜片在线观看高清观看| 午夜久久福利影院| 中文字幕亚洲不卡| 精品av久久707| 欧美丰满美乳xxx高潮www| 91亚洲精华国产精华精华液| 久久91精品国产91久久小草| 一区二区三区四区高清精品免费观看| 精品成人一区二区三区四区| 色丁香久综合在线久综合在线观看| 国产米奇在线777精品观看| 天天影视涩香欲综合网| 17c精品麻豆一区二区免费| 亚洲精品在线观看视频| 91精品综合久久久久久| 91久久线看在观草草青青| 成人理论电影网| 激情综合五月婷婷| 日本视频中文字幕一区二区三区| 亚洲精品免费在线观看| 国产精品私房写真福利视频| 久久久久国产精品免费免费搜索| 91精品国产色综合久久ai换脸| 91极品视觉盛宴| 91色porny| 波多野结衣中文字幕一区二区三区| 久久99国产精品久久99 | 在线观看视频一区| 成人性色生活片| 国产精品影视在线| 国产美女在线观看一区| 久久av中文字幕片| 麻豆精品在线播放| 日本中文一区二区三区| 五月天欧美精品| 日本伊人精品一区二区三区观看方式| 亚洲国产综合人成综合网站| 亚洲麻豆国产自偷在线| 国产精品家庭影院| 国产精品福利一区二区|