Home | History | Annotate | Line # | Download | only in msdos
      1   1.1  christos /*-
      2   1.1  christos  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
      3   1.1  christos  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
      4   1.1  christos  * All rights reserved.
      5   1.1  christos  * Original code by Paul Popelka (paulp (at) uts.amdahl.com) (see below).
      6   1.1  christos  *
      7   1.1  christos  * Redistribution and use in source and binary forms, with or without
      8   1.1  christos  * modification, are permitted provided that the following conditions
      9   1.1  christos  * are met:
     10   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  christos  *    documentation and/or other materials provided with the distribution.
     15   1.1  christos  * 3. All advertising materials mentioning features or use of this software
     16   1.1  christos  *    must display the following acknowledgement:
     17   1.1  christos  *	This product includes software developed by TooLs GmbH.
     18   1.1  christos  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     19   1.1  christos  *    derived from this software without specific prior written permission.
     20   1.1  christos  *
     21   1.1  christos  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     22   1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1  christos  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25   1.1  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26   1.1  christos  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     27   1.1  christos  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     28   1.1  christos  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     29   1.1  christos  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     30   1.1  christos  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1  christos  */
     32   1.1  christos /*
     33   1.1  christos  * Written by Paul Popelka (paulp (at) uts.amdahl.com)
     34   1.1  christos  *
     35   1.1  christos  * You can do anything you want with this software, just don't say you wrote
     36   1.1  christos  * it, and don't remove this notice.
     37   1.1  christos  *
     38   1.1  christos  * This software is provided "as is".
     39   1.1  christos  *
     40   1.1  christos  * The author supplies this software to be publicly redistributed on the
     41   1.1  christos  * understanding that the author is not responsible for the correct
     42   1.1  christos  * functioning of this software in any circumstances and is not liable for
     43   1.1  christos  * any damages caused by this software.
     44   1.1  christos  *
     45   1.1  christos  * October 1992
     46   1.1  christos  */
     47   1.1  christos 
     48   1.1  christos #if HAVE_NBTOOL_CONFIG_H
     49   1.1  christos #include "nbtool_config.h"
     50   1.1  christos #endif
     51   1.1  christos 
     52   1.1  christos #include <sys/cdefs.h>
     53  1.13  riastrad __KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.13 2022/04/09 10:05:35 riastradh Exp $");
     54   1.1  christos 
     55   1.1  christos #include <sys/param.h>
     56   1.1  christos 
     57   1.1  christos #include <ffs/buf.h>
     58   1.1  christos 
     59   1.1  christos #include <fs/msdosfs/bpb.h>
     60   1.1  christos #include <fs/msdosfs/bootsect.h>
     61   1.1  christos #include <fs/msdosfs/direntry.h>
     62   1.1  christos #include <fs/msdosfs/denode.h>
     63   1.1  christos #include <fs/msdosfs/msdosfsmount.h>
     64   1.1  christos #include <fs/msdosfs/fat.h>
     65   1.1  christos 
     66   1.1  christos #include <stdio.h>
     67   1.1  christos #include <errno.h>
     68   1.1  christos #include <stdlib.h>
     69   1.1  christos #include <string.h>
     70   1.6  christos #include <util.h>
     71  1.11     sevan #include <strings.h>
     72   1.2  christos 
     73   1.2  christos #include "makefs.h"
     74   1.1  christos #include "msdos.h"
     75   1.1  christos #include "mkfs_msdos.h"
     76   1.1  christos 
     77   1.1  christos #ifdef MSDOSFS_DEBUG
     78   1.1  christos #define DPRINTF(a) printf a
     79   1.1  christos #else
     80   1.1  christos #define DPRINTF(a)
     81   1.1  christos #endif
     82   1.1  christos 
     83   1.1  christos struct msdosfsmount *
     84   1.1  christos msdosfs_mount(struct vnode *devvp, int flags)
     85   1.1  christos {
     86   1.1  christos 	struct msdosfsmount *pmp = NULL;
     87   1.1  christos 	struct buf *bp;
     88   1.1  christos 	union bootsector *bsp;
     89   1.1  christos 	struct byte_bpb33 *b33;
     90   1.1  christos 	struct byte_bpb50 *b50;
     91   1.1  christos 	struct byte_bpb710 *b710;
     92   1.1  christos 	uint8_t SecPerClust;
     93   1.1  christos 	int	ronly = 0, error, tmp;
     94   1.1  christos 	int	bsize;
     95   1.7  christos 	struct msdos_options *m = devvp->fs->fs_specific;
     96   1.1  christos 	uint64_t psize = m->create_size;
     97   1.1  christos 	unsigned secsize = 512;
     98   1.1  christos 
     99   1.4  christos 	DPRINTF(("%s(bread 0)\n", __func__));
    100   1.9       agc 	if ((error = bread(devvp, 0, secsize, 0, &bp)) != 0)
    101   1.1  christos 		goto error_exit;
    102   1.1  christos 
    103   1.1  christos 	bsp = (union bootsector *)bp->b_data;
    104   1.1  christos 	b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
    105   1.1  christos 	b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
    106   1.1  christos 	b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB;
    107   1.1  christos 
    108   1.1  christos 	if (!(flags & MSDOSFSMNT_GEMDOSFS)) {
    109   1.1  christos 		if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
    110   1.1  christos 		    || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
    111  1.13  riastrad 			DPRINTF(("bootsig0 %d bootsig1 %d\n",
    112   1.1  christos 			    bsp->bs50.bsBootSectSig0,
    113   1.1  christos 			    bsp->bs50.bsBootSectSig1));
    114   1.1  christos 			error = EINVAL;
    115   1.1  christos 			goto error_exit;
    116   1.1  christos 		}
    117   1.1  christos 		bsize = 0;
    118   1.1  christos 	} else
    119   1.1  christos 		bsize = 512;
    120   1.1  christos 
    121   1.6  christos 	pmp = ecalloc(1, sizeof *pmp);
    122   1.1  christos 	/*
    123   1.1  christos 	 * Compute several useful quantities from the bpb in the
    124   1.1  christos 	 * bootsector.  Copy in the dos 5 variant of the bpb then fix up
    125   1.1  christos 	 * the fields that are different between dos 5 and dos 3.3.
    126   1.1  christos 	 */
    127   1.1  christos 	SecPerClust = b50->bpbSecPerClust;
    128   1.1  christos 	pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
    129   1.1  christos 	pmp->pm_ResSectors = getushort(b50->bpbResSectors);
    130   1.1  christos 	pmp->pm_FATs = b50->bpbFATs;
    131   1.1  christos 	pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
    132   1.1  christos 	pmp->pm_Sectors = getushort(b50->bpbSectors);
    133   1.1  christos 	pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
    134   1.1  christos 	pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
    135   1.1  christos 	pmp->pm_Heads = getushort(b50->bpbHeads);
    136   1.1  christos 	pmp->pm_Media = b50->bpbMedia;
    137   1.1  christos 
    138   1.4  christos 	DPRINTF(("%s(BytesPerSec=%u, ResSectors=%u, FATs=%d, RootDirEnts=%u, "
    139   1.4  christos 	    "Sectors=%u, FATsecs=%lu, SecPerTrack=%u, Heads=%u, Media=%u)\n",
    140   1.4  christos 	    __func__, pmp->pm_BytesPerSec, pmp->pm_ResSectors, pmp->pm_FATs,
    141   1.4  christos 	    pmp->pm_RootDirEnts, pmp->pm_Sectors, pmp->pm_FATsecs,
    142   1.4  christos 	    pmp->pm_SecPerTrack, pmp->pm_Heads, pmp->pm_Media));
    143   1.1  christos 	if (!(flags & MSDOSFSMNT_GEMDOSFS)) {
    144   1.1  christos 		/* XXX - We should probably check more values here */
    145   1.1  christos     		if (!pmp->pm_BytesPerSec || !SecPerClust
    146   1.1  christos 	    		|| pmp->pm_SecPerTrack > 63) {
    147   1.1  christos 			DPRINTF(("bytespersec %d secperclust %d "
    148  1.13  riastrad 			    "secpertrack %d\n",
    149   1.1  christos 			    pmp->pm_BytesPerSec, SecPerClust,
    150   1.1  christos 			    pmp->pm_SecPerTrack));
    151   1.1  christos 			error = EINVAL;
    152   1.1  christos 			goto error_exit;
    153   1.1  christos 		}
    154   1.1  christos 	}
    155   1.1  christos 
    156  1.10   mlelstv 	pmp->pm_flags = flags & MSDOSFSMNT_MNTOPT;
    157  1.10   mlelstv 	if (pmp->pm_flags & MSDOSFSMNT_GEMDOSFS)
    158  1.10   mlelstv 		pmp->pm_flags |= MSDOSFSMNT_NOWIN95;
    159  1.10   mlelstv 	if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
    160  1.10   mlelstv 		pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
    161  1.10   mlelstv 
    162   1.1  christos 	if (pmp->pm_Sectors == 0) {
    163   1.1  christos 		pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
    164   1.1  christos 		pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
    165   1.1  christos 	} else {
    166   1.1  christos 		pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
    167   1.1  christos 		pmp->pm_HugeSectors = pmp->pm_Sectors;
    168   1.1  christos 	}
    169   1.1  christos 
    170   1.1  christos 	if (pmp->pm_RootDirEnts == 0) {
    171   1.1  christos 		unsigned short vers = getushort(b710->bpbFSVers);
    172   1.1  christos 		/*
    173   1.1  christos 		 * Some say that bsBootSectSig[23] must be zero, but
    174   1.1  christos 		 * Windows does not require this and some digital cameras
    175   1.1  christos 		 * do not set these to zero.  Therefore, do not insist.
    176   1.1  christos 		 */
    177   1.1  christos 		if (pmp->pm_Sectors || pmp->pm_FATsecs || vers) {
    178   1.1  christos 			DPRINTF(("sectors %d fatsecs %lu vers %d\n",
    179   1.1  christos 			    pmp->pm_Sectors, pmp->pm_FATsecs, vers));
    180   1.1  christos 			error = EINVAL;
    181   1.1  christos 			goto error_exit;
    182   1.1  christos 		}
    183   1.1  christos 		pmp->pm_fatmask = FAT32_MASK;
    184   1.1  christos 		pmp->pm_fatmult = 4;
    185   1.1  christos 		pmp->pm_fatdiv = 1;
    186   1.1  christos 		pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
    187   1.1  christos 
    188   1.1  christos 		/* mirrorring is enabled if the FATMIRROR bit is not set */
    189   1.1  christos 		if ((getushort(b710->bpbExtFlags) & FATMIRROR) == 0)
    190   1.1  christos 			pmp->pm_flags |= MSDOSFS_FATMIRROR;
    191   1.1  christos 		else
    192   1.1  christos 			pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
    193   1.1  christos 	} else
    194   1.1  christos 		pmp->pm_flags |= MSDOSFS_FATMIRROR;
    195   1.1  christos 
    196   1.1  christos 	if (flags & MSDOSFSMNT_GEMDOSFS) {
    197   1.1  christos 		if (FAT32(pmp)) {
    198   1.1  christos 			DPRINTF(("FAT32 for GEMDOS\n"));
    199   1.1  christos 			/*
    200   1.1  christos 			 * GEMDOS doesn't know FAT32.
    201   1.1  christos 			 */
    202   1.1  christos 			error = EINVAL;
    203   1.1  christos 			goto error_exit;
    204   1.1  christos 		}
    205   1.1  christos 
    206   1.1  christos 		/*
    207   1.1  christos 		 * Check a few values (could do some more):
    208   1.1  christos 		 * - logical sector size: power of 2, >= block size
    209   1.1  christos 		 * - sectors per cluster: power of 2, >= 1
    210   1.1  christos 		 * - number of sectors:   >= 1, <= size of partition
    211   1.1  christos 		 */
    212   1.1  christos 		if ( (SecPerClust == 0)
    213   1.1  christos 		  || (SecPerClust & (SecPerClust - 1))
    214   1.1  christos 		  || (pmp->pm_BytesPerSec < bsize)
    215   1.1  christos 		  || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
    216   1.1  christos 		  || (pmp->pm_HugeSectors == 0)
    217   1.1  christos 		  || (pmp->pm_HugeSectors * (pmp->pm_BytesPerSec / bsize)
    218   1.1  christos 		      > psize)) {
    219   1.1  christos 			DPRINTF(("consistency checks for GEMDOS\n"));
    220   1.1  christos 			error = EINVAL;
    221   1.1  christos 			goto error_exit;
    222   1.1  christos 		}
    223   1.1  christos 		/*
    224   1.1  christos 		 * XXX - Many parts of the msdosfs driver seem to assume that
    225   1.1  christos 		 * the number of bytes per logical sector (BytesPerSec) will
    226   1.1  christos 		 * always be the same as the number of bytes per disk block
    227   1.1  christos 		 * Let's pretend it is.
    228   1.1  christos 		 */
    229   1.1  christos 		tmp = pmp->pm_BytesPerSec / bsize;
    230   1.1  christos 		pmp->pm_BytesPerSec  = bsize;
    231   1.1  christos 		pmp->pm_HugeSectors *= tmp;
    232   1.1  christos 		pmp->pm_HiddenSects *= tmp;
    233   1.1  christos 		pmp->pm_ResSectors  *= tmp;
    234   1.1  christos 		pmp->pm_Sectors     *= tmp;
    235   1.1  christos 		pmp->pm_FATsecs     *= tmp;
    236   1.1  christos 		SecPerClust         *= tmp;
    237   1.1  christos 	}
    238   1.1  christos 
    239   1.1  christos 	/* Check that fs has nonzero FAT size */
    240   1.1  christos 	if (pmp->pm_FATsecs == 0) {
    241   1.1  christos 		DPRINTF(("FATsecs is 0\n"));
    242   1.1  christos 		error = EINVAL;
    243   1.1  christos 		goto error_exit;
    244   1.1  christos 	}
    245   1.1  christos 
    246   1.1  christos 	pmp->pm_fatblk = pmp->pm_ResSectors;
    247   1.1  christos 	if (FAT32(pmp)) {
    248   1.1  christos 		pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
    249   1.1  christos 		pmp->pm_firstcluster = pmp->pm_fatblk
    250   1.1  christos 			+ (pmp->pm_FATs * pmp->pm_FATsecs);
    251   1.1  christos 		pmp->pm_fsinfo = getushort(b710->bpbFSInfo);
    252   1.1  christos 	} else {
    253   1.1  christos 		pmp->pm_rootdirblk = pmp->pm_fatblk +
    254   1.1  christos 			(pmp->pm_FATs * pmp->pm_FATsecs);
    255   1.1  christos 		pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
    256   1.1  christos 				       + pmp->pm_BytesPerSec - 1)
    257   1.1  christos 			/ pmp->pm_BytesPerSec;/* in sectors */
    258   1.1  christos 		pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
    259   1.1  christos 	}
    260   1.1  christos 
    261   1.1  christos 	pmp->pm_nmbrofclusters = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
    262   1.1  christos 	    SecPerClust;
    263   1.1  christos 	pmp->pm_maxcluster = pmp->pm_nmbrofclusters + 1;
    264   1.1  christos 	pmp->pm_fatsize = pmp->pm_FATsecs * pmp->pm_BytesPerSec;
    265   1.1  christos 
    266   1.1  christos 	if (flags & MSDOSFSMNT_GEMDOSFS) {
    267   1.1  christos 		if (pmp->pm_nmbrofclusters <= (0xff0 - 2)) {
    268   1.1  christos 			pmp->pm_fatmask = FAT12_MASK;
    269   1.1  christos 			pmp->pm_fatmult = 3;
    270   1.1  christos 			pmp->pm_fatdiv = 2;
    271   1.1  christos 		} else {
    272   1.1  christos 			pmp->pm_fatmask = FAT16_MASK;
    273   1.1  christos 			pmp->pm_fatmult = 2;
    274   1.1  christos 			pmp->pm_fatdiv = 1;
    275   1.1  christos 		}
    276   1.1  christos 	} else if (pmp->pm_fatmask == 0) {
    277   1.1  christos 		if (pmp->pm_maxcluster
    278   1.1  christos 		    <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
    279   1.1  christos 			/*
    280   1.1  christos 			 * This will usually be a floppy disk. This size makes
    281   1.1  christos 			 * sure that one FAT entry will not be split across
    282   1.1  christos 			 * multiple blocks.
    283   1.1  christos 			 */
    284   1.1  christos 			pmp->pm_fatmask = FAT12_MASK;
    285   1.1  christos 			pmp->pm_fatmult = 3;
    286   1.1  christos 			pmp->pm_fatdiv = 2;
    287   1.1  christos 		} else {
    288   1.1  christos 			pmp->pm_fatmask = FAT16_MASK;
    289   1.1  christos 			pmp->pm_fatmult = 2;
    290   1.1  christos 			pmp->pm_fatdiv = 1;
    291   1.1  christos 		}
    292   1.1  christos 	}
    293   1.1  christos 	if (FAT12(pmp))
    294   1.1  christos 		pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
    295   1.1  christos 	else
    296   1.1  christos 		pmp->pm_fatblocksize = MAXBSIZE;
    297   1.1  christos 
    298   1.1  christos 	pmp->pm_fatblocksec = pmp->pm_fatblocksize / pmp->pm_BytesPerSec;
    299   1.1  christos 	pmp->pm_bnshift = ffs(pmp->pm_BytesPerSec) - 1;
    300   1.1  christos 
    301   1.1  christos 	/*
    302   1.1  christos 	 * Compute mask and shift value for isolating cluster relative byte
    303   1.1  christos 	 * offsets and cluster numbers from a file offset.
    304   1.1  christos 	 */
    305   1.1  christos 	pmp->pm_bpcluster = SecPerClust * pmp->pm_BytesPerSec;
    306   1.1  christos 	pmp->pm_crbomask = pmp->pm_bpcluster - 1;
    307   1.1  christos 	pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
    308   1.1  christos 
    309   1.5  christos 	DPRINTF(("%s(fatmask=%lu, fatmult=%u, fatdiv=%u, fatblocksize=%lu, "
    310   1.5  christos 	    "fatblocksec=%lu, bnshift=%lu, pbcluster=%lu, crbomask=%lu, "
    311   1.5  christos 	    "cnshift=%lu)\n",
    312   1.5  christos 	    __func__, pmp->pm_fatmask, pmp->pm_fatmult, pmp->pm_fatdiv,
    313   1.5  christos 	    pmp->pm_fatblocksize, pmp->pm_fatblocksec, pmp->pm_bnshift,
    314   1.5  christos 	    pmp->pm_bpcluster, pmp->pm_crbomask, pmp->pm_cnshift));
    315   1.1  christos 	/*
    316   1.1  christos 	 * Check for valid cluster size
    317   1.1  christos 	 * must be a power of 2
    318   1.1  christos 	 */
    319   1.1  christos 	if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
    320  1.13  riastrad 		DPRINTF(("bpcluster %lu cnshift %lu\n",
    321   1.1  christos 		    pmp->pm_bpcluster, pmp->pm_cnshift));
    322   1.1  christos 		error = EINVAL;
    323   1.1  christos 		goto error_exit;
    324   1.1  christos 	}
    325   1.1  christos 
    326   1.1  christos 	/*
    327   1.1  christos 	 * Release the bootsector buffer.
    328   1.1  christos 	 */
    329   1.1  christos 	brelse(bp, BC_AGE);
    330   1.1  christos 	bp = NULL;
    331   1.1  christos 
    332   1.1  christos 	/*
    333   1.1  christos 	 * Check FSInfo.
    334   1.1  christos 	 */
    335   1.1  christos 	if (pmp->pm_fsinfo) {
    336   1.1  christos 		struct fsinfo *fp;
    337   1.1  christos 
    338   1.1  christos 		/*
    339   1.1  christos 		 * XXX	If the fsinfo block is stored on media with
    340   1.1  christos 		 *	2KB or larger sectors, is the fsinfo structure
    341   1.1  christos 		 *	padded at the end or in the middle?
    342   1.1  christos 		 */
    343   1.4  christos 		DPRINTF(("%s(bread %lu)\n", __func__,
    344   1.4  christos 		    (unsigned long)de_bn2kb(pmp, pmp->pm_fsinfo)));
    345   1.1  christos 		if ((error = bread(devvp, de_bn2kb(pmp, pmp->pm_fsinfo),
    346   1.9       agc 		    pmp->pm_BytesPerSec, 0, &bp)) != 0)
    347   1.1  christos 			goto error_exit;
    348   1.1  christos 		fp = (struct fsinfo *)bp->b_data;
    349   1.1  christos 		if (!memcmp(fp->fsisig1, "RRaA", 4)
    350   1.1  christos 		    && !memcmp(fp->fsisig2, "rrAa", 4)
    351   1.1  christos 		    && !memcmp(fp->fsisig3, "\0\0\125\252", 4)
    352   1.1  christos 		    && !memcmp(fp->fsisig4, "\0\0\125\252", 4))
    353   1.1  christos 			pmp->pm_nxtfree = getulong(fp->fsinxtfree);
    354   1.1  christos 		else
    355   1.1  christos 			pmp->pm_fsinfo = 0;
    356   1.1  christos 		brelse(bp, 0);
    357   1.1  christos 		bp = NULL;
    358   1.1  christos 	}
    359   1.1  christos 
    360   1.1  christos 	/*
    361   1.1  christos 	 * Check and validate (or perhaps invalidate?) the fsinfo structure?
    362   1.1  christos 	 * XXX
    363   1.1  christos 	 */
    364   1.1  christos 	if (pmp->pm_fsinfo) {
    365   1.1  christos 		if ((pmp->pm_nxtfree == 0xffffffffUL) ||
    366   1.1  christos 		    (pmp->pm_nxtfree > pmp->pm_maxcluster))
    367   1.1  christos 			pmp->pm_fsinfo = 0;
    368   1.1  christos 	}
    369   1.1  christos 
    370   1.1  christos 	/*
    371   1.1  christos 	 * Allocate memory for the bitmap of allocated clusters, and then
    372   1.1  christos 	 * fill it in.
    373   1.1  christos 	 */
    374   1.6  christos 	pmp->pm_inusemap = ecalloc(sizeof(*pmp->pm_inusemap),
    375   1.4  christos 	    ((pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS));
    376   1.1  christos 	/*
    377   1.1  christos 	 * fillinusemap() needs pm_devvp.
    378   1.1  christos 	 */
    379   1.1  christos 	pmp->pm_dev = 0;
    380   1.1  christos 	pmp->pm_devvp = devvp;
    381   1.1  christos 
    382   1.1  christos 	/*
    383   1.1  christos 	 * Have the inuse map filled in.
    384   1.1  christos 	 */
    385  1.12   thorpej 	if ((error = msdosfs_fillinusemap(pmp)) != 0) {
    386   1.1  christos 		DPRINTF(("fillinusemap %d\n", error));
    387   1.1  christos 		goto error_exit;
    388   1.1  christos 	}
    389   1.1  christos 
    390   1.1  christos 	/*
    391   1.1  christos 	 * Finish up.
    392   1.1  christos 	 */
    393   1.1  christos 	if (ronly)
    394   1.1  christos 		pmp->pm_flags |= MSDOSFSMNT_RONLY;
    395   1.1  christos 	else
    396   1.1  christos 		pmp->pm_fmod = 1;
    397   1.1  christos 
    398   1.1  christos 	/*
    399   1.1  christos 	 * If we ever do quotas for DOS filesystems this would be a place
    400   1.1  christos 	 * to fill in the info in the msdosfsmount structure. You dolt,
    401   1.1  christos 	 * quotas on dos filesystems make no sense because files have no
    402   1.1  christos 	 * owners on dos filesystems. of course there is some empty space
    403   1.1  christos 	 * in the directory entry where we could put uid's and gid's.
    404   1.1  christos 	 */
    405   1.1  christos 
    406   1.1  christos 	return pmp;
    407   1.1  christos 
    408   1.1  christos error_exit:
    409   1.1  christos 	if (bp)
    410   1.1  christos 		brelse(bp, BC_AGE);
    411   1.1  christos 	if (pmp) {
    412   1.1  christos 		if (pmp->pm_inusemap)
    413   1.1  christos 			free(pmp->pm_inusemap);
    414   1.1  christos 		free(pmp);
    415   1.1  christos 	}
    416   1.1  christos 	errno = error;
    417   1.8      maxv 	return NULL;
    418   1.1  christos }
    419   1.1  christos 
    420   1.1  christos int
    421   1.1  christos msdosfs_root(struct msdosfsmount *pmp, struct vnode *vp) {
    422   1.1  christos 	struct denode *ndep;
    423   1.1  christos 	int error;
    424   1.1  christos 
    425   1.1  christos 	*vp = *pmp->pm_devvp;
    426  1.12   thorpej 	if ((error = msdosfs_deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS,
    427  1.12   thorpej 	    &ndep)) != 0) {
    428   1.1  christos 		errno = error;
    429   1.1  christos 		return -1;
    430   1.1  christos 	}
    431   1.1  christos 	vp->v_data = ndep;
    432   1.1  christos 	return 0;
    433   1.1  christos }
    434