Subversion Repositories shark

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
 
1063 tullio 2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
2 pj 19
#include <fs/types.h>
20
#include <fs/errno.h>
21
#include <fs/task.h>
22
#include <fs/maccess.h>
23
#include <fs/stat.h>
24
#include <fs/fcntl.h>
25
 
26
#include "fsconst.h"
27
#include "file.h"
28
#include "dentry.h"
29
#include "inode.h"
30
#include "fileop.h"
31
#include "inodeop.h"
32
#include "fs.h"
33
 
34
#include "debug.h"
35
 
36
int k_opendir(char *upathname)
37
{
38
  declare_buffer(char,pathname,MAXPATHNAMELEN+1);
39
  int           len;
40
  struct file   *f;
41
  struct dentry *d;
42
  int           res;
43
  int           fd;
44
  __pid_t       pid;
45
 
46
  call_to_fs();
47
 
48
  printk4("k_opendir: START");
49
  pid=__get_pid();
50
 
51
  len=__verify_read_nolen((char*)upathname);
52
  if ((!len)||(len>MAXPATHNAMELEN)) return_from_fs(-EVERIFY);
53
  __copy_from_user(pathname,upathname,len+1);
54
 
55
  printk4("k_opendir: verifing memory... done");
56
 
57
  d=find_dentry_from(cwden_ptr(pid),(char *)pathname);
58
  if (d==NULL) return_from_fs(-ENOENT);
59
  /* NB: a questo punto ci dovrebbe essere il check per le directory! */
60
  if (!__S_ISDIR(d->d_inode->i_st.st_mode)) return_from_fs(-ENOENT);
61
 
62
  printk4("k_opendir: find dir entry... done");
63
 
64
  /* NB: andrebbe cercato se questo file e' gia' in uso! */
65
  f=get_file(NULL);
66
  if (f==NULL) {
67
    unlock_dentry(d);
68
    return_from_fs(-ENFILE);
69
  }
70
 
71
  printk4("k_open: getting system file entry... done");
72
 
73
  f->f_dentry=d;
74
  f->f_op=d->d_inode->i_op->default_file_ops;
75
  f->f_pos=0;
76
  f->f_flag_isdir=1;
77
 
78
  fd=get_fd(pid,f);
79
  if (fd==-1) {
80
    free_file(f);
81
    unlock_dentry(d);
82
    return_from_fs(-EMFILE);
83
  }
84
  if ((void*)fd==NULL) {
85
    /* Well, we can't return a value that can be confused with NULL :-( */
86
    int newfd;
87
    newfd=get_fd(pid,f);
88
    if (newfd==-1) {
89
      free_fd(pid,fd);
90
      free_file(f);
91
      unlock_dentry(d);
92
      return_from_fs(-EMFILE);
93
    }
94
    free_fd(pid,fd);
95
    fd=newfd;
96
  }
97
 
98
  printk4("k_open: getting file descriptor... done");
99
 
100
  res=f->f_op->open(f->f_dentry->d_inode,f);
101
  if (res!=0) {
102
    free_fd(pid,fd);
103
    free_file(f);
104
    unlock_dentry(d);
105
    return_from_fs(res);
106
  }
107
 
108
  printk4("k_open: called proper filesystem open... done");
109
 
110
  printk4("k_open: END");
111
  return_from_fs(fd);  
112
}