3 #include <bits/posix1_lim.h>
11 int unlinkat(int dirfd
, const char *pathname
, int flags
)
13 int (*real_unlinkat
)(int dirfd
, const char *pathname
, int flags
) = dlsym(RTLD_NEXT
, "unlinkat");
16 char fdlinkname
[_POSIX_PATH_MAX
];
17 char atdir
[_POSIX_PATH_MAX
];
18 char bkfilename
[_POSIX_PATH_MAX
];
28 if(fstatat(dirfd
, pathname
, &st
, flags
) == -1) {
33 if(dirfd
!= AT_FDCWD
) {
34 sprintf(fdlinkname
, "/proc/self/fd/%d", dirfd
);
35 if(readlink(fdlinkname
, atdir
, _POSIX_PATH_MAX
) == -1) {
41 if(getcwd(atdir
, _POSIX_PATH_MAX
) == NULL
) {
48 tm_info
= localtime(&timer
);
49 strftime(timebuf
, 20, "%Y-%m-%d %H:%M:%S", tm_info
);
53 retval
= real_unlinkat(dirfd
, pathname
, flags
);
55 if(retval
== 0 && atdir
[0] != 0) {
56 sprintf(bkfilename
, "%s/%s", getenv("HOME"), ".unlinked_inodes");
57 fd
= fopen(bkfilename
, "a");
59 fprintf(fd
, "%s %ld %s/%s\n", timebuf
, (long)st
.st_ino
, atdir
, pathname
);
70 // Fordítás: gcc -s -x c saveunlinkedinode.c -fPIC -shared -ldl -o saveunlinkedinode.so
71 // Futtatás: LD_PRELOAD=./saveunlinkedinode.so rm somefile