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 "../afs/param.h" /* Should be always first */
17 #include "../afs/sysincludes.h" /* Standard vendor system headers */
18 #include "../afs/afsincludes.h" /* Afs-based standard headers */
19 #include "../afs/osi_inode.h"
20 #include "../afs/afs_stats.h" /* statistics stuff */
21 #include <ufs/ufsmount.h>
23 /* given a vnode, return the `inode number'; if it's a UFS vnode just
24 return the i_number from the in kernel inode struct, if not stat
25 the file to get the inumber from there */
27 osi_vnodeToInumber(struct vnode *vnode)
32 /* use faster version with UFS */
33 if(vnode->v_tag == VT_UFS)
34 return VTOI(vnode)->i_number;
35 /* otherwise stat the file */
36 VOP_GETATTR(vnode, &attr, NULL, error);
38 osi_Panic("VOP_GETATTR = %d", error);
39 return attr.va_fileid;
42 /* return the id of the device containing the file */
44 osi_vnodeToDev(struct vnode *vnode)
49 /* use faster version with UFS */
50 if(vnode->v_tag == VT_UFS)
51 return VTOI(vnode)->i_dev;
52 /* otherwise stat the file */
53 VOP_GETATTR(vnode, &attr, NULL, error);
55 osi_Panic("VOP_GETATTR = %d", error);
59 getinode(fs, dev, inode, ipp, perror)
66 register struct vnode *vp;
67 char fake_vnode[FAKE_INODE_SIZE];
74 register struct ufsmount *ump;
75 register struct vnode *vp;
76 register struct mount *mp;
81 * XXX Also do the test for MFS
85 if (mp->m_stat.f_type == MOUNT_UFS) {
88 if (ump->um_fs == NULL)
90 if (ump->um_dev == dev) {
99 } while (mp != rootfs);
104 vp = (struct vnode *) fake_vnode;
105 fake_inode_init(vp, fs);
106 code = iget(VTOI(vp), inode, &ip, 0);
116 igetinode(vfsp, dev, inode, ipp, perror)
123 struct inode *pip, *ip;
124 extern struct osi_dev cacheDev;
125 register int code = 0;
129 AFS_STATCNT(igetinode);
131 if ((code = getinode(vfsp, dev, inode, &ip, perror)) != 0) {
135 if (ip->i_mode == 0) {
136 /* Not an allocated inode */
141 if (ip->i_nlink == 0 || (ip->i_mode&IFMT) != IFREG) {
153 struct vnode *vp = ITOV(ip);
155 AFS_STATCNT(iforget);
158 /* this whole thing is too wierd. Why??? XXX */
159 if (vp->v_usecount == 1) {
168 * icreate system call -- create an inode
170 afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval)
172 long dev, near_inode, param1, param2, param3, param4;
175 struct inode *ip, *newip;
179 AFS_STATCNT(afs_syscall_icreate);
184 code = getinode(0, (dev_t)dev, 2, &ip, &dummy);
188 code = ialloc(ip, (ino_t)near_inode, 0, &newip);
194 newip->i_flag |= IACC|IUPD|ICHG;
198 newip->i_mode = IFREG;
208 extern struct vfs_ubcops ufs_ubcops;
209 extern struct vm_ubc_object* ubc_object_allocate();
210 struct vm_ubc_object* vop;
211 vop = ubc_object_allocate(&vp, &ufs_ubcops,
212 vp->v_mount->m_funnel);
220 newip->i_flags |= IC_XUID|IC_XGID;
221 newip->i_flags &= ~IC_PROPLIST;
222 newip->i_vicep1 = param1;
223 if (param2 == 0x1fffffff/*INODESPECIAL*/) {
224 newip->i_vicep2 = ((0x1fffffff << 3) + (param4 & 0x3));
225 newip->i_vicep3a = (u_short)(param3 >> 16);
226 newip->i_vicep3b = (u_short)param3;
228 newip->i_vicep2 = (((param2 >> 16) & 0x1f) << 27) +
229 (((param4 >> 16) & 0x1f) << 22) +
231 newip->i_vicep3a = (u_short)param4;
232 newip->i_vicep3b = (u_short)param2;
234 newip->i_vicemagic = VICEMAGIC;
236 *retval = newip->i_number;
243 afs_syscall_iopen(dev, inode, usrmod, retval)
245 int dev, inode, usrmod;
249 struct vnode *vp = (struct vnode *)0;
252 extern struct fileops vnops;
255 struct ufile_entry *fe;
258 AFS_STATCNT(afs_syscall_iopen);
263 code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy);
268 if ((code = falloc(&fp, &fd, &fe)) != 0) {
273 if ((code = falloc(&fp, &fd)) != 0) {
281 fp->f_flag = (usrmod-FOPEN) & FMASK;
282 fp->f_type = DTYPE_VNODE;
284 fp->f_data = (caddr_t)ITOV(ip);
288 u_set_fe(fd, fe, fp, &u.u_file_state);
290 U_FD_SET(fd, fp, &u.u_file_state);
298 * Support for iinc() and idec() system calls--increment or decrement
300 * Restricted to super user.
301 * Only VICEMAGIC type inodes.
303 afs_syscall_iincdec(dev, inode, inode_p1, amount)
304 int dev, inode, inode_p1, amount;
313 code = igetinode(0, (dev_t)dev, (ino_t)inode, &ip, &dummy);
317 if (!IS_VICEMAGIC(ip)) {
319 } else if (ip->i_vicep1 != inode_p1) {
322 ip->i_nlink += amount;
323 if (ip->i_nlink == 0) {