title: MINIX 2 - syscall to kernel
body: <p>I want to make 2 syscalls to kernel (getlot and setlot). They have to read and set some value in struct proc, which is in kernel. What is the problem? What is missing?</p>
  
  <p>In /usr/include/minix/callnr.h I increased NCALLS and add 2 define</p>
  
  <pre><code> #define NCALLS       80    /* number of system calls allowed */
  
   #define SETLOT       78
   #define GETLOT       79
  </code></pre>
  
  <p>In usr/src/mm/main.c</p>
  
  <pre><code>PUBLIC void do_setlot()
  {
      message msg;
      msg = mm_in;
     _taskcall(SYSTASK, SYS_SETLOT), &amp;msg);
  }
  
  PUBLIC void do_getlot()
  {
      message msg;
      msg = mm_in;
     _taskcall(SYSTASK, SYS_GETLOT, &amp;msg);
  }
  </code></pre>
  
  <p>In /usr/src/mm/proto.h I added two prototypes</p>
  
  <pre><code>_PROTOTYPE( void do_setlot, (void));
  _PROTOTYPE( void do_getlot, (void));
  </code></pre>
  
  <p>In /usr/src/mm/table.c I added to the end of _PROTOTYPE (int (*call_vec[NCALLS]), (void) )</p>
  
  <pre><code>do_setlot,
  do_getlot,
  </code></pre>
  
  <p>In /usr/src/fs/table.c I added to the end of_PROTOTYPE (int (*call_vec[]), (void) ) </p>
  
  <pre><code>no_sys,
  no_sys,
  </code></pre>
  
  <p>In /usr/include/minix/com.h I created 2 SYS_xxx define</p>
  
  <pre><code>#   define SYS_SETLOT    22
  #   define SYS_GETLOT    23
  </code></pre>
  
  <p>In /usr/src/kernel/system.c I wrote</p>
  
  <pre><code>FORWARD _PROTOTYPE( int do_procsetlot, (message *m_ptr) );
  FORWARD _PROTOTYPE( int do_procgetlot, (message *m_ptr) );
  </code></pre>
  
  <p>Then added SYS_xxx to switch in PUBLIC void sys_task()</p>
  
  <pre><code>case SYS_SETLOT:    r = do_procsetlot(&amp;m);  break;
  case SYS_GETLOT:    r = do_procgetlot(&amp;m);  break; 
  </code></pre>
  
  <p>And at the bottom I wrote 2 definions</p>
  
  <pre><code>PRIVATE int do_procsetlot(m_ptr)
  register message *m_ptr;
  {
    pid_t prid;
    int i;
    int tickets;
    prid = m_ptr-&gt;m1_i1;
    tickets = m_ptr-&gt;m1_i2;
  
    if(tickets &gt; LOT_MAX)
      return EINVAL;
    if(tickets &lt; LOT_MIN)
      return EINVAL;
    for(i = 0 ; i &lt;NR_PROCS; i++)
    {
       if(proc[i].p_pid == prid)
       {
         proc[i].tickets_number = tickets;
         return 0;
       }
    {
    return EINVAL;
   }
  
  
  PRIVATE int do_procgetlot(m_ptr)
  register message *m_ptr;
  {
    int i;
    pid_t prid;
    prid = m_ptr-&gt;m1_i1;
  
    for(i = 0 ; i&lt; NR_PROCS; i++)
    {
      if(proc[i].p_pid == prid)
          return proc[i].tickets_number;
    }
   return EINVAL;
  }
  </code></pre>
  
  <p>Finally after make hdboot I got error:</p>
  
  <pre><code>exec cc -c -I/usr/include main.c
  exec cc -c -I/usr/include proc.c
  exec cc -c -I/usr/include system.c
  "system.c", line 1260: static not expected
  make in /usr/src/kernel: Exit code 1
  </code></pre>
  
  <p>Line 1260 is</p>
  
  <pre><code>PRIVATE int do_procgetlot(m_ptr)
  </code></pre>