2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * DUX inode operations
16 #include <afsconfig.h>
17 #include "../afs/param.h"
21 #include "../afs/sysincludes.h" /* Standard vendor system headers */
22 #include "../afs/afsincludes.h" /* Afs-based standard headers */
23 #include "../afs/osi_inode.h"
24 #include "../afs/afs_stats.h" /* statistics stuff */
25 #include <ufs/ufsmount.h>
27 /* given a vnode, return the `inode number'; if it's a UFS vnode just
28 return the i_number from the in kernel inode struct, if not stat
29 the file to get the inumber from there */
31 osi_vnodeToInumber(struct vnode *vnode)
36 /* use faster version with UFS */
37 if(vnode->v_tag == VT_UFS)
38 return VTOI(vnode)->i_number;
39 /* otherwise stat the file */
40 VOP_GETATTR(vnode, &attr, NULL, error);
42 osi_Panic("VOP_GETATTR = %d", error);
43 return attr.va_fileid;
46 /* return the id of the device containing the file */
48 osi_vnodeToDev(struct vnode *vnode)
53 /* use faster version with UFS */
54 if(vnode->v_tag == VT_UFS)
55 return VTOI(vnode)->i_dev;
56 /* otherwise stat the file */
57 VOP_GETATTR(vnode, &attr, NULL, error);
59 osi_Panic("VOP_GETATTR = %d", error);
63 getinode(fs, dev, inode, ipp, perror)
70 register struct vnode *vp;
71 char fake_vnode[FAKE_INODE_SIZE];
78 register struct ufsmount *ump;
79 register struct vnode *vp;
80 register struct mount *mp;
85 * XXX Also do the test for MFS
89 if (mp->m_stat.f_type == MOUNT_UFS) {
92 if (ump->um_fs == NULL)
94 if (ump->um_dev == dev) {
103 } while (mp != rootfs);
108 vp = (struct vnode *) fake_vnode;
109 fake_inode_init(vp, fs);
110 assert(vp->v_tag == VT_UFS);
111 code = iget(VTOI(vp), inode, &ip, 0);
121 igetinode(vfsp, dev, inode, ipp, perror)
128 struct inode *pip, *ip;
129 extern struct osi_dev cacheDev;
130 register int code = 0;
134 AFS_STATCNT(igetinode);
136 if ((code = getinode(vfsp, dev, inode, &ip, perror)) != 0) {
140 if (ip->i_mode == 0) {
141 /* Not an allocated inode */
146 if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) {
158 struct vnode *vp = ITOV(ip);
160 AFS_STATCNT(iforget);
163 /* this whole thing is too wierd. Why??? XXX */
164 if (vp->v_usecount == 1) {
173 * icreate system call -- create an inode
175 afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval)
177 long dev, near_inode, param1, param2, param3, param4;
180 struct inode *ip, *newip;
184 AFS_STATCNT(afs_syscall_icreate);
189 code = getinode(0, (dev_t)dev, 2, &ip, &dummy);
193 code = ialloc(ip, (ino_t)near_inode, 0, &newip);
199 newip->i_flag |= IACC|IUPD|ICHG;
203 newip->i_mode = IFREG;
213 extern struct vfs_ubcops ufs_ubcops;
214 extern struct vm_ubc_object* ubc_object_allocate();
215 struct vm_ubc_object* vop;
216 vop = ubc_object_allocate(&vp, &ufs_ubcops,
217 vp->v_mount->m_funnel);
225 newip->i_flags |= IC_XUID|IC_XGID;
226 newip->i_flags &= ~IC_PROPLIST;
227 newip->i_vicep1 = param1;
228 if (param2 == 0x1fffffff/*INODESPECIAL*/) {
229 newip->i_vicep2 = ((0x1fffffff << 3) + (param4 & 0x3));
230 newip->i_vicep3a = (u_short)(param3 >> 16);
231 newip->i_vicep3b = (u_short)param3;
233 newip->i_vicep2 = (((param2 >> 16) & 0x1f) << 27) +
234 (((param4 >> 16) & 0x1f) << 22) +
236 newip->i_vicep3a = (u_short)param4;
237 newip->i_vicep3b = (u_short)param2;
239 newip->i_vicemagic = VICEMAGIC;
241 *retval = newip->i_number;
248 afs_syscall_iopen(dev, inode, usrmod, retval)
250 int dev, inode, usrmod;
254 struct vnode *vp = (struct vnode *)0;
257 extern struct fileops vnops;
260 struct ufile_entry *fe;
263 AFS_STATCNT(afs_syscall_iopen);
268 code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy);
273 if ((code = falloc(&fp, &fd, &fe)) != 0) {
278 if ((code = falloc(&fp, &fd)) != 0) {
286 fp->f_flag = (usrmod-FOPEN) & FMASK;
287 fp->f_type = DTYPE_VNODE;
289 fp->f_data = (caddr_t)ITOV(ip);
293 u_set_fe(fd, fe, fp, &u.u_file_state);
295 U_FD_SET(fd, fp, &u.u_file_state);
303 * Support for iinc() and idec() system calls--increment or decrement
305 * Restricted to super user.
306 * Only VICEMAGIC type inodes.
308 afs_syscall_iincdec(dev, inode, inode_p1, amount)
309 int dev, inode, inode_p1, amount;
318 code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy);
322 if (!IS_VICEMAGIC(ip)) {
324 } else if (ip->i_vicep1 != inode_p1) {
327 ip->i_nlink += amount;
328 if (ip->i_nlink == 0) {