proc file system 에서 copy_from_user 함수 사용에 관한 질문입

a287848의 이미지

proc file system 을 이용해서 user -> kernel 로 구조체를

데이터로 넘겨주고자 합니다.

이 구조체를 커널 영역에서 사용하기 위한 코드를 작성했습니다.

물론 proc fs 의 write function 에 등록했구요

static int proc_write_func(struct file* file , const char *buffer , unsigned long count , void* data)
{
        printk("proc_write_func\n");
 
        struct boost_request *rq1 = (struct boost_request *)data ;
        struct boost_request *rq = kmalloc(sizeof(struct boost_request) , GFP_USER);
        copy_from_user(rq , rq1 , count);
 printk("Write function is called : in kernel ide driver file.\n");
        printk("Device : %20s\n" , rq->dev);
        printk("Sector : %ld\n" , rq->Sector);
        printk("Number of Sectors : %ld\n" , rq->Nr_sectors);
        printk("Jiffies : %ld\n" , rq->Jiffies);
        return count ;
}
 
 
user 프로그램에서는 write 를 사용해서
 
[code]
 
number = fwrite(&req , sizeof(req) , 1 , pfile1) ;
 
[/code]
 
이 방법으로  구조체를 커널로 넘겨주고 있는데
 
이상하게 copy_from_user() 를 이용한 데이터 복사가 안되네요.
 
printk 로 찍은 데이터는 모두 0 과 NULL 문자로 되어있습니다.
 
도움 부탁 드립니다. ^^
 
구조체는 문자열 하나와 integer 3 개로 된 단순한 구조체 입니다.
pastime의 이미지

a287848 wrote:
struct boost_request *rq1 = (struct boost_request *)data ;

이 부분에서 date 가 아니라 buffer 가 들어가야 맞을 듯 합니다만..

struct boost_request *rq1 = (struct boost_request *) buffer;
struct boost_request *rq = kmalloc(sizeof(struct boost_request) , GFP_USER);
copy_from_user(rq , rq1 , count); 
...

아래의 문서도 참고하시기 바랍니다.. 8)

http://wiki.kldp.org/wiki.php/ProcfsGuide