Last active
December 3, 2016 13:29
-
-
Save tuklusan/0c4d3970349853d8ad487c2f7feedcfa to your computer and use it in GitHub Desktop.
Zero Out Free Disk Space on Virtual Machines and Compact them Before Backup: Solaris, Linux, Windows, OpenVMS: http://supratim-sanyal.blogspot.com/2016/12/zero-out-free-disk-space-on-virtual.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------ | |
zerofile.c | |
Creates a file zerofile.zero in current directoy. This file is as big as disk space allows. | |
The file zerofile.zero must be deleted after this program exits and before backing up this | |
SIMH VM to a tarball. | |
Hopefully size of tarball is smaller because we wrote zeroes to all the empty space on hard | |
disks. | |
TESTED ON Compaq C V6.4-005 on OpenVMS VAX V7.3 | |
To Build ZEROFILE.EXE: | |
$ CC ZEROFILE.C | |
$ LINK ZEROFILE.OBJ | |
Then set default to the drive(s) in which unused space is to be filled with zeroes and run | |
this program. For example, to fill free space on DUA2: with zeroes (from a privileged | |
account) with this program compiled and executable present in DUA1:[TOOLS]ZEROFILE.EXE: | |
$ SET DEFAULT DUA2:[000000] | |
$ RUN DUA1:[TOOLS]ZEROFILE | |
$ DELETE/LOG/CONF ZEROFILE.ZERO;* | |
(C) 2016 SUPRATIM SANYAL <SUPRATIM AT RISEUP DOT NET> | |
FREELY USABLE AND REDISTRIBUTABLE UNDER GNU AGPLv3 | |
LICENSE: http://tuklusan.decsystem.org/agpl-3.0-standalone.html | |
--------- */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <ctype.h> | |
#include <ssdef.h> | |
#include <dvidef.h> | |
#include <descrip.h> | |
#include <stsdef.h> | |
#include <lnmdef.h> | |
#include <iodef.h> | |
#include <opcdef.h> | |
#include <errno.h> | |
main() | |
{ | |
FILE *fp; | |
int i=0,j=1; | |
const int block=512; | |
char *fname="zerofile.zero"; | |
if(NULL==(fp=fopen(fname,"w")))fprintf(stderr,"Cannot open [%s] for writing: [%d]",fname,errno),exit(1); | |
printf("REMEMBER TO DELETE %s WHEN THIS PROGRAM EXITS\n",fname); | |
fflush(NULL); | |
printf("Press ENTER to create file [%s] with zeroes to fill up hard drive:",fname); | |
getchar(); | |
while(1) | |
{ | |
for(i=0;i<block;i++)if(EOF==fputc('\0',fp))fclose(fp),exit(0); | |
printf("%d blocks...",j++); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment