1 /* 2 * Written by Paul Popelka (paulp@uts.amdahl.com) 3 * 4 * You can do anything you want with this software, 5 * just don't say you wrote it, 6 * and don't remove this notice. 7 * 8 * This software is provided "as is". 9 * 10 * The author supplies this software to be publicly 11 * redistributed on the understanding that the author 12 * is not responsible for the correct functioning of 13 * this software in any circumstances and is not liable 14 * for any damages caused by this software. 15 * 16 * October 1992 17 * 18 * $Id: dosfs_mount.h,v 1.1 94/10/19 23:46:50 bill Exp $ 19 * 20 */ 21 22 /* 23 * Layout of the mount control block for a msdos 24 * file system. 25 */ 26 struct pcfsmount { 27 struct mount *pm_mountp; /* vfs mount struct for this fs */ 28 dev_t pm_dev; /* block special device mounted */ 29 struct vnode *pm_devvp; /* vnode for block device mntd */ 30 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ 31 u_long pm_fatblk; /* block # of first FAT */ 32 u_long pm_rootdirblk; /* block # of root directory */ 33 u_long pm_rootdirsize; /* size in blocks (not clusters) */ 34 u_long pm_firstcluster; /* block number of first cluster */ 35 u_long pm_nmbrofclusters; /* # of clusters in filesystem */ 36 u_long pm_maxcluster; /* maximum cluster number */ 37 u_long pm_freeclustercount; /* number of free clusters */ 38 u_long pm_lookhere; /* start free cluster search here */ 39 u_long pm_bnshift; /* shift file offset right this 40 * amount to get a block number */ 41 u_long pm_brbomask; /* and a file offset with this 42 * mask to get block rel offset */ 43 u_long pm_cnshift; /* shift file offset right this 44 * amount to get a cluster number */ 45 u_long pm_crbomask; /* and a file offset with this 46 * mask to get cluster rel offset */ 47 u_long pm_bpcluster; /* bytes per cluster */ 48 u_long pm_depclust; /* directory entries per cluster */ 49 u_long pm_fmod; /* ~0 if fs is modified, this can 50 * rollover to 0 */ 51 u_long pm_fatblocksize; /* size of fat blocks in bytes */ 52 u_long pm_fatblocksec; /* size of fat blocks in sectors */ 53 u_long pm_fatsize; /* size of fat in bytes */ 54 u_char *pm_inusemap; /* ptr to bitmap of in-use clusters */ 55 char pm_ronly; /* read only if non-zero */ 56 char pm_waitonfat; /* wait for writes of the fat to complt, 57 * when 0 use bdwrite, else use bwrite */ 58 }; 59 /* 60 * How to compute pm_cnshift and pm_crbomask. 61 * 62 * pm_crbomask = (pm_SectPerClust * pm_BytesPerSect) - 1 63 * if (bytesperclust == 0) return EBADBLKSZ; 64 * bit = 1; 65 * for (i = 0; i < 32; i++) { 66 * if (bit & bytesperclust) { 67 * if (bit ^ bytesperclust) return EBADBLKSZ; 68 * pm_cnshift = i; 69 * break; 70 * } 71 * bit <<= 1; 72 * } 73 */ 74 75 /* 76 * Shorthand for fields in the bpb contained in 77 * the pcfsmount structure. 78 */ 79 #define pm_BytesPerSec pm_bpb.bpbBytesPerSec 80 #define pm_SectPerClust pm_bpb.bpbSecPerClust 81 #define pm_ResSectors pm_bpb.bpbResSectors 82 #define pm_FATs pm_bpb.bpbFATs 83 #define pm_RootDirEnts pm_bpb.bpbRootDirEnts 84 #define pm_Sectors pm_bpb.bpbSectors 85 #define pm_Media pm_bpb.bpbMedia 86 #define pm_FATsecs pm_bpb.bpbFATsecs 87 #define pm_SecPerTrack pm_bpb.bpbSecPerTrack 88 #define pm_Heads pm_bpb.bpbHeads 89 #define pm_HiddenSects pm_bpb.bpbHiddenSecs 90 #define pm_HugeSectors pm_bpb.bpbHugeSectors 91 92 /* 93 * Map a cluster number into a filesystem relative 94 * block number. 95 */ 96 #define cntobn(pmp, cn) \ 97 ((((cn)-CLUST_FIRST) * (pmp)->pm_SectPerClust) + (pmp)->pm_firstcluster) 98 99 /* 100 * Map a filesystem relative block number back into 101 * a cluster number. 102 */ 103 #define bntocn(pmp, bn) \ 104 ((((bn) - pmp->pm_firstcluster)/ (pmp)->pm_SectPerClust) + CLUST_FIRST) 105 106 /* 107 * Calculate block number for directory entry in root dir, offset dirofs 108 */ 109 #define roottobn(pmp, dirofs) \ 110 (((dirofs) / (pmp)->pm_depclust) * (pmp)->pm_SectPerClust \ 111 + (pmp)->pm_rootdirblk) 112 113 /* 114 * Calculate block number for directory entry at cluster dirclu, offset dirofs 115 */ 116 #define detobn(pmp, dirclu, dirofs) \ 117 ((dirclu) == PCFSROOT \ 118 ? roottobn((pmp), (dirofs)) \ 119 : cntobn((pmp), (dirclu))) 120 121 /* 122 * Convert pointer to buffer -> pointer to direntry 123 */ 124 #define bptoep(pmp, bp, dirofs) \ 125 ((struct direntry *)((bp)->b_un.b_addr) \ 126 + (dirofs) % (pmp)->pm_depclust) 127 128 129 /* 130 * Prototypes for PCFS virtual filesystem operations 131 */ 132 int pcfs_mount __P((struct mount *mp, char *path, caddr_t data, 133 struct nameidata *ndp, struct proc *p)); 134 int pcfs_start __P((struct mount *mp, int flags, struct proc *p)); 135 int pcfs_unmount __P((struct mount *mp, int mntflags, struct proc *p)); 136 int pcfs_root __P((struct mount *mp, struct vnode **vpp)); 137 int pcfs_quotactl __P((struct mount *mp, int cmds, int uid, /* should be uid_t */ 138 caddr_t arg, struct proc *p)); 139 int pcfs_statfs __P((struct mount *mp, struct statfs *sbp, struct proc *p)); 140 int pcfs_sync __P((struct mount *mp, int waitfor)); 141 int pcfs_fhtovp __P((struct mount *mp, struct fid *fhp, struct vnode **vpp)); 142 int pcfs_vptofh __P((struct vnode *vp, struct fid *fhp)); 143 int pcfs_init __P(()); 144