Subversion Repositories shark

Rev

Rev 2 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed


#include <fs/types.h>
#include <fs/errno.h>
#include <fs/task.h>
#include <fs/maccess.h>
#include <fs/major.h>

#include "file.h"
#include "inode.h"
#include "dentry.h"
#include "fs.h"

#include "debug.h"

int k_fstat(int fd, struct stat *buf)
{
  struct inode *in=NULL;
  __pid_t pid;

  call_to_fs();
 
  /* to do better: for console i/o */
  if (fd>=0&&fd<=2) {
    struct stat st;

    /* !!! */
    return_from_fs(-EBADF);
   
    st.st_dev=NULLDEV;
    st.st_ino=0;
    st.st_mode=((fd==0)?
                __S_IRUSR|__S_IRGRP|__S_IROTH:
                __S_IWUSR|__S_IWGRP|__S_IWOTH);
    st.st_nlink=1;
    st.st_uid=0;
    st.st_gid=0;
    st.st_size=0;
    st.st_atime=0;
    st.st_mtime=0;
    st.st_ctime=0;
     
    if (!__verify_write(buf,sizeof(struct stat))) return_from_fs(-EVERIFY);
    __copy_to_user(buf,&(in->i_st),sizeof(struct stat));
    return_from_fs(EOK);
  }
 
  /* don't try to use bad file descriptor */
  pid=__get_pid();
  if (check_fd(pid,fd)) {
    printk(KERN_INFO "k_fstat: using a bad file descriptor");
    return_from_fs(-EBADF);
  }

  if (!__verify_write(buf,sizeof(struct stat))) return_from_fs(-EVERIFY);

  in=file_ptr(pid,fd)->f_dentry->d_inode;
  __copy_to_user(buf,&(in->i_st),sizeof(struct stat));
 
  return_from_fs(EOK);
}