Re: silent semantic changes with reiser4

From: Christer Weinigel (christer_at_weinigel.se)
Date: 09/02/04

  • Next message: john stultz: "Re: Time runs exactly three times too fast"
    To: Jamie Lokier <jamie@shareable.org>
    Date:	02 Sep 2004 20:16:33 +0200
    
    

    Jamie Lokier <jamie@shareable.org> writes:

    > (For example, if I edit an HTML file which is encoded in iso-8859-1,
    > change it to utf-8 and indicate that in a META element, and save it
    > under the same name, the full content-type should change from
    > "text/html; charset=iso-8859-1" to "text/html; charset=utf-8".)
    >
    > I don't see how you can do that without kernel support.

    charset_cache = dbm(os.getenv('HOME') + '/.charset_cache')

    def get_charset(path):
        file_mtime = get_mtime(path)
        cache_tuple = dbm.get(path, (None, None))
        if file_mtime != cache_tuple[0]:
            cache_tuple = (file_mtime, figure_out_charset(path))
            dbm.put(path, cache_tuple)
        return cache_tuple[1]

    This code is guaranteed to always give you an up to date charset for a
    file, provided that the mtime is guaranteed to change every time the
    file changes.

    If the file can change during the call to get_charset you'll have to
    lock the file while you are working with it or handle it some other
    way (comparing mtime before and after and retrying if they differ),
    but that is true even if you do it all in the kernel. This has the
    added advantage that the cache is updated lazily, so the charset is
    never calculated unless someone really needs it.

    If the disk gets full, it is time to shrink the cache and preferably
    stale entries are evicted first. If that's not good enough, a
    notifier such as dnotify or inotify can be used to invalidate the
    cache immediately after the file has changed.

    If this gets popular, the cache management can be moved to a daemon
    (naturally with all the security aspects in mind).

    > Don't say dnotify or inotify, because neither would work.

    Why not? The approach above works on any filesystem, even without
    dnotify or inotify but will be more efficient with them.

      /Christer

    -- 
    "Just how much can I get away with and still go to heaven?"
    Freelance consultant specializing in device driver programming for Linux 
    Christer Weinigel <christer@weinigel.se>  http://www.weinigel.se
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: john stultz: "Re: Time runs exactly three times too fast"

    Relevant Pages

    • Re: silent semantic changes with reiser4
      ... > change it to utf-8 and indicate that in a META element, ... > Don't say dnotify or inotify, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [patch] make dnotify compile-time configurable
      ... you ifdef'ed out the dnotify variables in the inode structure. ... | struct inode changes break one path or the other and, well, I like to ... I'd rather see inotify additions and dnotify config options kept ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • Re: [patch] make dnotify compile-time configurable
      ... which use inotify and that there are none that use dnotify. ... send the line "unsubscribe linux-kernel" in ... Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • Re: The argument for fs assistance in handling archives (was: silent semantic changes with reiser4)
      ... > dontify doesn't cut it. ... Well, dnotify() really _is_ inotify(), since it does actually work on ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [patch] make dnotify compile-time configurable
      ... Whether or not dnotify is a configuration option is separate, ... But what matters if our inotify patch also carries the change? ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)