fs: return device filesystem is mounted on

This commit is contained in:
Matheus
2024-06-16 12:32:32 -03:00
parent a524d9b48b
commit 5b6d15a06c
5 changed files with 23 additions and 4 deletions
+13 -1
View File
@@ -142,6 +142,8 @@ typedef struct {
vfs_t vfs;
ext2superblock_t superblock;
vnode_t *backing;
int backingmajor;
int backingminor;
size_t blocksize;
size_t bgcount;
ext2node_t *root;
@@ -1043,6 +1045,8 @@ static int ext2_getattr(vnode_t *vnode, vattr_t *attr, cred_t *cred) {
attr->rdevmajor = 0;
attr->rdevminor = 0;
attr->devmajor = ((ext2fs_t *)vnode->vfs)->backingmajor;
attr->devminor = ((ext2fs_t *)vnode->vfs)->backingminor;
attr->uid = node->inode.uid;
attr->gid = node->inode.gid;
attr->inode = node->id;
@@ -1748,10 +1752,18 @@ static int ext2_mount(vfs_t **vfs, vnode_t *mountpoint, vnode_t *backing, void *
MUTEX_INIT(&fs->inodewritelock);
MUTEX_INIT(&fs->descriptorlock);
vattr_t vattr;
int err = VOP_GETATTR(backing, &vattr, NULL);
if (err)
goto cleanup;
fs->backingmajor = vattr.rdevmajor;
fs->backingminor = vattr.rdevminor;
// read superblock
size_t readcount;
int err = vfs_read(backing, &fs->superblock, sizeof(ext2superblock_t), SUPERBLOCK_OFFSET, &readcount, 0);
err = vfs_read(backing, &fs->superblock, sizeof(ext2superblock_t), SUPERBLOCK_OFFSET, &readcount, 0);
if (err)
goto cleanup;
+6 -2
View File
@@ -17,7 +17,8 @@
static scache_t *nodecache;
static tmpfsnode_t *newnode(vfs_t *vfs, int type);
static void freenode(tmpfsnode_t *node);
static vfsops_t vfsops;
static vfsops_t vfsops;
static uintmax_t currid = 1;
static int tmpfs_mount(vfs_t **vfs, vnode_t *mountpoint, vnode_t *backing, void *data) {
tmpfs_t *tmpfs = alloc(sizeof(tmpfs_t));
@@ -26,6 +27,7 @@ static int tmpfs_mount(vfs_t **vfs, vnode_t *mountpoint, vnode_t *backing, void
*vfs = (vfs_t *)tmpfs;
tmpfs->vfs.ops = &vfsops;
tmpfs->id = __atomic_fetch_add(&currid, 1, __ATOMIC_SEQ_CST);
return 0;
}
@@ -37,6 +39,8 @@ static int tmpfs_getattr(vnode_t *node, vattr_t *attr, cred_t *cred) {
tmpfsnode_t *tmpnode = (tmpfsnode_t *)node;
*attr = tmpnode->attr;
attr->blocksused = ROUND_UP(attr->size, PAGE_SIZE) / PAGE_SIZE;
attr->devmajor = 0;
attr->devminor = ((tmpfs_t *)node->vfs)->id;
VOP_UNLOCK(node);
return 0;
}
@@ -310,7 +314,7 @@ static int tmpfs_rename(vnode_t *source, char *oldname, vnode_t *target, char *n
goto cleanup;
}
// same link, rename is a no-op TODO still gotta unlink it though
// same link, rename is a no-op
if (sourcedir == targetdir && strcmp(oldname, newname) == 0)
goto cleanup;
+1
View File
@@ -9,6 +9,7 @@
typedef struct tmpfs_t {
vfs_t vfs;
uintmax_t inodenumber;
uintmax_t id;
} tmpfs_t;
typedef struct tmpfsnode_t {
+2
View File
@@ -38,6 +38,8 @@ typedef struct {
timespec_t ctime;
int rdevmajor;
int rdevminor;
int devmajor;
int devminor;
size_t blocksused;
} vattr_t;
+1 -1
View File
@@ -12,7 +12,7 @@ static int dostat(vnode_t *vnode, stat_t *stat) {
if (e)
return e;
stat->dev = 0; // TODO properly return this
stat->dev = TODEV(attr.devmajor, attr.devminor);
stat->rdev = TODEV(attr.rdevmajor, attr.rdevminor);
stat->ino = attr.inode;
stat->nlink = attr.nlinks;