]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
sigquit
[netatalk.git] / etc / afpd / volume.c
index aea89b3dcda19f6297fe188811df38046d4b2903..519c0c977e9a4f847450c891ceb3b4e13d0a3000 100644 (file)
@@ -512,11 +512,8 @@ static void volset(struct vol_option *options, struct vol_option *save,
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_TM;
             else if (strcasecmp(p, "searchdb") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_SEARCHDB;
-/* Found this in branch dir-rewrite, maybe we want to use it sometimes */
-#if 0
-            else if (strcasecmp(p, "cdrom") == 0)
-                options[VOLOPT_FLAGS].i_value |= AFPVOL_CDROM | AFPVOL_RO;
-#endif
+            else if (strcasecmp(p, "nonetids") == 0)
+                options[VOLOPT_FLAGS].i_value |= AFPVOL_NONETIDS;
             p = strtok(NULL, ",");
         }
 
@@ -1442,18 +1439,26 @@ static int getused_stat(const char *path,
                         int tflag,
                         struct FTW *ftw)
 {
-    if (tflag == FTW_F) {
-        getused_size += statp->st_size;
+    off_t low, high;
+
+    if (tflag == FTW_F || tflag == FTW_D) {
+        getused_size += statp->st_blocks * 512;
     }
+
     return 0;
 }
 
+#define GETUSED_CACHETIME 5
 /*!
  * Calculate used size of a volume with nftw
  *
- * 1) Check if the volume has been modified or the v_mtime has not
- *    yet been set
- * 2) Call nftw if yes
+ * The result is cached, we're try to avoid frequently calling nftw()
+ *
+ * 1) Call nftw an refresh if:
+ * 1a) - we're called the first time 
+ * 1b) - volume modification date is not yet set and the last time we've been called is
+ *       longer then 30 sec ago
+ * 1c) - the last volume modification is less then 30 sec old
  *
  * @param vol     (r) volume to calculate
  */
@@ -1461,18 +1466,22 @@ static int getused(const struct vol *vol)
 {
     static time_t vol_mtime = 0;
     int ret = 0;
+    time_t now = time(NULL);
 
-    if (!vol->v_mtime || (vol_mtime < vol->v_mtime)) { /* 1 */
-        vol_mtime = vol->v_mtime;
+    if (!vol_mtime
+        || (!vol->v_mtime && ((vol_mtime + GETUSED_CACHETIME) < now))
+        || (vol->v_mtime && ((vol_mtime + GETUSED_CACHETIME) < vol->v_mtime))
+        ) {
+        vol_mtime = now;
         getused_size = 0;
         ret = nftw(vol->v_path, getused_stat, NULL, 20, FTW_PHYS); /* 2 */
+        LOG(log_debug, logtype_afpd, "volparams: from nftw: %" PRIu64 " bytes",
+            getused_size);
     } else {
-        LOG(log_note, logtype_afpd, "volparams: cached used: %" PRIu64 " bytes",
+        LOG(log_debug, logtype_afpd, "volparams: cached used: %" PRIu64 " bytes",
             getused_size);
-
     }
 
-exit:
     return ret;
 }
 
@@ -1523,7 +1532,7 @@ getvolspace_done:
     if (vol->v_limitsize) {
         if (getused(vol) != 0)
             return AFPERR_MISC;
-        LOG(log_note, logtype_afpd, "volparams: used on volume: %" PRIu64 " bytes",
+        LOG(log_debug, logtype_afpd, "volparams: used on volume: %" PRIu64 " bytes",
             getused_size);
 
         *xbtotal = min(*xbtotal, (vol->v_limitsize * 1024 * 1024));
@@ -1645,7 +1654,8 @@ static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, cha
                         ashort |= VOLPBIT_ATTR_UNIXPRIV;
                     if (vol->v_flags & AFPVOL_TM)
                         ashort |= VOLPBIT_ATTR_TM;
-
+                    if (vol->v_flags & AFPVOL_NONETIDS)
+                        ashort |= VOLPBIT_ATTR_NONETIDS;
                     if (afp_version >= 32) {
                         if (vol->v_vfs_ea)
                             ashort |= VOLPBIT_ATTR_EXT_ATTRS;