title: How to check if the root filesystem has been mounted in linux
body: <p>I was wondering if it was possible to know if the rootfile system has been mounted from the kernel. Im trying to read a file from /bin but it doesnt work on boot. </p>
  
  <p><code>static int ret_my_file()</code> is in <code>fs/exec.c</code></p>
  
  <pre><code>static int ret_my_file()  
  {
  struct file* f;
  
  char *dbtext;
  struct path dbpath;
  
  mm_segment_t oldfs;
  struct kstat dbstat;
  
  kern_path("/bin/myfile", 0, &amp;dbpath);
  vfs_getattr(&amp;dbpath, &amp;dbstat);
  
  dbtext = vmalloc(dbstat.size*sizeof(char));
  f=filp_open("/bin/myfile", O_RDONLY, 0);
  
  oldfs=get_fs();
  set_fs (KERNEL_DS);
  vfs_read(f, dbtext, dbstat.size, &amp;f-&gt;f_pos);
  set_fs(oldfs);
  printk(KERN_CRIT "Db value is");
  printk(KERN_CRIT "%s\n",dbtext);
  vfree(dbtext);
  return 0;
  }
  </code></pre>
  
  <p>called in the function  <code>do_execveat_common()</code>  also in  <code>fs/exec.c</code>  as </p>
  
  <pre><code>static int do_execveat_common(int fd, struct filename *filename,
                             struct user_arg_ptr argv,
                             struct user_arg_ptr envp,
                            int flags)
  {
   char *pathbuf = NULL;
   struct linux_binprm *bprm;
   struct file *file;
   struct files_struct *displaced;
   int retval;
  
   retval=ret_my_file();
   ......}
  </code></pre>
  
  <p>but the function  <code>do_execveat_common()</code>  is called during boot up so i wanted to put a condition before  <code>retval=ret_my_file();</code>  so that it only runs after the root filesystem has been mounted</p>