]> arthur.barton.de Git - netatalk.git/commitdiff
Remove size check that required a costly fstat()
authorRalph Boehme <sloowfranklin@gmail.com>
Thu, 18 Apr 2013 08:58:44 +0000 (10:58 +0200)
committerRalph Boehme <sloowfranklin@gmail.com>
Thu, 18 Apr 2013 08:58:44 +0000 (10:58 +0200)
In case the client request count plus offset is large then the file,
we're supposed to send the available data and set AFP error to
AFPERR_EOF.
No need to use an extra fstat() for that, we can also simply check
the whether the amount of data read from the file matches the
requested amount.

From FR #78.

etc/afpd/fork.c

index 0c988828d609660bc096c8cf01c944f6f8e633dc..a77c6adcad5d826c54bc457f4b01ac1111798c1a 100644 (file)
@@ -759,7 +759,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
 {
     DSI          *dsi = obj->dsi;
     struct ofork *ofork;
 {
     DSI          *dsi = obj->dsi;
     struct ofork *ofork;
-    off_t        offset, saveoff, reqcount, savereqcount, size;
+    off_t        offset, saveoff, reqcount, savereqcount;
     ssize_t      cc, err;
     int          eid;
     uint16_t     ofrefnum;
     ssize_t      cc, err;
     int          eid;
     uint16_t     ofrefnum;
@@ -801,23 +801,9 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
 
     AFP_READ_START((long)reqcount);
 
 
     AFP_READ_START((long)reqcount);
 
-    /* reqcount isn't always truthful. we need to deal with that. */
-    size = ad_size(ofork->of_ad, eid);
-
     LOG(log_debug, logtype_afpd,
     LOG(log_debug, logtype_afpd,
-        "afp_read(fork: %" PRIu16 " [%s], off: %" PRIu64 ", len: %" PRIu64 ", size: %" PRIu64 ")",
-        ofork->of_refnum, (ofork->of_flags & AFPFORK_DATA) ? "data" : "reso", offset, reqcount, size);
-
-    if (offset >= size) {
-        err = AFPERR_EOF;
-        goto afp_read_err;
-    }
-
-    /* subtract off the offset */
-    if (reqcount + offset > size) {
-        reqcount = size - offset;
-        err = AFPERR_EOF;
-    }
+        "afp_read(fork: %" PRIu16 " [%s], off: %" PRIu64 ", len: %" PRIu64 ")",
+        ofork->of_refnum, (ofork->of_flags & AFPFORK_DATA) ? "data" : "reso", offset, reqcount);
 
     savereqcount = reqcount;
     saveoff = offset;
 
     savereqcount = reqcount;
     saveoff = offset;