2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
58 #include <rev_endian_fs.h>
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/resourcevar.h>
62 #include <sys/kernel.h>
67 #include <sys/mount_internal.h>
68 #include <sys/vnode_internal.h>
69 #include <sys/malloc.h>
71 #include <sys/quota.h>
74 #include <vfs/vfs_support.h>
76 #include <miscfs/specfs/specdev.h>
77 #include <miscfs/fifofs/fifo.h>
79 #include <ufs/ufs/quota.h>
80 #include <ufs/ufs/inode.h>
81 #include <ufs/ufs/dir.h>
82 #include <ufs/ufs/ufsmount.h>
83 #include <ufs/ufs/ufs_extern.h>
85 #include <ufs/ffs/fs.h>
86 #include <ufs/ffs/ffs_extern.h>
88 #include <ufs/ufs/ufs_byte_order.h>
89 #include <architecture/byte_order.h>
90 #endif /* REV_ENDIAN_FS */
92 #define VOPFUNC int (*)(void *)
94 /* Global vfs data structures for ufs. */
95 int (**ffs_vnodeop_p
)(void *);
96 struct vnodeopv_entry_desc ffs_vnodeop_entries
[] = {
97 { &vnop_default_desc
, (VOPFUNC
)vn_default_error
},
98 { &vnop_lookup_desc
, (VOPFUNC
)ufs_lookup
}, /* lookup */
99 { &vnop_create_desc
, (VOPFUNC
)ufs_create
}, /* create */
100 { &vnop_whiteout_desc
, (VOPFUNC
)ufs_whiteout
}, /* whiteout */
101 { &vnop_mknod_desc
, (VOPFUNC
)ufs_mknod
}, /* mknod */
102 { &vnop_open_desc
, (VOPFUNC
)ufs_open
}, /* open */
103 { &vnop_close_desc
, (VOPFUNC
)ufs_close
}, /* close */
104 { &vnop_getattr_desc
, (VOPFUNC
)ufs_getattr
}, /* getattr */
105 { &vnop_setattr_desc
, (VOPFUNC
)ufs_setattr
}, /* setattr */
106 { &vnop_read_desc
, (VOPFUNC
)ffs_read
}, /* read */
107 { &vnop_write_desc
, (VOPFUNC
)ffs_write
}, /* write */
108 { &vnop_ioctl_desc
, (VOPFUNC
)ufs_ioctl
}, /* ioctl */
109 { &vnop_select_desc
, (VOPFUNC
)ufs_select
}, /* select */
110 { &vnop_revoke_desc
, (VOPFUNC
)ufs_revoke
}, /* revoke */
111 { &vnop_mmap_desc
, (VOPFUNC
)ufs_mmap
}, /* mmap */
112 { &vnop_fsync_desc
, (VOPFUNC
)ffs_fsync
}, /* fsync */
113 { &vnop_remove_desc
, (VOPFUNC
)ufs_remove
}, /* remove */
114 { &vnop_link_desc
, (VOPFUNC
)ufs_link
}, /* link */
115 { &vnop_rename_desc
, (VOPFUNC
)ufs_rename
}, /* rename */
116 { &vnop_mkdir_desc
, (VOPFUNC
)ufs_mkdir
}, /* mkdir */
117 { &vnop_rmdir_desc
, (VOPFUNC
)ufs_rmdir
}, /* rmdir */
118 { &vnop_symlink_desc
, (VOPFUNC
)ufs_symlink
}, /* symlink */
119 { &vnop_readdir_desc
, (VOPFUNC
)ufs_readdir
}, /* readdir */
120 { &vnop_readlink_desc
, (VOPFUNC
)ufs_readlink
}, /* readlink */
121 { &vnop_inactive_desc
, (VOPFUNC
)ufs_inactive
}, /* inactive */
122 { &vnop_reclaim_desc
, (VOPFUNC
)ffs_reclaim
}, /* reclaim */
123 { &vnop_strategy_desc
, (VOPFUNC
)ufs_strategy
}, /* strategy */
124 { &vnop_pathconf_desc
, (VOPFUNC
)ufs_pathconf
}, /* pathconf */
125 { &vnop_advlock_desc
, (VOPFUNC
)err_advlock
}, /* advlock */
126 { &vnop_bwrite_desc
, (VOPFUNC
)vn_bwrite
},
127 { &vnop_pagein_desc
, (VOPFUNC
)ffs_pagein
}, /* Pagein */
128 { &vnop_pageout_desc
, (VOPFUNC
)ffs_pageout
}, /* Pageout */
129 { &vnop_copyfile_desc
, (VOPFUNC
)err_copyfile
}, /* Copy File */
130 { &vnop_blktooff_desc
, (VOPFUNC
)ffs_blktooff
}, /* blktooff */
131 { &vnop_offtoblk_desc
, (VOPFUNC
)ffs_offtoblk
}, /* offtoblk */
132 { &vnop_blockmap_desc
, (VOPFUNC
)ufs_blockmap
}, /* blockmap */
133 { &vnop_kqfilt_add_desc
, (VOPFUNC
)ufs_kqfilt_add
}, /* kqfilt_add */
134 { (struct vnodeop_desc
*)NULL
, (int(*)())NULL
}
136 struct vnodeopv_desc ffs_vnodeop_opv_desc
=
137 { &ffs_vnodeop_p
, ffs_vnodeop_entries
};
139 int (**ffs_specop_p
)(void *);
140 struct vnodeopv_entry_desc ffs_specop_entries
[] = {
141 { &vnop_default_desc
, (VOPFUNC
)vn_default_error
},
142 { &vnop_lookup_desc
, (VOPFUNC
)spec_lookup
}, /* lookup */
143 { &vnop_create_desc
, (VOPFUNC
)spec_create
}, /* create */
144 { &vnop_mknod_desc
, (VOPFUNC
)spec_mknod
}, /* mknod */
145 { &vnop_open_desc
, (VOPFUNC
)spec_open
}, /* open */
146 { &vnop_close_desc
, (VOPFUNC
)ufsspec_close
}, /* close */
147 { &vnop_getattr_desc
, (VOPFUNC
)ufs_getattr
}, /* getattr */
148 { &vnop_setattr_desc
, (VOPFUNC
)ufs_setattr
}, /* setattr */
149 { &vnop_read_desc
, (VOPFUNC
)ufsspec_read
}, /* read */
150 { &vnop_write_desc
, (VOPFUNC
)ufsspec_write
}, /* write */
151 { &vnop_ioctl_desc
, (VOPFUNC
)spec_ioctl
}, /* ioctl */
152 { &vnop_select_desc
, (VOPFUNC
)spec_select
}, /* select */
153 { &vnop_revoke_desc
, (VOPFUNC
)spec_revoke
}, /* revoke */
154 { &vnop_mmap_desc
, (VOPFUNC
)spec_mmap
}, /* mmap */
155 { &vnop_fsync_desc
, (VOPFUNC
)ffs_fsync
}, /* fsync */
156 { &vnop_remove_desc
, (VOPFUNC
)spec_remove
}, /* remove */
157 { &vnop_link_desc
, (VOPFUNC
)spec_link
}, /* link */
158 { &vnop_rename_desc
, (VOPFUNC
)spec_rename
}, /* rename */
159 { &vnop_mkdir_desc
, (VOPFUNC
)spec_mkdir
}, /* mkdir */
160 { &vnop_rmdir_desc
, (VOPFUNC
)spec_rmdir
}, /* rmdir */
161 { &vnop_symlink_desc
, (VOPFUNC
)spec_symlink
}, /* symlink */
162 { &vnop_readdir_desc
, (VOPFUNC
)spec_readdir
}, /* readdir */
163 { &vnop_readlink_desc
, (VOPFUNC
)spec_readlink
}, /* readlink */
164 { &vnop_inactive_desc
, (VOPFUNC
)ufs_inactive
}, /* inactive */
165 { &vnop_reclaim_desc
, (VOPFUNC
)ffs_reclaim
}, /* reclaim */
166 { &vnop_strategy_desc
, (VOPFUNC
)spec_strategy
}, /* strategy */
167 { &vnop_pathconf_desc
, (VOPFUNC
)spec_pathconf
}, /* pathconf */
168 { &vnop_advlock_desc
, (VOPFUNC
)err_advlock
}, /* advlock */
169 { &vnop_bwrite_desc
, (VOPFUNC
)vn_bwrite
},
170 { &vnop_devblocksize_desc
, (VOPFUNC
)spec_devblocksize
}, /* devblocksize */
171 { &vnop_pagein_desc
, (VOPFUNC
)ffs_pagein
}, /* Pagein */
172 { &vnop_pageout_desc
, (VOPFUNC
)ffs_pageout
}, /* Pageout */
173 { &vnop_copyfile_desc
, (VOPFUNC
)err_copyfile
}, /* Copy File */
174 { &vnop_blktooff_desc
, (VOPFUNC
)ffs_blktooff
}, /* blktooff */
175 { &vnop_offtoblk_desc
, (VOPFUNC
)ffs_offtoblk
}, /* offtoblk */
176 { &vnop_blockmap_desc
, (VOPFUNC
)spec_blockmap
}, /* blockmap */
177 { (struct vnodeop_desc
*)NULL
, (int(*)())NULL
}
179 struct vnodeopv_desc ffs_specop_opv_desc
=
180 { &ffs_specop_p
, ffs_specop_entries
};
183 int (**ffs_fifoop_p
)(void *);
184 struct vnodeopv_entry_desc ffs_fifoop_entries
[] = {
185 { &vnop_default_desc
, (VOPFUNC
)vn_default_error
},
186 { &vnop_lookup_desc
, (VOPFUNC
)fifo_lookup
}, /* lookup */
187 { &vnop_create_desc
, (VOPFUNC
)fifo_create
}, /* create */
188 { &vnop_mknod_desc
, (VOPFUNC
)fifo_mknod
}, /* mknod */
189 { &vnop_open_desc
, (VOPFUNC
)fifo_open
}, /* open */
190 { &vnop_close_desc
, (VOPFUNC
)ufsfifo_close
}, /* close */
191 { &vnop_getattr_desc
, (VOPFUNC
)ufs_getattr
}, /* getattr */
192 { &vnop_setattr_desc
, (VOPFUNC
)ufs_setattr
}, /* setattr */
193 { &vnop_read_desc
, (VOPFUNC
)ufsfifo_read
}, /* read */
194 { &vnop_write_desc
, (VOPFUNC
)ufsfifo_write
}, /* write */
195 { &vnop_ioctl_desc
, (VOPFUNC
)fifo_ioctl
}, /* ioctl */
196 { &vnop_select_desc
, (VOPFUNC
)fifo_select
}, /* select */
197 { &vnop_revoke_desc
, (VOPFUNC
)fifo_revoke
}, /* revoke */
198 { &vnop_mmap_desc
, (VOPFUNC
)fifo_mmap
}, /* mmap */
199 { &vnop_fsync_desc
, (VOPFUNC
)ffs_fsync
}, /* fsync */
200 { &vnop_remove_desc
, (VOPFUNC
)fifo_remove
}, /* remove */
201 { &vnop_link_desc
, (VOPFUNC
)fifo_link
}, /* link */
202 { &vnop_rename_desc
, (VOPFUNC
)fifo_rename
}, /* rename */
203 { &vnop_mkdir_desc
, (VOPFUNC
)fifo_mkdir
}, /* mkdir */
204 { &vnop_rmdir_desc
, (VOPFUNC
)fifo_rmdir
}, /* rmdir */
205 { &vnop_symlink_desc
, (VOPFUNC
)fifo_symlink
}, /* symlink */
206 { &vnop_readdir_desc
, (VOPFUNC
)fifo_readdir
}, /* readdir */
207 { &vnop_readlink_desc
, (VOPFUNC
)fifo_readlink
}, /* readlink */
208 { &vnop_inactive_desc
, (VOPFUNC
)ufs_inactive
}, /* inactive */
209 { &vnop_reclaim_desc
, (VOPFUNC
)ffs_reclaim
}, /* reclaim */
210 { &vnop_strategy_desc
, (VOPFUNC
)fifo_strategy
}, /* strategy */
211 { &vnop_pathconf_desc
, (VOPFUNC
)fifo_pathconf
}, /* pathconf */
212 { &vnop_advlock_desc
, (VOPFUNC
)err_advlock
}, /* advlock */
213 { &vnop_bwrite_desc
, (VOPFUNC
)vn_bwrite
},
214 { &vnop_pagein_desc
, (VOPFUNC
)ffs_pagein
}, /* Pagein */
215 { &vnop_pageout_desc
, (VOPFUNC
)ffs_pageout
}, /* Pageout */
216 { &vnop_copyfile_desc
, (VOPFUNC
)err_copyfile
}, /* Copy File */
217 { &vnop_blktooff_desc
, (VOPFUNC
)ffs_blktooff
}, /* blktooff */
218 { &vnop_offtoblk_desc
, (VOPFUNC
)ffs_offtoblk
}, /* offtoblk */
219 { &vnop_blockmap_desc
, (VOPFUNC
)ufs_blockmap
}, /* blockmap */
220 { &vnop_kqfilt_add_desc
, (VOPFUNC
)ufsfifo_kqfilt_add
}, /* kqfilt_add */
221 { (struct vnodeop_desc
*)NULL
, (int(*)())NULL
}
223 struct vnodeopv_desc ffs_fifoop_opv_desc
=
224 { &ffs_fifoop_p
, ffs_fifoop_entries
};
228 * Enabling cluster read/write operations.
230 int doclusterread
= 0;
231 int doclusterwrite
= 0;
233 #include <ufs/ufs/ufs_readwrite.c>
236 * Synch an open file.
241 struct vnop_fsync_args
/* {
244 vfs_context_t a_context;
247 return(ffs_fsync_internal(ap
->a_vp
, ap
->a_waitfor
));
252 ffs_fsync_internal(vnode_t vp
, int waitfor
)
255 int wait
= (waitfor
== MNT_WAIT
);
258 * Write out any clusters.
263 * Flush all dirty buffers associated with a vnode.
265 buf_flushdirtyblks(vp
, wait
, 0, (char *)"ffs_fsync");
268 return (ffs_update(vp
, &tv
, &tv
, wait
));
272 * Reclaim an inode so that it can be used for other purposes.
276 struct vnop_reclaim_args
/* {
278 vfs_context_t a_context;
281 register struct vnode
*vp
= ap
->a_vp
;
284 if ( (error
= ufs_reclaim(vp
, vfs_context_proc(ap
->a_context
))) )
287 FREE_ZONE(vnode_fsnode(vp
), sizeof (struct inode
), M_FFSNODE
);
289 vnode_clearfsnode(vp
);
294 /* Blktooff converts a logical block number to a file offset */
297 struct vnop_blktooff_args
/* {
303 register struct inode
*ip
;
306 if (ap
->a_vp
== NULL
)
309 fs
= VTOI(ap
->a_vp
)->I_FS
;
311 *ap
->a_offset
= (off_t
)lblktosize(fs
, ap
->a_lblkno
);
316 /* Blktooff converts a logical block number to a file offset */
319 struct vnop_offtoblk_args
/* {
327 if (ap
->a_vp
== NULL
)
330 fs
= VTOI(ap
->a_vp
)->I_FS
;
332 *ap
->a_lblkno
= (daddr64_t
)lblkno(fs
, ap
->a_offset
);