msdosfsmount.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* $OpenBSD: msdosfsmount.h,v 1.19 2009/01/05 01:14:40 krw Exp $ */
  2. /* $NetBSD: msdosfsmount.h,v 1.16 1997/10/17 11:24:24 ws Exp $ */
  3. /*-
  4. * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
  5. * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
  6. * All rights reserved.
  7. * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by TooLs GmbH.
  20. * 4. The name of TooLs GmbH may not be used to endorse or promote products
  21. * derived from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
  24. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  25. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  26. * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  29. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  31. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  32. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * Written by Paul Popelka (paulp@uts.amdahl.com)
  36. *
  37. * You can do anything you want with this software, just don't say you wrote
  38. * it, and don't remove this notice.
  39. *
  40. * This software is provided "as is".
  41. *
  42. * The author supplies this software to be publicly redistributed on the
  43. * understanding that the author is not responsible for the correct
  44. * functioning of this software in any circumstances and is not liable for
  45. * any damages caused by this software.
  46. *
  47. * October 1992
  48. */
  49. /*
  50. * Layout of the mount control block for a msdos file system.
  51. */
  52. struct msdosfsmount {
  53. struct mount *pm_mountp;/* vfs mount struct for this fs */
  54. dev_t pm_dev; /* block special device mounted */
  55. uid_t pm_uid; /* uid to set as owner of the files */
  56. gid_t pm_gid; /* gid to set as owner of the files */
  57. mode_t pm_mask; /* mask to and with file protection bits */
  58. struct vnode *pm_devvp; /* vnode for block device mntd */
  59. struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */
  60. uint32_t pm_BlkPerSec; /* # of DEV_BSIZE blocks in MSDOSFS sector */
  61. uint32_t pm_FATsecs; /* actual number of fat sectors */
  62. uint32_t pm_fatblk; /* block # of first FAT */
  63. uint32_t pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */
  64. uint32_t pm_rootdirsize; /* size in blocks (not clusters) */
  65. uint32_t pm_firstcluster; /* block number of first cluster */
  66. uint32_t pm_nmbrofclusters; /* # of clusters in filesystem */
  67. uint32_t pm_maxcluster; /* maximum cluster number */
  68. uint32_t pm_freeclustercount; /* number of free clusters */
  69. uint32_t pm_cnshift; /* shift file offset right this amount to get a cluster number */
  70. uint32_t pm_crbomask; /* and a file offset with this mask to get cluster rel offset */
  71. uint32_t pm_bnshift; /* shift file offset right this amount to get a block number */
  72. uint32_t pm_bpcluster; /* bytes per cluster */
  73. uint32_t pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */
  74. uint32_t pm_fatblocksize; /* size of fat blocks in bytes */
  75. uint32_t pm_fatblocksec; /* size of fat blocks in sectors */
  76. uint32_t pm_fatsize; /* size of fat in bytes */
  77. uint32_t pm_fatmask; /* mask to use for fat numbers */
  78. uint32_t pm_fsinfo; /* fsinfo block number */
  79. u_int pm_fatmult; /* these 2 values are used in fat */
  80. u_int pm_fatdiv; /* offset computation */
  81. u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */
  82. u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */
  83. u_int pm_flags; /* see below */
  84. struct netexport pm_export; /* export information */
  85. };
  86. /* Byte offset in FAT on filesystem pmp, cluster cn */
  87. #define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
  88. /*
  89. * Mount point flags:
  90. */
  91. #if 0
  92. /* Defined in <sys/mount.h> */
  93. #define MSDOSFSMNT_SHORTNAME 0x01
  94. #define MSDOSFSMNT_LONGNAME 0x02
  95. #define MSDOSFSMNT_NOWIN95 0x04
  96. #define MSDOSFSMNT_ALLOWDIRX 0x10
  97. #endif
  98. /* All flags above: */
  99. #define MSDOSFSMNT_MNTOPT \
  100. (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
  101. |MSDOSFSMNT_ALLOWDIRX)
  102. #define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */
  103. #define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */
  104. #define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */
  105. #define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data)
  106. /* Number of bits in one pm_inusemap item: */
  107. #define N_INUSEBITS (8 * sizeof(u_int))
  108. /*
  109. * Shorthand for fields in the bpb contained in the msdosfsmount structure.
  110. */
  111. #define pm_BytesPerSec pm_bpb.bpbBytesPerSec
  112. #define pm_ResSectors pm_bpb.bpbResSectors
  113. #define pm_FATs pm_bpb.bpbFATs
  114. #define pm_RootDirEnts pm_bpb.bpbRootDirEnts
  115. #define pm_Sectors pm_bpb.bpbSectors
  116. #define pm_Media pm_bpb.bpbMedia
  117. #define pm_SecPerTrack pm_bpb.bpbSecPerTrack
  118. #define pm_Heads pm_bpb.bpbHeads
  119. #define pm_HiddenSects pm_bpb.bpbHiddenSecs
  120. #define pm_HugeSectors pm_bpb.bpbHugeSectors
  121. /*
  122. * Convert pointer to buffer -> pointer to direntry
  123. */
  124. #define bptoep(pmp, bp, dirofs) \
  125. ((struct direntry *)(((bp)->b_data) \
  126. + ((dirofs) & (pmp)->pm_crbomask)))
  127. /*
  128. * Convert block number to cluster number
  129. */
  130. #define de_bn2cn(pmp, bn) \
  131. ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
  132. /*
  133. * Convert cluster number to block number
  134. */
  135. #define de_cn2bn(pmp, cn) \
  136. ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
  137. /*
  138. * Convert file offset to cluster number
  139. */
  140. #define de_cluster(pmp, off) \
  141. ((off) >> (pmp)->pm_cnshift)
  142. /*
  143. * Clusters required to hold size bytes
  144. */
  145. #define de_clcount(pmp, size) \
  146. (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
  147. /*
  148. * Convert file offset to block number
  149. */
  150. #define de_blk(pmp, off) \
  151. (de_cn2bn(pmp, de_cluster((pmp), (off))))
  152. /*
  153. * Convert cluster number to file offset
  154. */
  155. #define de_cn2off(pmp, cn) \
  156. ((cn) << (pmp)->pm_cnshift)
  157. /*
  158. * Convert block number to file offset
  159. */
  160. #define de_bn2off(pmp, bn) \
  161. ((bn) << (pmp)->pm_bnshift)
  162. /*
  163. * Map a cluster number into a filesystem relative block number.
  164. */
  165. #define cntobn(pmp, cn) \
  166. (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
  167. /*
  168. * Calculate block number for directory entry in root dir, offset dirofs
  169. */
  170. #define roottobn(pmp, dirofs) \
  171. (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
  172. /*
  173. * Calculate block number for directory entry at cluster dirclu, offset
  174. * dirofs
  175. */
  176. #define detobn(pmp, dirclu, dirofs) \
  177. ((dirclu) == MSDOSFSROOT \
  178. ? roottobn((pmp), (dirofs)) \
  179. : cntobn((pmp), (dirclu)))
  180. /* Calculate size of fsinfo block */
  181. #define fsi_size(pmp) \
  182. (1024 << ((pmp)->pm_BlkPerSec >> 2))
  183. /*
  184. * Prototypes for MSDOSFS virtual filesystem operations
  185. */
  186. int msdosfs_mount(struct mount *, const char *, void *, struct nameidata *, struct proc *);
  187. int msdosfs_start(struct mount *, int, struct proc *);
  188. int msdosfs_unmount(struct mount *, int, struct proc *);
  189. int msdosfs_root(struct mount *, struct vnode **);
  190. int msdosfs_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *);
  191. int msdosfs_statfs(struct mount *, struct statfs *, struct proc *);
  192. int msdosfs_sync(struct mount *, int, struct ucred *, struct proc *);
  193. int msdosfs_fhtovp(struct mount *, struct fid *, struct vnode **);
  194. int msdosfs_vptofh(struct vnode *, struct fid *);
  195. int msdosfs_init(struct vfsconf *);