All pastes #511539 Raw Edit

Hard disk wipe

public c v1 · immutable
#511539 ·published 2007-05-26 14:33 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <linux/hdreg.h>typedef struct hd_geometry geometry;int main(int argc, char** argv){	geometry* geom = malloc(sizeof(geometry));	int dev = open(argv[1], O_RDWR|O_SYNC);	ioctl(dev, HDIO_GETGEO, geom);		printf("Cylinders: %d\nHeads: %d\nSectors: %d\n",		geom->cylinders, geom->heads, geom->sectors);			int screen = 80*24;	long long disk = geom->cylinders * geom->sectors * geom->heads;	int sectors_per_block = disk/screen;			int* blank = malloc(128 * sizeof(int));	int it;	for (it = 0; it < 128; it++)	{		blank[it] = 0;	}		int f = 255/geom->heads;	int h = 255;	int c = geom->cylinders/f;	printf("\033[2J");			int i, j, k;	for (i = 0; i < geom->sectors; i++)	{		for (j = 0; j < c; j++)		{			for (k = 0; k < h; k++)			{				unsigned long long loc = ((j * h + k) * geom->sectors) + i;				lseek(dev, loc, SEEK_SET);				write(dev, blank, 512);								unsigned int place = loc/sectors_per_block;					printf("\033[%d;%dH*", place/80, place%80);					printf("\033[24;18HS %d", i);					printf("\033[24;38HC %d", j);					printf("\033[24;58HH %d", k);				fflush(stdout);			}		}		printf("\033[2J");	}	return 0;}