aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-tape.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:37 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:37 -0400
commit385a4b8787c70b708688bee65139f15b0f79f144 (patch)
treeebf6bb2a94e0b12fb06b2cc304ebe5b2fbf7245c /drivers/ide/ide-tape.c
parente996fc8ae96a822f037e25463cb8dac5b93839f7 (diff)
ide-tape: add ide_tape_set_media_lock() helper
Add ide_tape_set_media_lock() helper and convert idetape_mtioctop(), idetape_chrdev_open() and idetape_chrdev_release() to use it. There should be no functional changes caused by this patch (it is OK to modify ->door_locked if idetape_create_prevent_cmd() fails). Acked-by: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r--drivers/ide/ide-tape.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index d4a9c471dd13..26d5b0576f0a 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1299,6 +1299,16 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive,
1299 return 1; 1299 return 1;
1300} 1300}
1301 1301
1302static int ide_tape_set_media_lock(ide_drive_t *drive, int on)
1303{
1304 struct ide_atapi_pc pc;
1305
1306 if (!idetape_create_prevent_cmd(drive, &pc, on))
1307 return 0;
1308
1309 return idetape_queue_pc_tail(drive, &pc);
1310}
1311
1302static void __ide_tape_discard_merge_buffer(ide_drive_t *drive) 1312static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1303{ 1313{
1304 idetape_tape_t *tape = drive->driver_data; 1314 idetape_tape_t *tape = drive->driver_data;
@@ -1927,9 +1937,8 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1927 * attempting to eject. 1937 * attempting to eject.
1928 */ 1938 */
1929 if (tape->door_locked) { 1939 if (tape->door_locked) {
1930 if (idetape_create_prevent_cmd(drive, &pc, 0)) 1940 if (!ide_tape_set_media_lock(drive, 0))
1931 if (!idetape_queue_pc_tail(drive, &pc)) 1941 tape->door_locked = DOOR_UNLOCKED;
1932 tape->door_locked = DOOR_UNLOCKED;
1933 } 1942 }
1934 ide_tape_discard_merge_buffer(drive, 0); 1943 ide_tape_discard_merge_buffer(drive, 0);
1935 idetape_create_load_unload_cmd(drive, &pc, 1944 idetape_create_load_unload_cmd(drive, &pc,
@@ -1973,17 +1982,13 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1973 case MTFSR: 1982 case MTFSR:
1974 case MTBSR: 1983 case MTBSR:
1975 case MTLOCK: 1984 case MTLOCK:
1976 if (!idetape_create_prevent_cmd(drive, &pc, 1)) 1985 retval = ide_tape_set_media_lock(drive, 1);
1977 return 0;
1978 retval = idetape_queue_pc_tail(drive, &pc);
1979 if (retval) 1986 if (retval)
1980 return retval; 1987 return retval;
1981 tape->door_locked = DOOR_EXPLICITLY_LOCKED; 1988 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
1982 return 0; 1989 return 0;
1983 case MTUNLOCK: 1990 case MTUNLOCK:
1984 if (!idetape_create_prevent_cmd(drive, &pc, 0)) 1991 retval = ide_tape_set_media_lock(drive, 0);
1985 return 0;
1986 retval = idetape_queue_pc_tail(drive, &pc);
1987 if (retval) 1992 if (retval)
1988 return retval; 1993 return retval;
1989 tape->door_locked = DOOR_UNLOCKED; 1994 tape->door_locked = DOOR_UNLOCKED;
@@ -2085,7 +2090,6 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2085 unsigned int minor = iminor(inode), i = minor & ~0xc0; 2090 unsigned int minor = iminor(inode), i = minor & ~0xc0;
2086 ide_drive_t *drive; 2091 ide_drive_t *drive;
2087 idetape_tape_t *tape; 2092 idetape_tape_t *tape;
2088 struct ide_atapi_pc pc;
2089 int retval; 2093 int retval;
2090 2094
2091 if (i >= MAX_HWIFS * MAX_DRIVES) 2095 if (i >= MAX_HWIFS * MAX_DRIVES)
@@ -2148,11 +2152,9 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2148 2152
2149 /* Lock the tape drive door so user can't eject. */ 2153 /* Lock the tape drive door so user can't eject. */
2150 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 2154 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2151 if (idetape_create_prevent_cmd(drive, &pc, 1)) { 2155 if (!ide_tape_set_media_lock(drive, 1)) {
2152 if (!idetape_queue_pc_tail(drive, &pc)) { 2156 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
2153 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) 2157 tape->door_locked = DOOR_LOCKED;
2154 tape->door_locked = DOOR_LOCKED;
2155 }
2156 } 2158 }
2157 } 2159 }
2158 unlock_kernel(); 2160 unlock_kernel();
@@ -2185,7 +2187,6 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2185{ 2187{
2186 struct ide_tape_obj *tape = ide_tape_f(filp); 2188 struct ide_tape_obj *tape = ide_tape_f(filp);
2187 ide_drive_t *drive = tape->drive; 2189 ide_drive_t *drive = tape->drive;
2188 struct ide_atapi_pc pc;
2189 unsigned int minor = iminor(inode); 2190 unsigned int minor = iminor(inode);
2190 2191
2191 lock_kernel(); 2192 lock_kernel();
@@ -2204,10 +2205,8 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2204 (void) idetape_rewind_tape(drive); 2205 (void) idetape_rewind_tape(drive);
2205 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 2206 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2206 if (tape->door_locked == DOOR_LOCKED) { 2207 if (tape->door_locked == DOOR_LOCKED) {
2207 if (idetape_create_prevent_cmd(drive, &pc, 0)) { 2208 if (!ide_tape_set_media_lock(drive, 0))
2208 if (!idetape_queue_pc_tail(drive, &pc)) 2209 tape->door_locked = DOOR_UNLOCKED;
2209 tape->door_locked = DOOR_UNLOCKED;
2210 }
2211 } 2210 }
2212 } 2211 }
2213 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags); 2212 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);