X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Ffork.c;h=634f7ad8f7499239d421342b955c047fe5d64090;hb=b362b6f7b22b6e4e9e74760989f389149677917b;hp=2e235888590e5eed2ebe143ccb91b732f8361bf4;hpb=f422a450f02e1bc95a26a6b10f1446cc291d5007;p=netatalk.git diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index 2e235888..634f7ad8 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -331,7 +331,7 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si ad_open so that we can keep file locks together. FIXME: add the fork we are opening? */ - if ((opened = of_findname(s_path))) { + if ((opened = of_findname(vol, s_path))) { adsame = opened->of_ad; } @@ -638,6 +638,7 @@ afp_setfork_err: case EDQUOT: case EFBIG: case ENOSPC: + LOG(log_error, logtype_afpd, "afp_setforkparams: DISK FULL"); return AFPERR_DFULL; default: return AFPERR_PARAM; @@ -845,8 +846,6 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si u_int16_t ofrefnum; u_char nlmask, nlchar; - *rbuflen = 0; - ibuf += 2; memcpy(&ofrefnum, ibuf, sizeof( ofrefnum )); ibuf += sizeof( u_short ); @@ -895,6 +894,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) { @@ -902,12 +904,15 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si goto afp_read_err; } -#ifndef WITH_SENDFILE *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); err = read_file(ofork, eid, offset, nlmask, nlchar, rbuf, rbuflen, xlate); if (err < 0) goto afp_read_done; -#endif + 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. */ if ((obj->proto == AFPPROTO_DSI) && (*rbuflen < reqcount) && !nlmask) { @@ -939,6 +944,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; @@ -962,12 +968,6 @@ afp_read_loop: goto afp_read_exit; offset += *rbuflen; -#ifdef DEBUG1 - if (obj->options.flags & OPTION_DEBUG) { - printf( "(read) reply: %d, %d\n", *rbuflen, dsi->clientID); - bprint(rbuf, *rbuflen); - } -#endif /* dsi_read() also returns buffer size of next allocation */ cc = dsi_read(dsi, rbuf, *rbuflen); /* send it off */ if (cc < 0) @@ -1164,6 +1164,7 @@ static ssize_t write_file(struct ofork *ofork, int eid, case EDQUOT : case EFBIG : case ENOSPC : + LOG(log_error, logtype_afpd, "write_file: DISK FULL"); return( AFPERR_DFULL ); case EACCES: return AFPERR_ACCESS; @@ -1183,7 +1184,7 @@ static ssize_t write_file(struct ofork *ofork, int eid, static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64) { struct ofork *ofork; - off_t offset, saveoff, reqcount; + off_t offset, saveoff, reqcount, oldsize, newsize; int endflag, eid, xlate = 0, err = AFP_OK; u_int16_t ofrefnum; ssize_t cc; @@ -1223,8 +1224,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) { @@ -1232,9 +1234,12 @@ 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)) { + LOG(log_error, logtype_afpd, "write_fork: DISK FULL"); err = AFPERR_DFULL; goto afp_write_err; } @@ -1342,7 +1347,7 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s ofork->of_flags |= AFPFORK_MODIFIED; /* update write count */ - ofork->of_vol->v_written += reqcount; + ofork->of_vol->v_appended += (newsize > oldsize) ? (newsize - oldsize) : 0; *rbuflen = set_off_t (offset, rbuf, is64); return( AFP_OK );