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
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <atalk/adouble.h>
35 #define MIN(a,b) ((a)<(b)?(a):(b))
38 /* XXX: this would probably benefit from pread.
39 * locks have to be checked before each stream of consecutive
40 * ad_reads to prevent a denial in the middle from causing
42 ssize_t ad_read( ad, eid, off, buf, buflen)
51 /* We're either reading the data fork (and thus the data file)
52 * or we're reading anything else (and thus the header file). */
53 if ( eid == ADEID_DFORK ) {
54 if ( ad->ad_df.adf_off != off ) {
55 if ( lseek( ad->ad_df.adf_fd, (off_t) off, SEEK_SET ) < 0 ) {
58 ad->ad_df.adf_off = off;
60 if (( cc = read( ad->ad_df.adf_fd, buf, buflen )) < 0 ) {
63 ad->ad_df.adf_off += cc;
65 cc = ad->ad_eid[eid].ade_off + off;
67 #ifdef USE_MMAPPED_HEADERS
68 if (eid != ADEID_RFORK) {
69 memcpy(buf, ad->ad_data + cc, buflen);
74 if ( ad->ad_hf.adf_off != cc ) {
75 if ( lseek( ad->ad_hf.adf_fd, (off_t) cc, SEEK_SET ) < 0 ) {
78 ad->ad_hf.adf_off = cc;
81 if (( cc = read( ad->ad_hf.adf_fd, buf, buflen )) < 0 ) {
85 #ifndef USE_MMAPPED_HEADERS
87 * We've just read in bytes from the disk that we read earlier
88 * into ad_data. If we're going to write this buffer out later,
89 * we need to update ad_data.
91 if (ad->ad_hf.adf_off < ad_getentryoff(ad, ADEID_RFORK)) {
92 if ( ad->ad_hf.adf_flags & O_RDWR ) {
93 memcpy(buf, ad->ad_data + ad->ad_hf.adf_off,
94 MIN(sizeof( ad->ad_data ) - ad->ad_hf.adf_off, cc));
96 memcpy(ad->ad_data + ad->ad_hf.adf_off, buf,
97 MIN(sizeof( ad->ad_data ) - ad->ad_hf.adf_off, cc));
100 ad->ad_hf.adf_off += cc;