|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* $NetBSD: lfs.h,v 1.6 1994/12/21 20:01:01 mycroft Exp $ */
26:
27: /*-
28: * Copyright (c) 1991, 1993
29: * The Regents of the University of California. All rights reserved.
30: *
31: * Redistribution and use in source and binary forms, with or without
32: * modification, are permitted provided that the following conditions
33: * are met:
34: * 1. Redistributions of source code must retain the above copyright
35: * notice, this list of conditions and the following disclaimer.
36: * 2. Redistributions in binary form must reproduce the above copyright
37: * notice, this list of conditions and the following disclaimer in the
38: * documentation and/or other materials provided with the distribution.
39: * 3. All advertising materials mentioning features or use of this software
40: * must display the following acknowledgement:
41: * This product includes software developed by the University of
42: * California, Berkeley and its contributors.
43: * 4. Neither the name of the University nor the names of its contributors
44: * may be used to endorse or promote products derived from this software
45: * without specific prior written permission.
46: *
47: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57: * SUCH DAMAGE.
58: *
59: * @(#)lfs.h 8.5 (Berkeley) 7/8/94
60: */
61:
62: #define LFS_LABELPAD 8192 /* LFS label size */
63: #define LFS_SBPAD 8192 /* LFS superblock size */
64:
65: /*
66: * XXX
67: * This is a kluge and NEEDS to go away.
68: *
69: * Right now, ufs code handles most of the calls for directory operations
70: * such as create, mkdir, link, etc. As a result VOP_UPDATE is being
71: * called with waitfor set (since ffs does these things synchronously).
72: * Since LFS does not want to do these synchronously, we treat the last
73: * argument to lfs_update as a set of flags. If LFS_SYNC is set, then
74: * the update should be synchronous, if not, do it asynchronously.
75: * Unfortunately, this means that LFS won't work with NFS yet because
76: * NFS goes through paths that will make normal calls to ufs which will
77: * call lfs with a last argument of 1.
78: */
79: #define LFS_SYNC 0x02
80:
81: /* On-disk and in-memory checkpoint segment usage structure. */
82: typedef struct segusage SEGUSE;
83: struct segusage {
84: u_int32_t su_nbytes; /* number of live bytes */
85: u_int32_t su_lastmod; /* SEGUSE last modified timestamp */
86: u_int16_t su_nsums; /* number of summaries in segment */
87: u_int16_t su_ninos; /* number of inode blocks in seg */
88:
89: #define SEGUSE_ACTIVE 0x01 /* segment is currently being written */
90: #define SEGUSE_DIRTY 0x02 /* segment has data in it */
91: #define SEGUSE_SUPERBLOCK 0x04 /* segment contains a superblock */
92: u_int32_t su_flags;
93: };
94:
95: #define SEGUPB(fs) (1 << (fs)->lfs_sushift)
96: #define SEGTABSIZE_SU(fs) \
97: (((fs)->lfs_nseg + SEGUPB(fs) - 1) >> (fs)->lfs_sushift)
98:
99: /* On-disk file information. One per file with data blocks in the segment. */
100: typedef struct finfo FINFO;
101: struct finfo {
102: u_int32_t fi_nblocks; /* number of blocks */
103: u_int32_t fi_version; /* version number */
104: u_int32_t fi_ino; /* inode number */
105: daddr_t fi_blocks[1]; /* array of logical block numbers */
106: };
107:
108: /* On-disk and in-memory super block. */
109: struct lfs {
110: #define LFS_MAGIC 0x070162
111: u_int32_t lfs_magic; /* magic number */
112: #define LFS_VERSION 1
113: u_int32_t lfs_version; /* version number */
114:
115: u_int32_t lfs_size; /* number of blocks in fs */
116: u_int32_t lfs_ssize; /* number of blocks per segment */
117: u_int32_t lfs_dsize; /* number of disk blocks in fs */
118: u_int32_t lfs_bsize; /* file system block size */
119: u_int32_t lfs_fsize; /* size of frag blocks in fs */
120: u_int32_t lfs_frag; /* number of frags in a block in fs */
121:
122: /* Checkpoint region. */
123: ino_t lfs_free; /* start of the free list */
124: u_int32_t lfs_bfree; /* number of free disk blocks */
125: u_int32_t lfs_nfiles; /* number of allocated inodes */
126: int32_t lfs_avail; /* blocks available for writing */
127: u_int32_t lfs_uinodes; /* inodes in cache not yet on disk */
128: daddr_t lfs_idaddr; /* inode file disk address */
129: ino_t lfs_ifile; /* inode file inode number */
130: daddr_t lfs_lastseg; /* address of last segment written */
131: daddr_t lfs_nextseg; /* address of next segment to write */
132: daddr_t lfs_curseg; /* current segment being written */
133: daddr_t lfs_offset; /* offset in curseg for next partial */
134: daddr_t lfs_lastpseg; /* address of last partial written */
135: u_int32_t lfs_tstamp; /* time stamp */
136:
137: /* These are configuration parameters. */
138: u_int32_t lfs_minfree; /* minimum percentage of free blocks */
139:
140: /* These fields can be computed from the others. */
141: u_int64_t lfs_maxfilesize; /* maximum representable file size */
142: u_int32_t lfs_dbpseg; /* disk blocks per segment */
143: u_int32_t lfs_inopb; /* inodes per block */
144: u_int32_t lfs_ifpb; /* IFILE entries per block */
145: u_int32_t lfs_sepb; /* SEGUSE entries per block */
146: u_int32_t lfs_nindir; /* indirect pointers per block */
147: u_int32_t lfs_nseg; /* number of segments */
148: u_int32_t lfs_nspf; /* number of sectors per fragment */
149: u_int32_t lfs_cleansz; /* cleaner info size in blocks */
150: u_int32_t lfs_segtabsz; /* segment table size in blocks */
151:
152: u_int32_t lfs_segmask; /* calculate offset within a segment */
153: u_int32_t lfs_segshift; /* fast mult/div for segments */
154: u_int32_t lfs_bmask; /* calc block offset from file offset */
155: u_int32_t lfs_bshift; /* calc block number from file offset */
156: u_int32_t lfs_ffmask; /* calc frag offset from file offset */
157: u_int32_t lfs_ffshift; /* fast mult/div for frag from file */
158: u_int32_t lfs_fbmask; /* calc frag offset from block offset */
159: u_int32_t lfs_fbshift; /* fast mult/div for frag from block */
160: u_int32_t lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
161: u_int32_t lfs_sushift; /* fast mult/div for segusage table */
162:
163: int32_t lfs_maxsymlinklen; /* max length of an internal symlink */
164:
165: #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */
166: #define LFS_MAXNUMSB 10 /* superblock disk offsets */
167: daddr_t lfs_sboffs[LFS_MAXNUMSB];
168:
169: /* Checksum -- last valid disk field. */
170: u_int32_t lfs_cksum; /* checksum for superblock checking */
171:
172: /* These fields are set at mount time and are meaningless on disk. */
173: struct segment *lfs_sp; /* current segment being written */
174: struct vnode *lfs_ivnode; /* vnode for the ifile */
175: u_long lfs_seglock; /* single-thread the segment writer */
176: pid_t lfs_lockpid; /* pid of lock holder */
177: u_long lfs_iocount; /* number of ios pending */
178: u_long lfs_writer; /* don't allow any dirops to start */
179: u_long lfs_dirops; /* count of active directory ops */
180: u_long lfs_doifile; /* Write ifile blocks on next write */
181: u_long lfs_nactive; /* Number of segments since last ckp */
182: int8_t lfs_fmod; /* super block modified flag */
183: int8_t lfs_clean; /* file system is clean flag */
184: int8_t lfs_ronly; /* mounted read-only flag */
185: int8_t lfs_flags; /* currently unused flag */
186: u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */
187:
188: int32_t lfs_pad[40]; /* round to 512 bytes */
189: };
190:
191: /*
192: * Inode 0: out-of-band inode number
193: * Inode 1: IFILE inode number
194: * Inode 2: root inode
195: * Inode 3: lost+found inode number
196: */
197: #define LFS_UNUSED_INUM 0 /* out of band inode number */
198: #define LFS_IFILE_INUM 1 /* IFILE inode number */
199: #define LOSTFOUNDINO 3 /* lost+found inode number */
200: #define LFS_FIRST_INUM 4 /* first free inode number */
201:
202: /* Address calculations for metadata located in the inode */
203: #define S_INDIR(fs) -NDADDR
204: #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1)
205: #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1)
206:
207: /* Unassigned disk address. */
208: #define UNASSIGNED -1
209:
210: /* Unused logical block number */
211: #define LFS_UNUSED_LBN -1
212:
213: typedef struct ifile IFILE;
214: struct ifile {
215: u_int32_t if_version; /* inode version number */
216: #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */
217: daddr_t if_daddr; /* inode disk address */
218: ino_t if_nextfree; /* next-unallocated inode */
219: };
220:
221: /*
222: * Cleaner information structure. This resides in the ifile and is used
223: * to pass information between the cleaner and the kernel.
224: */
225: typedef struct _cleanerinfo {
226: u_int32_t clean; /* K: number of clean segments */
227: u_int32_t dirty; /* K: number of dirty segments */
228: } CLEANERINFO;
229:
230: #define CLEANSIZE_SU(fs) \
231: ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift)
232:
233: /*
234: * All summary blocks are the same size, so we can always read a summary
235: * block easily from a segment.
236: */
237: #define LFS_SUMMARY_SIZE 512
238:
239: /* On-disk segment summary information */
240: typedef struct segsum SEGSUM;
241: struct segsum {
242: u_int32_t ss_sumsum; /* check sum of summary block */
243: u_int32_t ss_datasum; /* check sum of data */
244: daddr_t ss_next; /* next segment */
245: u_int32_t ss_create; /* creation time stamp */
246: u_int16_t ss_nfinfo; /* number of file info structures */
247: u_int16_t ss_ninos; /* number of inodes in summary */
248:
249: #define SS_DIROP 0x01 /* segment begins a dirop */
250: #define SS_CONT 0x02 /* more partials to finish this write*/
251: u_int16_t ss_flags; /* used for directory operations */
252: u_int16_t ss_pad; /* extra space */
253: /* FINFO's and inode daddr's... */
254: };
255:
256: /* NINDIR is the number of indirects in a file system block. */
257: #define NINDIR(fs) ((fs)->lfs_nindir)
258:
259: /* INOPB is the number of inodes in a secondary storage block. */
260: #define INOPB(fs) ((fs)->lfs_inopb)
261:
262: #define blksize(fs) ((fs)->lfs_bsize)
263: #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask)
264: #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb)
265: #define dbtofsb(fs, b) ((b) >> (fs)->lfs_fsbtodb)
266: #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift)
267: #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift)
268: #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \
269: ((loc) >> (fs)->lfs_bshift)
270:
271: #define datosn(fs, daddr) /* disk address to segment number */ \
272: (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize))
273: #define sntoda(fs, sn) /* segment number to disk address */ \
274: ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \
275: (fs)->lfs_sboffs[0]))
276:
277: /* Read in the block with the cleaner info from the ifile. */
278: #define LFS_CLEANERINFO(CP, F, BP) { \
279: VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
280: if (bread((F)->lfs_ivnode, \
281: (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \
282: panic("lfs: ifile read"); \
283: (CP) = (CLEANERINFO *)(BP)->b_data; \
284: }
285:
286: /* Read in the block with a specific inode from the ifile. */
287: #define LFS_IENTRY(IP, F, IN, BP) { \
288: int _e; \
289: VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
290: if (_e = bread((F)->lfs_ivnode, \
291: (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz,\
292: (F)->lfs_bsize, NOCRED, &(BP))) \
293: panic("lfs: ifile read %d", _e); \
294: (IP) = (IFILE *)(BP)->b_data + (IN) % (F)->lfs_ifpb; \
295: }
296:
297: /* Read in the block with a specific segment usage entry from the ifile. */
298: #define LFS_SEGENTRY(SP, F, IN, BP) { \
299: int _e; \
300: VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
301: if (_e = bread((F)->lfs_ivnode, \
302: ((IN) >> (F)->lfs_sushift) + (F)->lfs_cleansz, \
303: (F)->lfs_bsize, NOCRED, &(BP))) \
304: panic("lfs: ifile read: %d", _e); \
305: (SP) = (SEGUSE *)(BP)->b_data + ((IN) & (F)->lfs_sepb - 1); \
306: }
307:
308: /*
309: * Determine if there is enough room currently available to write db
310: * disk blocks. We need enough blocks for the new blocks, the current,
311: * inode blocks, a summary block, plus potentially the ifile inode and
312: * the segment usage table, plus an ifile page.
313: */
314: #define LFS_FITS(fs, db) \
315: ((int32_t)((db + ((fs)->lfs_uinodes + INOPB((fs))) / \
316: INOPB((fs)) + fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE + \
317: (fs)->lfs_segtabsz)) < (fs)->lfs_avail)
318:
319: /* Determine if a buffer belongs to the ifile */
320: #define IS_IFILE(bp) (VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM)
321:
322: /*
323: * Structures used by lfs_bmapv and lfs_markv to communicate information
324: * about inodes and data blocks.
325: */
326: typedef struct block_info {
327: ino_t bi_inode; /* inode # */
328: daddr_t bi_lbn; /* logical block w/in file */
329: daddr_t bi_daddr; /* disk address of block */
330: time_t bi_segcreate; /* origin segment create time */
331: int bi_version; /* file version number */
332: void *bi_bp; /* data buffer */
333: } BLOCK_INFO;
334:
335: /* In-memory description of a segment about to be written. */
336: struct segment {
337: struct lfs *fs; /* file system pointer */
338: struct buf **bpp; /* pointer to buffer array */
339: struct buf **cbpp; /* pointer to next available bp */
340: struct buf **start_bpp; /* pointer to first bp in this set */
341: struct buf *ibp; /* buffer pointer to inode page */
342: struct finfo *fip; /* current fileinfo pointer */
343: struct vnode *vp; /* vnode being gathered */
344: void *segsum; /* segment summary info */
345: u_int32_t ninodes; /* number of inodes in this segment */
346: u_int32_t seg_bytes_left; /* bytes left in segment */
347: u_int32_t sum_bytes_left; /* bytes left in summary block */
348: u_int32_t seg_number; /* number of this segment */
349: daddr_t *start_lbp; /* beginning lbn for this set */
350:
351: #define SEGM_CKP 0x01 /* doing a checkpoint */
352: #define SEGM_CLEAN 0x02 /* cleaner call; don't sort */
353: #define SEGM_SYNC 0x04 /* wait for segment */
354: u_int16_t seg_flags; /* run-time flags for this segment */
355: };
356:
357: #define ISSPACE(F, BB, C) \
358: (((C)->cr_uid == 0 && (F)->lfs_bfree >= (BB)) || \
359: ((C)->cr_uid != 0 && IS_FREESPACE(F, BB)))
360:
361: #define IS_FREESPACE(F, BB) \
362: ((F)->lfs_bfree > ((F)->lfs_dsize * (F)->lfs_minfree / 100 + (BB)))
363:
364: #define ISSPACE_XXX(F, BB) \
365: ((F)->lfs_bfree >= (BB))
366:
367: #define DOSTATS
368: #ifdef DOSTATS
369: /* Statistics Counters */
370: struct lfs_stats {
371: u_int segsused;
372: u_int psegwrites;
373: u_int psyncwrites;
374: u_int pcleanwrites;
375: u_int blocktot;
376: u_int cleanblocks;
377: u_int ncheckpoints;
378: u_int nwrites;
379: u_int nsync_writes;
380: u_int wait_exceeded;
381: u_int write_exceeded;
382: u_int flush_invoked;
383: };
384: extern struct lfs_stats lfs_stats;
385: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.