/* DF-3019 - devfs_spec_open clone path: EPERM after clone leaks the cloned
 * vp exclusively locked+referenced forever. Root raises securelevel=2, then
 * opens cloned D_DISK (vn) FWRITE -> expect EPERM; each attempt burns a
 * vnode permanently (observable via debug.numvnodes ratchet).
 */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/sysctl.h>
int main(int argc,char**argv){
    int n=argc>1?atoi(argv[1]):10; char out[64];
    for(int i=0;i<n;i++){
        errno=0;
        int fd=open("/dev/vn",O_WRONLY);
        printf("open#%d fd=%d errno=%d (%s)\n",i,fd,errno,fd>=0?"OPENED-W":strerror(errno));
        if(fd>=0) close(fd);
    }
    return 0;
}
