code:iomove - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki
- 完成 读取/写入 功能
- 读取功能:从 bp->b_addr[o](缓存块偏移o字节) 读出 an个字节字节 到 指定地址空间 的 指定地址
- 写入功能:将 指定地址空间 的 指定地址的an个字节,写入 bp->b_addr[o](缓存块偏移o字节)
- 输入参数
- bp : 指定 的 struct buf
- o : 缓存块偏移量
- an : 传输字节数
- flag : 写标志
- 若为 B_WRITE,则函数执行写入功能
- 否则,函数执行读取功能
- u.segflg : 指定地址空间由u.segflg选择
- u.base : 指定地址由u.base给定
- 运行时修正以下参数
6350 /* Move ’an’ bytes at byte location
6351 * &bp->b_addr[o] to/from (flag) the
6352 * user/kernel (u.segflg) area starting at u.base.
6353 * Update all the arguments by the number
6354 * of bytes moved.
6355 *
6356 * There are 2 algorithms,
6357 * if source address, dest address and count
6358 * are all even in a user copy,
6359 * then the machine language copyin/copyout
6360 * is called.
6361 * If not, its done byte-by-byte with
6362 * cpass and passc.
6363 */
6364 iomove(bp, o, an, flag)
6365 struct buf *bp;
6366 {
6367 register char *cp;
6368 register int n, t;
6369
6370 n = an;
6371 cp = bp->b_addr + o;
6372 if(u.u_segflg==0 && ((n | cp | u.u_base)&01)==0) {
- cp 为 读取/写入 源地址
6373 if (flag==B_WRITE)
6374 cp = copyin(u.u_base, cp, n);
6375 else
6376 cp = copyout(cp, u.u_base, n);
6377 if (cp) {
6378 u.u_error = EFAULT;
6379 return;
6380 }
6381 u.u_base =+ n;
- 若出错
- 抛出错误,错误代码:EFAULT
- 函数返回
6382 dpadd(u.u_offset, n);
6383 u.u_count =- n;
6384 return;
- 修正参数
- 参考 user
6385 }
6386 if (flag==B_WRITE) {
6387 while(n--) {
6388 if ((t = cpass()) < 0)
6389 return;
6390 *cp++ = t;
6391 }
6392 } else
6393 while (n--)
6394 if(passc(*cp++) < 0)
6395 return;
6396 }
6397 /* ------------------------- */
6398
6399