[poppler] UniqueFileStream and deleted files

Fabio D'Urso fabiodurso at hotmail.it
Sun Mar 24 04:54:09 PDT 2013


On Saturday, March 23, 2013 08:58:10 PM Ihar `Philips` Filipau wrote:
> On 3/23/13, Albert Astals Cid <aacid at kde.org> wrote:
> > El Dissabte, 23 de març de 2013, a les 20:31:52, Ihar `Philips` Filipau va
> > 
> > escriure:
> >> I have further googled it up - and found only this procfs solution:
> > Your google skills are better than mine :D
> 
> I knew for a fact that it was possible on Linux to duplicate the fd
> without sharing the underlying kernel structure. So I googled harder.
> 
> >> Works on Linux, Solaris and AIX (the only OSs I know with the procfs;
> >> HP-UX doesn't have procfs) - but I gather that is little consolation.
> > 
> > Well, it's probably enough, what other OSs are you thinking about?
> 
> I have seen people porting the poppler to QNX (BlackBerry). BSD.
> 
> Though google indicates that both QNX and FreeBSD have some sort of
> procfs emulation.
> 
> > Windows? You can't delete open files on Windows so it should work.
> > 
> > Maybe MacOs will fail too?
> > 
> > Anyone with a mac to try?

I have an old powerpc-based mac with MacOSX 10.4 and it seems you can delete 
open files there too. I'm attaching the script I've used to test it.

> Just tried. Mac OS X doesn't have procfs.

Btw, I've found an interesting "pread" call in the man pages:
 ssize_t pread(int fd, void *buf, size_t count, off_t offset)

It is present both in Linux and Mac OS X.

Fabio
-------------- next part --------------
#!/bin/sh
echo "uname -a says:"
uname -a
echo " == Initialization =="
echo "Compiling test program..."
cat > latereader.c << EOF
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv) {
  printf("Opening file...\n");
  const int fd = open(argv[1], O_RDONLY);

  printf("Sleeping...\n");
  sleep(5);

  printf("Reading file: ");
  char buf;
  while ( read(fd, &buf, 1) == 1 )
    putchar(buf);
  close(fd);
}
EOF
gcc latereader.c -o latereader

echo "Creating file to be read..."
echo blablabla > testfile

echo " == Regular read on non-deleted file =="
./latereader testfile &
LATEREADER=$!
sleep 1 # Make sure that open() has already been called
lsof -p $LATEREADER
wait
echo "DONE"
echo

echo " == Read on a deleted file =="
./latereader testfile &
LATEREADER=$!
sleep 1 # Make sure that open() has already been called
echo "Removing file..."
rm testfile
lsof -p $LATEREADER
wait
echo "DONE"
-------------- next part --------------
uname -a says:
Darwin MAC-G5.local 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh powerpc
 == Initialization ==
Compiling test program...
Creating file to be read...
 == Regular read on non-deleted file ==
Opening file...
Sleeping...
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
latereade 1864 fabio  cwd   VDIR   14,2      238  3603342 /Users/fabio/read-deleted-file-test
latereade 1864 fabio  txt   VREG   14,2    14368  3603398 /Users/fabio/read-deleted-file-test/latereader
latereade 1864 fabio  txt   VREG   14,2  1797576   392921 /usr/lib/dyld
latereade 1864 fabio  txt   VREG   14,2  4398204   416131 /usr/lib/libSystem.B.dylib
latereade 1864 fabio    0u  VCHR    4,1 0t169095 52997380 /dev/ttyp1
latereade 1864 fabio    1u  VCHR    4,1 0t169095 52997380 /dev/ttyp1
latereade 1864 fabio    2u  VCHR    4,1 0t169095 52997380 /dev/ttyp1
latereade 1864 fabio    3r  VREG   14,2       10  3603399 /Users/fabio/read-deleted-file-test/testfile
Reading file: blablabla
[1]+  Done                    ./latereader testfile
DONE

 == Read on a deleted file ==
Opening file...
Sleeping...
Removing file...
COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
latereade 1868 fabio  cwd   VDIR   14,2      204  3603342 /Users/fabio/read-deleted-file-test
latereade 1868 fabio  txt   VREG   14,2    14368  3603398 /Users/fabio/read-deleted-file-test/latereader
latereade 1868 fabio  txt   VREG   14,2  1797576   392921 /usr/lib/dyld
latereade 1868 fabio  txt   VREG   14,2  4398204   416131 /usr/lib/libSystem.B.dylib
latereade 1868 fabio    0u  VCHR    4,1 0t169147 52997380 /dev/ttyp1
latereade 1868 fabio    1u  VCHR    4,1 0t169147 52997380 /dev/ttyp1
latereade 1868 fabio    2u  VCHR    4,1 0t169147 52997380 /dev/ttyp1
latereade 1868 fabio    3r  VREG                          stat(/Users/fabio/read-deleted-file-test/testfile): No such file or directory
Reading file: blablabla
[1]+  Done                    ./latereader testfile
DONE
-------------- next part --------------
uname -a says:
Linux fabio-laptop 3.8.3-203.fc18.i686 #1 SMP Mon Mar 18 13:20:52 UTC 2013 i686 i686 i386 GNU/Linux
 == Initialization ==
Compiling test program...
Creating file to be read...
 == Regular read on non-deleted file ==
Opening file...
Sleeping...
COMMAND     PID  USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
latereade 31897 fabio  cwd    DIR    8,5     4096 658720 /home/fabio/read-deleted-file-test
latereade 31897 fabio  rtd    DIR    8,5     4096      2 /
latereade 31897 fabio  txt    REG    8,5     7524 681106 /home/fabio/read-deleted-file-test/latereader
latereade 31897 fabio  mem    REG    8,5   147668   8609 /usr/lib/ld-2.16.so
latereade 31897 fabio  mem    REG    8,5  2032984   8612 /usr/lib/libc-2.16.so
latereade 31897 fabio    0u   CHR  136,4      0t0      7 /dev/pts/4
latereade 31897 fabio    1u   CHR  136,4      0t0      7 /dev/pts/4
latereade 31897 fabio    2u   CHR  136,4      0t0      7 /dev/pts/4
latereade 31897 fabio    3r   REG    8,5       10 681141 /home/fabio/read-deleted-file-test/testfile
Reading file: blablabla
[1]+  Done                    ./latereader testfile
DONE

 == Read on a deleted file ==
Opening file...
Sleeping...
Removing file...
COMMAND     PID  USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
latereade 31901 fabio  cwd    DIR    8,5     4096 658720 /home/fabio/read-deleted-file-test
latereade 31901 fabio  rtd    DIR    8,5     4096      2 /
latereade 31901 fabio  txt    REG    8,5     7524 681106 /home/fabio/read-deleted-file-test/latereader
latereade 31901 fabio  mem    REG    8,5   147668   8609 /usr/lib/ld-2.16.so
latereade 31901 fabio  mem    REG    8,5  2032984   8612 /usr/lib/libc-2.16.so
latereade 31901 fabio    0u   CHR  136,4      0t0      7 /dev/pts/4
latereade 31901 fabio    1u   CHR  136,4      0t0      7 /dev/pts/4
latereade 31901 fabio    2u   CHR  136,4      0t0      7 /dev/pts/4
latereade 31901 fabio    3r   REG    8,5       10 681141 /home/fabio/read-deleted-file-test/testfile (deleted)
Reading file: blablabla
[1]+  Done                    ./latereader testfile
DONE


More information about the poppler mailing list