Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
09caea65
Commit
09caea65
authored
Jun 05, 2003
by
Christoph Hellwig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PATCH] scsi_ioctl.c codingstyle fixes
dito
parent
5716e426
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
121 deletions
+81
-121
drivers/scsi/scsi_ioctl.c
drivers/scsi/scsi_ioctl.c
+81
-121
No files found.
drivers/scsi/scsi_ioctl.c
View file @
09caea65
...
...
@@ -90,75 +90,70 @@ static int ioctl_probe(struct Scsi_Host *host, void *buffer)
* The output area is then filled in starting from the command byte.
*/
static
int
ioctl_internal_command
(
Scsi_Device
*
dev
,
char
*
cmd
,
static
int
ioctl_internal_command
(
struct
scsi_device
*
s
dev
,
char
*
cmd
,
int
timeout
,
int
retries
)
{
struct
scsi_request
*
sreq
;
int
result
;
Scsi_Request
*
SRpnt
;
Scsi_Device
*
SDpnt
;
SCSI_LOG_IOCTL
(
1
,
printk
(
"Trying ioctl with scsi command %d
\n
"
,
*
cmd
));
SCSI_LOG_IOCTL
(
1
,
printk
(
"Trying ioctl with scsi command %d
\n
"
,
cmd
[
0
])
);
if
(
NULL
==
(
SRpnt
=
scsi_allocate_request
(
dev
))
)
{
sreq
=
scsi_allocate_request
(
sdev
);
if
(
!
sreq
)
{
printk
(
"SCSI internal ioctl failed, no memory
\n
"
);
return
-
ENOMEM
;
}
SRpnt
->
sr_data_direction
=
SCSI_DATA_NONE
;
scsi_wait_req
(
SRpnt
,
cmd
,
NULL
,
0
,
timeout
,
retries
);
sreq
->
sr_data_direction
=
SCSI_DATA_NONE
;
scsi_wait_req
(
sreq
,
cmd
,
NULL
,
0
,
timeout
,
retries
);
SCSI_LOG_IOCTL
(
2
,
printk
(
"Ioctl returned 0x%x
\n
"
,
SRpnt
->
sr_result
));
SCSI_LOG_IOCTL
(
2
,
printk
(
"Ioctl returned 0x%x
\n
"
,
sreq
->
sr_result
));
if
(
driver_byte
(
SRpnt
->
sr_result
)
!=
0
)
switch
(
SRpnt
->
sr_sense_buffer
[
2
]
&
0xf
)
{
if
(
driver_byte
(
sreq
->
sr_result
))
{
switch
(
sreq
->
sr_sense_buffer
[
2
]
&
0xf
)
{
case
ILLEGAL_REQUEST
:
if
(
cmd
[
0
]
==
ALLOW_MEDIUM_REMOVAL
)
dev
->
lockable
=
0
;
s
dev
->
lockable
=
0
;
else
printk
(
"SCSI device (ioctl) reports ILLEGAL REQUEST.
\n
"
);
break
;
case
NOT_READY
:
/* This happens if there is no disc in drive */
if
(
dev
->
removable
&&
(
cmd
[
0
]
!=
TEST_UNIT_READY
))
{
if
(
s
dev
->
removable
&&
(
cmd
[
0
]
!=
TEST_UNIT_READY
))
{
printk
(
KERN_INFO
"Device not ready. Make sure there is a disc in the drive.
\n
"
);
break
;
}
case
UNIT_ATTENTION
:
if
(
dev
->
removable
)
{
dev
->
changed
=
1
;
SRpnt
->
sr_result
=
0
;
/* This is no longer considered an error */
/* gag this error, VFS will log it anyway /axboe */
/* printk(KERN_INFO "Disc change detected.\n"); */
if
(
sdev
->
removable
)
{
sdev
->
changed
=
1
;
sreq
->
sr_result
=
0
;
/* This is no longer considered an error */
break
;
}
default:
/* Fall through for non-removable media */
printk
(
"SCSI error: host %d id %d lun %d return code = %x
\n
"
,
dev
->
host
->
host_no
,
dev
->
id
,
dev
->
lun
,
SRpnt
->
sr_result
);
s
dev
->
host
->
host_no
,
s
dev
->
id
,
s
dev
->
lun
,
sreq
->
sr_result
);
printk
(
"
\t
Sense class %x, sense error %x, extended sense %x
\n
"
,
sense_class
(
SRpnt
->
sr_sense_buffer
[
0
]),
sense_error
(
SRpnt
->
sr_sense_buffer
[
0
]),
SRpnt
->
sr_sense_buffer
[
2
]
&
0xf
);
sense_class
(
sreq
->
sr_sense_buffer
[
0
]),
sense_error
(
sreq
->
sr_sense_buffer
[
0
]),
sreq
->
sr_sense_buffer
[
2
]
&
0xf
);
}
}
result
=
SRpnt
->
sr_result
;
result
=
sreq
->
sr_result
;
SCSI_LOG_IOCTL
(
2
,
printk
(
"IOCTL Releasing command
\n
"
));
SDpnt
=
SRpnt
->
sr_device
;
scsi_release_request
(
SRpnt
);
SRpnt
=
NULL
;
scsi_release_request
(
sreq
);
return
result
;
}
int
scsi_set_medium_removal
(
Scsi_Device
*
dev
,
char
state
)
int
scsi_set_medium_removal
(
struct
scsi_device
*
s
dev
,
char
state
)
{
char
scsi_cmd
[
MAX_COMMAND_SIZE
];
int
ret
;
if
(
!
dev
->
removable
||
!
dev
->
lockable
)
if
(
!
sdev
->
removable
||
!
s
dev
->
lockable
)
return
0
;
scsi_cmd
[
0
]
=
ALLOW_MEDIUM_REMOVAL
;
...
...
@@ -168,11 +163,10 @@ int scsi_set_medium_removal(Scsi_Device *dev, char state)
scsi_cmd
[
4
]
=
state
;
scsi_cmd
[
5
]
=
0
;
ret
=
ioctl_internal_command
(
dev
,
scsi_cmd
,
IOCTL_NORMAL_TIMEOUT
,
NORMAL_RETRIES
);
ret
=
ioctl_internal_command
(
sdev
,
scsi_cmd
,
IOCTL_NORMAL_TIMEOUT
,
NORMAL_RETRIES
);
if
(
ret
==
0
)
dev
->
locked
=
state
==
SCSI_REMOVAL_PREVENT
;
sdev
->
locked
=
(
state
==
SCSI_REMOVAL_PREVENT
);
return
ret
;
}
...
...
@@ -209,13 +203,13 @@ int scsi_set_medium_removal(Scsi_Device *dev, char state)
*/
#define OMAX_SB_LEN 16
/* Old sense buffer length */
int
scsi_ioctl_send_command
(
Scsi_Device
*
dev
,
Scsi_Ioctl_Command
*
sic
)
int
scsi_ioctl_send_command
(
struct
scsi_device
*
sdev
,
struct
scsi_ioctl_command
*
sic
)
{
char
*
buf
;
unsigned
char
cmd
[
MAX_COMMAND_SIZE
];
char
*
cmd_in
;
Scsi_Request
*
SRpnt
;
Scsi_Device
*
SDpnt
;
struct
scsi_request
*
sreq
;
unsigned
char
opcode
;
unsigned
int
inlen
,
outlen
,
cmdlen
;
unsigned
int
needed
,
buf_needed
;
...
...
@@ -225,7 +219,7 @@ int scsi_ioctl_send_command(Scsi_Device * dev, Scsi_Ioctl_Command * sic)
if
(
!
sic
)
return
-
EINVAL
;
if
(
dev
->
host
->
unchecked_isa_dma
)
if
(
s
dev
->
host
->
unchecked_isa_dma
)
gfp_mask
|=
GFP_DMA
;
/*
...
...
@@ -259,11 +253,11 @@ int scsi_ioctl_send_command(Scsi_Device * dev, Scsi_Ioctl_Command * sic)
buf_needed
=
(
buf_needed
+
511
)
&
~
511
;
if
(
buf_needed
>
MAX_BUF
)
buf_needed
=
MAX_BUF
;
buf
=
(
char
*
)
kmalloc
(
buf_needed
,
gfp_mask
);
buf
=
kmalloc
(
buf_needed
,
gfp_mask
);
if
(
!
buf
)
return
-
ENOMEM
;
memset
(
buf
,
0
,
buf_needed
);
if
(
inlen
==
0
)
{
if
(
inlen
==
0
)
{
data_direction
=
SCSI_DATA_READ
;
}
else
if
(
outlen
==
0
)
{
data_direction
=
SCSI_DATA_WRITE
;
...
...
@@ -327,62 +321,34 @@ int scsi_ioctl_send_command(Scsi_Device * dev, Scsi_Ioctl_Command * sic)
break
;
}
#ifndef DEBUG_NO_CMD
SRpnt
=
scsi_allocate_request
(
dev
);
if
(
SRpnt
==
NULL
)
{
sreq
=
scsi_allocate_request
(
sdev
);
if
(
sreq
)
{
result
=
-
EINTR
;
goto
error
;
}
SRpnt
->
sr_data_direction
=
data_direction
;
scsi_wait_req
(
SRpnt
,
cmd
,
buf
,
needed
,
timeout
,
retries
);
sreq
->
sr_data_direction
=
data_direction
;
scsi_wait_req
(
sreq
,
cmd
,
buf
,
needed
,
timeout
,
retries
);
/*
* If there was an error condition, pass the info back to the user.
*/
result
=
SRpnt
->
sr_result
;
if
(
SRpnt
->
sr_result
)
{
int
sb_len
=
sizeof
(
SRpnt
->
sr_sense_buffer
);
result
=
sreq
->
sr_result
;
if
(
result
)
{
int
sb_len
=
sizeof
(
sreq
->
sr_sense_buffer
);
sb_len
=
(
sb_len
>
OMAX_SB_LEN
)
?
OMAX_SB_LEN
:
sb_len
;
if
(
copy_to_user
(
cmd_in
,
SRpnt
->
sr_sense_buffer
,
sb_len
))
if
(
copy_to_user
(
cmd_in
,
sreq
->
sr_sense_buffer
,
sb_len
))
result
=
-
EFAULT
;
}
else
{
if
(
copy_to_user
(
cmd_in
,
buf
,
outlen
))
result
=
-
EFAULT
;
}
SDpnt
=
SRpnt
->
sr_device
;
scsi_release_request
(
SRpnt
);
SRpnt
=
NULL
;
scsi_release_request
(
sreq
);
error:
if
(
buf
)
kfree
(
buf
);
return
result
;
#else
{
int
i
;
printk
(
"scsi_ioctl : device %d. command = "
,
dev
->
id
);
for
(
i
=
0
;
i
<
cmdlen
;
++
i
)
printk
(
"%02x "
,
cmd
[
i
]);
printk
(
"
\n
buffer ="
);
for
(
i
=
0
;
i
<
20
;
++
i
)
printk
(
"%02x "
,
buf
[
i
]);
printk
(
"
\n
"
);
printk
(
"inlen = %d, outlen = %d, cmdlen = %d
\n
"
,
inlen
,
outlen
,
cmdlen
);
printk
(
"buffer = %d, cmd_in = %d
\n
"
,
buffer
,
cmd_in
);
}
return
0
;
#endif
}
/*
...
...
@@ -395,14 +361,13 @@ int scsi_ioctl_send_command(Scsi_Device * dev, Scsi_Ioctl_Command * sic)
* device)
* any copy_to_user() error on failure there
*/
static
int
scsi_ioctl_get_pci
(
Scsi_Device
*
sdev
,
void
*
arg
)
static
int
scsi_ioctl_get_pci
(
struct
scsi_device
*
sdev
,
void
*
arg
)
{
struct
device
*
dev
=
scsi_get_device
(
sdev
->
host
);
if
(
!
dev
)
return
-
ENXIO
;
return
copy_to_user
(
arg
,
dev
->
bus_id
,
sizeof
(
dev
->
bus_id
));
if
(
!
dev
)
return
-
ENXIO
;
return
copy_to_user
(
arg
,
dev
->
bus_id
,
sizeof
(
dev
->
bus_id
));
}
...
...
@@ -411,12 +376,12 @@ scsi_ioctl_get_pci(Scsi_Device * sdev, void *arg)
* not take a major/minor number as the dev field. Rather, it takes
* a pointer to a scsi_devices[] element, a structure.
*/
int
scsi_ioctl
(
Scsi_Device
*
dev
,
int
cmd
,
void
*
arg
)
int
scsi_ioctl
(
struct
scsi_device
*
s
dev
,
int
cmd
,
void
*
arg
)
{
char
scsi_cmd
[
MAX_COMMAND_SIZE
];
/* No idea how this happens.... */
if
(
!
dev
)
if
(
!
s
dev
)
return
-
ENXIO
;
/*
...
...
@@ -425,24 +390,24 @@ int scsi_ioctl(Scsi_Device * dev, int cmd, void *arg)
* may try and take the device offline, in which case all further
* access to the device is prohibited.
*/
if
(
!
scsi_block_when_processing_errors
(
dev
))
{
if
(
!
scsi_block_when_processing_errors
(
sdev
))
return
-
ENODEV
;
}
switch
(
cmd
)
{
case
SCSI_IOCTL_GET_IDLUN
:
if
(
verify_area
(
VERIFY_WRITE
,
arg
,
sizeof
(
Scsi_I
dlun
)))
if
(
verify_area
(
VERIFY_WRITE
,
arg
,
sizeof
(
struct
scsi_i
dlun
)))
return
-
EFAULT
;
__put_user
((
dev
->
id
&
0xff
)
+
((
dev
->
lun
&
0xff
)
<<
8
)
+
((
dev
->
channel
&
0xff
)
<<
16
)
+
((
dev
->
host
->
host_no
&
0xff
)
<<
24
),
&
((
Scsi_Idlun
*
)
arg
)
->
dev_id
);
__put_user
(
dev
->
host
->
unique_id
,
&
((
Scsi_Idlun
*
)
arg
)
->
host_unique_id
);
__put_user
((
sdev
->
id
&
0xff
)
+
((
sdev
->
lun
&
0xff
)
<<
8
)
+
((
sdev
->
channel
&
0xff
)
<<
16
)
+
((
sdev
->
host
->
host_no
&
0xff
)
<<
24
),
&
((
struct
scsi_idlun
*
)
arg
)
->
dev_id
);
__put_user
(
sdev
->
host
->
unique_id
,
&
((
struct
scsi_idlun
*
)
arg
)
->
host_unique_id
);
return
0
;
case
SCSI_IOCTL_GET_BUS_NUMBER
:
return
put_user
(
dev
->
host
->
host_no
,
(
int
*
)
arg
);
return
put_user
(
sdev
->
host
->
host_no
,
(
int
*
)
arg
);
/*
* The next two ioctls either need to go or need to be changed to
* pass tagged queueing changes through the low level drivers.
...
...
@@ -454,61 +419,56 @@ int scsi_ioctl(Scsi_Device * dev, int cmd, void *arg)
case
SCSI_IOCTL_TAGGED_ENABLE
:
if
(
!
capable
(
CAP_SYS_ADMIN
))
return
-
EACCES
;
if
(
!
dev
->
tagged_supported
)
if
(
!
s
dev
->
tagged_supported
)
return
-
EINVAL
;
dev
->
tagged_queue
=
1
;
dev
->
current_tag
=
1
;
s
dev
->
tagged_queue
=
1
;
s
dev
->
current_tag
=
1
;
return
0
;
case
SCSI_IOCTL_TAGGED_DISABLE
:
if
(
!
capable
(
CAP_SYS_ADMIN
))
return
-
EACCES
;
if
(
!
dev
->
tagged_supported
)
if
(
!
s
dev
->
tagged_supported
)
return
-
EINVAL
;
dev
->
tagged_queue
=
0
;
dev
->
current_tag
=
0
;
s
dev
->
tagged_queue
=
0
;
s
dev
->
current_tag
=
0
;
return
0
;
case
SCSI_IOCTL_PROBE_HOST
:
return
ioctl_probe
(
dev
->
host
,
arg
);
return
ioctl_probe
(
s
dev
->
host
,
arg
);
case
SCSI_IOCTL_SEND_COMMAND
:
if
(
!
capable
(
CAP_SYS_ADMIN
)
||
!
capable
(
CAP_SYS_RAWIO
))
return
-
EACCES
;
return
scsi_ioctl_send_command
(
(
Scsi_Device
*
)
dev
,
(
Scsi_Ioctl_Command
*
)
arg
);
return
scsi_ioctl_send_command
(
s
dev
,
(
struct
scsi_ioctl_command
*
)
arg
);
case
SCSI_IOCTL_DOORLOCK
:
return
scsi_set_medium_removal
(
dev
,
SCSI_REMOVAL_PREVENT
);
return
scsi_set_medium_removal
(
s
dev
,
SCSI_REMOVAL_PREVENT
);
case
SCSI_IOCTL_DOORUNLOCK
:
return
scsi_set_medium_removal
(
dev
,
SCSI_REMOVAL_ALLOW
);
return
scsi_set_medium_removal
(
s
dev
,
SCSI_REMOVAL_ALLOW
);
case
SCSI_IOCTL_TEST_UNIT_READY
:
scsi_cmd
[
0
]
=
TEST_UNIT_READY
;
scsi_cmd
[
1
]
=
0
;
scsi_cmd
[
2
]
=
scsi_cmd
[
3
]
=
scsi_cmd
[
5
]
=
0
;
scsi_cmd
[
4
]
=
0
;
return
ioctl_internal_command
(
(
Scsi_Device
*
)
dev
,
scsi_cmd
,
return
ioctl_internal_command
(
s
dev
,
scsi_cmd
,
IOCTL_NORMAL_TIMEOUT
,
NORMAL_RETRIES
);
break
;
case
SCSI_IOCTL_START_UNIT
:
scsi_cmd
[
0
]
=
START_STOP
;
scsi_cmd
[
1
]
=
0
;
scsi_cmd
[
2
]
=
scsi_cmd
[
3
]
=
scsi_cmd
[
5
]
=
0
;
scsi_cmd
[
4
]
=
1
;
return
ioctl_internal_command
(
(
Scsi_Device
*
)
dev
,
scsi_cmd
,
return
ioctl_internal_command
(
s
dev
,
scsi_cmd
,
START_STOP_TIMEOUT
,
NORMAL_RETRIES
);
break
;
case
SCSI_IOCTL_STOP_UNIT
:
scsi_cmd
[
0
]
=
START_STOP
;
scsi_cmd
[
1
]
=
0
;
scsi_cmd
[
2
]
=
scsi_cmd
[
3
]
=
scsi_cmd
[
5
]
=
0
;
scsi_cmd
[
4
]
=
0
;
return
ioctl_internal_command
(
(
Scsi_Device
*
)
dev
,
scsi_cmd
,
return
ioctl_internal_command
(
s
dev
,
scsi_cmd
,
START_STOP_TIMEOUT
,
NORMAL_RETRIES
);
break
;
case
SCSI_IOCTL_GET_PCI
:
return
scsi_ioctl_get_pci
(
dev
,
arg
);
break
;
return
scsi_ioctl_get_pci
(
sdev
,
arg
);
default:
if
(
dev
->
host
->
hostt
->
ioctl
)
return
dev
->
host
->
hostt
->
ioctl
(
dev
,
cmd
,
arg
);
return
-
EINVAL
;
if
(
sdev
->
host
->
hostt
->
ioctl
)
return
sdev
->
host
->
hostt
->
ioctl
(
sdev
,
cmd
,
arg
);
}
return
-
EINVAL
;
}
...
...
@@ -518,13 +478,13 @@ int scsi_ioctl(Scsi_Device * dev, int cmd, void *arg)
* fs segment fiddling.
*/
int
kernel_scsi_ioctl
(
Scsi_Device
*
dev
,
int
cmd
,
void
*
arg
)
int
kernel_scsi_ioctl
(
struct
scsi_device
*
s
dev
,
int
cmd
,
void
*
arg
)
{
mm_segment_t
oldfs
;
int
tmp
;
oldfs
=
get_fs
();
set_fs
(
get_ds
());
tmp
=
scsi_ioctl
(
dev
,
cmd
,
arg
);
tmp
=
scsi_ioctl
(
s
dev
,
cmd
,
arg
);
set_fs
(
oldfs
);
return
tmp
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment