rm.c (44282) | rm.c (47584) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94"; 43#else 44static const char rcsid[] = | 1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94"; 43#else 44static const char rcsid[] = |
45 "$Id: rm.c,v 1.18 1997/08/07 21:37:39 steve Exp $"; | 45 "$Id: rm.c,v 1.19 1999/02/25 22:18:08 jkh Exp $"; |
46#endif 47#endif /* not lint */ 48 49#include <sys/types.h> 50#include <sys/stat.h> | 46#endif 47#endif /* not lint */ 48 49#include <sys/types.h> 50#include <sys/stat.h> |
51#include <sys/param.h> 52#include <sys/mount.h> |
|
51 52#include <err.h> 53#include <errno.h> 54#include <fcntl.h> 55#include <fts.h> 56#include <stdio.h> 57#include <stdlib.h> 58#include <string.h> --- 266 unchanged lines hidden (view full) --- 325 * kernel support. 326 */ 327void 328rm_overwrite(file, sbp) 329 char *file; 330 struct stat *sbp; 331{ 332 struct stat sb; | 53 54#include <err.h> 55#include <errno.h> 56#include <fcntl.h> 57#include <fts.h> 58#include <stdio.h> 59#include <stdlib.h> 60#include <string.h> --- 266 unchanged lines hidden (view full) --- 327 * kernel support. 328 */ 329void 330rm_overwrite(file, sbp) 331 char *file; 332 struct stat *sbp; 333{ 334 struct stat sb; |
335 struct statfs fsb; |
|
333 off_t len; | 336 off_t len; |
334 int fd, wlen; 335 char buf[8 * 1024]; | 337 int bsize, fd, wlen; 338 char *buf = NULL; |
336 337 fd = -1; 338 if (sbp == NULL) { 339 if (lstat(file, &sb)) 340 goto err; 341 sbp = &sb; 342 } 343 if (!S_ISREG(sbp->st_mode)) 344 return; 345 if ((fd = open(file, O_WRONLY, 0)) == -1) 346 goto err; | 339 340 fd = -1; 341 if (sbp == NULL) { 342 if (lstat(file, &sb)) 343 goto err; 344 sbp = &sb; 345 } 346 if (!S_ISREG(sbp->st_mode)) 347 return; 348 if ((fd = open(file, O_WRONLY, 0)) == -1) 349 goto err; |
350 if (fstatfs(fd, &fsb) == -1) 351 goto err; 352 bsize = MAX(fsb.f_iosize, 1024); 353 if ((buf = malloc(bsize)) == NULL) 354 err(1, "malloc"); |
|
347 348#define PASS(byte) { \ | 355 356#define PASS(byte) { \ |
349 memset(buf, byte, sizeof(buf)); \ | 357 memset(buf, byte, bsize); \ |
350 for (len = sbp->st_size; len > 0; len -= wlen) { \ | 358 for (len = sbp->st_size; len > 0; len -= wlen) { \ |
351 wlen = len < sizeof(buf) ? len : sizeof(buf); \ | 359 wlen = len < bsize ? len : bsize; \ |
352 if (write(fd, buf, wlen) != wlen) \ 353 goto err; \ 354 } \ 355} 356 PASS(0xff); 357 if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) 358 goto err; 359 PASS(0x00); 360 if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) 361 goto err; 362 PASS(0xff); | 360 if (write(fd, buf, wlen) != wlen) \ 361 goto err; \ 362 } \ 363} 364 PASS(0xff); 365 if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) 366 goto err; 367 PASS(0x00); 368 if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET)) 369 goto err; 370 PASS(0xff); |
363 if (!fsync(fd) && !close(fd)) | 371 if (!fsync(fd) && !close(fd)) { 372 free(buf); |
364 return; | 373 return; |
374 } |
|
365 366err: eval = 1; | 375 376err: eval = 1; |
377 if (buf) 378 free(buf); |
|
367 warn("%s", file); 368} 369 370 371int 372check(path, name, sp) 373 char *path, *name; 374 struct stat *sp; --- 71 unchanged lines hidden --- | 379 warn("%s", file); 380} 381 382 383int 384check(path, name, sp) 385 char *path, *name; 386 struct stat *sp; --- 71 unchanged lines hidden --- |