Ioctl() SCSI_IOCTL_SEND_COMMAND에 대해 질문드립니다.

alsrud의 이미지


안녕하세요 :) 혼자 C언어를 공부하며 오픈 소스를 보고 있는데요, ioctl함수의 SCSI_IOCTL_SEND_COMMAND에 대해 몇 가지 궁금한 점이 있어 질문을 올립니다.
코드는 스카시디스크의 시리얼 넘버를 읽어오는 코드 입니다.

Struct sdata {
		unsigned int inlen; //디바이스에 쓰여진 데이터의 길이
		unsigned int outlen; //디바이스로부터 읽어들인 데이터의 길이
		unsigned char cmd[4];
		unsigned char outbuf[24];
} sg_id;
 
sg_id.inlen = 0;
sg_id.outlen = sizeof(sg_id.outbuf); //outbuf->디바이스로부터 읽어들인 데이터
sg_id.cmd[0] = 0x12; 
sg_id.cmd[1] = 0x01; 
sg_id.cmd[2] = 0x80; 
sg_id.cmd[3] = 0x00; 
memset(sg_id.outbuf, 0x00, sg_id.outlen);
 
 
if ((fd = open(partname, O_RDONLY)) < 0)
	return (-1);
 
ret = ioctl(fd, SCSI_IOCTL_SEND_COMMAND, &sg_id);  
		close(fd);

1. cmd배열의 크기를 4로 지정한 이유와 초기값을 0x12, 0x01, 0x80, 0x00으로 준 이유가 궁금합니다.
2. SCSI_IOCTL_SEND_COMMAND가 실행되면 cmd배열의 명령을 실행해 sg_id구조체의 outbuf에 값을 저장해 가져온다는 의미가 맞는 것인지 궁금합니다.

SCSI_IOCTL_SEND_COMMAND를 구글링해도 정확한 정보를 찾을 수 없어 도움말씀 부탁드립니다^^

potatogim의 이미지

>> 1. cmd배열의 크기를 4로 지정한 이유와 초기값을 0x12, 0x01, 0x80, 0x00으로 준 이유가 궁금합니다.

일련 번호를 조회하기 위한 INQUIRY 명령의 정의가 0x12 0x01 0x80 0x00으로 되어있기 때문입니다. 당연히 4바이트가 필요하니 4로 지정한 것 뿐이구요.

>> 2. SCSI_IOCTL_SEND_COMMAND가 실행되면 cmd배열의 명령을 실행해 sg_id구조체의 outbuf에 값을 저장해 가져온다는 의미가 맞는 것인지 궁금합니다.

맞습니다.

Talk is cheap. Show me the code.

https://www.potatogim.net/

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.