fix: corner cases when printing large content through term interface
[lunaix-os.git] / lunaix-os / kernel / fs / mount.c
index 084a400a1993000a09f7a770fa844a3ec21f5927..2b996d413c8b304dfb6e7efc71454ddbd9a8c226 100644 (file)
@@ -33,7 +33,7 @@ vfs_create_mount(struct v_mount* parent, struct v_dnode* mnt_point)
         llist_append(&parent->submnts, &mnt->sibmnts);
         mutex_unlock(&mnt->parent->lock);
     }
-
+    
     atomic_fetch_add(&mnt_point->ref_count, 1);
 
     return mnt;
@@ -63,8 +63,10 @@ __vfs_do_unmount(struct v_mount* mnt)
 
     mnt_chillax(mnt->parent);
 
+    mnt->mnt_point->mnt = mnt->parent;
+
     vfs_sb_free(sb);
-    vfs_d_free(mnt->mnt_point);
+    atomic_fetch_sub(&mnt->mnt_point->ref_count, 1);
     vfree(mnt);
 
     return errno;
@@ -249,6 +251,11 @@ __DEFINE_LXSYSCALL4(int,
         goto done;
     }
 
+    if (mnt->mnt->mnt_point == mnt) {
+        errno = EBUSY;
+        goto done;
+    }
+
     // By our convention.
     // XXX could we do better?
     struct device* device = NULL;