커널 장치 드라이버 (device driver) 만들 때

mandugukbap의 이미지

Linux 커널 (3.2.x)에 디바이스 드라이버를 만들고 있습니다.

해당 디바이스 드라이버의 용도는 사용자 영역 (User-space)에서 대략 100 바이트 내외의 데이터를 커널 영역 (Kernel-space)으로 내려 보내서 커널 영역 전역 변수에 짧은 시간 저장해 두려는 목적입니다.

많은 분들의 도움으로 장치 드라이버를 작성할 수 있었습니다. 코드를 다 옮기려니 너무 길어서 대충 중요한 부분만 옮겨 보자면 저 아래 보이는 코드와 같습니다.

아무튼 해당 드라이버는 제가 원하는대로 작동을 하고 있습니다. 다만 이 모듈(드라이버)을 사용하기 위해서는 항상 mknod를 이용해 /dev/test_device 라는 노드를 생성해야 하더군요.

질문은, /dev/test_device같은 노드를 생성하는 과정 없이 아래의 코드를 User-space <-> Kernel-space 사이 자료 전달이 가능한 드라이버로 만들 방법은 없을까요? 예를 들어 제가 참고로 하고 있는 어떤 프로젝트에는 아래 제가 작성한 코드의 file_operations 대신 tcp_congestion_ops라는 struct를 사용하더군요. 하지만 해당 구조체는 TCP의 혼잡제어용으로 특화된 내용이라서 제가 원하는 간단한 자료 전달용으로 쓸 수는 없었습니다.

static struct file_operations vd_fops = {
        .read = test_device_read,
        .write = test_device_write,
        .open = test_device_open,
        .release = test_device_release
};
 
int __init test_device_init(void)
{
        if (register_chrdev(250, "test_device", &vd_fops) < 0 )
                printk(KERN_ALERT "TEST driver init failed\n");
        else
                printk(KERN_ALERT "TEST driver init successful\n");
 
        buffer = (char*) kmalloc(1024, GFP_KERNEL);
 
        if (buffer != NULL)
                memset(buffer, 0, 1024);
 
        return 0;
}
 
void __exit test_device_exit(void)
{
        unregister_chrdev(250, "test_device");
 
        printk(KERN_ALERT "TEST driver cleanup succcessful\n");
 
        kfree(buffer);
}

댓글 달기

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