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
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Massimiliano Giorgi <massy@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/*
18
 * Copyright (C) 1999 Massimiliano Giorgi
19
 *
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
36
/*
37
 * CVS :        $Id: file.h,v 1.1.1.1 2002-03-29 14:12:50 pj Exp $
38
 *
39
 * File:        $File$
40
 * Revision:    $Revision: 1.1.1.1 $
41
 * Last update: $Date: 2002-03-29 14:12:50 $
42
 */
43
 
44
/***
45
 This files contains the "file" structure that rapresents??? a file in the system and functions
46
 to manage the local descriptors table of every process (not task).
47
***/
48
 
49
#ifndef __FILE_H__
50
#define __FILE_H__
51
 
52
#include <fs/types.h>
53
#include <fs/limits.h>
54
#include <fs/fsconf.h>
55
#include <fs/task.h>
56
#include <fs/assert.h>
57
 
58
#ifdef MSDOS_FILESYSTEM
59
#include "msdos/msdos_f.h"
60
#endif
61
 
62
#include "mutex.h"
63
#include "inode.h"
64
 
65
struct file {
66
  struct file            *f_next;
67
 
68
  struct dentry          *f_dentry;
69
  struct file_operations *f_op;
70
 
71
 
72
  /*__uint32_t           f_flags;  */
73
  __loff_t               f_pos;
74
 
75
  __uint32_t             f_flag_isdir:1;
76
 
77
  unsigned int           f_count; /* number of fd that point to this */
78
 
79
  union {
80
#ifdef MSDOS_FILESYSTEM
81
    struct msdos_file_info msdos_f;
82
#endif
83
    unsigned               dummy;
84
  } u;
85
 
86
  unsigned long          f_reada, f_ramax, f_raend, f_ralen, f_rawin;
87
  unsigned int           f_uid, f_gid;
88
  int                    f_error;
89
  unsigned long          f_version;
90
};
91
 
92
struct file_descriptors {  
93
  struct file   *fd_file[MAXOPENFILES];
94
 
95
  __uint16_t    fd_flags[MAXOPENFILES];  /* FD_CLOEXEC*/
96
  __uint32_t    fd_fflags[MAXOPENFILES]; /* O_CREAT, O_SYNC, O_RDONLY, ...*/
97
 
98
  __mode_t      fd_umask;
99
  char          fd_cwd[MAXPATHNAMELEN+1];
100
  struct dentry *fd_cwden;
101
#ifdef MULTITHREAD
102
  __mutex_t     fd_mutex;
103
#endif
104
};
105
 
106
/* if fd_file[fd] is
107
 * NULL       -> fd is free
108
 * RESERVEDFD -> fd is reserved for console i/o
109
 * other      -> fd is usuable
110
 */
111
#define RESERVEDFD ((void*)-1)
112
 
113
int file_init(void);
114
 
115
struct file *get_file(struct inode *ptr);
116
void free_file(struct file *f);
117
 
118
int get_fd(__pid_t pid, struct file *f);
119
struct file *free_fd(__pid_t pid, int fd);
120
 
121
void enums_file(void (*func)(struct file *));
122
 
123
/* does not aquire or release a lock! */
124
int __isvalid_fd(__pid_t pid, int fd);
125
 
126
int __duplicate_fd(__pid_t pid, int fd, int low);
127
 
128
/* ------ */
129
 
130
extern struct file_descriptors desctable[];
131
 
132
#ifdef MULTITHREAD
133
 
134
extern __inline__ void lock_desctable(__pid_t pid)
135
{
136
  __fs_mutex_lock(&desctable[pid].fd_mutex);
137
}
138
 
139
extern __inline__ void unlock_desctable(__pid_t pid)
140
{
141
  __fs_mutex_unlock(&desctable[pid].fd_mutex);
142
}
143
 
144
extern __inline__ void init_mutex(__pid_t pid)
145
{
146
  __fs_mutex_init(&desctable[pid].fd_mutex);
147
}
148
 
149
#else
150
 
151
#define lock_desctable(pid)
152
 
153
#define unlock_desctable(pid)
154
 
155
#define init_mutex(pid)
156
 
157
#endif
158
 
159
extern __inline__ __mode_t *umask_ptr(__pid_t pid)
160
{
161
  return &desctable[pid].fd_umask;
162
}
163
 
164
extern __inline__ char *cwd_ptr(__pid_t pid)
165
{
166
  return desctable[pid].fd_cwd;
167
}
168
 
169
extern __inline__ struct dentry *cwden_ptr(__pid_t pid)
170
{
171
  return desctable[pid].fd_cwden;
172
}
173
 
174
extern __inline__ struct file *file_ptr(__pid_t pid, int i)
175
{
176
  return desctable[pid].fd_file[i];
177
}
178
 
179
extern __inline__ int check_fd(__pid_t pid, int fd)
180
{
181
  if (fd<0||fd>=MAXOPENFILES) return -1;
182
  _assert(pid>=0&&pid<MAXIMUMPROCESS);
183
  if (desctable[pid].fd_file[fd]==NULL) return -1;
184
  if (desctable[pid].fd_file[fd]==RESERVEDFD) return -1;
185
  if (desctable[pid].fd_file[fd]->f_count==0) return -1;
186
  return 0;
187
}
188
 
189
extern __inline__ __uint16_t *fildesflags_ptr(__pid_t pid, int i)
190
{
191
  return &desctable[pid].fd_flags[i];
192
}
193
 
194
extern __inline__ __uint32_t *fildesfflags_ptr(__pid_t pid, int i)
195
{
196
  return &desctable[pid].fd_fflags[i];
197
}
198
 
199
#endif