File system changes

  • Hi.

    Maybe somebody knows if a program at runtime can in some way be
    notified about file system changes. For example when a file or
    folder has been created/deleted/moved with Finder?

    Maybe there is some kind of notification, like on volumes
    mount/unmount?

    Thanks.
    Vic.
  • > Panther (Darwin 7) includes support for FreeBSD KEvents, which will do
    > exactly what you want. If you need Jag support you're out of luck and
    > will have to revert to polling the directory mod time with stat(). I've
    > attached some test code I wrote when implementing KEvent support for
    > the Ext2 filesystem.
    >
    > HTH.
    >
    > Anyone else: If the list manager strips the attachment, you can get it
    > via the web at
    > <http://cvs.sourceforge.net/viewcvs.py/ext2fsx/test/kqwatch.c?
    > rev=1.1&view=auto>
    Hi,

    I would like to get file change events (I am only interested in files being
    written) for a directory with many files in it and many sub directories.
    It seems to be necessary to open the file, so that the maximum amount of
    files you can watch is 255. (Panther has a 256 open files limitation (at
    least if I use FSRefs to open the files))

    So I assume I can't use kevents for when I want to monitor more than 255
    files? Is there any other solution for this than polling?

    Joe Ante
  • -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Joe,

    If you are interested in only adds/deletions to the directory, there is
    no need to open anything else. Just open the directory and your all
    set. If, however, you are interested for writes on the individual
    files, you will need to open each file. The 255 limit is either from
    Carbon or from the artificial limit imposed by the shell for users. For
    the latter, have a look at 'man setrlimit' -- (specifically
    RLIMIT_NOFILE) to possibly raise this limit. If the former, then switch
    to using BSD file descriptors or NSFileManager thereby avoiding Carbon.

    HTH.

    On Dec 18, 2003, at 6:14 PM, Joe Ante wrote:

    >> Panther (Darwin 7) includes support for FreeBSD KEvents, which will do
    >> exactly what you want. If you need Jag support you're out of luck and
    >> will have to revert to polling the directory mod time with stat().
    >> I've
    >> attached some test code I wrote when implementing KEvent support for
    >> the Ext2 filesystem.
    >>
    > Hi,
    >
    > I would like to get file change events (I am only interested in files
    > being
    > written) for a directory with many files in it and many sub
    > directories.
    > It seems to be necessary to open the file, so that the maximum amount
    > of
    > files you can watch is 255. (Panther has a 256 open files limitation
    > (at
    > least if I use FSRefs to open the files))
    >
    > So I assume I can't use kevents for when I want to monitor more than
    > 255
    > files? Is there any other solution for this than polling?
    >
    > Joe Ante
    >
    Brian Bergstrand <http://www.bergstrand.org/brian/>
    PGP Key: <http://www.bergstrand.org/brian/misc/public_key.txt>
    AIM: triryche206
    Technology is dominated by two types of people: those who understand
    what they do not manage, and those who manage what they do not
    understand. - Putt's Law

    -----BEGIN PGP SIGNATURE-----
    Version: PGP 8.0.3

    iQA/AwUBP+JpEXnR2Fu2x7aiEQIDfgCaAzLgcLpawVQ0IZdtUQMFDBzBmEMAoLoH
    BHONvtpABofTszVpxovOkHwK
    =Wkxc
    -----END PGP SIGNATURE-----
  • > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Joe,
    >
    > If you are interested in only adds/deletions to the directory, there is
    > no need to open anything else. Just open the directory and your all
    > set. If, however, you are interested for writes on the individual
    > files, you will need to open each file. The 255 limit is either from
    > Carbon or from the artificial limit imposed by the shell for users. For
    > the latter, have a look at 'man setrlimit' -- (specifically
    > RLIMIT_NOFILE) to possibly raise this limit. If the former, then switch
    > to using BSD file descriptors or NSFileManager thereby avoiding Carbon.
    Is there no limitation at all? Will the fie system get slower if I open like
    10.000 files and watch them?

    Joe Ante
  • -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    There is a system wide limit on the number of vnodes (which are the
    kernel structures that track files) based on the amount of memory in
    the machine. The limit on my 1.5GB machine is:

    $ sysctl kern.maxvnodes
    kern.maxvnodes = 25600

    In addition to this, there is a per-process soft limit to the number of
    open files that is much less than the maxvnodes #. I think this is what
    you are running into (256).

    Here's a test program that will print the current limits, and then
    raise the soft limit to 1/4 the system max. On my system this prints:
    No. Files soft = 256, hard (max) = 9223372036854775807.
    No. Files soft = 6400, hard (max) = 9223372036854775807.

    Compile this with : cc -o rl rlim.c

    HTH.

    // rlim.c
    #include <sys/types.h>
    #include <sys/time.h>
    #include <sys/resource.h>
    #include <sys/sysctl.h>
    #include <sys/errno.h>
    #include <stdio.h>

    int main () {
        struct rlimit rl;
        int e, mib[2];
        u_long files;

        // Current limits
        e = getrlimit(RLIMIT_NOFILE, &rl);
        if (!e)
          printf ("No. Files soft = %qd, hard (max) = %qd.\n",
              rl.rlim_cur, rl.rlim_max);
        else {
          perror("getrlimit failed with");
          return (errno);
        }

        mib[0] = CTL_KERN;
        mib[1] = KERN_MAXVNODES;
        e = sizeof(u_long);
        // Get system max files
        files = 0;
        sysctl(mib, 2, &files, (size_t*)&e, NULL, 0);
        e = 0;
        if (files) {
          rl.rlim_cur = files >> 2; // Set limit to 1/4 sys max.
          e = setrlimit(RLIMIT_NOFILE, &rl);
          if (!e)
              printf ("No. Files soft = %qd, hard (max) = %qd.\n",
                rl.rlim_cur, rl.rlim_max);
          else {
              e = errno;
              perror("setrlimit failed with");
          }
        } else {
          fprintf(stderr, "sysctl failed");
        }

        return (e);
    }

    On Dec 19, 2003, at 1:11 AM, Joe Ante wrote:
    >>
    >> The 255 limit is either from
    >> Carbon or from the artificial limit imposed by the shell for users.
    >> For
    >> the latter, have a look at 'man setrlimit' -- (specifically
    >> RLIMIT_NOFILE) to possibly raise this limit. If the former, then
    >> switch
    >> to using BSD file descriptors or NSFileManager thereby avoiding
    >> Carbon.
    > Is there no limitation at all? Will the fie system get slower if I
    > open like
    > 10.000 files and watch them?
    >
    > Joe Ante
    >
    Brian Bergstrand <http://www.bergstrand.org/brian/>
    PGP Key: <http://www.bergstrand.org/brian/misc/public_key.txt>
    AIM: triryche206
    Delusions of grandeur make me feel a lot better about myself. - Jane
    Wagner
    As of 10:30:04 AM, iTunes is playing "All Apologies" from "In Utero" by
    "Nirvana"

    -----BEGIN PGP SIGNATURE-----
    Version: PGP 8.0.3

    iQA/AwUBP+Mi1XnR2Fu2x7aiEQI8ZACgiA2JTXu16D+wcWkRywJ/sIzyrCkAoPyF
    rUwMgW10ynYedvdSV6Ikn2N4
    =t64n
    -----END PGP SIGNATURE-----
  • On 12/19/03 12:09 PM, Brian Bergstrand wrote:
    > There is a system wide limit on the number of vnodes (which are the
    > kernel structures that track files) based on the amount of memory in
    > the machine. The limit on my 1.5GB machine is:
    >
    > $ sysctl kern.maxvnodes
    > kern.maxvnodes = 25600
    >
    > In addition to this, there is a per-process soft limit to the number of
    > open files that is much less than the maxvnodes #. I think this is what
    > you are running into (256).

    Yeah, I run into the 255 soft limit a lot, and I'm not sure where the
    "correct" place to override it for a whole login session is.  Anyone know?
    I can't even launch Quake 3, for example, without running unlimit in a shell
    and then launching Quake from that shell prompt.  (Too many map files.)

    -John
previous month december 2003 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today