02. copy_to_user 寫入資料

02. copy_to_user 寫入資料

char *memory_buffer;
ssize_t memory_read(struct file *filp, char *buf, 
                    size_t count, loff_t *f_pos) { 
 
  /* Transfering data to user space */ 
  if(memory_buffer==null){
      memory_buffer = kmalloc(1, GFP_KERNEL);
  }
  copy_to_user(buf,memory_buffer,1);

  /* Changing reading position as best suits */ 
  if (*f_pos == 0) { 
    *f_pos+=1; 
    return 1; 
  } else { 
    return 0; 
  }
}
Linux Driver
CH01 簡介CH02 註冊CH03 記憶體CH04 硬體函數CH05 USB