2f412847794057a3a6b1f0f9754862ee83038914
[Ack-5.5.git] / util / int / monstruct.c
1 /*
2         Moving system structs between UNIX and EM
3 */
4
5 /* $Id: monstruct.c,v 2.4 1994/06/24 10:48:23 ceriel Exp $ */
6
7 #include        "sysidf.h"
8 #include        "v7ioctl.h"
9 #include        "global.h"
10 #include        "mem.h"
11 #include        "monstruct.h"
12
13 #include        <sys/types.h>
14 #include        <sys/stat.h>
15 #if __STDC__
16 #include        <time.h>
17 #endif
18 #include        <sys/times.h>
19 #include        <sgtty.h>
20
21 #ifdef  BSD_X                           /* from system.h */
22 #include        <sys/timeb.h>
23 #endif  /* BSD_X */
24 #ifdef  SYS_V                           /* from system.h */
25 struct timeb {  /* non-existing; we use an ad-hoc definition */
26         long time;
27         unsigned short millitm;
28         short timezone, dstflag;
29 }
30 #endif  /* SYS_V */
31
32 /******** System to EM memory ********/
33
34 PRIVATE mem_stfld(addr, offset, length, val)
35         ptr addr;
36         size offset, length;
37         long val;
38 {
39         mem_stn(addr + offset, val, length);
40 }
41
42 int stat2mem(addr, statb)
43         ptr addr;
44         struct stat *statb;
45 {
46         if (memfault(addr, V7st_sz))
47                 return 0;
48         mem_stfld(addr, V7st_dev, (long) statb->st_dev);
49         mem_stfld(addr, V7st_ino, (long) statb->st_ino);
50         mem_stfld(addr, V7st_mode, (long) statb->st_mode);
51         mem_stfld(addr, V7st_nlink, (long) statb->st_nlink);
52         mem_stfld(addr, V7st_uid, (long) statb->st_uid);
53         mem_stfld(addr, V7st_gid, (long) statb->st_gid);
54         mem_stfld(addr, V7st_rdev, (long) statb->st_rdev);
55         mem_stfld(addr, V7st_size, (long) statb->st_size);
56         mem_stfld(addr, V7st_atime, (long) statb->st_atime);
57         mem_stfld(addr, V7st_mtime, (long) statb->st_mtime);
58         mem_stfld(addr, V7st_ctime, (long) statb->st_ctime);
59         return 1;
60 }
61
62 int timeb2mem(addr, timebb)
63         ptr addr;
64         struct timeb *timebb;
65 {
66         if (memfault(addr, V7tb_sz))
67                 return 0;
68         mem_stfld(addr, V7tb_time, (long) timebb->time);
69         mem_stfld(addr, V7tb_millitm, (long) timebb->millitm);
70         mem_stfld(addr, V7tb_timezone, (long) timebb->timezone);
71         mem_stfld(addr, V7tb_dstflag, (long) timebb->dstflag);
72         return 1;
73 }
74
75 int tms2mem(addr, tmsb)
76         ptr addr;
77         struct tms *tmsb;
78 {
79         if (memfault(addr, V7tms_sz))
80                 return 0;
81         mem_stfld(addr, V7tms_utime, (long) tmsb->tms_utime);
82         mem_stfld(addr, V7tms_stime, (long) tmsb->tms_stime);
83         mem_stfld(addr, V7tms_cutime, (long) tmsb->tms_cutime);
84         mem_stfld(addr, V7tms_cstime, (long) tmsb->tms_cstime);
85         return 1;
86 }
87
88 int sgttyb2mem(addr, sgttybb)
89         ptr addr;
90         struct sgttyb *sgttybb;
91 {
92         if (memfault(addr, V7sg_sz))
93                 return 0;
94         mem_stfld(addr, V7sg_ispeed, (long) sgttybb->sg_ispeed);
95         mem_stfld(addr, V7sg_ospeed, (long) sgttybb->sg_ospeed);
96         mem_stfld(addr, V7sg_erase, (long) sgttybb->sg_erase);
97         mem_stfld(addr, V7sg_kill, (long) sgttybb->sg_kill);
98         mem_stfld(addr, V7sg_flags, (long) sgttybb->sg_flags);
99         return 1;
100 }
101
102 #ifdef  BSD_X                           /* from system.h */
103 int tchars2mem(addr, tcharsb)
104         ptr addr;
105         struct tchars *tcharsb;
106 {
107         if (memfault(addr, V7t_sz_tch))
108                 return 0;
109         mem_stfld(addr, V7t_intrc, (long) tcharsb->t_intrc);
110         mem_stfld(addr, V7t_quitc, (long) tcharsb->t_quitc);
111         mem_stfld(addr, V7t_startc, (long) tcharsb->t_startc);
112         mem_stfld(addr, V7t_stopc, (long) tcharsb->t_stopc);
113         mem_stfld(addr, V7t_eofc, (long) tcharsb->t_eofc);
114         mem_stfld(addr, V7t_brkc, (long) tcharsb->t_brkc);
115         return 1;
116 }
117
118 #ifndef V7IOCTL
119 int ltchars2mem(addr, ltcharsb)
120         ptr addr;
121         struct ltchars *ltcharsb;
122 {
123         if (memfault(addr, V7t_sz_ltch))
124                 return 0;
125         mem_stfld(addr, V7t_suspc, (long) ltcharsb->t_suspc);
126         mem_stfld(addr, V7t_dsuspc, (long) ltcharsb->t_dsuspc);
127         mem_stfld(addr, V7t_rprntc, (long) ltcharsb->t_rprntc);
128         mem_stfld(addr, V7t_flushc, (long) ltcharsb->t_flushc);
129         mem_stfld(addr, V7t_werasc, (long) ltcharsb->t_werasc);
130         mem_stfld(addr, V7t_lnextc, (long) ltcharsb->t_lnextc);
131         return 1;
132 }
133 #endif  /* V7IOCTL */
134 #endif  /* BSD_X */
135
136
137 /******** EM memory to system ********/
138
139 PRIVATE unsigned long mem_ldfld(addr, offset, length)
140         ptr addr;
141         size offset, length;
142 {
143         return mem_ldu(addr + offset, length);
144 }
145
146 int mem2sgtty(addr, sgttybb)
147         ptr addr;
148         struct sgttyb *sgttybb;
149 {
150         if (memfault(addr, V7sg_sz))
151                 return 0;
152         sgttybb->sg_ispeed = (char) mem_ldfld(addr, V7sg_ispeed);
153         sgttybb->sg_ospeed = (char) mem_ldfld(addr, V7sg_ospeed);
154         sgttybb->sg_erase = (char) mem_ldfld(addr, V7sg_erase);
155         sgttybb->sg_kill = (char) mem_ldfld(addr, V7sg_kill);
156         sgttybb->sg_flags = (short) mem_ldfld(addr, V7sg_flags);
157         return 1;
158 }
159
160 #ifdef  BSD_X                           /* from system.h */
161 int mem2tchars(addr, tcharsb)
162         ptr addr;
163         struct tchars *tcharsb;
164 {
165         if (memfault(addr, V7t_sz_tch))
166                 return 0;
167         tcharsb->t_intrc = (char) mem_ldfld(addr, V7t_intrc);
168         tcharsb->t_quitc = (char) mem_ldfld(addr, V7t_quitc);
169         tcharsb->t_startc = (char) mem_ldfld(addr, V7t_startc);
170         tcharsb->t_stopc = (char) mem_ldfld(addr, V7t_stopc);
171         tcharsb->t_eofc = (char) mem_ldfld(addr, V7t_eofc);
172         tcharsb->t_brkc = (char) mem_ldfld(addr, V7t_brkc);
173         return 1;
174 }
175
176 #ifndef V7IOCTL
177 int mem2ltchars(addr, ltcharsb)
178         ptr addr;
179         struct ltchars *ltcharsb;
180 {
181         if (memfault(addr, V7t_sz_ltch))
182                 return 0;
183         ltcharsb->t_suspc = (char) mem_ldfld(addr, V7t_suspc);
184         ltcharsb->t_dsuspc = (char) mem_ldfld(addr, V7t_dsuspc);
185         ltcharsb->t_rprntc = (char) mem_ldfld(addr, V7t_rprntc);
186         ltcharsb->t_flushc = (char) mem_ldfld(addr, V7t_flushc);
187         ltcharsb->t_werasc = (char) mem_ldfld(addr, V7t_werasc);
188         ltcharsb->t_lnextc = (char) mem_ldfld(addr, V7t_lnextc);
189         return 1;
190 }
191 #endif  /* V7IOCTL */
192 #endif  /* BSD_X */
193