1 #ifndef __ALT_FILE_H__
2 #define __ALT_FILE_H__
3 
4 /******************************************************************************
5 *                                                                             *
6 * License Agreement                                                           *
7 *                                                                             *
8 * Copyright (c) 2004 Altera Corporation, San Jose, California, USA.           *
9 * All rights reserved.                                                        *
10 *                                                                             *
11 * Permission is hereby granted, free of charge, to any person obtaining a     *
12 * copy of this software and associated documentation files (the "Software"),  *
13 * to deal in the Software without restriction, including without limitation   *
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
15 * and/or sell copies of the Software, and to permit persons to whom the       *
16 * Software is furnished to do so, subject to the following conditions:        *
17 *                                                                             *
18 * The above copyright notice and this permission notice shall be included in  *
19 * all copies or substantial portions of the Software.                         *
20 *                                                                             *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
27 * DEALINGS IN THE SOFTWARE.                                                   *
28 *                                                                             *
29 *                                                                             *
30 * Altera does not recommend, suggest or require that this reference design    *
31 * file be used in conjunction or combination with any other product.          *
32 ******************************************************************************/
33 
34 /******************************************************************************
35 *                                                                             *
36 * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT.                       *
37 *                                                                             *
38 ******************************************************************************/
39 
40 #include "sys/alt_dev.h"
41 #include "sys/alt_llist.h"
42 #include "os/alt_sem.h"
43 
44 #include "alt_types.h"
45 
46 /*
47  * This header provides the internal defenitions required to control file
48  * access. These variables and functions are not guaranteed to exist in
49  * future implementations of the HAL.
50  */
51 
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif /* __cplusplus */
56 
57 /*
58  * The function alt_find_dev() is used to search the device list "list" to
59  * locate a device named "name". If a match is found, then a pointer to the
60  * device is returned, otherwise NULL is returned.
61  */
62 
63 extern alt_dev* alt_find_dev (const char* name, alt_llist* list);
64 
65 /*
66  * alt_find_file() is used to search the list of registered file systems to
67  * find the filesystem that the file named "name" belongs to. If a match is
68  * found, then a pointer to the filesystems alt_dev structure is returned,
69  * otherwise NULL is returned.
70  *
71  * Note that a match does not indicate that the file exists, only that a
72  * filesystem exists that is registered for a partition that could contain
73  * the file. The filesystems open() function would need to be called in order
74  * to determine if the file exists.
75  */
76 
77 extern alt_dev* alt_find_file (const char* name);
78 
79 /*
80  * alt_get_fd() is used to allocate a file descriptor for the device or
81  * filesystem "dev". A negative return value indicates an error, otherwise the
82  * return value is the index of the file descriptor within the file descriptor
83  * pool.
84  */
85 
86 extern int alt_get_fd (alt_dev* dev);
87 
88 /*
89  * alt_release_fd() is called to free the file descriptor with index "fd".
90  */
91 
92 extern void alt_release_fd (int fd);
93 
94 /*
95  * alt_fd_lock() is called by ioctl() to mark the file descriptor "fd" as
96  * being open for exclusive access. Subsequent calls to open() for the device
97  * associated with "fd" will fail. A device is unlocked by either calling
98  * close() for "fd", or by an alternate call to ioctl() (see ioctl.c for
99  * details).
100  */
101 
102 extern int alt_fd_lock (alt_fd* fd);
103 
104 /*
105  * alt_fd_unlock() is called by ioctl() to unlock a descriptor previously
106  * locked by a call to alt_fd_lock().
107  */
108 
109 extern int alt_fd_unlock (alt_fd* fd);
110 
111 /*
112  * "alt_fd_list" is the pool of file descriptors.
113  */
114 
115 extern alt_fd alt_fd_list[];
116 
117 /*
118  * flags used by alt_fd.
119  *
120  * ALT_FD_EXCL is used to mark a file descriptor as locked for exclusive
121  * access, i.e. further calls to open() for the associated device should
122  * fail.
123  *
124  * ALT_FD_DEV marks a dile descriptor as belonging to a device as oposed to a
125  * filesystem.
126  */
127 
128 #define ALT_FD_EXCL 0x80000000
129 #define ALT_FD_DEV  0x40000000
130 
131 #define ALT_FD_FLAGS_MASK (ALT_FD_EXCL | ALT_FD_DEV)
132 
133 /*
134  * "alt_dev_list" is the head of the linked list of registered devices.
135  */
136 
137 extern alt_llist alt_dev_list;
138 
139 /*
140  * "alt_fs_list" is the head of the linked list of registered filesystems.
141  */
142 
143 extern alt_llist alt_fs_list;
144 
145 /*
146  * "alt_fd_list_lock" is a semaphore used to ensure that access to the pool
147  * of file descriptors is thread safe.
148  */
149 
150 ALT_EXTERN_SEM(alt_fd_list_lock)
151 
152 /*
153  * "alt_max_fd" is a 'high water mark'. It indicates the highest file
154  * descriptor allocated. Use of this can save searching the entire pool
155  * for active file descriptors, which helps avoid contention on access
156  * to the file descriptor pool.
157  */
158 
159 extern alt_32 alt_max_fd;
160 
161 /*
162  * alt_io_redirect() is called at startup to redirect stdout, stdin, and
163  * stderr to the devices named in the input arguments. By default these streams
164  * are directed at /dev/null, and are then redirected using this function once
165  * all of the devices have been registered within the system.
166  */
167 
168 extern void alt_io_redirect(const char* stdout_dev,
169                             const char* stdin_dev,
170                             const char* stderr_dev);
171 
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif /* __ALT_FILE_H__ */
178