File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037
0038 #ifndef lint
0039 #if 0
0040 static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
0041 #include <sys/cdefs.h>
0042 __FBSDID("$FreeBSD: src/bin/dd/position.c,v 1.23 2004/04/06 20:06:46 markm Exp $");
0043 #endif
0044 #endif
0045
0046 #include <sys/types.h>
0047 #if RTEMS_REMOVED
0048 #include <sys/mtio.h>
0049 #endif
0050
0051 #include "err.h"
0052 #include <errno.h>
0053 #include <inttypes.h>
0054 #include <unistd.h>
0055
0056 #include "dd.h"
0057 #include "extern-dd.h"
0058
0059
0060
0061
0062
0063
0064
0065 void
0066 pos_in(rtems_shell_dd_globals* globals)
0067 {
0068 off_t cnt;
0069 int warned;
0070 ssize_t nr;
0071 size_t bcnt;
0072
0073
0074 if (in.flags & ISSEEK) {
0075 errno = 0;
0076 if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1 &&
0077 errno != 0)
0078 err(exit_jump, 1, "%s", in.name);
0079 return;
0080 }
0081
0082
0083 if (in.offset < 0)
0084 errx(exit_jump, 1, "%s: illegal offset", "iseek/skip");
0085
0086
0087
0088
0089
0090
0091 for (bcnt = in.dbsz, cnt = in.offset, warned = 0; cnt;) {
0092 if ((nr = read(in.fd, in.db, bcnt)) > 0) {
0093 if (in.flags & ISPIPE) {
0094 if (!(bcnt -= nr)) {
0095 bcnt = in.dbsz;
0096 --cnt;
0097 }
0098 } else
0099 --cnt;
0100 continue;
0101 }
0102
0103 if (nr == 0) {
0104 if (files_cnt > 1) {
0105 --files_cnt;
0106 continue;
0107 }
0108 errx(exit_jump, 1, "skip reached end of input");
0109 }
0110
0111
0112
0113
0114
0115
0116 if (ddflags & C_NOERROR) {
0117 if (!warned) {
0118 warn("%s", in.name);
0119 warned = 1;
0120 summary(globals);
0121 }
0122 continue;
0123 }
0124 err(exit_jump, 1, "%s", in.name);
0125 }
0126 }
0127
0128 void
0129 pos_out(rtems_shell_dd_globals* globals)
0130 {
0131 #if RTEMS_REMOVED
0132 struct mtop t_op;
0133 off_t cnt;
0134 ssize_t n;
0135 #endif
0136
0137
0138
0139
0140
0141
0142 if (out.flags & (ISSEEK | ISPIPE)) {
0143 errno = 0;
0144 if (lseek(out.fd, out.offset * out.dbsz, SEEK_CUR) == -1 &&
0145 errno != 0)
0146 err(exit_jump, 1, "%s", out.name);
0147 return;
0148 }
0149
0150
0151 if (out.offset < 0)
0152 errx(exit_jump, 1, "%s: illegal offset", "oseek/seek");
0153
0154 #if RTEMS_REMOVED
0155
0156 if (out.flags & NOREAD) {
0157 t_op.mt_op = MTFSR;
0158 t_op.mt_count = out.offset;
0159
0160 if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
0161 err(1, "%s", out.name);
0162 return;
0163 }
0164
0165
0166 for (cnt = 0; cnt < out.offset; ++cnt) {
0167 if ((n = read(out.fd, out.db, out.dbsz)) > 0)
0168 continue;
0169
0170 if (n == -1)
0171 err(1, "%s", out.name);
0172
0173
0174
0175
0176
0177
0178 t_op.mt_op = MTBSR;
0179 t_op.mt_count = 1;
0180 if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
0181 err(1, "%s", out.name);
0182
0183 while (cnt++ < out.offset) {
0184 n = write(out.fd, out.db, out.dbsz);
0185 if (n == -1)
0186 err(1, "%s", out.name);
0187 if ((size_t)n != out.dbsz)
0188 errx(1, "%s: write failure", out.name);
0189 }
0190 break;
0191 }
0192 #endif
0193 }