xref: /original-bsd/sys/kern/vfs_xxx.c (revision a141c157)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)vfs_xxx.c	7.1 (Berkeley) 06/05/86
7  */
8 
9 #include "param.h"
10 #include "systm.h"
11 #include "inode.h"
12 #include "fs.h"
13 #include "mount.h"
14 #include "dir.h"
15 #include "user.h"
16 #include "buf.h"
17 #include "conf.h"
18 
19 #ifdef COMPAT
20 #include "file.h"
21 #include "kernel.h"
22 
23 /*
24  * Oh, how backwards compatibility is ugly!!!
25  */
26 struct	ostat {
27 	dev_t	ost_dev;
28 	u_short	ost_ino;
29 	u_short ost_mode;
30 	short  	ost_nlink;
31 	short  	ost_uid;
32 	short  	ost_gid;
33 	dev_t	ost_rdev;
34 	int	ost_size;
35 	int	ost_atime;
36 	int	ost_mtime;
37 	int	ost_ctime;
38 };
39 
40 /*
41  * The old fstat system call.
42  */
43 ofstat()
44 {
45 	register struct file *fp;
46 	register struct a {
47 		int	fd;
48 		struct ostat *sb;
49 	} *uap = (struct a *)u.u_ap;
50 	extern struct file *getinode();
51 
52 	fp = getinode(uap->fd);
53 	if (fp == NULL)
54 		return;
55 	ostat1((struct inode *)fp->f_data, uap->sb);
56 }
57 
58 /*
59  * Old stat system call.  This version follows links.
60  */
61 ostat()
62 {
63 	register struct inode *ip;
64 	register struct a {
65 		char	*fname;
66 		struct ostat *sb;
67 	} *uap = (struct a *)u.u_ap;
68 	register struct nameidata *ndp = &u.u_nd;
69 
70 	ndp->ni_nameiop = LOOKUP | FOLLOW;
71 	ndp->ni_segflg = UIO_USERSPACE;
72 	ndp->ni_dirp = uap->fname;
73 	ip = namei(ndp);
74 	if (ip == NULL)
75 		return;
76 	ostat1(ip, uap->sb);
77 	iput(ip);
78 }
79 
80 ostat1(ip, ub)
81 	register struct inode *ip;
82 	struct ostat *ub;
83 {
84 	struct ostat ds;
85 
86 	IUPDAT(ip, &time, &time, 0);
87 	/*
88 	 * Copy from inode table
89 	 */
90 	ds.ost_dev = ip->i_dev;
91 	ds.ost_ino = (short)ip->i_number;
92 	ds.ost_mode = (u_short)ip->i_mode;
93 	ds.ost_nlink = ip->i_nlink;
94 	ds.ost_uid = (short)ip->i_uid;
95 	ds.ost_gid = (short)ip->i_gid;
96 	ds.ost_rdev = (dev_t)ip->i_rdev;
97 	ds.ost_size = (int)ip->i_size;
98 	ds.ost_atime = (int)ip->i_atime;
99 	ds.ost_mtime = (int)ip->i_mtime;
100 	ds.ost_ctime = (int)ip->i_ctime;
101 	u.u_error = copyout((caddr_t)&ds, (caddr_t)ub, sizeof(ds));
102 }
103 
104 /*
105  * Set IUPD and IACC times on file.
106  * Can't set ICHG.
107  */
108 outime()
109 {
110 	register struct a {
111 		char	*fname;
112 		time_t	*tptr;
113 	} *uap = (struct a *)u.u_ap;
114 	register struct inode *ip;
115 	time_t tv[2];
116 	struct timeval tv0, tv1;
117 
118 	if ((ip = owner(uap->fname, FOLLOW)) == NULL)
119 		return;
120 	u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv));
121 	if (u.u_error == 0) {
122 		ip->i_flag |= IACC|IUPD|ICHG;
123 		tv0.tv_sec = tv[0]; tv0.tv_usec = 0;
124 		tv1.tv_sec = tv[1]; tv1.tv_usec = 0;
125 		iupdat(ip, &tv0, &tv1, 0);
126 	}
127 	iput(ip);
128 }
129 #endif
130