linux (but not samba) quotas

Jim McDonough jmcd at
Tue Mar 27 21:48:13 GMT 2001

Some time ago, someone presented an interesting situation...suppose the
local fs quotas, but not samba quota support, are enabled.  When an NT
client tries to write a file too large (say 1MB) to fit within the user's
quota (say 4K remaining), the file size is set, then the file is written.
An error is returned that the disk is full, but a (sort of) inconsistency
arises: the file size appears to be 1MB, but only 4K worth of data is in
the file.  Yeah yeah, sparse files and all that, but we've got folks
complaining about that.  Since quota support isn't enabled, we can't detect
that it won't fit, and we end up with this improper state.  I'd like to
propose the following patch that checks to see if the file write failed due
to quota limits and truncate the file at the current position.  I don't
feel that this is the "right" thing to do, although there may not be a
"right" answer.  Anyway, here's the code from 2.2:

--- lib/util_sock.c Tue Mar 27 11:56:58 2001
+++ ../../../mine/samba-2.2/source/lib/util_sock.c      Tue Mar 27 11:56:27
@@ -493,6 +493,7 @@
   size_t total=0;
   ssize_t ret;
+  off_t off;

   while (total < N)
@@ -508,6 +509,10 @@

     if (ret == -1) {
       DEBUG(0,("write_data: write failure. Error = %s\n", strerror(errno)
+      if (errno == EDQUOTA) {
+        off = lseek(fd, 0, SEEK_CUR);
+    ftruncate(fd, off);
+      }
       return -1;
     if (ret == 0) return total;

Jim McDonough
Linux Technology Center
IBM Boulder

Notes: Jim McDonough/Boulder/IBM @ IBMUS
Internet: jmcd at

Phone: (303) 924-5822
T/L: 263-5822

More information about the samba-technical mailing list