2 * $Id: ad_flush.c,v 1.7 2005-04-28 20:49:52 bfernhomberg 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"
38 #if AD_VERSION == AD_VERSION1
40 #define EID_DISK(a) (a)
44 static const u_int32_t set_eid[] = {
47 AD_DEV, AD_INO, AD_SYN, AD_ID
50 #define EID_DISK(a) (set_eid[a])
53 /* rebuild the header */
54 void ad_rebuild_header(struct adouble *ad)
63 * Rebuild any header information that might have changed.
67 temp = htonl( ad->ad_magic );
68 memcpy(buf, &temp, sizeof( temp ));
69 buf += sizeof( temp );
71 temp = htonl( ad->ad_version );
72 memcpy(buf, &temp, sizeof( temp ));
73 buf += sizeof( temp );
75 memcpy(buf, ad->ad_filler, sizeof( ad->ad_filler ));
76 buf += sizeof( ad->ad_filler );
79 buf += sizeof( nent );
80 for ( eid = 0, nent = 0; eid < ADEID_MAX; eid++ ) {
81 if ( ad->ad_eid[ eid ].ade_off == 0 ) {
84 temp = htonl( EID_DISK(eid) );
85 memcpy(buf, &temp, sizeof( temp ));
86 buf += sizeof( temp );
88 temp = htonl( ad->ad_eid[ eid ].ade_off );
89 memcpy(buf, &temp, sizeof( temp ));
90 buf += sizeof( temp );
92 temp = htonl( ad->ad_eid[ eid ].ade_len );
93 memcpy(buf, &temp, sizeof( temp ));
94 buf += sizeof( temp );
98 memcpy(nentp, &nent, sizeof( nent ));
102 int ad_flush( ad, adflags )
108 if (( adflags & ADFLAGS_HF ) && ( ad->ad_hf.adf_flags & O_RDWR )) {
109 /* sync our header */
110 if (ad->ad_rlen > 0xffffffff) {
111 ad_setentrylen(ad, ADEID_RFORK, 0xffffffff);
114 ad_setentrylen(ad, ADEID_RFORK, ad->ad_rlen);
116 ad_rebuild_header(ad);
117 len = ad_getentryoff(ad, ADEID_RFORK);
118 /* now flush it out */
119 if (adf_pwrite(&ad->ad_hf, ad->ad_data, len, 0) != len) {
130 /* use refcounts so that we don't have to re-establish fcntl locks. */
131 int ad_close( ad, adflags )
137 if (( adflags & ADFLAGS_DF ) && ad->ad_df.adf_fd != -1 &&
138 !(--ad->ad_df.adf_refcount)) {
139 if ( close( ad->ad_df.adf_fd ) < 0 ) {
142 ad->ad_df.adf_fd = -1;
143 adf_lock_free(&ad->ad_df);
146 if (( adflags & ADFLAGS_HF ) && ad->ad_hf.adf_fd != -1 &&
147 !(--ad->ad_hf.adf_refcount)) {
148 if ( close( ad->ad_hf.adf_fd ) < 0 ) {
151 ad->ad_hf.adf_fd = -1;
152 adf_lock_free(&ad->ad_hf);