커널 모듈에서 ioctl 사용...

MythRab의 이미지

모듈에서 디바이스에 ioctl을 내릴 수 있는 방법/구문을 알고 싶습니다.
identity 정보를 얻고 싶은데요...
유저 프로그램에서는
ioctl(fd, cmd, &arg) 이렇게 사용하는데
커널모드에서는 struct file* 를 사용해야 하겠죠...
struct file에 f_op를 봤는데, 여기의 ioctl은 ioctl 명령을 받을 때 사용하는 것 같습니다. 형식대로 해봤는데 에러가 납니다.
구글에서 뒤져봐도 찾아지지가 않네요. :(

관련 문건을 알려주셔도 감사하겠습니다.

owlet의 이미지

모듈에서는
static int ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
형태로 함수를 만들어서 등록하시면 됩니다.
cmd와 arg는 유저프로그램에서 ioctl(fd, cmd, arg)라고 실행했을때의 cmd와 arg가 그대로 넘어옵니다.
arg의 경우 필요하지않으면 사용하지않아도 되고, 필요하다면 유저프로그램에서 포인터로 넘긴후
모듈에서 copy_to_user혹은 copy_from_user를 이용해서 사용하시면 됩니다.

MythRab의 이미지

제가 설명을 잘 못한 것 같습니다.
일반적으로
유저 프로그램에서 ioctl(fd, cmd, arg)형식으로 ioctl명령을 수행하면 드라이버(?)에서 ioctl에 대한 처리 함수(위에서 말씀하신 것과 같이)를 만들어 리턴 값이 필요한 경우 arg 변수에 넘겨주는데요.

제가 말씀드린건 유저 프로그램에 ioctl명령을 내리는 것처럼 모듈(드라이버가 아닙니다)에서 디바이스에 ioctl 명령을 내리는 방법이었습니다.
커널레밸이기 때문에 int 형의 화일 디스크립터가 아니라 struct file을 사용해야 할 것 같은데....

Heading, heading again, again, ... ㅜㅜ 피난다

owlet의 이미지

모듈에서라면 ioctl을 거칠 필요없이 바로 컨트롤하면 될테고,

파일디스크립터같은건 필요가 없겠지요..

별로 고민할 필요가 없어보이는데요?

kiwist의 이미지

owlet wrote:
모듈에서라면 ioctl을 거칠 필요없이 바로 컨트롤하면 될테고,

파일디스크립터같은건 필요가 없겠지요..

별로 고민할 필요가 없어보이는데요?

위 방법에 저도 동의합니다. 하지만 님께서 유저모드의 ioctl 시스템콜과 동일한 역할을 하는 함수를 원하신다면, 하나 만들어 쓰는 것도 괜찮을 것 같습니다. ^^

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.