Print this page
7653 tmpfs: calling unlink() on a directory which isn't empty should fail


1088         struct vnode *dvp,
1089         char *nm,
1090         struct cred *cred,
1091         caller_context_t *ct,
1092         int flags)
1093 {
1094         struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1095         int error;
1096         struct tmpnode *tp = NULL;
1097 
1098         error = tdirlookup(parent, nm, &tp, cred);
1099         if (error)
1100                 return (error);
1101 
1102         ASSERT(tp);
1103         rw_enter(&parent->tn_rwlock, RW_WRITER);
1104         rw_enter(&tp->tn_rwlock, RW_WRITER);
1105 
1106         if (tp->tn_type != VDIR ||
1107             (error = secpolicy_fs_linkdir(cred, dvp->v_vfsp)) == 0)
1108                 error = tdirdelete(parent, tp, nm, tp->tn_type == VDIR ?
1109                     DR_RMDIR : DR_REMOVE, cred);
1110 
1111         rw_exit(&tp->tn_rwlock);
1112         rw_exit(&parent->tn_rwlock);
1113         vnevent_remove(TNTOV(tp), dvp, nm, ct);
1114         tmpnode_rele(tp);
1115 
1116         TRACE_3(TR_FAC_TMPFS, TR_TMPFS_REMOVE,
1117             "tmpfs remove:dvp %p nm %s error %d", dvp, nm, error);
1118         return (error);
1119 }
1120 
1121 /* ARGSUSED4 */
1122 static int
1123 tmp_link(
1124         struct vnode *dvp,
1125         struct vnode *srcvp,
1126         char *tnm,
1127         struct cred *cred,
1128         caller_context_t *ct,
1129         int flags)


1408         }
1409         if (self->tn_type != VDIR) {
1410                 error = ENOTDIR;
1411                 goto done1;
1412         }
1413 
1414         mutex_enter(&self->tn_tlock);
1415         if (self->tn_nlink > 2) {
1416                 mutex_exit(&self->tn_tlock);
1417                 error = EEXIST;
1418                 goto done1;
1419         }
1420         mutex_exit(&self->tn_tlock);
1421 
1422         if (vn_vfswlock(vp)) {
1423                 error = EBUSY;
1424                 goto done1;
1425         }
1426         if (vn_mountedvfs(vp) != NULL) {
1427                 error = EBUSY;
1428                 goto done;
1429         }
1430 
1431         /*
1432          * Check for an empty directory
1433          * i.e. only includes entries for "." and ".."
1434          */
1435         if (self->tn_dirents > 2) {
1436                 error = EEXIST;         /* SIGH should be ENOTEMPTY */
1437                 /*
1438                  * Update atime because checking tn_dirents is logically
1439                  * equivalent to reading the directory
1440                  */
1441                 gethrestime(&self->tn_atime);
1442                 goto done;
1443         }
1444 
1445         error = tdirdelete(parent, self, nm, DR_RMDIR, cred);
1446 done:
1447         vn_vfsunlock(vp);
1448 done1:
1449         rw_exit(&self->tn_rwlock);
1450         rw_exit(&parent->tn_rwlock);
1451         vnevent_rmdir(TNTOV(self), dvp, nm, ct);
1452         tmpnode_rele(self);
1453 
1454         return (error);
1455 }
1456 
1457 /* ARGSUSED2 */
1458 static int
1459 tmp_readdir(
1460         struct vnode *vp,
1461         struct uio *uiop,




1088         struct vnode *dvp,
1089         char *nm,
1090         struct cred *cred,
1091         caller_context_t *ct,
1092         int flags)
1093 {
1094         struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1095         int error;
1096         struct tmpnode *tp = NULL;
1097 
1098         error = tdirlookup(parent, nm, &tp, cred);
1099         if (error)
1100                 return (error);
1101 
1102         ASSERT(tp);
1103         rw_enter(&parent->tn_rwlock, RW_WRITER);
1104         rw_enter(&tp->tn_rwlock, RW_WRITER);
1105 
1106         if (tp->tn_type != VDIR ||
1107             (error = secpolicy_fs_linkdir(cred, dvp->v_vfsp)) == 0)
1108                 error = tdirdelete(parent, tp, nm, DR_REMOVE, cred);

1109 
1110         rw_exit(&tp->tn_rwlock);
1111         rw_exit(&parent->tn_rwlock);
1112         vnevent_remove(TNTOV(tp), dvp, nm, ct);
1113         tmpnode_rele(tp);
1114 
1115         TRACE_3(TR_FAC_TMPFS, TR_TMPFS_REMOVE,
1116             "tmpfs remove:dvp %p nm %s error %d", dvp, nm, error);
1117         return (error);
1118 }
1119 
1120 /* ARGSUSED4 */
1121 static int
1122 tmp_link(
1123         struct vnode *dvp,
1124         struct vnode *srcvp,
1125         char *tnm,
1126         struct cred *cred,
1127         caller_context_t *ct,
1128         int flags)


1407         }
1408         if (self->tn_type != VDIR) {
1409                 error = ENOTDIR;
1410                 goto done1;
1411         }
1412 
1413         mutex_enter(&self->tn_tlock);
1414         if (self->tn_nlink > 2) {
1415                 mutex_exit(&self->tn_tlock);
1416                 error = EEXIST;
1417                 goto done1;
1418         }
1419         mutex_exit(&self->tn_tlock);
1420 
1421         if (vn_vfswlock(vp)) {
1422                 error = EBUSY;
1423                 goto done1;
1424         }
1425         if (vn_mountedvfs(vp) != NULL) {
1426                 error = EBUSY;














1427                 goto done;
1428         }
1429 
1430         error = tdirdelete(parent, self, nm, DR_RMDIR, cred);
1431 done:
1432         vn_vfsunlock(vp);
1433 done1:
1434         rw_exit(&self->tn_rwlock);
1435         rw_exit(&parent->tn_rwlock);
1436         vnevent_rmdir(TNTOV(self), dvp, nm, ct);
1437         tmpnode_rele(self);
1438 
1439         return (error);
1440 }
1441 
1442 /* ARGSUSED2 */
1443 static int
1444 tmp_readdir(
1445         struct vnode *vp,
1446         struct uio *uiop,