]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/fork.c
Merge master
[netatalk.git] / etc / afpd / fork.c
index 4133eebdbe40544bee0f1d77810f617ee8fb865a..2887f93e332767983bd43a5e2f92cb9e9c62d325 100644 (file)
@@ -16,7 +16,6 @@
 #include <sys/socket.h>
 #include <inttypes.h>
 
-#include <netatalk/at.h>
 #include <atalk/dsi.h>
 #include <atalk/afp.h>
 #include <atalk/adouble.h>
 #include <atalk/util.h>
 #include <atalk/cnid.h>
 #include <atalk/bstradd.h>
+#include <atalk/globals.h>
 
 #include "fork.h"
 #include "file.h"
-#include "globals.h"
 #include "directory.h"
 #include "desktop.h"
 #include "volume.h"
@@ -36,7 +35,7 @@
 struct ofork *writtenfork;
 #endif
 
-static int getforkparams(struct ofork *ofork, u_int16_t bitmap, char *buf, size_t *buflen)
+static int getforkparams(struct ofork *ofork, uint16_t bitmap, char *buf, size_t *buflen)
 {
     struct path         path;
     struct stat     *st;
@@ -90,7 +89,7 @@ static int getforkparams(struct ofork *ofork, u_int16_t bitmap, char *buf, size_
 
 static off_t get_off_t(char **ibuf, int is64)
 {
-    u_int32_t             temp;
+    uint32_t             temp;
     off_t                 ret;
 
     ret = 0;
@@ -111,7 +110,7 @@ static off_t get_off_t(char **ibuf, int is64)
 
 static int set_off_t(off_t offset, char *rbuf, int is64)
 {
-    u_int32_t  temp;
+    uint32_t  temp;
     int        ret;
 
     ret = 0;
@@ -428,10 +427,10 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         goto openfork_err;
     }
 
-    *rbuflen = buflen + 2 * sizeof( u_int16_t );
+    *rbuflen = buflen + 2 * sizeof( uint16_t );
     bitmap = htons( bitmap );
-    memcpy(rbuf, &bitmap, sizeof( u_int16_t ));
-    rbuf += sizeof( u_int16_t );
+    memcpy(rbuf, &bitmap, sizeof( uint16_t ));
+    rbuf += sizeof( uint16_t );
 
     /* check  WriteInhibit bit if we have a ressource fork
      * the test is done here, after some Mac trafic capture
@@ -495,7 +494,7 @@ int afp_setforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen, char *rbuf _U
 {
     struct ofork    *ofork;
     off_t       size;
-    u_int16_t       ofrefnum, bitmap;
+    uint16_t       ofrefnum, bitmap;
     int                 err;
     int                 is64;
     int                 eid;
@@ -633,8 +632,8 @@ static int byte_lock(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf
     struct ofork    *ofork;
     off_t               offset, length;
     int                 eid;
-    u_int16_t       ofrefnum;
-    u_int8_t            flags;
+    uint16_t       ofrefnum;
+    uint8_t            flags;
     int                 lockop;
 
     *rbuflen = 0;
@@ -814,7 +813,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
     off_t       offset, saveoff, reqcount, savereqcount;
     ssize_t     cc, err;
     int         eid, xlate = 0;
-    u_int16_t       ofrefnum;
+    uint16_t       ofrefnum;
     u_char      nlmask, nlchar;
 
     ibuf += 2;
@@ -870,6 +869,9 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         goto afp_read_err;
     }
 
+    LOG(log_debug, logtype_afpd, "afp_read(name: \"%s\", offset: %jd, reqcount: %jd)",
+        of_name(ofork), (intmax_t)offset, (intmax_t)reqcount);
+
     savereqcount = reqcount;
     saveoff = offset;
     if (ad_tmplock(ofork->of_ad, eid, ADLOCK_RD, saveoff, savereqcount,ofork->of_refnum) < 0) {
@@ -877,11 +879,19 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
         goto afp_read_err;
     }
 
+<<<<<<< HEAD
 #define min(a,b)    ((a)<(b)?(a):(b))
     *rbuflen = min( reqcount, *rbuflen );
+=======
+    *rbuflen = MIN(reqcount, *rbuflen);
+    LOG(log_debug, logtype_afpd, "afp_read(name: \"%s\", offset: %jd, reqcount: %jd): reading %jd bytes from file",
+        of_name(ofork), (intmax_t)offset, (intmax_t)reqcount, (intmax_t)*rbuflen);
+>>>>>>> netafp/master
     err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen, xlate);
     if (err < 0)
         goto afp_read_done;
+    LOG(log_debug, logtype_afpd, "afp_read(name: \"%s\", offset: %jd, reqcount: %jd): got %jd bytes from file",
+        of_name(ofork), (intmax_t)offset, (intmax_t)reqcount, (intmax_t)*rbuflen);
 
     /* dsi can stream requests. we can only do this if we're not checking
      * for an end-of-line character. oh well. */
@@ -914,6 +924,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
             int fd;
 
             fd = ad_readfile_init(ofork->of_ad, eid, &offset, 0);
+
             if (dsi_stream_read_file(dsi, fd, offset, dsi->datasize) < 0) {
                 if (errno == EINVAL || errno == ENOSYS)
                     goto afp_read_loop;
@@ -978,7 +989,7 @@ int afp_read_ext(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rb
 int afp_flush(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct vol *vol;
-    u_int16_t vid;
+    uint16_t vid;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -995,7 +1006,7 @@ int afp_flush(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, s
 int afp_flushfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct ofork    *ofork;
-    u_int16_t       ofrefnum;
+    uint16_t       ofrefnum;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1027,7 +1038,7 @@ int afp_flushfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U
 int afp_syncfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct ofork        *ofork;
-    u_int16_t           ofrefnum;
+    uint16_t           ofrefnum;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1098,7 +1109,7 @@ int flushfork(struct ofork *ofork)
 int afp_closefork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct ofork    *ofork;
-    u_int16_t       ofrefnum;
+    uint16_t       ofrefnum;
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1167,10 +1178,17 @@ static ssize_t write_file(struct ofork *ofork, int eid,
  * in reqcount et al. */
 static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64)
 {
+<<<<<<< HEAD
     struct ofork    *ofork;
     off_t               offset, saveoff, reqcount;
     int             endflag, eid, xlate = 0, err = AFP_OK;
-    u_int16_t       ofrefnum;
+    uint16_t       ofrefnum;
+=======
+    struct ofork       *ofork;
+    off_t           offset, saveoff, reqcount, oldsize, newsize;
+    int                        endflag, eid, xlate = 0, err = AFP_OK;
+    u_int16_t          ofrefnum;
+>>>>>>> netafp/master
     ssize_t             cc;
 
     /* figure out parameters */
@@ -1213,8 +1231,9 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
         goto afp_write_err;
     }
 
+    oldsize = ad_size(ofork->of_ad, eid);
     if (endflag)
-        offset += ad_size(ofork->of_ad, eid);
+        offset += oldsize;
 
     /* handle bogus parameters */
     if (reqcount < 0 || offset < 0) {
@@ -1222,6 +1241,8 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
         goto afp_write_err;
     }
 
+    newsize = ((offset + reqcount) > oldsize) ? (offset + reqcount) : oldsize;
+
     /* offset can overflow on 64-bit capable filesystems.
      * report disk full if that's going to happen. */
     if (sum_neg(is64, offset, reqcount)) {
@@ -1304,6 +1325,12 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
     if ( ad_meta_fileno( ofork->of_ad ) != -1 ) /* META */
         ofork->of_flags |= AFPFORK_DIRTY;
 
+    /* we have modified any fork, remember until close_fork */
+    ofork->of_flags |= AFPFORK_MODIFIED;
+
+    /* update write count */
+    ofork->of_vol->v_appended += (newsize > oldsize) ? (newsize - oldsize) : 0;
+
     *rbuflen = set_off_t (offset, rbuf, is64);
     return( AFP_OK );
 
@@ -1337,7 +1364,7 @@ int afp_getforkparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbu
 {
     struct ofork    *ofork;
     int             ret;
-    u_int16_t       ofrefnum, bitmap;
+    uint16_t       ofrefnum, bitmap;
     size_t          buflen;
     ibuf += 2;
     memcpy(&ofrefnum, ibuf, sizeof( ofrefnum ));