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
make log a bit verbose for some useful information
[lunaix-os.git]
/
lunaix-os
/
kernel
/
fs
/
ramfs
/
ramfs.c
diff --git
a/lunaix-os/kernel/fs/ramfs/ramfs.c
b/lunaix-os/kernel/fs/ramfs/ramfs.c
index 37f8869ac6ca3ec322d3f87e4dc4a610adcaa4a3..b7512e5eefa1f534acafee81bf2b6f005df80a97 100644
(file)
--- a/
lunaix-os/kernel/fs/ramfs/ramfs.c
+++ b/
lunaix-os/kernel/fs/ramfs/ramfs.c
@@
-9,7
+9,7
@@
*
*/
#include <klibc/string.h>
*
*/
#include <klibc/string.h>
-#include <lunaix/fs.h>
+#include <lunaix/fs
/api
.h>
#include <lunaix/fs/ramfs.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/spike.h>
#include <lunaix/fs/ramfs.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/spike.h>
@@
-41,7
+41,7
@@
'mountibility' for other fs.
*/
'mountibility' for other fs.
*/
-
volatile static
inode_t ino = 0;
+
static volatile
inode_t ino = 0;
extern const struct v_inode_ops ramfs_inode_ops;
extern const struct v_file_ops ramfs_file_ops;
extern const struct v_inode_ops ramfs_inode_ops;
extern const struct v_file_ops ramfs_file_ops;
@@
-64,11
+64,10
@@
__ramfs_mknod(struct v_dnode* dnode, struct v_inode** nod_out, u32_t flags)
rinode->flags = flags;
inode->data = rinode;
rinode->flags = flags;
inode->data = rinode;
+ inode->itype = VFS_IFFILE;
if ((flags & RAMF_DIR)) {
if ((flags & RAMF_DIR)) {
- inode->itype = VFS_IFDIR;
- } else {
- inode->itype = VFS_IFFILE;
+ inode->itype |= VFS_IFDIR;
}
if ((flags & RAMF_SYMLINK)) {
}
if ((flags & RAMF_SYMLINK)) {
@@
-88,11
+87,16
@@
__ramfs_mknod(struct v_dnode* dnode, struct v_inode** nod_out, u32_t flags)
int
ramfs_readdir(struct v_file* file, struct dir_context* dctx)
{
int
ramfs_readdir(struct v_file* file, struct dir_context* dctx)
{
-
int i = 0
;
+
unsigned int i = 2
;
struct v_dnode *pos, *n;
struct v_dnode *pos, *n;
+
+ if (fsapi_handle_pseudo_dirent(file, dctx)) {
+ return 1;
+ }
+
llist_for_each(pos, n, &file->dnode->children, siblings)
{
llist_for_each(pos, n, &file->dnode->children, siblings)
{
- if (i++ >=
dctx->index
) {
+ if (i++ >=
file->f_pos
) {
dctx->read_complete_callback(dctx,
pos->name.value,
pos->name.len,
dctx->read_complete_callback(dctx,
pos->name.value,
pos->name.len,
@@
-110,7
+114,7
@@
ramfs_mkdir(struct v_inode* this, struct v_dnode* dnode)
}
int
}
int
-ramfs_create(struct v_inode* this, struct v_dnode* dnode)
+ramfs_create(struct v_inode* this, struct v_dnode* dnode
, unsigned int itype
)
{
return __ramfs_mknod(dnode, NULL, RAMF_FILE);
}
{
return __ramfs_mknod(dnode, NULL, RAMF_FILE);
}
@@
-119,8
+123,8
@@
void
ramfs_inode_init(struct v_superblock* vsb, struct v_inode* inode)
{
inode->id = ino++;
ramfs_inode_init(struct v_superblock* vsb, struct v_inode* inode)
{
inode->id = ino++;
- inode->ops = &ramfs_inode_ops;
- inode->default_fops = &ramfs_file_ops;
+ inode->ops =
(struct v_inode_ops*)
&ramfs_inode_ops;
+ inode->default_fops =
(struct v_file_ops*)
&ramfs_file_ops;
}
int
}
int
@@
-137,16
+141,6
@@
ramfs_unmount(struct v_superblock* vsb)
return 0;
}
return 0;
}
-void
-ramfs_init()
-{
- struct filesystem* ramfs = fsm_new_fs("ramfs", -1);
- ramfs->mount = ramfs_mount;
- ramfs->unmount = ramfs_unmount;
-
- fsm_register(ramfs);
-}
-
int
ramfs_mksymlink(struct v_inode* this, const char* target)
{
int
ramfs_mksymlink(struct v_inode* this, const char* target)
{
@@
-154,7
+148,7
@@
ramfs_mksymlink(struct v_inode* this, const char* target)
assert(!(rinode->flags & RAMF_SYMLINK));
assert(!(rinode->flags & RAMF_SYMLINK));
- size_t len = strlen(target);
+ size_t len = strlen(target)
+ 1
;
char* symlink = valloc(len);
if (!symlink) {
char* symlink = valloc(len);
if (!symlink) {
@@
-163,9
+157,10
@@
ramfs_mksymlink(struct v_inode* this, const char* target)
memcpy(symlink, target, len);
memcpy(symlink, target, len);
- this->itype
|
= VFS_IFSYMLINK;
+ this->itype = VFS_IFSYMLINK;
rinode->flags |= RAMF_SYMLINK;
rinode->symlink = symlink;
rinode->flags |= RAMF_SYMLINK;
rinode->symlink = symlink;
+ rinode->size = len;
return 0;
}
return 0;
}
@@
-181,19
+176,21
@@
ramfs_read_symlink(struct v_inode* this, const char** path_out)
*path_out = rinode->symlink;
*path_out = rinode->symlink;
- return
0
;
+ return
rinode->size
;
}
int
}
int
-ramfs_unlink(struct v_inode* this)
+ramfs_unlink(struct v_inode* this
, struct v_dnode* name
)
{
struct ram_inode* rinode = RAM_INODE(this->data);
if ((rinode->flags & RAMF_SYMLINK)) {
rinode->flags &= ~RAMF_SYMLINK;
{
struct ram_inode* rinode = RAM_INODE(this->data);
if ((rinode->flags & RAMF_SYMLINK)) {
rinode->flags &= ~RAMF_SYMLINK;
- this->itype &= ~VFS_IFSYMLINK;
+ this->itype &= ~F_SYMLINK;
+
vfree(rinode->symlink);
vfree(rinode->symlink);
- return;
+
+ return 0;
}
// TODO
}
// TODO
@@
-201,6
+198,17
@@
ramfs_unlink(struct v_inode* this)
return 0;
}
return 0;
}
+static void
+ramfs_init()
+{
+ struct filesystem* fs;
+ fs = fsapi_fs_declare("ramfs", FSTYPE_PSEUDO);
+
+ fsapi_fs_set_mntops(fs, ramfs_mount, ramfs_unmount);
+ fsapi_fs_finalise(fs);
+}
+EXPORT_FILE_SYSTEM(ramfs, ramfs_init);
+
const struct v_inode_ops ramfs_inode_ops = { .mkdir = ramfs_mkdir,
.rmdir = default_inode_rmdir,
.dir_lookup =
const struct v_inode_ops ramfs_inode_ops = { .mkdir = ramfs_mkdir,
.rmdir = default_inode_rmdir,
.dir_lookup =
@@
-215,7
+223,8
@@
const struct v_inode_ops ramfs_inode_ops = { .mkdir = ramfs_mkdir,
const struct v_file_ops ramfs_file_ops = { .readdir = ramfs_readdir,
.close = default_file_close,
.read = default_file_read,
const struct v_file_ops ramfs_file_ops = { .readdir = ramfs_readdir,
.close = default_file_close,
.read = default_file_read,
- .read_page = default_file_read,
+ .read_page = default_file_read
_page
,
.write = default_file_write,
.write = default_file_write,
- .write_page = default_file_write,
+ .write_page =
+ default_file_write_page,
.seek = default_file_seek };
\ No newline at end of file
.seek = default_file_seek };
\ No newline at end of file