Exemplo n.º 1
0
/*
 * write_chunks: write the chunk_buf on the device. The number of write
 * operations are based on the parameters write_end, offset, and chunksize.
 *
 * Returns 0 on success, or -ve error number on failure.
 */
int write_chunks(int fd, unsigned long long offset,unsigned long long write_end,
		 char *chunk_buf, size_t chunksize, const time_t time_st,
		 const ino_t inode_st, const char *file)
{
	unsigned long long stride, count = 0;

	stride = full ? chunksize : (ONE_GB - chunksize);
	for (offset = offset & ~(chunksize - 1); offset < write_end;
	     offset += stride) {
		int ret;

		if (lseek64(fd, offset, SEEK_SET) == -1) {
			fprintf(stderr, "\n%s: lseek64(%s+%llu) failed: %s\n",
				progname, file, offset, strerror(errno));
			return -errno;
		}
		if (offset + chunksize > write_end)
			chunksize = write_end - offset;
		if (!full && offset > chunksize) {
			fill_chunk(chunk_buf, chunksize, offset, time_st,
				   inode_st);
			ret = write_retry(fd, chunk_buf, chunksize,
					  offset, file);
			if (ret < 0)
				return ret;
			offset += chunksize;
			count += chunksize;
			if (offset + chunksize > write_end)
				chunksize = write_end - offset;
		}
		fill_chunk(chunk_buf, chunksize, offset, time_st, inode_st);
		ret = write_retry(fd, chunk_buf, chunksize, offset, file);
		if (ret < 0)
			return ret;

		count += chunksize;
		if (verbose > 1)
			show_rate("write", offset, &count);
	}

	if (verbose > 1) {
		show_rate("write", offset, &count);
		printf("\nwrite complete\n");
	}
	if (fsync(fd) == -1) {
		fprintf(stderr, "%s: fsync failed: %s\n", progname,
			strerror(errno));
		return -errno;
	}
	return 0;
}
Exemplo n.º 2
0
int main(void)
{
    int fd;

    fd = open("/dev/ttyS1",O_RDWR |O_NONBLOCK);
    if(fd < 0){
        exit(1);
    }
    set_opt_str(fd,9600,8,'N',1);

    while(1){
        show_ip(fd,1);
        show_rate(fd,1);
        show_temperature(fd,1);
    }
    close(fd);
    
    return 0;
}
Exemplo n.º 3
0
/*
 * read_chunk: reads the chunk_buf from the device. The number of read
 * operations are based on the parameters read_end, offset, and chunksize.
 */
int read_chunks(int fd, unsigned long long offset, unsigned long long read_end,
		char *chunk_buf, size_t chunksize, const time_t time_st,
		const ino_t inode_st, const char *file)
{
	unsigned long long stride, count = 0;

	if (ioctl(fd, BLKFLSBUF, 0) < 0 && verbose)
		fprintf(stderr, "%s: ioctl BLKFLSBUF failed: %s (ignoring)\n",
			progname, strerror(errno));

	stride = full ? chunksize : (ONE_GB - chunksize);
	for (offset = offset & ~(chunksize - 1); offset < read_end;
	     offset += stride) {
		ssize_t nread;

		if (lseek64(fd, offset, SEEK_SET) == -1) {
			fprintf(stderr, "\n%s: lseek64(%llu) failed: %s\n",
				progname, offset, strerror(errno));
			return 1;
		}
		if (offset + chunksize > read_end)
			chunksize = read_end - offset;

		if (!full && offset > chunksize) {
			nread = read(fd, chunk_buf, chunksize);
			if (nread < 0) {
				fprintf(stderr,"\n%s: read %s@%llu+%zi failed: "
					"%s\n", progname, file, offset,
					chunksize, strerror(errno));
				error_count++;
				return 1;
			}
			if (nread < chunksize) {
				fprintf(stderr, "\n%s: read %s@%llu+%zi short: "
					"%zi read\n", progname, file, offset,
					chunksize, nread);
				error_count++;
			}
			if (verify_chunk(chunk_buf, nread, offset, time_st,
					 inode_st, file) != 0)
				return 1;
			offset += chunksize;
			count += chunksize;

			/* Need to reset position after read error */
			if (nread < chunksize &&
			    lseek64(fd, offset, SEEK_SET) == -1) {
				fprintf(stderr,
					"\n%s: lseek64(%s@%llu) failed: %s\n",
					progname, file, offset,strerror(errno));
				return 1;
			}
			if (offset + chunksize >= read_end)
				chunksize = read_end - offset;
		}

		nread = read(fd, chunk_buf, chunksize);
		if (nread < 0) {
			fprintf(stderr, "\n%s: read failed: %s\n", progname,
				strerror(errno));
			error_count++;
			return 1;
		}
		if (nread < chunksize) {
			fprintf(stderr, "\n%s: read %s@%llu+%zi short: "
				"%zi read\n", progname, file, offset,
				chunksize, nread);
			error_count++;
		}

		if (verify_chunk(chunk_buf, nread, offset, time_st,
				 inode_st, file) != 0)
			return 1;

		count += chunksize;
		if (verbose > 1)
			show_rate("read", offset, &count);
	}
	if (verbose > 1) {
		show_rate("read", offset, &count);
		printf("\nread complete\n");
	}
	return 0;
}
Exemplo n.º 4
0
int do_login(int argc, char *outfile, char *outtyp, char *outcomp, int forcehead)
{
	DSK_PDRIVER outdr = NULL;
	dsk_err_t e;
	DSK_GEOMETRY dg;
	unsigned char drv_status;
	const char *comp;
	char *comment;
	int indent = 0;
	int opt, any;

	dsk_reportfunc_set(report, report_end);	
	e = dsk_open(&outdr, outfile, outtyp, outcomp);
	if (!e) e = dsk_set_retry(outdr, retries);
	if (forcehead >= 0 && !e) e = dsk_set_forcehead(outdr, forcehead);
	if (!e) e = dsk_getgeom(outdr, &dg);
	if (!e)
	{
		if (argc > 1)
		{
			printf("%s:\n", outfile);
			indent = 2;
		}
                printf(          "%-*.*sDriver:      %s\n", 
				indent, indent, "", dsk_drvdesc(outdr));
		comp = dsk_compname(outdr);
                if (comp) 
		{
			printf("%-*.*sCompression: %s\n", 
				indent, indent, "", dsk_compdesc(outdr));
		}

		if (forcehead >= 0) 
		{
			printf("%-*.*s[Forced to read from side %d]\n", 
					indent, indent, "", forcehead);
		}

		printf("%-*.*sSidedness:     %s\n"
                       "%-*.*sCylinders:     %2d\n"
		       "%-*.*sHeads:          %d\n"
                       "%-*.*sSectors:      %3d\n"
                       "%-*.*sFirst sector: %3d\n"
                       "%-*.*sSector size: %4ld\n"
		       "%-*.*sData rate:     %s\n"
		       "%-*.*sRecord mode:  %s\n"
		       "%-*.*sComplement:   %s\n"
		       "%-*.*sR/W gap:     0x%02x\n"
		       "%-*.*sFormat gap:  0x%02x\n",
			indent, indent, "", show_sidedness(dg.dg_sidedness), 
			indent, indent, "", dg.dg_cylinders,
			indent, indent, "", dg.dg_heads, 
			indent, indent, "", dg.dg_sectors, 
			indent, indent, "", dg.dg_secbase,
			indent, indent, "", (long)dg.dg_secsize, 
			indent, indent, "", show_rate(dg.dg_datarate),
			indent, indent, "", show_recmode(dg.dg_fm),
			indent, indent, "", (dg.dg_fm & RECMODE_COMPLEMENT) ? "Yes" : "No",
			indent, indent, "", dg.dg_rwgap,   
			indent, indent, "", dg.dg_fmtgap);
		e = dsk_drive_status(outdr, &dg, 0, &drv_status);
		if (!e)
		{	
			printf("\n%-*.*sDrive status:  0x%02x\n", 
				indent, indent, "", drv_status);
		}
		e = dsk_get_comment(outdr, &comment);
		if (!e && comment)  
		{
			char *c;
			printf("%-*.*sComment:       ", indent, indent, "");
			c = comment;
			while (*c)
			{
				putchar(*c);
				if (*c == '\n') printf("%-*.*s               ", 
					indent, indent, "");
				c++;
			}
		}	
		putchar('\n');
/* Dump filesystem options -- ie, any options beginning "FS." */
		opt = 0;
		any = 0;
		while (dsk_option_enum(outdr, opt, &comment) == DSK_ERR_OK &&
				comment != NULL)
		{
			int value;
			char buf[30];

			if (!strncmp(comment, "FS:", 3) &&
		            dsk_get_option(outdr, comment, &value) == DSK_ERR_OK)
			{
				if (!any) 
				{
					printf("%-*.*sFilesystem parameters:\n",
						indent, indent, "");
					any = 1;
				}
				sprintf(buf, "%s:", comment + 3);
				printf("%-*.*s%-15.15s0x%02x\n",
					indent, indent, "", buf, value);
			}			
			++opt;
		}
	}
	if (outdr) 
	{
		if (!e) e = dsk_close(&outdr); else dsk_close(&outdr);
	}
	if (e)
	{
		fprintf(stderr, "%s: %s\n", outfile, dsk_strerror(e));
		return 1;
	}
	return 0;
}