But for some reason it only copies the file I make once and then just keeps overwriting it. I tried adding a variable so it would change the name and not overwrite the previous file but it still doesn't work.
Any suggestions?
(sorry if this is the worst programming you've ever seen)
Big thanks!
Too straight forward Jim I want that last fs block even if the fs has a silly 2 byte block size
#include <stdio.h>
#include <errno.h>
#include <sys/vfs.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MAX_PHYSIO 128 /* size of phsyical io in blocks */
char *outbuf;
struct statfs vbuf;
int main() {
int tickle = 5; /* how often to print progress based on number of writes */
int count = 0;
int fd;
long outsize;
int j;
/* create the file */
if( (fd = open("fill.all", O_CREAT | O_WRONLY)) < 0 )
{
perror("fill.all: ");
exit(fd);
}
/* get filesystem info */
fstatfs( fd, &vbuf);
outsize = vbuf.f_bsize * MAX_PHYSIO; /* calculate output size */
outbuf = (char *) malloc(outsize); /* allocate the buffer */
printf("Free blocks: %d\nOutput Buffer size: %d\n", vbuf.f_bfree, outsize);
j = tickle ;
while( write(fd, outbuf, outsize) > 0 )
{
if ( j == 0)
{
fstatfs(fd ,&vbuf);
printf("Blocks left: %d\n", vbuf.f_bfree);
j = tickle;
}
else
j--;
}
fstatfs( fd, &vbuf);
if (vbuf.f_bfree > 0)
write(fd, outbuf, vbuf.f_bfree);
printf("done\n");
}
For extra fun you can add an fsync() call after the last write call. Could lock up your system for a bit ... depending on your RAID type and implementation