/proc 파일을 읽고 쓰는 것에서...

csw0228의 이미지

/proc 파일 생성까지는 잘 해냈는데 읽고 쓰는데서 문제가 생겼네요..
커널 2.6에서 개발중인데 에러는 없는데 cat /proc/파일명을 하면 read 함수에서 디버그부분만 계속 출력하네요.. 뭐가 문제인가요??
write 함수는 정상적인거 같은데 read가 문제라 확인할 방법이 없네요..
참고로 디버그함수는 그냥 printk 함수를 그냥 define 으로 편하게 형식으로 지정해놓은것 뿐이라 문제는 없습니다.

static struct proc_dir_entry *proc_entry; /* proc 파일 생성을 위한 구조체*/
static char *message_buf; /* proc 파일에서 사용할 버퍼 */

/* 메시지를 읽는 함수 */
static ssize_t procfile_read(struct file *file, char __user *buffer, size_t size, loff_t *ppos)
{
DEBUG("procfile_read() called."); /* printk를 조금 조작한 함수 */
DEBUG("Entering: file=%p,buffer=%p,size=%i,*ppos=%lli",file,buffer,size,*ppos);

if (copy_to_user(buffer, &message_buf[0], size))
return -EFAULT;

return size;
}

/* 메시지를 쓰는 함수 */
static ssize_t procfile_write(struct file *file, const char __user *buffer, size_t size, loff_t *ppos)
{
DEBUG("procfile_write() called.");

if (size > PROCFS_MAX_SIZE) {
printk(KERN_INFO "Message Buffer is full!\n");
return -ENOSPC;
}

/* 사용자 영역에서 커널 영역으로 버퍼를 복사한다. */
if (copy_from_user( &message_buf[0], buffer, size ))
return -EFAULT;
message_buf[size-1] = '\0';

return size;
}

static struct file_operations proc_crypto_fops = {
read: procfile_read,
write: procfile_write,
};

int init_module()
{
message_buf = (char *)vmalloc(PROCFS_MAX_SIZE); /* 가상으로 연속된 메모리 블록을 할당한다. */
memset(message_buf, 0, PROCFS_MAX_SIZE); /* 버퍼 초기화 */

proc_entry=create_proc_entry(PROCFS_NAME, 0644, NULL);
proc_entry->proc_fops = &proc_crypto_fops;
proc_entry->owner=THIS_MODULE;
return 0;
}

void cleanup_module()
{
remove_proc_entry(PROCFS_NAME, NULL);
vfree(message_buf);
}

댓글 달기

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 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.