Question: (c) Consider the following piece of kernel code. The intention is that whenever data is written to a proc-file, this data is written to a

(c) Consider the following piece of kernel code. The intention is that whenever data is written to a proc-file, this data is written to a device. The device provides two functions: start_transfer starts the transfer of count bytes to the device and returns immediately, and transfer finished, which is called by the device when the data transfer is finished. The function kernelWrite should return the number of bytes transferred to the device. 1 int total_transferred = 0; 2 /* total number of bytes transferred since module loaded */ 3 int transferred = 0; 4 /* bytes transferred to device in single transaction */ 5 6 /* called by device when transfer finished */ 7 /* called in interrupt mode */ 8 void transfer_finished (int count) { 9 transferred = transferred + count; 10 /* wakeup waiting process */ 11 } 12 13 /* called every time data is transferred to kern 14 , as a result of writing to proc-file */ 15 int kernelWrite(char * buffer, int count) { 16 /* buffer is pointer to user space */ 17 start_transfer (buffer, count); 18 /* go to sleep until woken up in transfer finish */ 19 transferred = transferred + count; 20 return transferred; 21 } 22 23 void init module (void) { 24 /* set up proc-structure - code omitted */ 25 proc->write_proc = kernelWrite; 26 } 27 } This kernel code compiles correctly but does not work as intended. Identify these errors and suggest remedies. If you think critical sections are required, it is sufficient to indicate begin and end of a critical section, and whether you would use semaphores or spinlocks to protect the critical section. (c) Consider the following piece of kernel code. The intention is that whenever data is written to a proc-file, this data is written to a device. The device provides two functions: start_transfer starts the transfer of count bytes to the device and returns immediately, and transfer finished, which is called by the device when the data transfer is finished. The function kernelWrite should return the number of bytes transferred to the device. 1 int total_transferred = 0; 2 /* total number of bytes transferred since module loaded */ 3 int transferred = 0; 4 /* bytes transferred to device in single transaction */ 5 6 /* called by device when transfer finished */ 7 /* called in interrupt mode */ 8 void transfer_finished (int count) { 9 transferred = transferred + count; 10 /* wakeup waiting process */ 11 } 12 13 /* called every time data is transferred to kern 14 , as a result of writing to proc-file */ 15 int kernelWrite(char * buffer, int count) { 16 /* buffer is pointer to user space */ 17 start_transfer (buffer, count); 18 /* go to sleep until woken up in transfer finish */ 19 transferred = transferred + count; 20 return transferred; 21 } 22 23 void init module (void) { 24 /* set up proc-structure - code omitted */ 25 proc->write_proc = kernelWrite; 26 } 27 } This kernel code compiles correctly but does not work as intended. Identify these errors and suggest remedies. If you think critical sections are required, it is sufficient to indicate begin and end of a critical section, and whether you would use semaphores or spinlocks to protect the critical
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
