2

Can someone tell me in which part of the following code the information about all the files that are present in a directory is present? I'm trying to filter out few files that are to be hidden when ls tries to list all the files in the directory.

int vfs_readdir(struct file *file, filldir_t filler, void *buf)

{

      struct inode *inode = file->f_path.dentry->d_inode;
      int res = -ENOTDIR;
      if (!file->f_op || !file->f_op->readdir)
              goto out;

      res = security_file_permission(file, MAY_READ);
      if (res)
              goto out;

      res = mutex_lock_killable(&inode->i_mutex);
      if (res)
              goto out;

      res = -ENOENT;
      if (!IS_DEADDIR(inode)) {
              res = file->f_op->readdir(file, buf, filler);
              file_accessed(file);
      }
      mutex_unlock(&inode->i_mutex);
   out:
      return res;
}
  • Is this really what you want to do? You will create a system with an inconsistent VFS, here be dragons! Since you have control of the kernel, maybe you also control which version of `ls` you ship. Implementing it in user-space seems like a better idea to me. That said, the best solution would be to place these files in a directory that the user does not have permission to list (i.e. no `x` rights). Any reason this can not be done? – wkz Oct 23 '12 at 06:36
  • What ever mechanism I implement has to be in the VFS layer and not the user level. I know how to manipulate ls so that a perticular directory can be hidden but I'm not able to hide the files in a directory without hiding the directory itself. Can anyone tell me how the files present in the directory are being passed to the ls command. – scumbagbrain Oct 25 '12 at 22:40
  • If you remove the x flag on the directory, but keep x permissions on the parent directory, the folder would be visible but not its contents. – wkz Oct 27 '12 at 14:34

0 Answers0