Note that there are some explanatory texts on larger screens.

plurals
  1. POKernel Panic after changes in sys_close
    primarykey
    data
    text
    <p>I'm doing a course on operating systems and we work in Linux Red Hat 8.0 AS part of an assignment I had to change sys close and sys open. Changes to sys close passed without an incident, but when I introduce the changes to sys close suddenly the OS encounters an error during booting, claiming it cannot mount root fs, and invokes panic. EIP is reportedly at sys close when this happens. </p> <p>Here are the changes I made (look for the "HW1 additions" comment): In fs/open.c: </p> <pre><code>asmlinkage long sys_open(const char * filename, int flags, int mode) { char * tmp; int fd, error; event_t* new_event; #if BITS_PER_LONG != 32 flags |= O_LARGEFILE; #endif tmp = getname(filename); fd = PTR_ERR(tmp); if (!IS_ERR(tmp)) { fd = get_unused_fd(); if (fd &gt;= 0) { struct file *f = filp_open(tmp, flags, mode); error = PTR_ERR(f); if (IS_ERR(f)) goto out_error; fd_install(fd, f); } /* HW1 additions */ if (current-&gt;record_flag==1){ new_event=(event_t*)kmalloc(sizeof(event_t), GFP_KERNEL); if (!new_event){ new_event-&gt;type=Open; strcpy(new_event-&gt;filename, tmp); file_queue_add(*new_event, current-&gt;queue); } } /* End HW1 additions */ out: putname(tmp); } return fd; out_error: put_unused_fd(fd); fd = error; goto out; } asmlinkage long sys_close(unsigned int fd) { struct file * filp; struct files_struct *files = current-&gt;files; event_t* new_event; char* tmp = files-&gt;fd[fd]-&gt;f_dentry-&gt;d_name.name; write_lock(&amp;files-&gt;file_lock); if (fd &gt;= files-&gt;max_fds) goto out_unlock; filp = files-&gt;fd[fd]; if (!filp) goto out_unlock; files-&gt;fd[fd] = NULL; FD_CLR(fd, files-&gt;close_on_exec); __put_unused_fd(files, fd); write_unlock(&amp;files-&gt;file_lock); /* HW1 additions */ if(current-&gt;record_flag == 1){ new_event=(event_t*)kmalloc(sizeof(event_t), GFP_KERNEL); if (!new_event){ new_event-&gt;type=Close; strcpy(new_event-&gt;filename, tmp); file_queue_add(*new_event, current-&gt;queue); } } /* End HW1 additions */ return filp_close(filp, files); out_unlock: write_unlock(&amp;files-&gt;file_lock); return -EBADF; } </code></pre> <p>The task_struct defined in schedule.h was changed at the end to include: </p> <pre><code>unsigned int record_flag; /* when zero: do not record. when one: record. */ file_queue* queue; </code></pre> <p>And file queue as well as event t are defined in a separate file as follows: </p> <pre><code>typedef enum {Open, Close} EventType; typedef struct event_t{ EventType type; char filename[256]; }event_t; typedef struct file_quque_t{ event_t queue[101]; int head, tail; }file_queue; </code></pre> <p>file queue add works like this: </p> <pre><code>void file_queue_add(event_t event, file_queue* queue){ queue-&gt;queue[queue-&gt;head]=event; queue-&gt;head = (queue-&gt;head+1) % 101; if (queue-&gt;head==queue-&gt;tail){ queue-&gt;tail=(queue-&gt;tail+1) % 101; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload