FreeBSD/sys/fs/msdosfs/msdosfs_vnops.c
/*
 * Create a regular file. On entry the directory to contain the file being
 * created is locked.  We must release before we return. We must also free
 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
 * only if the SAVESTART bit in cn_flags is clear on success.
 */
Create a regular file. On entry the directory to contain the file being
created is locked.  We must release before we return. We must also free
the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
only if the SAVESTART bit in cn_flags is clear on success.
Create a regular file . On entry the directory to contain the file being created is locked . We must release before we return . We must also free the pathname buffer pointed at by cnp - > cn_pnbuf always on error or only if the SAVESTART bit in cn_flags is clear on success .
static int
msdosfs_create(struct vop_create_args *ap)
{
	struct componentname *cnp = ap->a_cnp;
	struct denode ndirent;
	struct denode *dep;
	struct denode *pdep = VTODE(ap->a_dvp);
	struct timespec ts;
	int error;
#ifdef MSDOSFS_DEBUG
	printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
#endif
	if (pdep->de_StartCluster == MSDOSFSROOT
	    && pdep->de_fndoffset >= pdep->de_FileSize) {
		error = ENOSPC;
		goto bad;
	}
#ifdef DIAGNOSTIC
	if ((cnp->cn_flags & HASBUF) == 0)
		panic("msdosfs_create: no name");
#endif
	bzero(&ndirent, sizeof(ndirent));
	error = uniqdosname(pdep, cnp, ndirent.de_Name);
	if (error)
		goto bad;
	ndirent.de_Attributes = ATTR_ARCHIVE;
	ndirent.de_LowerCase = 0;
	ndirent.de_StartCluster = 0;
	ndirent.de_FileSize = 0;
	ndirent.de_pmp = pdep->de_pmp;
	ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
	getnanotime(&ts);
	DETIMES(&ndirent, &ts, &ts, &ts);
	error = createde(&ndirent, pdep, &dep, cnp);
	if (error)
		goto bad;
	*ap->a_vpp = DETOV(dep);
	if ((cnp->cn_flags & MAKEENTRY) != 0)
		cache_enter(ap->a_dvp, *ap->a_vpp, cnp);
	return (0);
bad:
	return (error);
}
static int msdosfs_create ( struct vop_create_args * ap ) { struct componentname * cnp = ap -> a_cnp ; struct denode ndirent ; struct denode * dep ; struct denode * pdep = VTODE ( ap -> a_dvp ) ; struct timespec ts ; int error ; #ifdef MSDOSFS_DEBUG printf ( " \n " , cnp , ap -> a_vap ) ; #endif if ( pdep -> de_StartCluster == MSDOSFSROOT && pdep -> de_fndoffset >= pdep -> de_FileSize ) { error = ENOSPC ; goto bad ; } #ifdef DIAGNOSTIC if ( ( cnp -> cn_flags & HASBUF ) == 0 ) panic ( " " ) ; #endif bzero ( & ndirent , sizeof ( ndirent ) ) ; error = uniqdosname ( pdep , cnp , ndirent . de_Name ) ; if ( error ) goto bad ; ndirent . de_Attributes = ATTR_ARCHIVE ; ndirent . de_LowerCase = 0 ; ndirent . de_StartCluster = 0 ; ndirent . de_FileSize = 0 ; ndirent . de_pmp = pdep -> de_pmp ; ndirent . de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE ; getnanotime ( & ts ) ; DETIMES ( & ndirent , & ts , & ts , & ts ) ; error = createde ( & ndirent , pdep , & dep , cnp ) ; if ( error ) goto bad ; * ap -> a_vpp = DETOV ( dep ) ; if ( ( cnp -> cn_flags & MAKEENTRY ) != 0 ) cache_enter ( ap -> a_dvp , * ap -> a_vpp , cnp ) ; return ( 0 ) ; bad : return ( error ) ; }
Create a regular file.
Create a regular file .
/*
	 * If this is the root directory and there is no space left we
	 * can't do anything.  This is because the root directory can not
	 * change size.
	 */ /*
	 * Create a directory entry for the file, then call createde() to
	 * have it installed. NOTE: DOS files are always executable.  We
	 * use the absence of the owner write bit to make the file
	 * readonly.
	 */