cfilefilenamesinodeminix

Retrieve a file's inode number by the filename on MINIX


I want to create a new system call in VFS server which will be given a filename as a parameter and will print this certain file's inode number in MINIX3.2.1. I examined the code of the do_stat() function(inside /usr/src/servers/vfs/stadir.c) and i found out that i have to assign to a vnode struct variable the faction eat_path() in order to access v_inode_nr which is the inode number.In order to do that how am i able to assign the file i am looking for,where to put the user input filename(m_in.m1_p1)?

Here is the do_stat() function inside stadir.c

int do_stat() {
  /* Perform the stat(name, buf) system call. */
  int r;
  struct vnode *vp;
  struct vmnt *vmp;
  char fullpath[PATH_MAX];
  struct lookup resolve;
  int old_stat = 0;
  vir_bytes vname1, statbuf;
  size_t vname1_length;

  vname1 = (vir_bytes)job_m_in.name1;
  vname1_length = (size_t)job_m_in.name1_length;
  statbuf = (vir_bytes)job_m_in.m1_p2;

  lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
  resolve.l_vmnt_lock = VMNT_READ;
  resolve.l_vnode_lock = VNODE_READ;

  if (job_call_nr == PREV_STAT)
    old_stat = 1;

  if (fetch_name(vname1, vname1_length, fullpath) != OK)
    return (err_code);
  if ((vp = eat_path(&resolve, fp)) == NULL)
    return (err_code);
  r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, statbuf, old_stat);

  unlock_vnode(vp);
  unlock_vmnt(vmp);

  put_vnode(vp);
  return r;
}

Solution

  • I've found a solution to my problem, i was not able to understand the way fetch_name() parameters work(vname1,vname1_length and fullpath). So in order to do that I looked into /usr/src/vfs/params.h #define name m3_p1 #define flength m2_l1 #define name1 m1_p1 #define name2 m1_p2 #define name_length m3_i1 #define name1_length m1_i1 #define name2_length m1_i2 #define nbytes m1_i2

    Υou can see name1 stands for m1_p1 and name1_length stands for m1_i1 message variables.

    As for fetch_name function,i looked /usr/src/vfs/utility.c

    int fetch_name(vir_bytes path, size_t len, char *dest)
    {
    /* Go get path and put it in 'dest'.  */
    int r;
    

    So fetch_name actually gets the path (filename from the user) and converts it to fullpath of the file.

    The question now is what's actually size_t len variable is...I looked it up online and i found out that it's the strlen of the path variable!