2 * $Id: ad_flush.c,v 1.5 2002-10-11 14:18:36 didg Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
30 #include <atalk/adouble.h>
37 #include "ad_private.h"
39 /* rebuild the header */
40 void ad_rebuild_header(struct adouble *ad)
49 * Rebuild any header information that might have changed.
53 temp = htonl( ad->ad_magic );
54 memcpy(buf, &temp, sizeof( temp ));
55 buf += sizeof( temp );
57 temp = htonl( ad->ad_version );
58 memcpy(buf, &temp, sizeof( temp ));
59 buf += sizeof( temp );
61 memcpy(buf, ad->ad_filler, sizeof( ad->ad_filler ));
62 buf += sizeof( ad->ad_filler );
65 buf += sizeof( nent );
66 for ( eid = 0, nent = 0; eid < ADEID_MAX; eid++ ) {
67 if ( ad->ad_eid[ eid ].ade_off == 0 ) {
71 memcpy(buf, &temp, sizeof( temp ));
72 buf += sizeof( temp );
74 temp = htonl( ad->ad_eid[ eid ].ade_off );
75 memcpy(buf, &temp, sizeof( temp ));
76 buf += sizeof( temp );
78 temp = htonl( ad->ad_eid[ eid ].ade_len );
79 memcpy(buf, &temp, sizeof( temp ));
80 buf += sizeof( temp );
84 memcpy(nentp, &nent, sizeof( nent ));
88 int ad_flush( ad, adflags )
94 if (( adflags & ADFLAGS_HF ) && ( ad->ad_hf.adf_flags & O_RDWR )) {
96 if (ad->ad_rlen > 0xffffffff) {
97 ad_setentrylen(ad, ADEID_RFORK, 0xffffffff);
100 ad_setentrylen(ad, ADEID_RFORK, ad->ad_rlen);
102 ad_rebuild_header(ad);
103 len = ad_getentryoff(ad, ADEID_RFORK);
104 /* now flush it out */
105 if (adf_pwrite(&ad->ad_hf, ad->ad_data, len, 0) != len) {
116 /* use refcounts so that we don't have to re-establish fcntl locks. */
117 int ad_close( ad, adflags )
123 if (( adflags & ADFLAGS_DF ) && ad->ad_df.adf_fd != -1 &&
124 !(--ad->ad_df.adf_refcount)) {
125 if ( close( ad->ad_df.adf_fd ) < 0 ) {
128 ad->ad_df.adf_fd = -1;
129 adf_lock_free(&ad->ad_df);
132 if (( adflags & ADFLAGS_HF ) && ad->ad_hf.adf_fd != -1 &&
133 !(--ad->ad_hf.adf_refcount)) {
134 if ( close( ad->ad_hf.adf_fd ) < 0 ) {
137 ad->ad_hf.adf_fd = -1;
138 adf_lock_free(&ad->ad_hf);