Deleted Added
full compact
msdosfsmount.h (12338) msdosfsmount.h (13765)
1/* $Id: msdosfsmount.h,v 1.4 1995/11/07 14:06:45 phk Exp $ */
1/* $Id: msdosfsmount.h,v 1.5 1995/11/16 11:48:10 bde Exp $ */
2/* $NetBSD: msdosfsmount.h,v 1.7 1994/08/21 18:44:17 ws Exp $ */
3
4/*-
5 * Copyright (C) 1994 Wolfgang Solfrank.
6 * Copyright (C) 1994 TooLs GmbH.
7 * All rights reserved.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/*
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
37 *
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
40 *
41 * This software is provided "as is".
42 *
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
47 *
48 * October 1992
49 */
50
51/*
52 * Layout of the mount control block for a msdos file system.
53 */
54struct msdosfsmount {
55 struct mount *pm_mountp;/* vfs mount struct for this fs */
56 dev_t pm_dev; /* block special device mounted */
57 uid_t pm_mounter; /* uid of the user who mounted the FS */
58 uid_t pm_uid; /* uid to set as owner of the files */
59 gid_t pm_gid; /* gid to set as owner of the files */
60 mode_t pm_mask; /* mask to and with file protection bits */
61 struct vnode *pm_devvp; /* vnode for block device mntd */
62 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */
63 u_long pm_fatblk; /* block # of first FAT */
64 u_long pm_rootdirblk; /* block # of root directory */
65 u_long pm_rootdirsize; /* size in blocks (not clusters) */
66 u_long pm_firstcluster; /* block number of first cluster */
67 u_long pm_nmbrofclusters; /* # of clusters in filesystem */
68 u_long pm_maxcluster; /* maximum cluster number */
69 u_long pm_freeclustercount; /* number of free clusters */
70 u_long pm_bnshift; /* shift file offset right this amount to get a block number */
71 u_long pm_brbomask; /* and a file offset with this mask to get block rel offset */
72 u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */
73 u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */
74 u_long pm_bpcluster; /* bytes per cluster */
75 u_long pm_depclust; /* directory entries per cluster */
76 u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */
77 u_long pm_fatblocksize; /* size of fat blocks in bytes */
78 u_long pm_fatblocksec; /* size of fat blocks in sectors */
79 u_long pm_fatsize; /* size of fat in bytes */
80 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */
81 char pm_ronly; /* read only if non-zero */
2/* $NetBSD: msdosfsmount.h,v 1.7 1994/08/21 18:44:17 ws Exp $ */
3
4/*-
5 * Copyright (C) 1994 Wolfgang Solfrank.
6 * Copyright (C) 1994 TooLs GmbH.
7 * All rights reserved.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/*
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
37 *
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
40 *
41 * This software is provided "as is".
42 *
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
47 *
48 * October 1992
49 */
50
51/*
52 * Layout of the mount control block for a msdos file system.
53 */
54struct msdosfsmount {
55 struct mount *pm_mountp;/* vfs mount struct for this fs */
56 dev_t pm_dev; /* block special device mounted */
57 uid_t pm_mounter; /* uid of the user who mounted the FS */
58 uid_t pm_uid; /* uid to set as owner of the files */
59 gid_t pm_gid; /* gid to set as owner of the files */
60 mode_t pm_mask; /* mask to and with file protection bits */
61 struct vnode *pm_devvp; /* vnode for block device mntd */
62 struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */
63 u_long pm_fatblk; /* block # of first FAT */
64 u_long pm_rootdirblk; /* block # of root directory */
65 u_long pm_rootdirsize; /* size in blocks (not clusters) */
66 u_long pm_firstcluster; /* block number of first cluster */
67 u_long pm_nmbrofclusters; /* # of clusters in filesystem */
68 u_long pm_maxcluster; /* maximum cluster number */
69 u_long pm_freeclustercount; /* number of free clusters */
70 u_long pm_bnshift; /* shift file offset right this amount to get a block number */
71 u_long pm_brbomask; /* and a file offset with this mask to get block rel offset */
72 u_long pm_cnshift; /* shift file offset right this amount to get a cluster number */
73 u_long pm_crbomask; /* and a file offset with this mask to get cluster rel offset */
74 u_long pm_bpcluster; /* bytes per cluster */
75 u_long pm_depclust; /* directory entries per cluster */
76 u_long pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */
77 u_long pm_fatblocksize; /* size of fat blocks in bytes */
78 u_long pm_fatblocksec; /* size of fat blocks in sectors */
79 u_long pm_fatsize; /* size of fat in bytes */
80 u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */
81 char pm_ronly; /* read only if non-zero */
82 char pm_waitonfat; /* wait for writes of the fat to complt, when 0 use bdwrite, else use bwrite */
82 char pm_waitonfat; /* wait for writes of the fat to complete, when 0 use bdwrite, else use bwrite */
83 struct netexport pm_export; /* export information */
84};
85
86/* Number of bits in one pm_inusemap item: */
87#define N_INUSEBITS (8 * sizeof(u_int))
88
89/*
90 * How to compute pm_cnshift and pm_crbomask.
91 *
92 * pm_crbomask = (pm_SectPerClust * pm_BytesPerSect) - 1
93 * if (bytesperclust == * 0)
94 * return EBADBLKSZ;
95 * bit = 1;
96 * for (i = 0; i < 32; i++) {
97 * if (bit & bytesperclust) {
98 * if (bit ^ bytesperclust)
99 * return EBADBLKSZ;
100 * pm_cnshift = * i;
101 * break;
102 * }
103 * bit <<= 1;
104 * }
105 */
106
107/*
108 * Shorthand for fields in the bpb contained in the msdosfsmount structure.
109 */
110#define pm_BytesPerSec pm_bpb.bpbBytesPerSec
111#define pm_SectPerClust pm_bpb.bpbSecPerClust
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_FATsecs pm_bpb.bpbFATsecs
118#define pm_SecPerTrack pm_bpb.bpbSecPerTrack
119#define pm_Heads pm_bpb.bpbHeads
120#define pm_HiddenSects pm_bpb.bpbHiddenSecs
121#define pm_HugeSectors pm_bpb.bpbHugeSectors
122
123/*
124 * Map a cluster number into a filesystem relative block number.
125 */
126#define cntobn(pmp, cn) \
127 ((((cn)-CLUST_FIRST) * (pmp)->pm_SectPerClust) + (pmp)->pm_firstcluster)
128
129/*
130 * Map a filesystem relative block number back into a cluster number.
131 */
132#define bntocn(pmp, bn) \
133 ((((bn) - pmp->pm_firstcluster)/ (pmp)->pm_SectPerClust) + CLUST_FIRST)
134
135/*
136 * Calculate block number for directory entry in root dir, offset dirofs
137 */
138#define roottobn(pmp, dirofs) \
139 (((dirofs) / (pmp)->pm_depclust) * (pmp)->pm_SectPerClust \
140 + (pmp)->pm_rootdirblk)
141
142/*
143 * Calculate block number for directory entry at cluster dirclu, offset
144 * dirofs
145 */
146#define detobn(pmp, dirclu, dirofs) \
147 ((dirclu) == MSDOSFSROOT \
148 ? roottobn((pmp), (dirofs)) \
149 : cntobn((pmp), (dirclu)))
150
151/*
152 * Convert pointer to buffer -> pointer to direntry
153 */
154#define bptoep(pmp, bp, dirofs) \
155 ((struct direntry *)((bp)->b_data) \
156 + (dirofs) % (pmp)->pm_depclust)
157
158
159/*
160 * Convert filesize to block number
161 */
162#define de_blk(pmp, off) \
163 ((off) >> (pmp)->pm_cnshift)
164
165/*
166 * Clusters required to hold size bytes
167 */
168#define de_clcount(pmp, size) \
169 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
170
171int msdosfs_init __P((void));
83 struct netexport pm_export; /* export information */
84};
85
86/* Number of bits in one pm_inusemap item: */
87#define N_INUSEBITS (8 * sizeof(u_int))
88
89/*
90 * How to compute pm_cnshift and pm_crbomask.
91 *
92 * pm_crbomask = (pm_SectPerClust * pm_BytesPerSect) - 1
93 * if (bytesperclust == * 0)
94 * return EBADBLKSZ;
95 * bit = 1;
96 * for (i = 0; i < 32; i++) {
97 * if (bit & bytesperclust) {
98 * if (bit ^ bytesperclust)
99 * return EBADBLKSZ;
100 * pm_cnshift = * i;
101 * break;
102 * }
103 * bit <<= 1;
104 * }
105 */
106
107/*
108 * Shorthand for fields in the bpb contained in the msdosfsmount structure.
109 */
110#define pm_BytesPerSec pm_bpb.bpbBytesPerSec
111#define pm_SectPerClust pm_bpb.bpbSecPerClust
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_FATsecs pm_bpb.bpbFATsecs
118#define pm_SecPerTrack pm_bpb.bpbSecPerTrack
119#define pm_Heads pm_bpb.bpbHeads
120#define pm_HiddenSects pm_bpb.bpbHiddenSecs
121#define pm_HugeSectors pm_bpb.bpbHugeSectors
122
123/*
124 * Map a cluster number into a filesystem relative block number.
125 */
126#define cntobn(pmp, cn) \
127 ((((cn)-CLUST_FIRST) * (pmp)->pm_SectPerClust) + (pmp)->pm_firstcluster)
128
129/*
130 * Map a filesystem relative block number back into a cluster number.
131 */
132#define bntocn(pmp, bn) \
133 ((((bn) - pmp->pm_firstcluster)/ (pmp)->pm_SectPerClust) + CLUST_FIRST)
134
135/*
136 * Calculate block number for directory entry in root dir, offset dirofs
137 */
138#define roottobn(pmp, dirofs) \
139 (((dirofs) / (pmp)->pm_depclust) * (pmp)->pm_SectPerClust \
140 + (pmp)->pm_rootdirblk)
141
142/*
143 * Calculate block number for directory entry at cluster dirclu, offset
144 * dirofs
145 */
146#define detobn(pmp, dirclu, dirofs) \
147 ((dirclu) == MSDOSFSROOT \
148 ? roottobn((pmp), (dirofs)) \
149 : cntobn((pmp), (dirclu)))
150
151/*
152 * Convert pointer to buffer -> pointer to direntry
153 */
154#define bptoep(pmp, bp, dirofs) \
155 ((struct direntry *)((bp)->b_data) \
156 + (dirofs) % (pmp)->pm_depclust)
157
158
159/*
160 * Convert filesize to block number
161 */
162#define de_blk(pmp, off) \
163 ((off) >> (pmp)->pm_cnshift)
164
165/*
166 * Clusters required to hold size bytes
167 */
168#define de_clcount(pmp, size) \
169 (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
170
171int msdosfs_init __P((void));