[RFC 1/3] ramfs: add foofs for testing
Alexander Aring
alex.aring at gmail.com
Fri Feb 28 02:44:26 EST 2014
Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
fs/ramfs.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/fs/ramfs.c b/fs/ramfs.c
index f45a454..4b93c2e 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -608,6 +608,48 @@ static int ramfs_probe(struct device_d *dev)
return 0;
}
+static int foofs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
+{
+ if (f->pos == strlen("Hello World!\n"))
+ return 0;
+
+ return sprintf(buf, "%s", "Hello World!\n");
+}
+
+static int foofs_probe(struct device_d *dev)
+{
+ struct ramfs_inode *n;
+ struct ramfs_priv *priv = xzalloc(sizeof(struct ramfs_priv));
+
+ dev->priv = priv;
+
+ priv->root.name = "/";
+ priv->root.mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
+ priv->root.parent = &priv->root;
+ n = ramfs_get_inode();
+ n->name = strdup(".");
+ n->mode = S_IFDIR;
+ n->parent = &priv->root;
+ n->child = n;
+ priv->root.child = n;
+ n = ramfs_get_inode();
+ n->name = strdup("..");
+ n->mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
+ n->parent = &priv->root;
+ n->child = priv->root.child;
+ priv->root.child->next = n;
+
+ /* just for test zero file read */
+ n = ramfs_get_inode();
+ n->name = strdup("foobar");
+ n->mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
+ n->parent = &priv->root;
+ n->child = priv->root.child;
+ priv->root.child->next = n;
+
+ return 0;
+}
+
static void ramfs_remove(struct device_d *dev)
{
free(dev->priv);
@@ -638,8 +680,35 @@ static struct fs_driver_d ramfs_driver = {
}
};
+static struct fs_driver_d foofs_driver = {
+ .create = ramfs_create,
+ .unlink = ramfs_unlink,
+ .open = ramfs_open,
+ .close = ramfs_close,
+ .truncate = ramfs_truncate,
+ .read = foofs_read,
+ .write = ramfs_write,
+ .lseek = ramfs_lseek,
+ .mkdir = ramfs_mkdir,
+ .rmdir = ramfs_rmdir,
+ .opendir = ramfs_opendir,
+ .readdir = ramfs_readdir,
+ .closedir = ramfs_closedir,
+ .stat = ramfs_stat,
+ .symlink = ramfs_symlink,
+ .readlink = ramfs_readlink,
+ .flags = FS_DRIVER_NO_DEV,
+ .drv = {
+ .probe = foofs_probe,
+ .remove = ramfs_remove,
+ .name = "foofs",
+ }
+};
+
+
static int ramfs_init(void)
{
+ register_fs_driver(&foofs_driver);
return register_fs_driver(&ramfs_driver);
}
--
1.9.0
More information about the barebox
mailing list