git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rewrite the device subsystem interfaces (#48)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
device
/
devfs.c
diff --git
a/lunaix-os/kernel/device/devfs.c
b/lunaix-os/kernel/device/devfs.c
index 28f923ab411d2aad16cf7cc4eb862f4177d8f56d..c105f66a71bbed5072e6544de25b3bea75b9c27e 100644
(file)
--- a/
lunaix-os/kernel/device/devfs.c
+++ b/
lunaix-os/kernel/device/devfs.c
@@
-65,17
+65,21
@@
devfs_write_page(struct v_inode* inode, void* buffer, size_t fpos)
}
int
}
int
-devfs_get_itype(
struct device_meta* dm
)
+devfs_get_itype(
morph_t* obj
)
{
int itype = VFS_IFDEV;
{
int itype = VFS_IFDEV;
- if (
valid_device_subtype_ref(dm, DEV_CAT
)) {
+ if (
morph_type_of(obj, devcat_morpher
)) {
return VFS_IFDIR;
}
return VFS_IFDIR;
}
- struct device* dev = resolve_device(dm);
- int dev_if = dev->dev_type & DEV_MSKIF;
+ struct device* dev = resolve_device(obj);
+
+ if (!dev) {
+ return itype;
+ }
+ int dev_if = dev->dev_type & DEV_MSKIF;
if (dev_if == DEV_IFVOL) {
itype |= VFS_IFVOLDEV;
}
if (dev_if == DEV_IFVOL) {
itype |= VFS_IFVOLDEV;
}
@@
-84,26
+88,38
@@
devfs_get_itype(struct device_meta* dm)
return itype;
}
return itype;
}
-int
-devfs_get_dtype(
struct device_meta* dev
)
+
static inline
int
+devfs_get_dtype(
morph_t* dev_morph
)
{
{
- if (
valid_device_subtype_ref(dev, DEV_CAT
)) {
+ if (
morph_type_of(dev_morph, devcat_morpher
)) {
return DT_DIR;
}
return DT_FILE;
}
return DT_DIR;
}
return DT_FILE;
}
+static inline morph_t*
+__try_resolve(struct v_inode* inode)
+{
+ if (!inode->data) {
+ return dev_object_root;
+ }
+
+ return resolve_device_morph(inode->data);
+}
+
int
int
-devfs_mknod(struct v_dnode* dnode,
struct device_meta* dev
)
+devfs_mknod(struct v_dnode* dnode,
morph_t* obj
)
{
{
- assert(dev);
+ struct v_inode* devnod;
+
+ assert(obj);
-
struct v_inode* devnod = vfs_i_find(dnode->super_block, dev->dev_uid
);
+
devnod = vfs_i_find(dnode->super_block, morpher_uid(obj)
);
if (!devnod) {
if ((devnod = vfs_i_alloc(dnode->super_block))) {
if (!devnod) {
if ((devnod = vfs_i_alloc(dnode->super_block))) {
- devnod->id =
dev->dev_uid
;
- devnod->data =
dev
;
- devnod->itype = devfs_get_itype(
dev
);
+ devnod->id =
morpher_uid(obj)
;
+ devnod->data =
changeling_ref(obj)
;
+ devnod->itype = devfs_get_itype(
obj
);
vfs_i_addhash(devnod);
} else {
vfs_i_addhash(devnod);
} else {
@@
-118,30
+134,28
@@
devfs_mknod(struct v_dnode* dnode, struct device_meta* dev)
int
devfs_dirlookup(struct v_inode* this, struct v_dnode* dnode)
{
int
devfs_dirlookup(struct v_inode* this, struct v_dnode* dnode)
{
- void* data = this->data;
- struct device_meta* rootdev = resolve_device_meta(data);
+ morph_t *mobj, *root;
- if (data && !rootdev) {
+ root = __try_resolve(this);
+ if (!root) {
return ENOTDIR;
}
return ENOTDIR;
}
- struct device_meta* dev =
- device_getbyhname(rootdev, &dnode->name);
-
- if (!dev) {
+ mobj = changeling_find(root, &dnode->name);
+ if (!mobj) {
return ENOENT;
}
return ENOENT;
}
- return devfs_mknod(dnode,
dev
);
+ return devfs_mknod(dnode,
mobj
);
}
int
devfs_readdir(struct v_file* file, struct dir_context* dctx)
{
}
int
devfs_readdir(struct v_file* file, struct dir_context* dctx)
{
- void* data = file->inode->data;
- struct device_meta* rootdev = resolve_device_meta(data);
+ morph_t *mobj, *root;
- if (data && !rootdev) {
+ root = __try_resolve(file->inode);
+ if (!root) {
return ENOTDIR;
}
return ENOTDIR;
}
@@
-149,15
+163,14
@@
devfs_readdir(struct v_file* file, struct dir_context* dctx)
return 1;
}
return 1;
}
- struct device_meta* dev =
- device_getbyoffset(rootdev, file->f_pos - 2);
-
- if (!dev) {
+ mobj = changeling_get_at(root, file->f_pos - 2);
+ if (!mobj) {
return 0;
}
return 0;
}
- dctx->read_complete_callback(
- dctx, dev->name.value, dev->name.len, devfs_get_dtype(dev));
+ dctx->read_complete_callback(dctx,
+ mobj->name.value, mobj->name.len,
+ devfs_get_dtype(mobj));
return 1;
}
return 1;
}