source: trunk/kernel/fs/devfs/devfs_context.c @ 10

Last change on this file since 10 was 9, checked in by alain, 8 years ago

Bloup

File size: 2.6 KB
Line 
1/*
2 * devfs/devfs_context.c - devfs context related operations
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <chdev.h>
24#include <driver.h>
25#include <kmem.h>
26#include <string.h>
27#include <vfs.h>
28#include <errno.h>
29#include <metafs.h>
30#include <cpu.h>
31
32#include <devfs.h>
33#include <devfs-private.h>
34
35
36struct devfs_db_s devfs_db;
37
38void devfs_root_init(void)
39{
40        spinlock_init(&devfs_db.lock, "DevFs DB");
41
42        metafs_init(&devfs_db.root, 
43#if CONFIG_ROOTFS_IS_VFAT
44                    "DEV"
45#else
46                    "dev"
47#endif
48                );
49}
50
51void devfs_register(struct device_s *dev)
52{
53        spinlock_lock(&devfs_db.lock);
54        metafs_register(&devfs_db.root, &dev->node);
55        spinlock_unlock(&devfs_db.lock);
56}
57
58
59VFS_CREATE_CONTEXT(devfs_create_context)
60{
61        struct devfs_context_s *ctx;
62 
63        VFS_SET(context->ctx_flags, VFS_FS_LOCAL);
64        context->ctx_type    = FS_TYPE_DEVFS;
65        context->ctx_op      = (struct vfs_context_op_s *) &devfs_ctx_op;
66        context->ctx_inode_op = (struct vfs_inode_op_s *) &devfs_i_op;
67        context->ctx_file_op = (struct vfs_file_op_s *) &devfs_f_op;
68
69        ctx     = &context->ctx_devfs;
70        ctx->db = &devfs_db.root;
71
72        return 0;
73}
74
75VFS_DESTROY_CONTEXT(devfs_destroy_context)
76{
77        return 0;
78}
79
80VFS_READ_ROOT(devfs_read_root)
81{ 
82        root->i_links = 1;
83        root->i_size  = 0;
84        root->i_attr  = VFS_DIR;
85        root->i_number = vfs_inum_new(context);
86 
87        return 0;
88}
89
90VFS_WRITE_ROOT(devfs_write_root)
91{
92        return 0;
93}
94
95KMEM_OBJATTR_INIT(devfs_kmem_context_init)
96{
97        attr->type   = KMEM_DEVFS_CTX;
98        attr->name   = "KCM DevFs CTX";
99        attr->size   = sizeof(struct devfs_context_s);
100        attr->aligne = 0;
101        attr->min    = CONFIG_DEVFS_CTX_MIN;
102        attr->max    = CONFIG_DEVFS_CTX_MAX;
103        attr->ctor   = NULL;
104        attr->dtor   = NULL;
105        return 0;
106}
107
108
109const struct vfs_context_op_s devfs_ctx_op = 
110{
111        .create     = devfs_create_context,
112        .destroy    = devfs_destroy_context,
113        .read_root  = devfs_read_root,
114        .repli_root = NULL,
115        .write_root = devfs_write_root
116};
Note: See TracBrowser for help on using the repository browser.