Subversion Repositories shark

Rev

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

Rev Author Line No. Line
2 pj 1
 
2
#include <fs/types.h>
3
#include <fs/errno.h>
4
#include <fs/task.h>
5
#include <fs/maccess.h>
6
#include <fs/stat.h>
7
#include <fs/fcntl.h>
8
 
9
#include "fsconst.h"
10
#include "file.h"
11
#include "dentry.h"
12
#include "inode.h"
13
#include "fileop.h"
14
#include "inodeop.h"
15
#include "fs.h"
16
 
17
#include "debug.h"
18
 
19
int k_opendir(char *upathname)
20
{
21
  declare_buffer(char,pathname,MAXPATHNAMELEN+1);
22
  int           len;
23
  struct file   *f;
24
  struct dentry *d;
25
  int           res;
26
  int           fd;
27
  __pid_t       pid;
28
 
29
  call_to_fs();
30
 
31
  printk4("k_opendir: START");
32
  pid=__get_pid();
33
 
34
  len=__verify_read_nolen((char*)upathname);
35
  if ((!len)||(len>MAXPATHNAMELEN)) return_from_fs(-EVERIFY);
36
  __copy_from_user(pathname,upathname,len+1);
37
 
38
  printk4("k_opendir: verifing memory... done");
39
 
40
  d=find_dentry_from(cwden_ptr(pid),(char *)pathname);
41
  if (d==NULL) return_from_fs(-ENOENT);
42
  /* NB: a questo punto ci dovrebbe essere il check per le directory! */
43
  if (!__S_ISDIR(d->d_inode->i_st.st_mode)) return_from_fs(-ENOENT);
44
 
45
  printk4("k_opendir: find dir entry... done");
46
 
47
  /* NB: andrebbe cercato se questo file e' gia' in uso! */
48
  f=get_file(NULL);
49
  if (f==NULL) {
50
    unlock_dentry(d);
51
    return_from_fs(-ENFILE);
52
  }
53
 
54
  printk4("k_open: getting system file entry... done");
55
 
56
  f->f_dentry=d;
57
  f->f_op=d->d_inode->i_op->default_file_ops;
58
  f->f_pos=0;
59
  f->f_flag_isdir=1;
60
 
61
  fd=get_fd(pid,f);
62
  if (fd==-1) {
63
    free_file(f);
64
    unlock_dentry(d);
65
    return_from_fs(-EMFILE);
66
  }
67
  if ((void*)fd==NULL) {
68
    /* Well, we can't return a value that can be confused with NULL :-( */
69
    int newfd;
70
    newfd=get_fd(pid,f);
71
    if (newfd==-1) {
72
      free_fd(pid,fd);
73
      free_file(f);
74
      unlock_dentry(d);
75
      return_from_fs(-EMFILE);
76
    }
77
    free_fd(pid,fd);
78
    fd=newfd;
79
  }
80
 
81
  printk4("k_open: getting file descriptor... done");
82
 
83
  res=f->f_op->open(f->f_dentry->d_inode,f);
84
  if (res!=0) {
85
    free_fd(pid,fd);
86
    free_file(f);
87
    unlock_dentry(d);
88
    return_from_fs(res);
89
  }
90
 
91
  printk4("k_open: called proper filesystem open... done");
92
 
93
  printk4("k_open: END");
94
  return_from_fs(fd);  
95
}