1/* 2 * This function is in a separate file here 3 * so that it can locally define _FILE_OFFSET_BITS=64 4 * to automatically get 64-bit open/fstat/etc.. functions and types. 5 * Eventually, all of hdparm should do that, but for now.. 6 */ 7#define _FILE_OFFSET_BITS 64 8#include <unistd.h> 9#include <string.h> 10#include <stdlib.h> 11#include <stdio.h> 12#include <fcntl.h> 13#include <errno.h> 14#include <sys/syscall.h> 15#include <linux/types.h> 16#include <linux/fs.h> 17 18#include "hdparm.h" 19 20int do_fallocate_syscall (const char *path, __u64 bytecount) 21{ 22 int err; 23 24#ifndef SYS_fallocate 25 bytecount = 0; 26 fprintf(stderr, "Error: this copy of hdparm was built without %s support\n", path); 27 err = EINVAL; 28#else 29 int fd; 30 loff_t offset = 0, len; 31 int mode = 0; 32 33 fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0600); 34 if (fd == -1) { 35 err = errno; 36 } else { 37 len = bytecount; 38 err = syscall(SYS_fallocate, fd, mode, offset, len); 39 if (err >= 0) { 40 fsync(fd); 41 exit(0); 42 } 43 err = errno; 44 unlink(path); 45 } 46 perror(path); 47#endif 48 return err; 49} 50