next up previous contents
Next: About this document ... Up: Pobieranie arg Previous: Dodatek A   Spis rzeczy

Dodatek B

Funkcja czytajaca z urzadzenia bedacego zwykla pamiecia



static ssize_t random_write(struct file * file,
const char * buffer, size_t count, loff_t *ppos)
{

  int              ret = 0;
  size_t           bytes; 
  __u32            buf[16]; 
  const char       *p = buffer;  
  size_t           c = count;

		 while (c > 0) { 

bytes = MIN(c, sizeof(buf));

bytes -= copy_from_user(&buf, p, bytes);
if (!bytes) {
ret = -EFAULT;
break;
}
c -= bytes;
p += bytes;

/* Convert bytes to words */
bytes = (bytes + 3) / sizeof(__u32);
add_entropy_words(random_state, buf, bytes);
}
if (p == buffer) {
return (ssize_t)ret;
} else {
file->f_dentry->d_inode->i_mtime = CURRENT_TIME;
mark_inode_dirty(file->f_dentry->d_inode);
return (ssize_t)(p - buffer);
}
}



jasiek 2002-01-25