c - SEEK_HOLE and SEEK_DATA not working in Ubuntu 12.04.2 LTS -


when compiling error:

cc     holetest.c   -o holetest holetest.c: in function ‘test_seek’: holetest.c:48:19: error: ‘seek_hole’ undeclared (first use in function) holetest.c:48:19: note: each undeclared identifier reported once each function appears in holetest.c:51:19: error: ‘seek_data’ undeclared (first use in function) make: *** [holetest] error 1 

if remove seek_hole , seek_data have no issues.

have missed include or library?

makefile:

all: holetest  holetest: holetest.c     rm -f holetest     gcc holetest.c -o holetest 

holetest.c:

#include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h>  #define filename "/tmp/partly.sparse" #define file_size (1<<30) #define start_string "start of file\n" #define start_len strlen(start_string) #define end_string "\nend of file\n" #define end_len strlen(end_string)  #define debug(m, ...) fprintf(stderr, "%i: debug %10.10s:%3.0d: " m "\n", getpid(), __file__, __line__, ##__va_args__); fflush(stderr); #define log_err(m, ...) fprintf(stderr, "%i: error errno:%i %10.10s:%3.0d: " m "\n", getpid(), errno, __file__, __line__, ##__va_args__); fflush(stderr);  #define quit_if(cond, ...) { \         if(cond) { \                 log_err(__va_args__); \                 perror(null); \                 exit(errno); \         } \ } while(0);  int make_partly_sparse(const char *filename, off_t size) {         int r, fd;         fd = open(filename, o_rdwr|o_creat, 0755);         quit_if(fd < 1, "unable create %s", filename);         r = write(fd, start_string, start_len);         quit_if(r < start_len, "unable write %s", filename);         r = lseek(fd, file_size - end_len, seek_set);         quit_if(r < 0, "unable seek %s", filename);         r = write(fd, end_string, end_len);         quit_if(r < end_len, "unable write %s", filename);         r = close(fd);         quit_if(r < 0, "unable close %s", filename);         return 0; }  int test_seek(const char *filename) {         int r, fd;         fd = open(filename, o_rdwr|o_creat, 0755);         quit_if(fd < 1, "unable open %s", filename);         debug("seeking hole @ %li", start_len);         r = lseek(fd, 0, seek_hole);         quit_if(r < 0, "unable seek %s", filename);         quit_if(r != start_len, "seek_hole unsupported %i", r);         r = lseek(fd, 0, seek_data);         quit_if(r < 0, "unable seek %s", filename);         quit_if(r != (file_size - end_len), "seek_data unsupported %i", r);         r = close(fd);         quit_if(r < 0, "unable close %s", filename);         return 0; }  int main(int argc, char *argv[]) {         debug("making sparse file: %s", filename);         make_partly_sparse(filename, file_size);         test_seek(filename);         return 0; } 

system:

$ cat /etc/lsb-release  distrib_id=ubuntu distrib_release=12.04 distrib_codename=precise distrib_description="ubuntu 12.04.2 lts"  $ uname -a linux tux 3.2.0-45-generic #70-ubuntu smp wed may 29 20:12:06 utc 2013 x86_64 x86_64 x86_64 gnu/linux  $ grep "ext" /etc/fstab uuid=be3aacb3-6457-4ba1-92bb-0f63ad514f40 /               ext4    errors=remount-ro 0       1 

update:

it compiles doesn't work, seek_hole skips right on hole , seeks end of file.

$ make rm -f holetest gcc -d_gnu_source holetest.c -o holetest  $ ./holetest  18731: debug holetest.c: 60: making sparse file: /tmp/partly.sparse 18731: debug holetest.c: 47: seeking hole @ 14 18731: error errno:0 holetest.c: 50: seek_hole unsupported 1073741824 success  $ du /tmp/partly.sparse  8   /tmp/partly.sparse  $ ls -la /tmp/partly.sparse  -rwxr-xr-x 1 chris chris 1073741824 aug 16 14:08 /tmp/partly.sparse 

stdio.h defines them as;

/* possibilities third argument `fseek'.    these values should not changed.  */ #define seek_set        0       /* seek beginning of file.  */ #define seek_cur        1       /* seek current position.  */ #define seek_end        2       /* seek end of file.  */ #ifdef __use_gnu # define seek_data      3       /* seek next data.  */ # define seek_hole      4       /* seek next hole.  */ #endif 

__use_gnu internal symbol set when define _gnu_source, means use them need compile -d_gnu_source.

$ gcc test.c  test.c: in function ‘test_seek’: test.c:48:26: error: ‘seek_hole’ undeclared (first use in function) test.c:48:26: note: each undeclared identifier reported once each function appears in test.c:51:26: error: ‘seek_data’ undeclared (first use in function) $ gcc -d_gnu_source test.c  $  

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -