OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [fileio/] [v2_0/] [src/] [devfs.cxx] - Blame information for rev 773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      devfs.cxx
4
//
5
//      Fileio device filesystem
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):           nickg
44
// Contributors:        nickg
45
// Date:                2000-05-25
46
// Purpose:             Fileio device filesystem
47
// Description:         This file implements a simple filesystem that interfaces
48
//                      to the existing device IO subsystem.
49
//                      
50
//              
51
//              
52
//
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
 
57
#include <pkgconf/hal.h>
58
#include <pkgconf/kernel.h>
59
#include <pkgconf/io_fileio.h>
60
 
61
#include <cyg/kernel/ktypes.h>         // base kernel types
62
#include <cyg/infra/cyg_trac.h>        // tracing macros
63
#include <cyg/infra/cyg_ass.h>         // assertion macros
64
 
65
#include "fio.h"                       // Private header
66
 
67
#include <cyg/io/devtab.h>              // device subsystem
68
#include <cyg/io/config_keys.h>         // CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN
69
 
70
//==========================================================================
71
// Forward definitions
72
 
73
// Filesystem operations
74
static int dev_mount    ( cyg_fstab_entry *fste, cyg_mtab_entry *mte );
75
static int dev_umount   ( cyg_mtab_entry *mte );
76
static int dev_open     ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
77
                          int mode,  cyg_file *fte );
78
static int dev_unlink   ( cyg_mtab_entry *mte, cyg_dir dir, const char *name );
79
static int dev_mkdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name );
80
static int dev_rmdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name );
81
static int dev_rename   ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1,
82
                          cyg_dir dir2, const char *name2 );
83
static int dev_link     ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1,
84
                          cyg_dir dir2, const char *name2, int type );
85
static int dev_opendir  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
86
                          cyg_file *fte );
87
static int dev_chdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
88
                          cyg_dir *dir_out );
89
static int dev_stat     ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
90
                          struct stat *buf);
91
static int dev_getinfo  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
92
                          int key, void *buf, int len );
93
static int dev_setinfo  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
94
                          int key, void *buf, int len );
95
 
96
// File operations
97
static int dev_fo_read      (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
98
static int dev_fo_write     (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
99
static int dev_fo_lseek     (struct CYG_FILE_TAG *fp, off_t *pos, int whence );
100
static int dev_fo_ioctl     (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com,
101
                             CYG_ADDRWORD data);
102
static int dev_fo_select    (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info);
103
static int dev_fo_fsync     (struct CYG_FILE_TAG *fp, int mode );
104
static int dev_fo_close     (struct CYG_FILE_TAG *fp);
105
static int dev_fo_fstat     (struct CYG_FILE_TAG *fp, struct stat *buf );
106
static int dev_fo_getinfo   (struct CYG_FILE_TAG *fp, int key, void *buf, int len );
107
static int dev_fo_setinfo   (struct CYG_FILE_TAG *fp, int key, void *buf, int len );
108
 
109
 
110
//==========================================================================
111
// Filesystem table entries
112
 
113
FSTAB_ENTRY( dev_fste, "devfs", 0,
114
             CYG_SYNCMODE_NONE,         // dev system has its own sync mechanism
115
             dev_mount,
116
             dev_umount,
117
             dev_open,
118
             dev_unlink,
119
             dev_mkdir,
120
             dev_rmdir,
121
             dev_rename,
122
             dev_link,
123
             dev_opendir,
124
             dev_chdir,
125
             dev_stat,
126
             dev_getinfo,
127
             dev_setinfo);
128
 
129
MTAB_ENTRY( dev_mte,
130
                   "/dev",
131
                   "devfs",
132
                   "",
133
                   0);
134
 
135
static cyg_fileops dev_fileops =
136
{
137
    dev_fo_read,
138
    dev_fo_write,
139
    dev_fo_lseek,
140
    dev_fo_ioctl,
141
    dev_fo_select,
142
    dev_fo_fsync,
143
    dev_fo_close,
144
    dev_fo_fstat,
145
    dev_fo_getinfo,
146
    dev_fo_setinfo
147
};
148
 
149
//==========================================================================
150
// Filesystem operations
151
 
152
// -------------------------------------------------------------------------
153
 
154
static int dev_mount    ( cyg_fstab_entry *fste, cyg_mtab_entry *mte )
155
{
156
    // Nothing to do here. The device IO subsystem has already initialized
157
    // iteslf, and the fileio infrastructure will do the rest.
158
 
159
    return 0;
160
}
161
 
162
// -------------------------------------------------------------------------
163
 
164
static int dev_umount   ( cyg_mtab_entry *mte )
165
{
166
    // Nothing to do here.
167
 
168
    return 0;
169
}
170
 
171
// -------------------------------------------------------------------------
172
 
173
static int dev_open     ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
174
                          int mode,  cyg_file *file )
175
{
176
    Cyg_ErrNo err;
177
    cyg_io_handle_t handle;
178
 
179
    // The name we are passed will point to the first character after
180
    // "/dev/". We know that the full string contains the prefix string,
181
    // so we back the pointer up by 5 chars.
182
    // A better approach would be for the device table entries to only
183
    // contain the part of the string after the prefix.
184
 
185
    name -= 5;
186
 
187
    err = cyg_io_lookup( name, &handle );
188
 
189
    if( err < 0 )
190
        return -err;
191
 
192
    // If we want non-blocking mode, configure the device for it.
193
    if( (mode & (O_NONBLOCK|O_RDONLY)) == (O_NONBLOCK|O_RDONLY) )
194
    {
195
        cyg_uint32 f = 0;
196
        cyg_uint32 fsize = sizeof(f);
197
        err = cyg_io_set_config( handle, CYG_IO_SET_CONFIG_READ_BLOCKING,
198
                                 (void *)&f, &fsize);
199
        if( err < 0 )
200
            return -err;
201
    }
202
 
203
    if( (mode & (O_NONBLOCK|O_WRONLY)) == (O_NONBLOCK|O_WRONLY) )
204
    {
205
        cyg_uint32 f = 0;
206
        cyg_uint32 fsize = sizeof(f);
207
        err = cyg_io_set_config( handle, CYG_IO_SET_CONFIG_WRITE_BLOCKING,
208
                                 (void *)&f, &fsize);
209
        if( err < 0 )
210
            return -err;
211
    }
212
 
213
    // Initialize the file object
214
 
215
    file->f_flag |= mode & CYG_FILE_MODE_MASK;
216
    file->f_type = CYG_FILE_TYPE_FILE;
217
    file->f_ops = &dev_fileops;
218
    file->f_offset = 0;
219
    file->f_data = (CYG_ADDRWORD)handle;
220
    file->f_xops = 0;
221
 
222
    return 0;
223
}
224
 
225
// -------------------------------------------------------------------------
226
 
227
static int dev_unlink   ( cyg_mtab_entry *mte, cyg_dir dir, const char *name )
228
{
229
    return EROFS;
230
}
231
 
232
// -------------------------------------------------------------------------
233
 
234
static int dev_mkdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name )
235
{
236
    return EROFS;
237
}
238
 
239
// -------------------------------------------------------------------------
240
 
241
static int dev_rmdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name )
242
{
243
    return EROFS;
244
}
245
 
246
// -------------------------------------------------------------------------
247
 
248
static int dev_rename   ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1,
249
                          cyg_dir dir2, const char *name2 )
250
{
251
    return EROFS;
252
}
253
 
254
// -------------------------------------------------------------------------
255
 
256
static int dev_link     ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1,
257
                          cyg_dir dir2, const char *name2, int type )
258
{
259
    return EROFS;
260
}
261
 
262
// -------------------------------------------------------------------------
263
 
264
static int dev_opendir  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
265
                          cyg_file *fte )
266
{
267
    return ENOTDIR;
268
}
269
 
270
// -------------------------------------------------------------------------
271
 
272
static int dev_chdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
273
                          cyg_dir *dir_out )
274
{
275
    return ENOTDIR;
276
}
277
 
278
// -------------------------------------------------------------------------
279
 
280
static int dev_stat     ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
281
                          struct stat *buf)
282
{
283
    Cyg_ErrNo err;
284
    cyg_io_handle_t handle;
285
 
286
    name -= 5;          // See comment in dev_open()
287
 
288
    err = cyg_io_lookup( name, &handle );
289
 
290
    if( err < 0 )
291
        return -err;
292
 
293
    // Just fill in the stat buffer with some constant values.
294
 
295
    // FIXME: change this when block devices are available
296
    buf->st_mode = __stat_mode_CHR;
297
 
298
    buf->st_ino         = (ino_t)handle;    // map dev handle to inode
299
    buf->st_dev         = 0; // (dev_t)handle;    // same with dev id
300
    buf->st_nlink       = 0;
301
    buf->st_uid         = 0;
302
    buf->st_gid         = 0;
303
    buf->st_size        = 0;
304
    buf->st_atime       = 0;
305
    buf->st_mtime       = 0;
306
    buf->st_ctime       = 0;
307
 
308
    return ENOERR;
309
}
310
 
311
// -------------------------------------------------------------------------
312
 
313
static int dev_getinfo  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
314
                          int key, void *buf, int len )
315
{
316
    return ENOSYS;
317
}
318
 
319
// -------------------------------------------------------------------------
320
 
321
static int dev_setinfo  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
322
                          int key, void *buf, int len )
323
{
324
    return ENOSYS;
325
}
326
 
327
//==========================================================================
328
// File operations
329
 
330
 
331
// -------------------------------------------------------------------------
332
 
333
static int dev_fo_read      (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
334
{
335
    Cyg_ErrNo err = 0;
336
    int i;
337
 
338
    // Now loop over the iovecs until they are all done, or
339
    // we get an error.
340
    for( i = 0; i < uio->uio_iovcnt; i++ )
341
    {
342
        cyg_iovec *iov = &uio->uio_iov[i];
343
        cyg_uint32 len = iov->iov_len;
344
        cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)fp->f_data;
345
 
346
        if (t->status & CYG_DEVTAB_STATUS_BLOCK)
347
            err = cyg_io_bread( (cyg_io_handle_t)t,
348
                                iov->iov_base,
349
                                &len, fp->f_offset);
350
        else
351
            err = cyg_io_read( (cyg_io_handle_t)t,
352
                               iov->iov_base,
353
                               &len);
354
 
355
        if( -EAGAIN == err ) // must be in non-blocking mode
356
        {
357
            uio->uio_resid -= len;
358
            return ENOERR;
359
        }
360
        if( err < 0 ) break;
361
 
362
        uio->uio_resid -= len;
363
    }
364
 
365
    return -err;
366
}
367
 
368
// -------------------------------------------------------------------------
369
 
370
static int dev_fo_write     (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
371
{
372
    Cyg_ErrNo err = 0;
373
    int i;
374
 
375
    // Now loop over the iovecs until they are all done, or
376
    // we get an error.
377
    for( i = 0; i < uio->uio_iovcnt; i++ )
378
    {
379
        cyg_iovec *iov = &uio->uio_iov[i];
380
        cyg_uint32 len = iov->iov_len;
381
        cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)fp->f_data;
382
 
383
        if (t->status & CYG_DEVTAB_STATUS_BLOCK)
384
            err = cyg_io_bwrite( (cyg_io_handle_t)t,
385
                                 iov->iov_base,
386
                                 &len, fp->f_offset);
387
        else
388
            err = cyg_io_write( (cyg_io_handle_t)t,
389
                                iov->iov_base,
390
                                &len);
391
 
392
        if( -EAGAIN == err ) // must be in non-blocking mode
393
        {
394
            uio->uio_resid -= len;
395
            return ENOERR;
396
        }
397
        if( err < 0 ) break;
398
 
399
        uio->uio_resid -= len;
400
    }
401
 
402
    return -err;
403
}
404
 
405
// -------------------------------------------------------------------------
406
 
407
static int dev_fo_lseek     (struct CYG_FILE_TAG *fp, off_t *pos, int whence )
408
{
409
    // All current devices have no notion of position. Just return zero
410
    // as the new position.
411
 
412
    *pos = 0;
413
 
414
    return ENOERR;
415
}
416
 
417
// -------------------------------------------------------------------------
418
 
419
static int dev_fo_ioctl     (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com,
420
                             CYG_ADDRWORD data)
421
{
422
    return ENOSYS;
423
}
424
 
425
// -------------------------------------------------------------------------
426
 
427
static cyg_bool dev_fo_select    (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info)
428
{
429
    return cyg_io_select( (cyg_io_handle_t)fp->f_data,
430
                          which,
431
                          info);
432
}
433
 
434
// -------------------------------------------------------------------------
435
 
436
static int dev_fo_fsync     (struct CYG_FILE_TAG *fp, int mode )
437
{
438
    Cyg_ErrNo err;
439
 
440
    err = cyg_io_get_config((cyg_io_handle_t)fp->f_data,
441
                            CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN,
442
                            NULL, NULL);
443
 
444
    return -err;
445
}
446
 
447
// -------------------------------------------------------------------------
448
 
449
static int dev_fo_close     (struct CYG_FILE_TAG *fp)
450
{
451
    return ENOERR;
452
}
453
 
454
// -------------------------------------------------------------------------
455
 
456
static int dev_fo_fstat     (struct CYG_FILE_TAG *fp, struct stat *buf )
457
{
458
    // Just fill in the stat buffer with some constant values.
459
 
460
    // FIXME: change this when block devices are available
461
    buf->st_mode = __stat_mode_CHR;
462
 
463
    buf->st_ino         = (ino_t)fp->f_data;    // map dev handle to inode
464
    buf->st_dev         = (dev_t)fp->f_data;    // same with dev id
465
    buf->st_nlink       = 0;
466
    buf->st_uid         = 0;
467
    buf->st_gid         = 0;
468
    buf->st_size        = 0;
469
    buf->st_atime       = 0;
470
    buf->st_mtime       = 0;
471
    buf->st_ctime       = 0;
472
 
473
    return ENOERR;
474
}
475
 
476
// -------------------------------------------------------------------------
477
 
478
static int dev_fo_getinfo   (struct CYG_FILE_TAG *fp, int key, void *buf, int len )
479
{
480
    Cyg_ErrNo err = 0;
481
    cyg_uint32 ll = len;
482
 
483
    err = cyg_io_get_config( (cyg_io_handle_t)fp->f_data, key, buf, &ll );
484
 
485
    return -err;
486
}
487
 
488
// -------------------------------------------------------------------------
489
 
490
static int dev_fo_setinfo   (struct CYG_FILE_TAG *fp, int key, void *buf, int len )
491
{
492
    Cyg_ErrNo err = 0;
493
    cyg_uint32 ll = len;
494
 
495
    err = cyg_io_set_config( (cyg_io_handle_t)fp->f_data, key, buf, &ll );
496
 
497
    return -err;
498
}
499
 
500
// -------------------------------------------------------------------------
501
// EOF devfs.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.