|
|
1.1 root 1: /* rdwri.c 4.6 81/03/08 */
2:
3: #include "../h/param.h"
4: #include "../h/systm.h"
5: #include "../h/inode.h"
6: #include "../h/dir.h"
7: #include "../h/user.h"
8: #include "../h/buf.h"
9: #include "../h/conf.h"
10: #include "../h/cmap.h"
11: #include "../h/proc.h"
12: #include "../h/acct.h"
13:
14: /*
15: * Read the file corresponding to
16: * the inode pointed at by the argument.
17: * The actual read arguments are found
18: * in the variables:
19: * u_base core address for destination
20: * u_offset byte offset in file
21: * u_count number of bytes to read
22: * u_segflg read to kernel/user
23: */
24: readi(ip)
25: register struct inode *ip;
26: {
27:
28: if(u.u_count == 0)
29: return;
30: ip->i_flag |= IACC;
31: if (ip->i_sptr) {
32: u.u_nbadio = 0; /* approximates a bad-count per stream */
33: stread(ip);
34: return;
35: }
36: (*fstypsw[ip->i_fstyp].t_read)(ip);
37: }
38:
39: /*
40: * Write the file corresponding to
41: * the inode pointed at by the argument.
42: * The actual write arguments are found
43: * in the variables:
44: * u_base core address for source
45: * u_offset byte offset in file
46: * u_count number of bytes to write
47: * u_segflg write to kernel/user/user I
48: */
49:
50: writei(ip)
51: register struct inode *ip;
52: {
53:
54: if (ip->i_sptr) {
55: ip->i_flag |= IUPD|ICHG;
56: stwrite(ip);
57: return;
58: }
59: (*fstypsw[ip->i_fstyp].t_write)(ip);
60: }
61:
62: /*
63: * Return the logical maximum
64: * of the 2 arguments.
65: */
66: unsigned
67: max(a, b)
68: unsigned a, b;
69: {
70:
71: if(a > b)
72: return(a);
73: return(b);
74: }
75:
76: /*
77: * Return the logical minimum
78: * of the 2 arguments.
79: */
80: unsigned
81: min(a, b)
82: unsigned a, b;
83: {
84:
85: if(a < b)
86: return(a);
87: return(b);
88: }
89:
90: /*
91: * Move n bytes at byte location
92: * &bp->b_un.b_addr[o] to/from (flag) the
93: * user/kernel (u.segflg) area starting at u.base.
94: * Update all the arguments by the number
95: * of bytes moved.
96: */
97: iomove(cp, n, flag)
98: register caddr_t cp;
99: register unsigned n;
100: {
101: register int t;
102:
103: if (n==0)
104: return;
105: if (u.u_segflg != 1) {
106: if (flag==B_WRITE)
107: t = copyin(u.u_base, (caddr_t)cp, n);
108: else
109: t = copyout((caddr_t)cp, u.u_base, n);
110: if (t) {
111: u.u_error = EFAULT;
112: return;
113: }
114: } else
115: if (flag == B_WRITE)
116: bcopy(u.u_base, (caddr_t)cp, n);
117: else
118: bcopy((caddr_t)cp, u.u_base, n);
119: u.u_base += n;
120: u.u_offset += n;
121: u.u_count -= n;
122: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.