FreeBSD/tools/test/upsdl/upsdl.c
/* Create a FILESIZE sized file - then remove file data from the cache*/
Create a FILESIZE sized file - then remove file data from the cache
Create a FILESIZE sized file - then remove file data from the cache
int prepareFile(char* filename,int* fdp)
{
  int fd;
  int len;
  int status;
  void *addr;
  fd = open(filename,O_CREAT | O_TRUNC | O_RDWR,S_IRWXU);
  if (fd == -1)
    {
      perror("Creating file");
      return fd;
    }
  len = write(fd,wbuffer,FILESIZE);
  if (len < 0)
    {
      perror("Write failed");
      return 1;
    }
  status = fsync(fd);
   if (status != 0)
    {
        perror("fsync failed");
	return 1;
    }
  addr = mmap(NULL,FILESIZE, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0);
  if (addr == MAP_FAILED)
    {
      perror("Mmap failed");
      return 1;
    }
  status = msync(addr,FILESIZE,MS_INVALIDATE | MS_SYNC);
  if (status != 0)
    {
        perror("Msync failed");
	return 1;
    }
  munmap(addr,FILESIZE);
  *fdp = fd;
  return 0;
}
int prepareFile ( char * filename , int * fdp ) { int fd ; int len ; int status ; void * addr ; fd = open ( filename , O_CREAT | O_TRUNC | O_RDWR , S_IRWXU ) ; if ( fd == -1 ) { perror ( " " ) ; return fd ; } len = write ( fd , wbuffer , FILESIZE ) ; if ( len < 0 ) { perror ( " " ) ; return 1 ; } status = fsync ( fd ) ; if ( status != 0 ) { perror ( " " ) ; return 1 ; } addr = mmap ( NULL , FILESIZE , PROT_READ | PROT_WRITE , MAP_SHARED , fd , 0 ) ; if ( addr == MAP_FAILED ) { perror ( " " ) ; return 1 ; } status = msync ( addr , FILESIZE , MS_INVALIDATE | MS_SYNC ) ; if ( status != 0 ) { perror ( " " ) ; return 1 ; } munmap ( addr , FILESIZE ) ; * fdp = fd ; return 0 ; }
Create a FILESIZE sized file - then remove file data from the cache
Create a FILESIZE sized file - then remove file data from the cache