/* * Cleanup any remaining I/O and flush output. If necesssary, output file * is truncated. */ static void dd_close(void) { if (cfunc == def) def_close(); else if (cfunc == block) block_close(); else if (cfunc == unblock) unblock_close(); if (ddflags & C_OSYNC && out.dbcnt < out.dbsz) { (void)memset(out.dbp, 0, out.dbsz - out.dbcnt); out.dbcnt = out.dbsz; } /* If there are pending sparse blocks, make sure * to write out the final block un-sparse */ if ((out.dbcnt == 0) && pending) { memset(out.db, 0, out.dbsz); out.dbcnt = out.dbsz; out.dbp = out.db + out.dbcnt; pending -= out.dbsz; } if (out.dbcnt) dd_out(1); /* * Reporting nfs write error may be defered until next * write(2) or close(2) system call. So, we need to do an * extra check. If an output is stdout, the file structure * may be shared among with other processes and close(2) just * decreases the reference count. */ if (out.fd == STDOUT_FILENO && fsync(out.fd) == -1 && errno != EINVAL) { fprintf(stderr, "fsync stdout: %s\n", strerror(errno)); exit(1); /* NOTREACHED */ } if (close(out.fd) == -1) { fprintf(stderr, "close: %s\n", strerror(errno)); exit(1); /* NOTREACHED */ } }
/* * Cleanup any remaining I/O and flush output. If necessary, output file * is truncated. */ static void dd_close(void) { if (cfunc == def) def_close(); else if (cfunc == block) block_close(); else if (cfunc == unblock) unblock_close(); if (ddflags & C_OSYNC && out.dbcnt && out.dbcnt < out.dbsz) { if (ddflags & (C_BLOCK|C_UNBLOCK)) memset(out.dbp, ' ', out.dbsz - out.dbcnt); else memset(out.dbp, 0, out.dbsz - out.dbcnt); out.dbcnt = out.dbsz; } if (out.dbcnt) dd_out(1); }
int main (int argc, char **argv) { int result = handle_options(argc, argv); struct device *dev; int i; if (result != 0) exit(result); if (argc - optind != 1) { printf ("Necesita un argumento que es el nombre del" " sistema de ficheross\n\n"); while (optind < argc) printf ("'%s' ", argv[optind++]); printf ("\n"); usage(-2); } dev = block_create(argv[optind], num_blocks, block_size); if (dev == NULL) { printf("Error creando el sistema de ficheros %s (%s)\n", argv[optind], strerror(errno)); exit(-1); } if (block_close(dev) == -1) { printf("Error cerrando el sistema de ficheros %s 1\n", argv[optind]); exit(-1); } dev = block_open(argv[optind]); if (dev == NULL) { printf("Error abriendo el sistema de ficheros %s 2\n", argv[optind]); exit(-1); } for (i = 0; i < num_blocks; i++) { int buffer[block_size/4]; int j; for (j = 0; j < block_size/4; j++) buffer[j] = i; result = block_write(dev, buffer, i); if (result == -1) printf("Error escribiendo bloque %d, (Error %s)\n", i, strerror(errno)); } if (block_close(dev) == -1) { printf("Error cerrando el sistema de ficheros %s 2\n", argv[optind]); exit(-1); } dev = block_open(argv[optind]); if (dev == NULL) { printf("Error abriendo el sistema de ficheros %s 3\n", argv[optind]); exit(-1); } for (i = 0; i < num_blocks; i++) { int buffer[block_size/4]; int j; result = block_read(dev, buffer, i); if (result == -1) printf("Error leyendo bloque %d, (Error %s)\n", i, strerror(errno)); for (j = 0; j < block_size/4; j++) if (buffer[j] != i) { printf("Contenido blque %d erroreo\n", i); break; } } if (block_close(dev) == -1) { printf("Error cerrando el sistema de ficheros %s 4\n", argv[optind]); exit(-1); } exit (0); }
int ClientConn::Close() { block_close(conn_handle_); conn_handle_ = NETLIB_INVALID_HANDLE; return 0; }