Subversion Repositories shark

Rev

Rev 2 | Rev 1063 | 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/stat.h>
#include <fs/fcntl.h>

#include "fsconst.h"
#include "file.h"
#include "dentry.h"
#include "inode.h"
#include "fileop.h"
#include "inodeop.h"
#include "fs.h"

#include "debug.h"

int k_opendir(char *upathname)
{
  declare_buffer(char,pathname,MAXPATHNAMELEN+1);
  int           len;
  struct file   *f;
  struct dentry *d;
  int           res;
  int           fd;
  __pid_t       pid;

  call_to_fs();
 
  printk4("k_opendir: START");
  pid=__get_pid();
 
  len=__verify_read_nolen((char*)upathname);
  if ((!len)||(len>MAXPATHNAMELEN)) return_from_fs(-EVERIFY);
  __copy_from_user(pathname,upathname,len+1);
 
  printk4("k_opendir: verifing memory... done");
 
  d=find_dentry_from(cwden_ptr(pid),(char *)pathname);
  if (d==NULL) return_from_fs(-ENOENT);
  /* NB: a questo punto ci dovrebbe essere il check per le directory! */
  if (!__S_ISDIR(d->d_inode->i_st.st_mode)) return_from_fs(-ENOENT);

  printk4("k_opendir: find dir entry... done");

  /* NB: andrebbe cercato se questo file e' gia' in uso! */
  f=get_file(NULL);
  if (f==NULL) {
    unlock_dentry(d);
    return_from_fs(-ENFILE);
  }

  printk4("k_open: getting system file entry... done");
 
  f->f_dentry=d;
  f->f_op=d->d_inode->i_op->default_file_ops;
  f->f_pos=0;
  f->f_flag_isdir=1;
 
  fd=get_fd(pid,f);
  if (fd==-1) {
    free_file(f);
    unlock_dentry(d);
    return_from_fs(-EMFILE);
  }
  if ((void*)fd==NULL) {
    /* Well, we can't return a value that can be confused with NULL :-( */
    int newfd;
    newfd=get_fd(pid,f);
    if (newfd==-1) {
      free_fd(pid,fd);
      free_file(f);
      unlock_dentry(d);
      return_from_fs(-EMFILE);
    }
    free_fd(pid,fd);
    fd=newfd;
  }
 
  printk4("k_open: getting file descriptor... done");
 
  res=f->f_op->open(f->f_dentry->d_inode,f);
  if (res!=0) {
    free_fd(pid,fd);
    free_file(f);
    unlock_dentry(d);
    return_from_fs(res);
  }

  printk4("k_open: called proper filesystem open... done");

  printk4("k_open: END");
  return_from_fs(fd);  
}