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