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
25 #include <sys/types.h>
26 #include <sys/param.h>
27 #include <atalk/adouble.h>
31 #define MIN(a,b) ((a)<(b)?(a):(b))
34 /* XXX: this would probably benefit from pread.
35 * locks have to be checked before each stream of consecutive
36 * ad_reads to prevent a denial in the middle from causing
38 ssize_t ad_read( ad, eid, off, buf, buflen)
47 /* We're either reading the data fork (and thus the data file)
48 * or we're reading anything else (and thus the header file). */
49 if ( eid == ADEID_DFORK ) {
50 if ( ad->ad_df.adf_off != off ) {
51 if ( lseek( ad->ad_df.adf_fd, (off_t) off, SEEK_SET ) < 0 ) {
54 ad->ad_df.adf_off = off;
56 if (( cc = read( ad->ad_df.adf_fd, buf, buflen )) < 0 ) {
59 ad->ad_df.adf_off += cc;
61 cc = ad->ad_eid[eid].ade_off + off;
63 #ifdef USE_MMAPPED_HEADERS
64 if (eid != ADEID_RFORK) {
65 memcpy(buf, ad->ad_data + cc, buflen);
70 if ( ad->ad_hf.adf_off != cc ) {
71 if ( lseek( ad->ad_hf.adf_fd, (off_t) cc, SEEK_SET ) < 0 ) {
74 ad->ad_hf.adf_off = cc;
77 if (( cc = read( ad->ad_hf.adf_fd, buf, buflen )) < 0 ) {
81 #ifndef USE_MMAPPED_HEADERS
83 * We've just read in bytes from the disk that we read earlier
84 * into ad_data. If we're going to write this buffer out later,
85 * we need to update ad_data.
87 if (ad->ad_hf.adf_off < ad_getentryoff(ad, ADEID_RFORK)) {
88 if ( ad->ad_hf.adf_flags & O_RDWR ) {
89 memcpy(buf, ad->ad_data + ad->ad_hf.adf_off,
90 MIN(sizeof( ad->ad_data ) - ad->ad_hf.adf_off, cc));
92 memcpy(ad->ad_data + ad->ad_hf.adf_off, buf,
93 MIN(sizeof( ad->ad_data ) - ad->ad_hf.adf_off, cc));
96 ad->ad_hf.adf_off += cc;