2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation, and that the name of The University
10 * of Michigan not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. This software is supplied as is without expressed or
13 * implied warranties of any kind.
15 * Research Systems Unix Group
16 * The University of Michigan
18 * 535 W. William Street
21 * netatalk@itd.umich.edu
26 #endif /* HAVE_CONFIG_H */
29 #include <sys/param.h>
33 #include <atalk/adouble.h>
35 #include <atalk/logger.h>
36 #include <atalk/util.h>
38 ssize_t adf_pread(struct ad_fd *ad_fd, void *buf, size_t count, off_t offset)
43 if ( ad_fd->adf_off != offset ) {
44 if ( lseek( ad_fd->adf_fd, offset, SEEK_SET ) < 0 ) {
47 ad_fd->adf_off = offset;
49 if (( cc = read( ad_fd->adf_fd, buf, count )) < 0 ) {
54 cc = pread(ad_fd->adf_fd, buf, count, offset );
59 /* XXX: locks have to be checked before each stream of consecutive
60 * ad_reads to prevent a denial in the middle from causing
62 ssize_t ad_read( struct adouble *ad, const uint32_t eid, off_t off, char *buf, const size_t buflen)
68 /* We're either reading the data fork (and thus the data file)
69 * or we're reading anything else (and thus the header file). */
70 if ( eid == ADEID_DFORK ) {
71 if (ad->ad_data_fork.adf_syml !=0 ) {
72 /* It's a symlink, we already have the target in adf_syml */
73 cc = strlen(ad->ad_data_fork.adf_syml);
75 /* Request buffersize is too small, force AFPERR_PARAM */
77 memcpy(buf, ad->ad_data_fork.adf_syml, cc);
79 cc = adf_pread(&ad->ad_data_fork, buf, buflen, off);
82 if (! AD_RSRC_OPEN(ad))
83 /* resource fork is not open ( cf etc/afp/fork.c) */
86 if (ad->ad_vers == AD_VERSION_EA) {
90 r_off = off + ADEDOFF_RFORK_OSX;
93 r_off = ad_getentryoff(ad, eid) + off;
96 if (( cc = adf_pread( &ad->ad_resource_fork, buf, buflen, r_off )) < 0 )