This source file includes following definitions.
- cvtstat
- compat_35_sys_stat
- compat_35_sys_lstat
- compat_35_sys_fstat
- compat_35_sys_fhstat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/filedesc.h>
42 #include <sys/kernel.h>
43 #include <sys/proc.h>
44 #include <sys/file.h>
45 #include <sys/vnode.h>
46 #include <sys/namei.h>
47 #include <sys/dirent.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
50 #include <sys/stat.h>
51
52 #include <sys/mount.h>
53 #include <sys/syscallargs.h>
54
55 static void cvtstat(struct stat *, struct stat35 *);
56
57
58
59
60 static void
61 cvtstat(struct stat *st, struct stat35 *ost)
62 {
63
64 ost->st_dev = st->st_dev;
65 ost->st_ino = st->st_ino;
66 ost->st_mode = st->st_mode & 0xffff;
67 ost->st_nlink = st->st_nlink & 0xffff;
68 ost->st_uid = st->st_uid;
69 ost->st_gid = st->st_gid;
70 ost->st_rdev = st->st_rdev;
71 ost->st_atimespec = st->st_atimespec;
72 ost->st_mtimespec = st->st_mtimespec;
73 ost->st_ctimespec = st->st_ctimespec;
74 ost->st_size = st->st_size;
75 ost->st_blocks = st->st_blocks;
76 ost->st_blksize = st->st_blksize;
77 ost->st_flags = st->st_flags;
78 ost->st_gen = st->st_gen;
79 }
80
81
82
83
84
85 int
86 compat_35_sys_stat(struct proc *p, void *v, register_t *retval)
87 {
88 struct compat_35_sys_stat_args
89
90
91 *uap = v;
92 struct stat sb;
93 struct stat35 osb;
94 int error;
95 struct nameidata nd;
96
97 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
98 SCARG(uap, path), p);
99 if ((error = namei(&nd)) != 0)
100 return (error);
101 error = vn_stat(nd.ni_vp, &sb, p);
102 vput(nd.ni_vp);
103 if (error)
104 return (error);
105
106 if (suser(p, 0))
107 sb.st_gen = 0;
108 cvtstat(&sb, &osb);
109 error = copyout(&osb, SCARG(uap, ub), sizeof(osb));
110 return (error);
111 }
112
113
114
115
116
117 int
118 compat_35_sys_lstat(struct proc *p, void *v, register_t *retval)
119 {
120 struct compat_35_sys_lstat_args
121
122
123 *uap = v;
124 struct stat sb;
125 struct stat35 osb;
126 int error;
127 struct nameidata nd;
128
129 NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
130 SCARG(uap, path), p);
131 if ((error = namei(&nd)) != 0)
132 return (error);
133 error = vn_stat(nd.ni_vp, &sb, p);
134 vput(nd.ni_vp);
135 if (error)
136 return (error);
137
138 if (suser(p, 0))
139 sb.st_gen = 0;
140 cvtstat(&sb, &osb);
141 error = copyout(&osb, SCARG(uap, ub), sizeof(osb));
142 return (error);
143 }
144
145
146
147
148
149 int
150 compat_35_sys_fstat(struct proc *p, void *v, register_t *retval)
151 {
152 struct compat_35_sys_fstat_args
153
154
155 *uap = v;
156 int fd = SCARG(uap, fd);
157 struct filedesc *fdp = p->p_fd;
158 struct file *fp;
159 struct stat ub;
160 struct stat35 oub;
161 int error;
162
163 if ((fp = fd_getfile(fdp, fd)) == NULL)
164 return (EBADF);
165 FREF(fp);
166 error = (*fp->f_ops->fo_stat)(fp, &ub, p);
167 FRELE(fp);
168 if (error == 0) {
169
170
171 if (suser(p, 0))
172 ub.st_gen = 0;
173 cvtstat(&ub, &oub);
174 error = copyout(&oub, SCARG(uap, sb), sizeof(oub));
175 }
176 return (error);
177 }
178
179
180 int
181 compat_35_sys_fhstat(struct proc *p, void *v, register_t *retval)
182 {
183 struct sys_fhstat_args
184
185
186 *uap = v;
187 struct stat ub;
188 struct stat35 oub;
189 int error;
190 fhandle_t fh;
191 struct mount *mp;
192 struct vnode *vp;
193
194
195
196
197 if ((error = suser(p, 0)))
198 return (error);
199
200 if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fhandle_t))) != 0)
201 return (error);
202
203 if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
204 return (ESTALE);
205 if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
206 return (error);
207 error = vn_stat(vp, &ub, p);
208 vput(vp);
209 if (error)
210 return (error);
211 cvtstat(&ub, &oub);
212 error = copyout(&oub, SCARG(uap, sb), sizeof(oub));
213 return (error);
214 }