Deleted Added
full compact
ibcs2_misc.c (139799) ibcs2_misc.c (141488)
1/*-
2 * Copyright (c) 1995 Steven Wallace
3 * Copyright (c) 1994, 1995 Scott Bartram
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and

--- 33 unchanged lines hidden (view full) ---

42 * SUCH DAMAGE.
43 *
44 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
45 *
46 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
47 */
48
49#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1995 Steven Wallace
3 * Copyright (c) 1994, 1995 Scott Bartram
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and

--- 33 unchanged lines hidden (view full) ---

42 * SUCH DAMAGE.
43 *
44 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
45 *
46 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
47 */
48
49#include <sys/cdefs.h>
50__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_misc.c 139799 2005-01-06 23:22:04Z imp $");
50__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_misc.c 141488 2005-02-07 22:02:18Z jhb $");
51
52/*
53 * IBCS2 compatibility module.
54 *
55 * IBCS2 system calls that are implemented differently in BSD are
56 * handled here.
57 */
58#include "opt_mac.h"
59
60#include <sys/param.h>
61#include <sys/systm.h>
62#include <sys/dirent.h>
63#include <sys/fcntl.h>
64#include <sys/filedesc.h>
51
52/*
53 * IBCS2 compatibility module.
54 *
55 * IBCS2 system calls that are implemented differently in BSD are
56 * handled here.
57 */
58#include "opt_mac.h"
59
60#include <sys/param.h>
61#include <sys/systm.h>
62#include <sys/dirent.h>
63#include <sys/fcntl.h>
64#include <sys/filedesc.h>
65#include <sys/imgact.h>
65#include <sys/kernel.h>
66#include <sys/lock.h>
67#include <sys/mac.h>
68#include <sys/malloc.h>
69#include <sys/file.h> /* Must come after sys/malloc.h */
70#include <sys/mutex.h>
71#include <sys/reboot.h>
72#include <sys/resourcevar.h>

--- 118 unchanged lines hidden (view full) ---

191 return 0;
192}
193
194int
195ibcs2_execv(td, uap)
196 struct thread *td;
197 struct ibcs2_execv_args *uap;
198{
66#include <sys/kernel.h>
67#include <sys/lock.h>
68#include <sys/mac.h>
69#include <sys/malloc.h>
70#include <sys/file.h> /* Must come after sys/malloc.h */
71#include <sys/mutex.h>
72#include <sys/reboot.h>
73#include <sys/resourcevar.h>

--- 118 unchanged lines hidden (view full) ---

192 return 0;
193}
194
195int
196ibcs2_execv(td, uap)
197 struct thread *td;
198 struct ibcs2_execv_args *uap;
199{
199 struct execve_args ea;
200 caddr_t sg = stackgap_init();
200 struct image_args eargs;
201 char *path;
202 int error;
201
203
202 CHECKALTEXIST(td, &sg, uap->path);
203 ea.fname = uap->path;
204 ea.argv = uap->argp;
205 ea.envv = NULL;
206 return execve(td, &ea);
204 CHECKALTEXIST(td, uap->path, &path);
205
206 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
207 free(path, M_TEMP);
208 if (error == 0)
209 error = kern_execve(td, &eargs, NULL);
210 exec_free_args(&eargs);
211 return (error);
207}
208
209int
210ibcs2_execve(td, uap)
211 struct thread *td;
212 struct ibcs2_execve_args *uap;
213{
212}
213
214int
215ibcs2_execve(td, uap)
216 struct thread *td;
217 struct ibcs2_execve_args *uap;
218{
214 caddr_t sg = stackgap_init();
215 CHECKALTEXIST(td, &sg, uap->path);
216 return execve(td, (struct execve_args *)uap);
219 struct image_args eargs;
220 char *path;
221 int error;
222
223 CHECKALTEXIST(td, uap->path, &path);
224
225 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
226 uap->envp);
227 free(path, M_TEMP);
228 if (error == 0)
229 error = kern_execve(td, &eargs, NULL);
230 exec_free_args(&eargs);
231 return (error);
217}
218
219int
220ibcs2_umount(td, uap)
221 struct thread *td;
222 struct ibcs2_umount_args *uap;
223{
224 struct unmount_args um;

--- 393 unchanged lines hidden (view full) ---

618 return (error);
619}
620
621int
622ibcs2_mknod(td, uap)
623 struct thread *td;
624 struct ibcs2_mknod_args *uap;
625{
232}
233
234int
235ibcs2_umount(td, uap)
236 struct thread *td;
237 struct ibcs2_umount_args *uap;
238{
239 struct unmount_args um;

--- 393 unchanged lines hidden (view full) ---

633 return (error);
634}
635
636int
637ibcs2_mknod(td, uap)
638 struct thread *td;
639 struct ibcs2_mknod_args *uap;
640{
626 caddr_t sg = stackgap_init();
641 char *path;
642 int error;
627
643
628 CHECKALTCREAT(td, &sg, uap->path);
629 if (S_ISFIFO(uap->mode)) {
630 struct mkfifo_args ap;
631 ap.path = uap->path;
632 ap.mode = uap->mode;
633 return mkfifo(td, &ap);
634 } else {
635 struct mknod_args ap;
636 ap.path = uap->path;
637 ap.mode = uap->mode;
638 ap.dev = uap->dev;
639 return mknod(td, &ap);
640 }
644 CHECKALTCREAT(td, uap->path, &path);
645 if (S_ISFIFO(uap->mode))
646 error = kern_mkfifo(td, path, UIO_SYSSPACE, uap->mode);
647 else
648 error = kern_mknod(td, path, UIO_SYSSPACE, uap->mode, uap->dev);
649 free(path, M_TEMP);
650 return (error);
641}
642
643int
644ibcs2_getgroups(td, uap)
645 struct thread *td;
646 struct ibcs2_getgroups_args *uap;
647{
648 int error, i;

--- 94 unchanged lines hidden (view full) ---

743 return 0;
744}
745
746int
747ibcs2_pathconf(td, uap)
748 struct thread *td;
749 struct ibcs2_pathconf_args *uap;
750{
651}
652
653int
654ibcs2_getgroups(td, uap)
655 struct thread *td;
656 struct ibcs2_getgroups_args *uap;
657{
658 int error, i;

--- 94 unchanged lines hidden (view full) ---

753 return 0;
754}
755
756int
757ibcs2_pathconf(td, uap)
758 struct thread *td;
759 struct ibcs2_pathconf_args *uap;
760{
761 char *path;
762 int error;
763
764 CHECKALTEXIST(td, uap->path, &path);
751 uap->name++; /* iBCS2 _PC_* defines are offset by one */
765 uap->name++; /* iBCS2 _PC_* defines are offset by one */
752 return pathconf(td, (struct pathconf_args *)uap);
766 error = kern_pathconf(td, path, UIO_SYSSPACE, uap->name);
767 free(path, M_TEMP);
768 return (error);
753}
754
755int
756ibcs2_fpathconf(td, uap)
757 struct thread *td;
758 struct ibcs2_fpathconf_args *uap;
759{
760 uap->name++; /* iBCS2 _PC_* defines are offset by one */

--- 67 unchanged lines hidden (view full) ---

828 return 0;
829}
830
831int
832ibcs2_alarm(td, uap)
833 struct thread *td;
834 struct ibcs2_alarm_args *uap;
835{
769}
770
771int
772ibcs2_fpathconf(td, uap)
773 struct thread *td;
774 struct ibcs2_fpathconf_args *uap;
775{
776 uap->name++; /* iBCS2 _PC_* defines are offset by one */

--- 67 unchanged lines hidden (view full) ---

844 return 0;
845}
846
847int
848ibcs2_alarm(td, uap)
849 struct thread *td;
850 struct ibcs2_alarm_args *uap;
851{
852 struct itimerval itv, oitv;
836 int error;
853 int error;
837 struct itimerval *itp, *oitp;
838 struct setitimer_args sa;
839 caddr_t sg = stackgap_init();
840
854
841 itp = stackgap_alloc(&sg, sizeof(*itp));
842 oitp = stackgap_alloc(&sg, sizeof(*oitp));
843 timevalclear(&itp->it_interval);
844 itp->it_value.tv_sec = uap->sec;
845 itp->it_value.tv_usec = 0;
846
847 sa.which = ITIMER_REAL;
848 sa.itv = itp;
849 sa.oitv = oitp;
850 error = setitimer(td, &sa);
855 timevalclear(&itv.it_interval);
856 itv.it_value.tv_sec = uap->sec;
857 itv.it_value.tv_usec = 0;
858 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
851 if (error)
859 if (error)
852 return error;
853 if (oitp->it_value.tv_usec)
854 oitp->it_value.tv_sec++;
855 td->td_retval[0] = oitp->it_value.tv_sec;
856 return 0;
860 return (error);
861 if (oitv.it_value.tv_usec != 0)
862 oitv.it_value.tv_sec++;
863 td->td_retval[0] = oitv.it_value.tv_sec;
864 return (0);
857}
858
859int
860ibcs2_times(td, uap)
861 struct thread *td;
862 struct ibcs2_times_args *uap;
863{
865}
866
867int
868ibcs2_times(td, uap)
869 struct thread *td;
870 struct ibcs2_times_args *uap;
871{
864 int error;
865 struct getrusage_args ga;
872 struct rusage ru;
873 struct timeval t;
866 struct tms tms;
874 struct tms tms;
867 struct timeval t;
868 caddr_t sg = stackgap_init();
869 struct rusage *ru = stackgap_alloc(&sg, sizeof(*ru));
875 int error;
876
870#define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
871
877#define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
878
872 ga.who = RUSAGE_SELF;
873 ga.rusage = ru;
874 error = getrusage(td, &ga);
879 error = kern_getrusage(td, RUSAGE_SELF, &ru);
875 if (error)
880 if (error)
876 return error;
877 tms.tms_utime = CONVTCK(ru->ru_utime);
878 tms.tms_stime = CONVTCK(ru->ru_stime);
881 return (error);
882 tms.tms_utime = CONVTCK(ru.ru_utime);
883 tms.tms_stime = CONVTCK(ru.ru_stime);
879
884
880 ga.who = RUSAGE_CHILDREN;
881 error = getrusage(td, &ga);
885 error = kern_getrusage(td, RUSAGE_CHILDREN, &ru);
882 if (error)
886 if (error)
883 return error;
884 tms.tms_cutime = CONVTCK(ru->ru_utime);
885 tms.tms_cstime = CONVTCK(ru->ru_stime);
887 return (error);
888 tms.tms_cutime = CONVTCK(ru.ru_utime);
889 tms.tms_cstime = CONVTCK(ru.ru_stime);
886
887 microtime(&t);
890
891 microtime(&t);
888 td->td_retval[0] = CONVTCK(t);
892 td->td_retval[0] = CONVTCK(t);
889
893
890 return copyout((caddr_t)&tms, (caddr_t)uap->tp,
891 sizeof(struct tms));
894 return (copyout(&tms, uap->tp, sizeof(struct tms)));
892}
893
894int
895ibcs2_stime(td, uap)
896 struct thread *td;
897 struct ibcs2_stime_args *uap;
898{
899 int error;

--- 11 unchanged lines hidden (view full) ---

911 return 0;
912}
913
914int
915ibcs2_utime(td, uap)
916 struct thread *td;
917 struct ibcs2_utime_args *uap;
918{
895}
896
897int
898ibcs2_stime(td, uap)
899 struct thread *td;
900 struct ibcs2_stime_args *uap;
901{
902 int error;

--- 11 unchanged lines hidden (view full) ---

914 return 0;
915}
916
917int
918ibcs2_utime(td, uap)
919 struct thread *td;
920 struct ibcs2_utime_args *uap;
921{
922 struct ibcs2_utimbuf ubuf;
923 struct timeval tbuf[2], *tp;
924 char *path;
919 int error;
925 int error;
920 struct utimes_args sa;
921 struct timeval *tp;
922 caddr_t sg = stackgap_init();
923
926
924 CHECKALTEXIST(td, &sg, uap->path);
925 sa.path = uap->path;
926 if (uap->buf) {
927 if (uap->buf) {
927 struct ibcs2_utimbuf ubuf;
928
929 if ((error = copyin((caddr_t)uap->buf, (caddr_t)&ubuf,
930 sizeof(ubuf))) != 0)
931 return error;
932 sa.tptr = stackgap_alloc(&sg,
933 2 * sizeof(struct timeval *));
934 tp = (struct timeval *)sa.tptr;
935 tp->tv_sec = ubuf.actime;
936 tp->tv_usec = 0;
937 tp++;
938 tp->tv_sec = ubuf.modtime;
939 tp->tv_usec = 0;
928 error = copyin(uap->buf, &ubuf, sizeof(ubuf));
929 if (error)
930 return (error);
931 tbuf[0].tv_sec = ubuf.actime;
932 tbuf[0].tv_usec = 0;
933 tbuf[1].tv_sec = ubuf.modtime;
934 tbuf[1].tv_usec = 0;
935 tp = tbuf;
940 } else
936 } else
941 sa.tptr = NULL;
942 return utimes(td, &sa);
937 tp = NULL;
938
939 CHECKALTEXIST(td, uap->path, &path);
940 error = kern_utimes(td, path, UIO_SYSSPACE, tp, UIO_SYSSPACE);
941 free(path, M_TEMP);
942 return (error);
943}
944
945int
946ibcs2_nice(td, uap)
947 struct thread *td;
948 struct ibcs2_nice_args *uap;
949{
950 int error;

--- 153 unchanged lines hidden (view full) ---

1104 return EINVAL; /* XXX - TODO */
1105}
1106
1107int
1108ibcs2_unlink(td, uap)
1109 struct thread *td;
1110 struct ibcs2_unlink_args *uap;
1111{
943}
944
945int
946ibcs2_nice(td, uap)
947 struct thread *td;
948 struct ibcs2_nice_args *uap;
949{
950 int error;

--- 153 unchanged lines hidden (view full) ---

1104 return EINVAL; /* XXX - TODO */
1105}
1106
1107int
1108ibcs2_unlink(td, uap)
1109 struct thread *td;
1110 struct ibcs2_unlink_args *uap;
1111{
1112 caddr_t sg = stackgap_init();
1112 char *path;
1113 int error;
1113
1114
1114 CHECKALTEXIST(td, &sg, uap->path);
1115 return unlink(td, (struct unlink_args *)uap);
1115 CHECKALTEXIST(td, uap->path, &path);
1116 error = kern_unlink(td, path, UIO_SYSSPACE);
1117 free(path, M_TEMP);
1118 return (error);
1116}
1117
1118int
1119ibcs2_chdir(td, uap)
1120 struct thread *td;
1121 struct ibcs2_chdir_args *uap;
1122{
1119}
1120
1121int
1122ibcs2_chdir(td, uap)
1123 struct thread *td;
1124 struct ibcs2_chdir_args *uap;
1125{
1123 caddr_t sg = stackgap_init();
1126 char *path;
1127 int error;
1124
1128
1125 CHECKALTEXIST(td, &sg, uap->path);
1126 return chdir(td, (struct chdir_args *)uap);
1129 CHECKALTEXIST(td, uap->path, &path);
1130 error = kern_chdir(td, path, UIO_SYSSPACE);
1131 free(path, M_TEMP);
1132 return (error);
1127}
1128
1129int
1130ibcs2_chmod(td, uap)
1131 struct thread *td;
1132 struct ibcs2_chmod_args *uap;
1133{
1133}
1134
1135int
1136ibcs2_chmod(td, uap)
1137 struct thread *td;
1138 struct ibcs2_chmod_args *uap;
1139{
1134 caddr_t sg = stackgap_init();
1140 char *path;
1141 int error;
1135
1142
1136 CHECKALTEXIST(td, &sg, uap->path);
1137 return chmod(td, (struct chmod_args *)uap);
1143 CHECKALTEXIST(td, uap->path, &path);
1144 error = kern_chmod(td, path, UIO_SYSSPACE, uap->mode);
1145 free(path, M_TEMP);
1146 return (error);
1138}
1139
1140int
1141ibcs2_chown(td, uap)
1142 struct thread *td;
1143 struct ibcs2_chown_args *uap;
1144{
1147}
1148
1149int
1150ibcs2_chown(td, uap)
1151 struct thread *td;
1152 struct ibcs2_chown_args *uap;
1153{
1145 caddr_t sg = stackgap_init();
1154 char *path;
1155 int error;
1146
1156
1147 CHECKALTEXIST(td, &sg, uap->path);
1148 return chown(td, (struct chown_args *)uap);
1157 CHECKALTEXIST(td, uap->path, &path);
1158 error = kern_chown(td, path, UIO_SYSSPACE, uap->uid, uap->gid);
1159 free(path, M_TEMP);
1160 return (error);
1149}
1150
1151int
1152ibcs2_rmdir(td, uap)
1153 struct thread *td;
1154 struct ibcs2_rmdir_args *uap;
1155{
1161}
1162
1163int
1164ibcs2_rmdir(td, uap)
1165 struct thread *td;
1166 struct ibcs2_rmdir_args *uap;
1167{
1156 caddr_t sg = stackgap_init();
1168 char *path;
1169 int error;
1157
1170
1158 CHECKALTEXIST(td, &sg, uap->path);
1159 return rmdir(td, (struct rmdir_args *)uap);
1171 CHECKALTEXIST(td, uap->path, &path);
1172 error = kern_rmdir(td, path, UIO_SYSSPACE);
1173 free(path, M_TEMP);
1174 return (error);
1160}
1161
1162int
1163ibcs2_mkdir(td, uap)
1164 struct thread *td;
1165 struct ibcs2_mkdir_args *uap;
1166{
1175}
1176
1177int
1178ibcs2_mkdir(td, uap)
1179 struct thread *td;
1180 struct ibcs2_mkdir_args *uap;
1181{
1167 caddr_t sg = stackgap_init();
1182 char *path;
1183 int error;
1168
1184
1169 CHECKALTCREAT(td, &sg, uap->path);
1170 return mkdir(td, (struct mkdir_args *)uap);
1185 CHECKALTEXIST(td, uap->path, &path);
1186 error = kern_mkdir(td, path, UIO_SYSSPACE, uap->mode);
1187 free(path, M_TEMP);
1188 return (error);
1171}
1172
1173int
1174ibcs2_symlink(td, uap)
1175 struct thread *td;
1176 struct ibcs2_symlink_args *uap;
1177{
1189}
1190
1191int
1192ibcs2_symlink(td, uap)
1193 struct thread *td;
1194 struct ibcs2_symlink_args *uap;
1195{
1178 caddr_t sg = stackgap_init();
1196 char *path, *link;
1197 int error;
1179
1198
1180 CHECKALTEXIST(td, &sg, uap->path);
1181 CHECKALTCREAT(td, &sg, uap->link);
1182 return symlink(td, (struct symlink_args *)uap);
1199 CHECKALTEXIST(td, uap->path, &path);
1200
1201 /*
1202 * Have to expand CHECKALTCREAT() so that 'path' can be freed on
1203 * errors.
1204 */
1205 error = ibcs2_emul_find(td, uap->link, UIO_USERSPACE, &link, 1);
1206 if (link == NULL) {
1207 free(path, M_TEMP);
1208 return (error);
1209 }
1210 error = kern_symlink(td, path, link, UIO_SYSSPACE);
1211 free(path, M_TEMP);
1212 free(link, M_TEMP);
1213 return (error);
1183}
1184
1185int
1186ibcs2_rename(td, uap)
1187 struct thread *td;
1188 struct ibcs2_rename_args *uap;
1189{
1214}
1215
1216int
1217ibcs2_rename(td, uap)
1218 struct thread *td;
1219 struct ibcs2_rename_args *uap;
1220{
1190 caddr_t sg = stackgap_init();
1221 char *from, *to;
1222 int error;
1191
1223
1192 CHECKALTEXIST(td, &sg, uap->from);
1193 CHECKALTCREAT(td, &sg, uap->to);
1194 return rename(td, (struct rename_args *)uap);
1224 CHECKALTEXIST(td, uap->from, &from);
1225
1226 /*
1227 * Have to expand CHECKALTCREAT() so that 'from' can be freed on
1228 * errors.
1229 */
1230 error = ibcs2_emul_find(td, uap->to, UIO_USERSPACE, &to, 1);
1231 if (link == NULL) {
1232 free(from, M_TEMP);
1233 return (error);
1234 }
1235 error = kern_rename(td, from, to, UIO_SYSSPACE);
1236 free(from, M_TEMP);
1237 free(to, M_TEMP);
1238 return (error);
1195}
1196
1197int
1198ibcs2_readlink(td, uap)
1199 struct thread *td;
1200 struct ibcs2_readlink_args *uap;
1201{
1239}
1240
1241int
1242ibcs2_readlink(td, uap)
1243 struct thread *td;
1244 struct ibcs2_readlink_args *uap;
1245{
1202 caddr_t sg = stackgap_init();
1246 char *path;
1247 int error;
1203
1248
1204 CHECKALTEXIST(td, &sg, uap->path);
1205 return readlink(td, (struct readlink_args *) uap);
1249 CHECKALTEXIST(td, uap->path, &path);
1250 error = kern_readlink(td, path, UIO_SYSSPACE, uap->buf, UIO_USERSPACE,
1251 uap->count);
1252 free(path, M_TEMP);
1253 return (error);
1206}
1254}