[PATCH 04/22] ide-floppy: add ide_floppy_set_media_lock() helper

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Bartlomiej Zolnierkiewicz
Date: Sunday, August 10, 2008 - 8:35 am

Add ide_floppy_set_media_lock() helper and convert idefloppy_open(),
idefloppy_release() and ide_floppy_lockdoor() to use it.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
---
 drivers/ide/ide-floppy.c |   39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

Index: b/drivers/ide/ide-floppy.c
===================================================================
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -1037,6 +1037,17 @@ static ide_driver_t idefloppy_driver = {
 #endif
 };
 
+static void ide_floppy_set_media_lock(ide_drive_t *drive, int on)
+{
+	struct ide_atapi_pc pc;
+
+	/* IOMEGA Clik! drives do not support lock/unlock commands */
+	if ((drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE) == 0) {
+		idefloppy_create_prevent_cmd(&pc, on);
+		(void)idefloppy_queue_pc_tail(drive, &pc);
+	}
+}
+
 static int idefloppy_open(struct inode *inode, struct file *filp)
 {
 	struct gendisk *disk = inode->i_bdev->bd_disk;
@@ -1083,12 +1094,9 @@ static int idefloppy_open(struct inode *
 			ret = -EROFS;
 			goto out_put_floppy;
 		}
+
 		drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
-		/* IOMEGA Clik! drives do not support lock/unlock commands */
-		if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-			idefloppy_create_prevent_cmd(&pc, 1);
-			(void) idefloppy_queue_pc_tail(drive, &pc);
-		}
+		ide_floppy_set_media_lock(drive, 1);
 		check_disk_change(inode->i_bdev);
 	} else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
 		ret = -EBUSY;
@@ -1107,17 +1115,11 @@ static int idefloppy_release(struct inod
 	struct gendisk *disk = inode->i_bdev->bd_disk;
 	struct ide_floppy_obj *floppy = ide_floppy_g(disk);
 	ide_drive_t *drive = floppy->drive;
-	struct ide_atapi_pc pc;
 
 	debug_log("Reached %s\n", __func__);
 
 	if (floppy->openers == 1) {
-		/* IOMEGA Clik! drives do not support lock/unlock commands */
-		if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-			idefloppy_create_prevent_cmd(&pc, 0);
-			(void) idefloppy_queue_pc_tail(drive, &pc);
-		}
-
+		ide_floppy_set_media_lock(drive, 0);
 		drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
 	}
 
@@ -1143,21 +1145,12 @@ static int ide_floppy_lockdoor(ide_drive
 			       unsigned long arg, unsigned int cmd)
 {
 	idefloppy_floppy_t *floppy = drive->driver_data;
+	int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
 
 	if (floppy->openers > 1)
 		return -EBUSY;
 
-	/* The IOMEGA Clik! Drive doesn't support this command -
-	 * no room for an eject mechanism */
-	if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-		int prevent = arg ? 1 : 0;
-
-		if (cmd == CDROMEJECT)
-			prevent = 0;
-
-		idefloppy_create_prevent_cmd(pc, prevent);
-		(void) idefloppy_queue_pc_tail(floppy->drive, pc);
-	}
+	ide_floppy_set_media_lock(drive, prevent);
 
 	if (cmd == CDROMEJECT) {
 		idefloppy_create_start_stop_cmd(pc, 2);
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/22] ide: more work on generic ATAPI support, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:35 am)
[PATCH 01/22] ide-floppy: fixup ide_floppy_io_buffers(), Bartlomiej Zolnierki ..., (Sun Aug 10, 8:35 am)
[PATCH 02/22] ide-scsi: cleanup ide_scsi_io_buffers(), Bartlomiej Zolnierki ..., (Sun Aug 10, 8:35 am)
[PATCH 03/22] ide: add ide_io_buffers() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:35 am)
[PATCH 04/22] ide-floppy: add ide_floppy_set_media_lock() ..., Bartlomiej Zolnierki ..., (Sun Aug 10, 8:35 am)
[PATCH 05/22] ide-tape: add ide_tape_set_media_lock() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 06/22] ide: add ide_init_pc() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 07/22] ide: add ide_queue_pc_head() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 08/22] ide: add ide_queue_pc_tail() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 09/22] ide-floppy: -&gt;{srfp,wp} -&gt; IDE_AFLAG_{SRFP,WP}, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 10/22] ide-floppy: move floppy ioctls handling to i ..., Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 11/22] ide: add ide_set_media_lock() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 12/22] ide: add ide_do_start_stop() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:36 am)
[PATCH 13/22] ide: add ide_do_test_unit_ready() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 14/22] ide: move IDE{FLOPPY,TAPE}_WAIT_CMD defines ..., Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 15/22] ide: drop dsc_handle argument from ide_pc_intr(), Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 16/22] ide: add pointer to the current packet comma ..., Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 17/22] ide: drop 'timeout' and 'expiry' arguments f ..., Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 18/22] ide: add request_sense_{pc,rq} to ide_drive_t, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 19/22] ide: add ide_retry_pc() helper, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 20/22] ide: add -&gt;pc_{update,io}_buffers methods, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 21/22] ide: make ide_pc_intr() static, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:37 am)
[PATCH 22/22] ide: make ide_transfer_pc() static, Bartlomiej Zolnierki ..., (Sun Aug 10, 8:38 am)
Re: [PATCH 11/22] ide: add ide_set_media_lock() helper, Borislav Petkov, (Sun Aug 10, 11:02 pm)
Re: [PATCH 00/22] ide: more work on generic ATAPI support, Borislav Petkov, (Sun Aug 10, 11:36 pm)
Re: [PATCH 11/22] ide: add ide_set_media_lock() helper, Bartlomiej Zolnierki ..., (Tue Aug 12, 2:05 am)
Re: [PATCH 11/22] ide: add ide_set_media_lock() helper, Boris Petkov, (Tue Aug 12, 6:37 am)
Re: [PATCH 11/22] ide: add ide_set_media_lock() helper, Bartlomiej Zolnierki ..., (Tue Aug 12, 10:48 am)
Re: [PATCH 13/22] ide: add ide_do_test_unit_ready() helper, Sergei Shtylyov, (Sat Aug 23, 2:31 pm)
Re: [PATCH 07/22] ide: add ide_queue_pc_head() helper, Sergei Shtylyov, (Sat Aug 23, 2:57 pm)
Re: [PATCH 08/22] ide: add ide_queue_pc_tail() helper, Sergei Shtylyov, (Sat Aug 23, 2:58 pm)