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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sr.c

?? 內核是系統的心臟
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 *      sr.c by David Giller
 *
 *      adapted from:
 *	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_CDROM_MAJOR
#include "../block/blk.h"
#include "scsi.h"
#include "hosts.h"
#include "sr.h"
#include "scsi_ioctl.h"   /* For the door lock/unlock commands */
#include "constants.h"

#define MAX_RETRIES 1
#define SR_TIMEOUT 500

int NR_SR=0;
int MAX_SR=0;
Scsi_CD * scsi_CDs;
static int * sr_sizes;

static int * sr_blocksizes;

static int sr_open(struct inode *, struct file *);
static void get_sectorsize(int);

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

void requeue_sr_request (Scsi_Cmnd * SCpnt);

static void sr_release(struct inode * inode, struct file * file)
{
	sync_dev(inode->i_rdev);
	if(! --scsi_CDs[MINOR(inode->i_rdev)].device->access_count)
	  sr_ioctl(inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
}

static struct file_operations sr_fops = 
{
	NULL,			/* lseek - default */
	block_read,		/* read - general block-dev read */
	block_write,		/* write - general block-dev write */
	NULL,			/* readdir - bad */
	NULL,			/* select */
	sr_ioctl,		/* ioctl */
	NULL,			/* mmap */
	sr_open,       		/* no special open code */
	sr_release,		/* release */
	NULL			/* fsync */
};

/*
 * This function checks to see if the media has been changed in the
 * CDROM drive.  It is possible that we have already sensed a change,
 * or the drive may have sensed one and not yet reported it.  We must
 * be ready for either case. This function always reports the current
 * value of the changed bit.  If flag is 0, then the changed bit is reset.
 * This function could be done as an ioctl, but we would need to have
 * an inode for that to work, and we do not always have one.
 */

int check_cdrom_media_change(int full_dev, int flag){
	int retval, target;
	struct inode inode;

	target =  MINOR(full_dev);

	if (target >= NR_SR) {
		printk("CD-ROM request error: invalid device.\n");
		return 0;
	};

	inode.i_rdev = full_dev;  /* This is all we really need here */
	retval = sr_ioctl(&inode, NULL, SCSI_IOCTL_TEST_UNIT_READY, 0);

	if(retval){ /* Unable to test, unit probably not ready.  This usually
		     means there is no disc in the drive.  Mark as changed,
		     and we will figure it out later once the drive is
		     available again.  */

	  scsi_CDs[target].device->changed = 1;
	  return 1; /* This will force a flush, if called from
		       check_disk_change */
	};

	retval = scsi_CDs[target].device->changed;
	if(!flag) {
	  scsi_CDs[target].device->changed = 0;
	  /* If the disk changed, the capacity will now be different,
	     so we force a re-read of this information */
	  if (retval) scsi_CDs[target].needs_sector_size = 1;
	};
	return retval;
}

/*
 * 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->this_count;

#ifdef DEBUG
	printk("sr.c done: %x %x\n",result, SCpnt->request.bh->b_data);
#endif
	if (!result)
		{ /* No error */
		  if (SCpnt->use_sg == 0) {
		    if (SCpnt->buffer != SCpnt->request.buffer)
		      {
			int offset;
			offset = (SCpnt->request.sector % 4) << 9;
			memcpy((char *)SCpnt->request.buffer, 
			       (char *)SCpnt->buffer + offset, 
			       this_count << 9);
			/* Even though we are not using scatter-gather, we look
			   ahead and see if there is a linked request for the
			   other half of this buffer.  If there is, then satisfy
			   it. */
			if((offset == 0) && this_count == 2 &&
			   SCpnt->request.nr_sectors > this_count && 
			   SCpnt->request.bh &&
			   SCpnt->request.bh->b_reqnext &&
			   SCpnt->request.bh->b_reqnext->b_size == 1024) {
			  memcpy((char *)SCpnt->request.bh->b_reqnext->b_data, 
				 (char *)SCpnt->buffer + 1024, 
				 1024);
			  this_count += 2;
			};
			
			scsi_free(SCpnt->buffer, 2048);
		      }
		  } else {
		    struct scatterlist * sgpnt;
		    int i;
		    sgpnt = (struct scatterlist *) SCpnt->buffer;
		    for(i=0; i<SCpnt->use_sg; i++) {
		      if (sgpnt[i].alt_address) {
			if (sgpnt[i].alt_address != sgpnt[i].address) {
			  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 */
		    if(SCpnt->request.sector % 4) this_count -= 2;
/* See   if there is a padding record at the end that needs to be removed */
		    if(this_count > SCpnt->request.nr_sectors)
		      this_count -= 2;
		  };

#ifdef DEBUG
		printk("(%x %x %x) ",SCpnt->request.bh, SCpnt->request.nr_sectors, 
		       this_count);
#endif
		if (SCpnt->request.nr_sectors > this_count)
			{	 
			SCpnt->request.errors = 0;
			if (!SCpnt->request.bh)
			    panic("sr.c: linked page request (%lx %x)",
				  SCpnt->request.sector, this_count);
			}

		  end_scsi_request(SCpnt, 1, this_count);  /* All done */
		  requeue_sr_request(SCpnt);
		  return;
		} /* Normal completion */

	/* We only come through here if we have an error of some kind */

/* 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++) {
	    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 {
	  if (SCpnt->buffer != SCpnt->request.buffer)
	    scsi_free(SCpnt->buffer, SCpnt->bufflen);
	};

	if (driver_byte(result) != 0) {
		if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70) {
			if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
				/* detected disc change.  set a bit and quietly refuse	*/
				/* further access.					*/
		    
				scsi_CDs[DEVICE_NR(SCpnt->request.dev)].device->changed = 1;
				end_scsi_request(SCpnt, 0, this_count);
			        requeue_sr_request(SCpnt);
				return;
			}
		}
	    
		if (SCpnt->sense_buffer[2] == ILLEGAL_REQUEST) {
			printk("CD-ROM error: Drive reports ILLEGAL REQUEST.\n");
			if (scsi_CDs[DEVICE_NR(SCpnt->request.dev)].ten) {
				scsi_CDs[DEVICE_NR(SCpnt->request.dev)].ten = 0;
				requeue_sr_request(SCpnt);
				result = 0;
				return;
			} else {
			  printk("CD-ROM error: Drive reports %d.\n", SCpnt->sense_buffer[2]);				
			  end_scsi_request(SCpnt, 0, this_count);
			  requeue_sr_request(SCpnt); /* Do next request */
			  return;
			}

		}

		if (SCpnt->sense_buffer[2] == NOT_READY) {
			printk("CDROM not ready.  Make sure you have a disc in the drive.\n");
			end_scsi_request(SCpnt, 0, this_count);
			requeue_sr_request(SCpnt); /* Do next request */
			return;
		};
	      }
	
	/* We only get this far if we have an error we have not recognized */
	if(result) {
	  printk("SCSI CD error : host %d id %d lun %d return code = %03x\n", 
		 scsi_CDs[DEVICE_NR(SCpnt->request.dev)].device->host->host_no, 
		 scsi_CDs[DEVICE_NR(SCpnt->request.dev)].device->id,
		 scsi_CDs[DEVICE_NR(SCpnt->request.dev)].device->lun,
		 result);
	    
	  if (status_byte(result) == CHECK_CONDITION)
		  print_sense("sr", SCpnt);
	  
	  end_scsi_request(SCpnt, 0, SCpnt->request.current_nr_sectors);
	  requeue_sr_request(SCpnt);
  }
}

static int sr_open(struct inode * inode, struct file * filp)
{
	if(MINOR(inode->i_rdev) >= NR_SR || 
	   !scsi_CDs[MINOR(inode->i_rdev)].device) return -ENODEV;   /* No such device */

        check_disk_change(inode->i_rdev);

	if(!scsi_CDs[MINOR(inode->i_rdev)].device->access_count++)
	  sr_ioctl(inode, NULL, SCSI_IOCTL_DOORLOCK, 0);

	/* If this device did not have media in the drive at boot time, then
	   we would have been unable to get the sector size.  Check to see if
	   this is the case, and try again.
	   */

	if(scsi_CDs[MINOR(inode->i_rdev)].needs_sector_size)
	  get_sectorsize(MINOR(inode->i_rdev));

	return 0;
}


/*
 * do_sr_request() is the request handler function for the sr driver.  Its function in life 
 * is to take block device requests, and translate them to SCSI commands.
 */
	
static void do_sr_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;

    if (flag++ == 0)
      SCpnt = allocate_device(&CURRENT,
			      scsi_CDs[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_SR > 1){
      struct request *req1;
      req1 = NULL;
      cli();
      req = CURRENT;
      while(req){
	SCpnt = request_queueable(req,
				  scsi_CDs[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_sr_request(SCpnt);
  };  /* While */
}    

void requeue_sr_request (Scsi_Cmnd * SCpnt)
{
	unsigned int dev, block, realcount;
	unsigned char cmd[10], *buffer, tries;
	int this_count, start, end_rec;

	tries = 2;

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

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

	if (dev >= NR_SR)
		{
		/* printk("CD-ROM request error: invalid device.\n");			*/
		end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
		tries = 2;
		goto repeat;
		}

	if (!scsi_CDs[dev].use)
		{
		/* printk("CD-ROM request error: device marked not in use.\n");		*/
		end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91香蕉国产在线观看软件| 国产精品色噜噜| 亚洲二区在线视频| 99久久婷婷国产综合精品| 精品播放一区二区| 国产精品一区二区果冻传媒| 制服丝袜中文字幕一区| 石原莉奈在线亚洲二区| 欧美老女人第四色| 日韩在线一二三区| 欧美精三区欧美精三区| 婷婷成人激情在线网| 欧美高清激情brazzers| 亚洲午夜一二三区视频| 国产欧美一区二区精品性| 亚洲韩国一区二区三区| 91精品国模一区二区三区| 丝袜亚洲另类欧美| 久久久久久久网| av中文字幕在线不卡| 亚洲国产视频a| 日韩精品一区二区在线| 国产麻豆精品视频| 日韩美女精品在线| 欧美一区二区三区婷婷月色 | 欧美猛男男办公室激情| 另类人妖一区二区av| 一区二区中文视频| 欧美精品一二三| 成人精品国产福利| 亚洲综合免费观看高清在线观看| 欧美丝袜第三区| 国产不卡免费视频| 视频一区二区不卡| 国产精品久久久久久久久久免费看| 欧美在线观看禁18| 国产白丝精品91爽爽久久| 天堂一区二区在线| 亚洲日韩欧美一区二区在线| 精品欧美一区二区三区精品久久 | 国产精品69久久久久水密桃| 曰韩精品一区二区| 中文字幕精品一区二区三区精品| 欧美喷潮久久久xxxxx| 91久久香蕉国产日韩欧美9色| 亚洲色图20p| 日韩写真欧美这视频| 欧美性大战久久久久久久| 成人99免费视频| 国产精品91一区二区| 日韩综合一区二区| 亚洲第一会所有码转帖| 一区二区三区av电影 | 国产精品久久久久久久久果冻传媒| 91精品国产福利在线观看| 欧美色图一区二区三区| 色老综合老女人久久久| 在线观看视频一区二区欧美日韩| 99免费精品视频| 91行情网站电视在线观看高清版| 91丨porny丨最新| 欧美少妇bbb| 在线电影国产精品| 欧美一卡二卡三卡| 日韩欧美在线123| 久久久综合视频| 国产精品伦理在线| 亚洲午夜免费视频| 美女一区二区久久| 大美女一区二区三区| 日本韩国精品在线| 精品奇米国产一区二区三区| 国产精品视频一二三| 天天免费综合色| 激情丁香综合五月| 91国偷自产一区二区三区观看| 欧美一区二区三区免费大片| 欧美男人的天堂一二区| 国产欧美一区二区在线观看| 久久久www免费人成精品| 精品久久国产97色综合| 亚洲欧美自拍偷拍| 日韩成人av影视| 色婷婷精品大在线视频| 久久婷婷成人综合色| 亚洲一区精品在线| 成人av网站在线| 久久久久久黄色| 亚洲美女少妇撒尿| 国产夫妻精品视频| 欧美一卡二卡三卡四卡| 亚洲成av人综合在线观看| 99热在这里有精品免费| 久久日韩精品一区二区五区| 亚洲最大的成人av| 成人不卡免费av| 久久精品一区八戒影视| 日韩精品色哟哟| 欧美日韩国产一二三| 亚洲一区欧美一区| 在线观看91视频| 亚洲一区二区视频在线观看| 色8久久精品久久久久久蜜| 亚洲视频在线一区观看| 波多野结衣欧美| 综合久久久久久久| 91在线小视频| 亚洲国产欧美另类丝袜| 欧美在线啊v一区| 日产精品久久久久久久性色| 欧美一区二区美女| 久久se这里有精品| 国产精品无遮挡| 99精品偷自拍| 午夜在线成人av| 精品国产乱码久久久久久免费| 国产精品夜夜嗨| 亚洲少妇30p| 欧美性猛片aaaaaaa做受| 自拍偷拍国产精品| 5858s免费视频成人| 久久精品二区亚洲w码| 中文文精品字幕一区二区| 94色蜜桃网一区二区三区| 三级欧美在线一区| 中文字幕欧美日韩一区| 欧美中文字幕一区二区三区亚洲| 亚洲中国最大av网站| www欧美成人18+| 日本高清不卡视频| 成人永久aaa| 另类小说视频一区二区| 亚洲美女视频一区| 国产欧美一区视频| 日韩欧美高清在线| 欧美日韩国产综合一区二区| 成人午夜免费av| 激情综合一区二区三区| 午夜成人在线视频| 国产精品久99| 国产女人aaa级久久久级| 91麻豆精品国产无毒不卡在线观看| 成人在线综合网站| 国产精品一二三四区| 久久99久久99小草精品免视看| 亚洲超丰满肉感bbw| 亚洲一区二区精品久久av| 亚洲天天做日日做天天谢日日欢| 精品国产成人系列| 精品免费视频一区二区| 91精品国产免费| 精品国产99国产精品| 日韩精品综合一本久道在线视频| 欧美精品日韩一本| 欧美精品乱码久久久久久按摩 | 色综合久久久久久久久| 色综合久久综合网97色综合| 99国产精品99久久久久久| av中文字幕一区| 成人永久aaa| 国产成人免费视频精品含羞草妖精| 日本中文字幕不卡| 久久国产精品区| 成人免费视频免费观看| 国产69精品久久久久毛片| 91美女片黄在线观看| 欧美日韩中文国产| 久久精品一区二区| 亚洲精品高清在线观看| 蜜臀av在线播放一区二区三区| 精品中文字幕一区二区小辣椒| 粉嫩av一区二区三区| 欧美丝袜丝交足nylons| 久久精品一区二区三区不卡牛牛| 中文字幕中文字幕一区二区| 一区二区在线观看视频 | 亚洲成人综合视频| 国产寡妇亲子伦一区二区| 成人午夜电影小说| 欧美一区二区三区在| 中文字幕在线免费不卡| 日本不卡高清视频| 色哟哟日韩精品| 久久久久国产精品厨房| 夜夜嗨av一区二区三区中文字幕| 极品少妇xxxx精品少妇| 欧美精品久久久久久久多人混战 | 亚洲天堂av老司机| 国产毛片一区二区| 欧美一区二区成人6969| 亚洲一区二区美女| 欧美性感一类影片在线播放| √…a在线天堂一区| 国产91丝袜在线18| 精品美女在线观看| 免费观看30秒视频久久| 欧美福利电影网| 亚洲国产wwwccc36天堂| 欧洲另类一二三四区| 亚洲夂夂婷婷色拍ww47 |