31 March 2005

mod_dav Quota Patch Redux

I haven’t written about my patch to Apache httpd’s mod_dav module to show free disk space lately, and it apparently fell off the website when I moved things to the new server with built-in UPS. Thanks to the Internet Wayback Machine and TNPI, I’ve recovered the text and patch on the new server.

Anyone who has used Mac OS X’s iDisk tool may have noticed that the window shows how much space is available for writing unlike most WebDAV servers. I noticed this and wanted this feature on my own WebDAV server and created a patch to mod_dav that adds the needed properties. The specification for sending this information to clients is not finalized so this patch may stop working for some clients some day when the specification changes and clients change with it.

The patch is available here and should apply cleanly to the source for recent versions of Apache 2.0 (it was originally written for 2.0.47). This patch shows disk free, not quotas if you happen to have them enabled. And even then, the only the quota that applies to Apache is the quota for the user it runs as.

If you notice in the patch there are a couple places where real big numbers get divided by 512. This is because for some strange reason, when MacOSX’s mount_webdav bits calculate disk free they want to be getting the stats in 512-byte blocks. All the documentation I’ve found about <d:quota> and <d:quotaused> seems suggest that this number should be in bytes. But then again in those specs it was <d:quota-bytes>. /sbin/mount_webdav also does some really funny stuff when these numbers get large, I wonder in my mind if there is a buffer overflow or something lurking under the surface in mount_webdav’s quota handling.

The patch is much nicer now than it was when I first tried it in the handles the quota property. It handles this property through the avenues it is supposed to rather than pasting a quota onto every single PROPFIND that comes along. Whether that PROPFIND is looking for DAV:quota or not.

Further down the correct path than I am right now is implementing something along the lines of statfs(2) or statvfs(2) in the Apache Portable Runtime. Arguably it might be a better idea to just have functions that return the total disk space and available disk space. Especially since Windows may or may not support statfs() in its POSIX API. But in any case, the raw system calls in repos.c right now in this patch aren’t really appropriate.

It would be nice if this patch could be integrated into the Apache httpd project. That however will depend on the statfs calls being integrated into the APR.

1 comment:

Anonymous said...

Just made a script that makes us of your patch, downloads the apache source for debian/ubuntu and applies your patch and makes a package.

You can find the script at http://peppesbodega.nu/node/apachepatch-for-mod_dav-for-idisk-etc