2 * $Id: ad_open.c,v 1.60.2.1 2010-01-02 10:22:33 franklahm Exp $
4 * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
5 * Copyright (c) 1990,1991 Regents of The University of Michigan.
8 * Permission to use, copy, modify, and distribute this software and
9 * its documentation for any purpose and without fee is hereby granted,
10 * provided that the above copyright notice appears in all copies and
11 * that both that copyright notice and this permission notice appear
12 * in supporting documentation, and that the name of The University
13 * of Michigan not be used in advertising or publicity pertaining to
14 * distribution of the software without specific, written prior
15 * permission. This software is supplied as is without expressed or
16 * implied warranties of any kind.
18 * Research Systems Unix Group
19 * The University of Michigan
21 * 535 W. William Street
24 * netatalk@itd.umich.edu
26 * NOTE: I don't use inline because a good compiler should be
27 * able to optimize all the static below. Didier
32 #endif /* HAVE_CONFIG_H */
36 #include <atalk/adouble.h>
37 #include <sys/param.h>
38 #include <atalk/logger.h>
40 #include <atalk/util.h>
43 #include "ad_private.h"
47 #define MAX(a, b) ((a) < (b) ? (b) : (a))
51 * AppleDouble entry default offsets.
52 * The layout looks like this:
54 * this is the v1 layout:
56 * | NAME | COMMENT | FILEI | FINDERI | RFORK |
58 * we need to change it to look like this:
61 * field length (in bytes)
64 * FILEDATESI 16 replaces FILEI
68 * SHORTNAME 12 8.3 new
71 * so, all we need to do is replace FILEI with FILEDATESI, move RFORK,
72 * and add in the new fields.
74 * NOTE: the HFS module will need similar modifications to interact with
78 #define ADEDOFF_MAGIC (0)
79 #define ADEDOFF_VERSION (ADEDOFF_MAGIC + ADEDLEN_MAGIC)
80 #define ADEDOFF_FILLER (ADEDOFF_VERSION + ADEDLEN_VERSION)
81 #define ADEDOFF_NENTRIES (ADEDOFF_FILLER + ADEDLEN_FILLER)
83 /* initial lengths of some of the fields */
84 #define ADEDLEN_INIT 0
86 /* make sure we don't redefine ADEDOFF_FILEI */
89 #endif /* ADEDOFF_FILEI */
91 #define ADEDOFF_NAME_V1 (AD_HEADER_LEN + ADEID_NUM_V1*AD_ENTRY_LEN)
92 #define ADEDOFF_COMMENT_V1 (ADEDOFF_NAME_V1 + ADEDLEN_NAME)
93 #define ADEDOFF_FILEI (ADEDOFF_COMMENT_V1 + ADEDLEN_COMMENT)
94 #define ADEDOFF_FINDERI_V1 (ADEDOFF_FILEI + ADEDLEN_FILEI)
95 #define ADEDOFF_RFORK_V1 (ADEDOFF_FINDERI_V1 + ADEDLEN_FINDERI)
97 /* i stick things in a slightly different order than their eid order in
98 * case i ever want to separate RootInfo behaviour from the rest of the
100 #define ADEDOFF_NAME_V2 (AD_HEADER_LEN + ADEID_NUM_V2*AD_ENTRY_LEN)
101 #define ADEDOFF_COMMENT_V2 (ADEDOFF_NAME_V2 + ADEDLEN_NAME)
102 #define ADEDOFF_FILEDATESI (ADEDOFF_COMMENT_V2 + ADEDLEN_COMMENT)
103 #define ADEDOFF_FINDERI_V2 (ADEDOFF_FILEDATESI + ADEDLEN_FILEDATESI)
104 #define ADEDOFF_DID (ADEDOFF_FINDERI_V2 + ADEDLEN_FINDERI)
105 #define ADEDOFF_AFPFILEI (ADEDOFF_DID + ADEDLEN_DID)
106 #define ADEDOFF_SHORTNAME (ADEDOFF_AFPFILEI + ADEDLEN_AFPFILEI)
107 #define ADEDOFF_PRODOSFILEI (ADEDOFF_SHORTNAME + ADEDLEN_SHORTNAME)
108 #define ADEDOFF_PRIVDEV (ADEDOFF_PRODOSFILEI + ADEDLEN_PRODOSFILEI)
109 #define ADEDOFF_PRIVINO (ADEDOFF_PRIVDEV + ADEDLEN_PRIVDEV)
110 #define ADEDOFF_PRIVSYN (ADEDOFF_PRIVINO + ADEDLEN_PRIVINO)
111 #define ADEDOFF_PRIVID (ADEDOFF_PRIVSYN + ADEDLEN_PRIVSYN)
113 #define ADEDOFF_RFORK_V2 (ADEDOFF_PRIVID + ADEDLEN_PRIVID)
115 #define ADEID_NUM_OSX 2
116 #define ADEDOFF_FINDERI_OSX (AD_HEADER_LEN + ADEID_NUM_OSX*AD_ENTRY_LEN)
117 #define ADEDOFF_RFORK_OSX (ADEDOFF_FINDERI_OSX + ADEDLEN_FINDERI)
119 /* we keep local copies of a bunch of stuff so that we can initialize things
122 /* this is to prevent changing timezones from causing problems with
123 localtime volumes. the screw-up is 30 years. we use a delta of 5
125 #define TIMEWARP_DELTA 157680000
129 u_int32_t id, offset, len;
132 static const struct entry entry_order1[ADEID_NUM_V1 +1] = {
133 {ADEID_NAME, ADEDOFF_NAME_V1, ADEDLEN_INIT}, /* 3 */
134 {ADEID_COMMENT, ADEDOFF_COMMENT_V1, ADEDLEN_INIT}, /* 4 */
135 {ADEID_FILEI, ADEDOFF_FILEI, ADEDLEN_FILEI}, /* 7 */
136 {ADEID_FINDERI, ADEDOFF_FINDERI_V1, ADEDLEN_FINDERI}, /* 9 */
137 {ADEID_RFORK, ADEDOFF_RFORK_V1, ADEDLEN_INIT}, /* 2 */
141 #if AD_VERSION == AD_VERSION1
142 #define DISK_EID(ad, a) (a)
144 #else /* AD_VERSION == AD_VERSION2 */
146 static u_int32_t get_eid(struct adouble *ad, u_int32_t eid)
150 if (ad->ad_version == AD_VERSION1)
153 return ADEID_PRIVDEV;
155 return ADEID_PRIVINO;
157 return ADEID_PRIVSYN;
164 #define DISK_EID(ad, a) get_eid(ad, a)
166 static const struct entry entry_order2[ADEID_NUM_V2 +1] = {
167 {ADEID_NAME, ADEDOFF_NAME_V2, ADEDLEN_INIT},
168 {ADEID_COMMENT, ADEDOFF_COMMENT_V2, ADEDLEN_INIT},
169 {ADEID_FILEDATESI, ADEDOFF_FILEDATESI, ADEDLEN_FILEDATESI},
170 {ADEID_FINDERI, ADEDOFF_FINDERI_V2, ADEDLEN_FINDERI},
171 {ADEID_DID, ADEDOFF_DID, ADEDLEN_DID},
172 {ADEID_AFPFILEI, ADEDOFF_AFPFILEI, ADEDLEN_AFPFILEI},
173 {ADEID_SHORTNAME, ADEDOFF_SHORTNAME, ADEDLEN_INIT},
174 {ADEID_PRODOSFILEI, ADEDOFF_PRODOSFILEI, ADEDLEN_PRODOSFILEI},
175 {ADEID_PRIVDEV, ADEDOFF_PRIVDEV, ADEDLEN_INIT},
176 {ADEID_PRIVINO, ADEDOFF_PRIVINO, ADEDLEN_INIT},
177 {ADEID_PRIVSYN, ADEDOFF_PRIVSYN, ADEDLEN_INIT},
178 {ADEID_PRIVID, ADEDOFF_PRIVID, ADEDLEN_INIT},
179 {ADEID_RFORK, ADEDOFF_RFORK_V2, ADEDLEN_INIT},
184 /* OS X adouble finder info and resource fork only
186 static const struct entry entry_order_osx[ADEID_NUM_OSX +1] = {
187 {ADEID_FINDERI, ADEDOFF_FINDERI_OSX, ADEDLEN_FINDERI},
188 {ADEID_RFORK, ADEDOFF_RFORK_OSX, ADEDLEN_INIT},
193 #define ADEID_NUM_SFM 3
194 static const struct entry entry_order_sfm[ADEID_NUM_SFM +1] = {
195 {ADEID_FINDERI, 16, ADEDLEN_FINDERI}, /* 9 */
196 {ADEID_SFMRESERVE2, 16+32, 6}, /* 21 */
197 {ADEID_FILEI, 60, ADEDLEN_FILEI}, /* 7 */
202 #endif /* AD_VERSION == AD_VERSION2 */
204 #if AD_VERSION == AD_VERSION2
206 /* update a version 2 adouble resource fork with our private entries */
207 static int ad_update(struct adouble *ad, const char *path)
210 u_int16_t nentries = 0;
211 off_t off, shiftdata=0;
212 const struct entry *eid;
213 static off_t entry_len[ADEID_MAX];
214 static char databuf[ADEID_MAX][256], *buf;
218 /* check to see if we should convert this header. */
219 if (!path || ad->ad_flags != AD_VERSION2)
222 LOG(log_maxdebug, logtype_default, "ad_update: checking whether '%s' needs an upgrade.", path);
224 if (!(ad->ad_md->adf_flags & O_RDWR)) {
225 /* we were unable to open the file read write the last time */
229 if (ad->ad_eid[ADEID_RFORK].ade_off) {
230 shiftdata = ADEDOFF_RFORK_V2 -ad->ad_eid[ADEID_RFORK].ade_off;
233 memcpy(&nentries, ad->ad_data + ADEDOFF_NENTRIES, sizeof( nentries ));
234 nentries = ntohs( nentries );
236 if ( shiftdata == 0 && nentries == ADEID_NUM_V2)
239 memset(entry_len, 0, sizeof(entry_len));
240 memset(databuf, 0, sizeof(databuf));
242 /* bail if we can't get a lock */
243 if (ad_tmplock(ad, ADEID_RFORK, ADLOCK_WR, 0, 0, 0) < 0)
246 fd = ad->ad_md->adf_fd;
248 if (fstat(fd, &st)) {
252 if (st.st_size > 0x7fffffff) {
253 LOG(log_debug, logtype_default, "ad_update: file '%s' too big for update.", path);
258 off = ad->ad_eid[ADEID_RFORK].ade_off;
259 if (off > st.st_size) {
260 LOG(log_error, logtype_default, "ad_update: invalid resource fork offset. (off: %u)", off);
265 if (ad->ad_eid[ADEID_RFORK].ade_len > st.st_size - off) {
266 LOG(log_error, logtype_default, "ad_update: invalid resource fork length. (rfork len: %u)", ad->ad_eid[ADEID_RFORK].ade_len);
271 if ((void *) (buf = (char *)
272 mmap(NULL, st.st_size + shiftdata,
273 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) ==
278 /* last place for failure. */
279 if (sys_ftruncate(fd, st.st_size + shiftdata) < 0) {
283 /* move the RFORK. this assumes that the RFORK is at the end */
285 memmove(buf + ADEDOFF_RFORK_V2, buf + off, ad->ad_eid[ADEID_RFORK].ade_len);
288 munmap(buf, st.st_size + shiftdata);
290 /* now, fix up our copy of the header */
291 memset(ad->ad_filler, 0, sizeof(ad->ad_filler));
293 /* save the header entries */
296 if( ad->ad_eid[eid->id].ade_off != 0) {
297 if ( eid->id > 2 && ad->ad_eid[eid->id].ade_len < 256)
298 memcpy( databuf[eid->id], ad->ad_data +ad->ad_eid[eid->id].ade_off, ad->ad_eid[eid->id].ade_len);
299 entry_len[eid->id] = ad->ad_eid[eid->id].ade_len;
304 memset(ad->ad_data + AD_HEADER_LEN, 0, AD_DATASZ - AD_HEADER_LEN);
306 /* copy the saved entries to the new header */
309 if ( eid->id > 2 && entry_len[eid->id] > 0) {
310 memcpy(ad->ad_data+eid->offset, databuf[eid->id], entry_len[eid->id]);
312 ad->ad_eid[eid->id].ade_off = eid->offset;
313 ad->ad_eid[eid->id].ade_len = entry_len[eid->id];
317 /* rebuild the header and cleanup */
318 LOG(log_debug, logtype_default, "updated AD2 header %s", path);
323 ad_tmplock(ad, ADEID_RFORK, ADLOCK_CLR, 0, 0, 0);
328 /* ------------------------------------------
329 FIXME work only if < 2GB
331 static int ad_convert(struct adouble *ad, const char *path)
338 /* use resource fork offset from file */
347 if (!(ad->ad_md->adf_flags & ( O_RDWR))) {
348 /* we were unable to open the file read write the last time */
352 /* check to see if we should convert this header. */
353 toV2 = ad->ad_version == AD_VERSION1 && ad->ad_flags == AD_VERSION2;
354 toV1 = ad->ad_version == AD_VERSION2 && ad->ad_flags == AD_VERSION1;
359 /* convert from v1 to v2. what does this mean?
360 * 1) change FILEI into FILEDATESI
361 * 2) create space for SHORTNAME, AFPFILEI, DID, and PRODOSI
362 * 3) move FILEI attributes into AFPFILEI
363 * 4) initialize ACCESS field of FILEDATESI.
364 * 5) move the resource fork
367 /* bail if we can't get a lock */
368 if (ad_tmplock(ad, ADEID_RFORK, ADLOCK_WR, 0, 0, 0) < 0)
371 /* we reuse fd from the resource fork */
372 fd = ad->ad_md->adf_fd;
374 if (ad->ad_eid[ADEID_RFORK].ade_off) {
375 shiftdata = ADEDOFF_RFORK_V2 -ad->ad_eid[ADEID_RFORK].ade_off;
378 shiftdata = ADEDOFF_RFORK_V2 -ADEDOFF_RFORK_V1; /* 136 */
381 if (fstat(fd, &st)) {
385 if (st.st_size > 0x7fffffff -shiftdata) {
386 LOG(log_debug, logtype_default, "ad_v1tov2: file too big.");
391 off = ad->ad_eid[ADEID_RFORK].ade_off;
393 if (off > st.st_size) {
394 LOG(log_error, logtype_default, "ad_v1tov2: invalid resource fork offset. (off: %u)", off);
399 if (ad->ad_eid[ADEID_RFORK].ade_len > st.st_size - off) {
400 LOG(log_error, logtype_default, "ad_v1tov2: invalid resource fork length. (rfork len: %u)", ad->ad_eid[ADEID_RFORK].ade_len);
405 if ((void *) (buf = (char *)
406 mmap(NULL, st.st_size + shiftdata,
407 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) ==
412 /* last place for failure. */
414 if (sys_ftruncate(fd, st.st_size + shiftdata) < 0) {
418 /* move the RFORK. this assumes that the RFORK is at the end */
420 memmove(buf + ADEDOFF_RFORK_V2, buf + off, ad->ad_eid[ADEID_RFORK].ade_len);
423 munmap(buf, st.st_size + shiftdata);
425 /* now, fix up our copy of the header */
426 memset(ad->ad_filler, 0, sizeof(ad->ad_filler));
428 /* replace FILEI with FILEDATESI */
429 ad_getattr(ad, &attr);
430 ad->ad_eid[ADEID_FILEDATESI].ade_off = ADEDOFF_FILEDATESI;
431 ad->ad_eid[ADEID_FILEDATESI].ade_len = ADEDLEN_FILEDATESI;
432 ad->ad_eid[ADEID_FILEI].ade_off = 0;
433 ad->ad_eid[ADEID_FILEI].ade_len = 0;
435 /* add in the new entries */
436 ad->ad_eid[ADEID_DID].ade_off = ADEDOFF_DID;
437 ad->ad_eid[ADEID_DID].ade_len = ADEDLEN_DID;
438 ad->ad_eid[ADEID_AFPFILEI].ade_off = ADEDOFF_AFPFILEI;
439 ad->ad_eid[ADEID_AFPFILEI].ade_len = ADEDLEN_AFPFILEI;
440 ad->ad_eid[ADEID_SHORTNAME].ade_off = ADEDOFF_SHORTNAME;
441 ad->ad_eid[ADEID_SHORTNAME].ade_len = ADEDLEN_INIT;
442 ad->ad_eid[ADEID_PRODOSFILEI].ade_off = ADEDOFF_PRODOSFILEI;
443 ad->ad_eid[ADEID_PRODOSFILEI].ade_len = ADEDLEN_PRODOSFILEI;
445 ad->ad_eid[ADEID_PRIVDEV].ade_off = ADEDOFF_PRIVDEV;
446 ad->ad_eid[ADEID_PRIVDEV].ade_len = ADEDLEN_INIT;
447 ad->ad_eid[ADEID_PRIVINO].ade_off = ADEDOFF_PRIVINO;
448 ad->ad_eid[ADEID_PRIVINO].ade_len = ADEDLEN_INIT;
449 ad->ad_eid[ADEID_PRIVSYN].ade_off = ADEDOFF_PRIVSYN;
450 ad->ad_eid[ADEID_PRIVSYN].ade_len = ADEDLEN_INIT;
451 ad->ad_eid[ADEID_PRIVID].ade_off = ADEDOFF_PRIVID;
452 ad->ad_eid[ADEID_PRIVID].ade_len = ADEDLEN_INIT;
454 /* shift the old entries (NAME, COMMENT, FINDERI, RFORK) */
455 ad->ad_eid[ADEID_NAME].ade_off = ADEDOFF_NAME_V2;
456 ad->ad_eid[ADEID_COMMENT].ade_off = ADEDOFF_COMMENT_V2;
457 ad->ad_eid[ADEID_FINDERI].ade_off = ADEDOFF_FINDERI_V2;
458 ad->ad_eid[ADEID_RFORK].ade_off = ADEDOFF_RFORK_V2;
460 /* switch to dest version */
461 ad->ad_version = (toV2)?AD_VERSION2:AD_VERSION1;
463 /* move our data buffer to make space for the new entries. */
464 memmove(ad->ad_data + ADEDOFF_NAME_V2, ad->ad_data + ADEDOFF_NAME_V1,
465 ADEDOFF_RFORK_V1 - ADEDOFF_NAME_V1);
467 /* now, fill in the space with appropriate stuff. we're
468 operating as a v2 file now. */
469 ad_setdate(ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
470 memset(ad_entry(ad, ADEID_DID), 0, ADEDLEN_DID);
471 memset(ad_entry(ad, ADEID_AFPFILEI), 0, ADEDLEN_AFPFILEI);
472 ad_setattr(ad, attr);
473 memset(ad_entry(ad, ADEID_SHORTNAME), 0, ADEDLEN_SHORTNAME);
474 memset(ad_entry(ad, ADEID_PRODOSFILEI), 0, ADEDLEN_PRODOSFILEI);
476 /* rebuild the header and cleanup */
481 ad_tmplock(ad, ADEID_RFORK, ADLOCK_CLR, 0, 0, 0);
485 #endif /* AD_VERSION == AD_VERSION2 */
487 /* -------------------------------------
490 static void parse_entries(struct adouble *ad, char *buf,
493 u_int32_t eid, len, off;
496 /* now, read in the entry bits */
497 for (; nentries > 0; nentries-- ) {
498 memcpy(&eid, buf, sizeof( eid ));
499 eid = DISK_EID(ad, ntohl( eid ));
500 buf += sizeof( eid );
501 memcpy(&off, buf, sizeof( off ));
503 buf += sizeof( off );
504 memcpy(&len, buf, sizeof( len ));
506 buf += sizeof( len );
508 if (eid && eid < ADEID_MAX && off < sizeof(ad->ad_data) &&
509 (off +len <= sizeof(ad->ad_data) || eid == ADEID_RFORK)) {
510 ad->ad_eid[ eid ].ade_off = off;
511 ad->ad_eid[ eid ].ade_len = len;
512 } else if (!warning) {
514 LOG(log_debug, logtype_default, "ad_refresh: nentries %hd eid %d",
521 /* this reads enough of the header so that we can figure out all of
522 * the entry lengths and offsets. once that's done, we just read/mmap
523 * the rest of the header in.
525 * NOTE: we're assuming that the resource fork is kept at the end of
526 * the file. also, mmapping won't work for the hfs fs until it
527 * understands how to mmap header files. */
528 static int ad_header_read(struct adouble *ad, struct stat *hst)
530 char *buf = ad->ad_data;
534 static int warning = 0;
537 /* read the header */
538 if ((header_len = adf_pread( ad->ad_md, buf, sizeof(ad->ad_data), 0)) < 0) {
541 if (header_len < AD_HEADER_LEN) {
546 memcpy(&ad->ad_magic, buf, sizeof( ad->ad_magic ));
547 memcpy(&ad->ad_version, buf + ADEDOFF_VERSION, sizeof( ad->ad_version ));
549 /* tag broken v1 headers. just assume they're all right.
550 * we detect two cases: null magic/version
551 * byte swapped magic/version
552 * XXX: in the future, you'll need the v1compat flag.
553 * (ad->ad_flags & ADFLAGS_V1COMPAT) */
554 if (!ad->ad_magic && !ad->ad_version) {
556 LOG(log_debug, logtype_default, "notice: fixing up null v1 magic/version.");
559 ad->ad_magic = AD_MAGIC;
560 ad->ad_version = AD_VERSION1;
562 } else if (ad->ad_magic == AD_MAGIC && ad->ad_version == AD_VERSION1) {
564 LOG(log_debug, logtype_default, "notice: fixing up byte-swapped v1 magic/version.");
569 ad->ad_magic = ntohl( ad->ad_magic );
570 ad->ad_version = ntohl( ad->ad_version );
573 if ((ad->ad_magic != AD_MAGIC) || ((ad->ad_version != AD_VERSION1)
574 #if AD_VERSION == AD_VERSION2
575 && (ad->ad_version != AD_VERSION2)
576 #endif /* AD_VERSION == AD_VERSION2 */
578 LOG(log_debug, logtype_default, "ad_open: can't parse AppleDouble header.");
583 memcpy(ad->ad_filler, buf + ADEDOFF_FILLER, sizeof( ad->ad_filler ));
584 memcpy(&nentries, buf + ADEDOFF_NENTRIES, sizeof( nentries ));
585 nentries = ntohs( nentries );
587 /* read in all the entry headers. if we have more than the
588 * maximum, just hope that the rfork is specified early on. */
589 len = nentries*AD_ENTRY_LEN;
591 if (len + AD_HEADER_LEN > sizeof(ad->ad_data))
592 len = sizeof(ad->ad_data) - AD_HEADER_LEN;
594 buf += AD_HEADER_LEN;
595 if (len > header_len - AD_HEADER_LEN) {
596 LOG(log_debug, logtype_default, "ad_header_read: can't read entry info.");
601 /* figure out all of the entry offsets and lengths. if we aren't
602 * able to read a resource fork entry, bail. */
603 nentries = len / AD_ENTRY_LEN;
604 parse_entries(ad, buf, nentries);
605 if (!ad_getentryoff(ad, ADEID_RFORK)
606 || (ad_getentryoff(ad, ADEID_RFORK) > sizeof(ad->ad_data))
608 LOG(log_debug, logtype_default, "ad_header_read: problem with rfork entry offset.");
613 if (ad_getentryoff(ad, ADEID_RFORK) > header_len) {
614 LOG(log_debug, logtype_default, "ad_header_read: can't read in entries.");
621 if (fstat(ad->ad_md->adf_fd, &st) < 0) {
622 return 1; /* fail silently */
625 ad->ad_rlen = hst->st_size - ad_getentryoff(ad, ADEID_RFORK);
627 /* fix up broken dates */
628 if (ad->ad_version == AD_VERSION1) {
631 /* check to see if the ad date is wrong. just see if we have
632 * a modification date in the future. */
633 if (((ad_getdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, &aint)) == 0) &&
634 (aint > TIMEWARP_DELTA + hst->st_mtime)) {
635 ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, aint - AD_DATE_DELTA);
636 ad_getdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, &aint);
637 ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, aint - AD_DATE_DELTA);
638 ad_getdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, &aint);
639 ad_setdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, aint - AD_DATE_DELTA);
646 /* ---------------------------
651 byte afpi_Signature[4]; /* Must be 0x00504641 */
652 byte afpi_Version[4]; /* Must be 0x00010000 */
653 byte afpi_Reserved1[4];
654 byte afpi_BackupTime[4]; /* Backup time for the file/dir */
655 byte finderinfo[32]; /* Finder info */
656 byte afpi_ProDosInfo[6]; /* ProDos Info */
657 byte afpi_Reserved2[6];
661 static int ad_header_sfm_read(struct adouble *ad, struct stat *hst)
663 char *buf = ad->ad_data;
664 const struct entry *eid;
668 /* read the header */
669 if ((header_len = adf_pread( ad->ad_md, buf, sizeof(ad->ad_data), 0)) < 0) {
672 if (header_len != AD_SFM_LEN) {
677 memcpy(&ad->ad_magic, buf, sizeof( ad->ad_magic ));
678 memcpy(&ad->ad_version, buf + 4, sizeof( ad->ad_version ));
680 /* FIXME in the great Microsoft tradition they aren't in network order */
682 if (ad->ad_magic == SFM_MAGIC && ad->ad_version == AD_VERSION1) {
683 static int warning = 0;
685 LOG(log_debug, logtype_default, "notice: fixing up byte-swapped v1 magic/version.");
690 ad->ad_magic = ntohl( ad->ad_magic );
691 ad->ad_version = ntohl( ad->ad_version );
694 if ((ad->ad_magic != SFM_MAGIC) || ((ad->ad_version != AD_VERSION1) )) {
696 LOG(log_debug, logtype_default, "ad_header_sfm_read: can't parse AppleDouble header.");
700 /* reinit adouble table */
701 eid = entry_order_sfm;
703 ad->ad_eid[eid->id].ade_off = eid->offset;
704 ad->ad_eid[eid->id].ade_len = eid->len;
708 /* steal some prodos for attribute */
712 memcpy(&attribute, buf + 48 +4, sizeof(attribute));
713 ad_setattr(ad, attribute );
716 if (ad->ad_resource_fork.adf_fd != -1) {
717 /* we have a resource fork use it rather than the metadata */
718 if (fstat(ad->ad_resource_fork.adf_fd, &st) < 0) {
724 ad->ad_rlen = st.st_size;
727 else if (hst == NULL) {
729 if (fstat(ad->ad_md->adf_fd, &st) < 0) {
730 return 1; /* fail silently */
734 /* fix up broken dates */
735 if (ad->ad_version == AD_VERSION1) {
738 /* check to see if the ad date is wrong. just see if we have
739 * a modification date in the future. */
740 if (((ad_getdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, &aint)) == 0) &&
741 (aint > TIMEWARP_DELTA + hst->st_mtime)) {
742 ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, aint - AD_DATE_DELTA);
743 ad_getdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, &aint);
744 ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, aint - AD_DATE_DELTA);
745 ad_getdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, &aint);
746 ad_setdate(ad, AD_DATE_BACKUP | AD_DATE_UNIX, aint - AD_DATE_DELTA);
753 /* ---------------------------------------
754 * Put the .AppleDouble where it needs to be:
758 * \ b/.AppleDouble/.Parent
760 * FIXME: should do something for pathname > MAXPATHLEN
763 ad_path( const char *path, int adflags)
765 static char pathbuf[ MAXPATHLEN + 1];
769 if ( adflags & ADFLAGS_DIR ) {
770 l = strlcpy( pathbuf, path, sizeof(pathbuf));
772 if ( l && l < MAXPATHLEN) {
775 strlcpy(pathbuf +l, ".AppleDouble/.Parent", sizeof(pathbuf) -l);
777 if (NULL != ( slash = strrchr( path, '/' )) ) {
780 /* XXX we must return NULL here and test in the caller */
783 memcpy( pathbuf, path, l);
788 l += strlcpy( pathbuf +l, ".AppleDouble/", sizeof(pathbuf) -l);
789 strlcpy( pathbuf + l, slash, sizeof(pathbuf) -l);
795 /* -------------------- */
796 static int ad_mkrf(char *path)
800 * Probably .AppleDouble doesn't exist, try to mkdir it.
802 if (NULL == ( slash = strrchr( path, '/' )) ) {
807 if ( ad_mkdir( path, 0777 ) < 0 ) {
814 /* ---------------------------------------
815 * Put the resource fork where it needs to be:
819 ad_path_osx(const char *path, int adflags _U_)
821 static char pathbuf[ MAXPATHLEN + 1];
822 char c, *slash, buf[MAXPATHLEN + 1];
824 if (!strcmp(path,".")) {
826 getcwd(buf, MAXPATHLEN);
829 strlcpy(buf, path, MAXPATHLEN +1);
831 if (NULL != ( slash = strrchr( buf, '/' )) ) {
834 strlcpy( pathbuf, buf, MAXPATHLEN +1);
840 strlcat( pathbuf, "._", MAXPATHLEN +1);
841 strlcat( pathbuf, slash, MAXPATHLEN +1);
844 /* -------------------- */
845 static int ad_mkrf_osx(char *path _U_)
850 /* ---------------------------------------
851 * Put the .AppleDouble where it needs to be:
853 * / a/.AppleDouble/b/AFP_AfpInfo
855 * \ b/.AppleDouble/.Parent/AFP_AfpInfo
859 ad_path_sfm( const char *path, int adflags)
861 static char pathbuf[ MAXPATHLEN + 1];
862 char c, *slash, buf[MAXPATHLEN + 1];
865 l = strlcpy(buf, path, MAXPATHLEN +1);
866 if ( adflags & ADFLAGS_DIR ) {
867 strcpy( pathbuf, buf);
868 if ( *buf != '\0' && l < MAXPATHLEN) {
874 if (NULL != ( slash = strrchr( buf, '/' )) ) {
877 strcpy( pathbuf, buf);
884 strlcat( pathbuf, ".AppleDouble/", MAXPATHLEN +1);
885 strlcat( pathbuf, slash, MAXPATHLEN +1);
887 if ((adflags == ADFLAGS_RF)) {
888 strlcat( pathbuf, "/AFP_Resource", MAXPATHLEN +1);
891 strlcat( pathbuf, "/AFP_AfpInfo", MAXPATHLEN +1);
896 /* -------------------- */
897 static int ad_mkrf_sfm(char *path)
901 * Probably .AppleDouble doesn't exist, try to mkdir it.
903 if (NULL == ( slash = strrchr( path, '/' )) ) {
908 if ( ad_mkdir( path, 0777 ) < 0 ) {
909 if ( errno == ENOENT ) {
912 if (NULL == ( slash1 = strrchr( path, '/' )) )
916 if ( ad_mkdir( path, 0777 ) < 0 )
919 if ( ad_mkdir( path, 0777 ) < 0 )
929 /* -------------------------
930 * Support inherited protection modes for AppleDouble files. The supplied
931 * mode is ANDed with the parent directory's mask value in lieu of "umask",
932 * and that value is returned.
935 #define DEFMASK 07700 /* be conservative */
938 *ad_dir(const char *path)
940 static char modebuf[ MAXPATHLEN + 1];
943 * For a path with directories in it, remove the final component
944 * (path or subdirectory name) to get the name we want to stat.
945 * For a path which is just a filename, use "." instead.
947 slash = strrchr( path, '/' );
952 if (len >= MAXPATHLEN) {
953 errno = ENAMETOOLONG;
954 return NULL; /* can't do it */
956 memcpy( modebuf, path, len );
958 /* is last char a '/' ? */
960 slash = modebuf+ len;
962 while (modebuf < slash && slash[-1] == '/') {
965 if (modebuf == slash) {
969 while (modebuf < slash && *slash != '/') {
972 if (modebuf == slash) {
975 *slash = '\0'; /* remove pathname component */
980 modebuf[0] = '.'; /* use current directory */
985 /* ---------------- */
986 static uid_t default_uid = -1;
988 int ad_setfuid(const uid_t id)
994 /* ---------------- */
995 uid_t ad_getfuid(void)
1001 return inode of path parent directory
1003 int ad_stat(const char *path, struct stat *stbuf)
1012 return lstat( p, stbuf );
1016 if we are root change path user/ group
1017 It can be a native function for BSD cf. FAQ.Q10
1018 path: pathname to chown
1019 stbuf: parent directory inode
1021 use fstat and fchown or lchown with linux?
1023 #define EMULATE_SUIDDIR
1025 static int ad_chown(const char *path, struct stat *stbuf)
1028 #ifdef EMULATE_SUIDDIR
1031 if (default_uid != (uid_t)-1) {
1032 /* we are root (admin) */
1033 id = (default_uid)?default_uid:stbuf->st_uid;
1034 ret = chown( path, id, stbuf->st_gid );
1041 return access right and inode of path parent directory
1043 static int ad_mode_st(const char *path, int *mode, struct stat *stbuf)
1048 if (ad_stat(path, stbuf) != 0) {
1052 *mode &= stbuf->st_mode;
1057 return access right of path parent directory
1060 ad_mode( const char *path, int mode)
1063 ad_mode_st(path, &mode, &stbuf);
1068 * Use mkdir() with mode bits taken from ad_mode().
1071 ad_mkdir( const char *path, int mode)
1078 LOG(log_debug9, logtype_default, "ad_mkdir: Creating directory with mode %d", mode);
1081 st_invalid = ad_mode_st(path, &mode, &stbuf);
1082 ret = mkdir( path, mode );
1083 if (ret || st_invalid)
1085 ad_chown(path, &stbuf);
1090 /* ----------------- */
1091 static int ad_error(struct adouble *ad, int adflags)
1094 if ((adflags & ADFLAGS_NOHF)) {
1095 /* FIXME double check : set header offset ?*/
1098 if ((adflags & ADFLAGS_DF)) {
1099 ad_close( ad, ADFLAGS_DF );
1105 static int new_rfork(const char *path, struct adouble *ad, int adflags);
1110 #define AD_SET(a) a = 0
1113 /* --------------------------- */
1114 static int ad_check_size(struct adouble *ad _U_, struct stat *st)
1116 if (st->st_size > 0 && st->st_size < AD_DATASZ1)
1121 /* --------------------------- */
1122 static int ad_check_size_sfm(struct adouble *ad _U_, struct stat *st)
1124 if (st->st_size > 0 && st->st_size < AD_SFM_LEN)
1129 /* --------------------------- */
1130 static int ad_header_upgrade(struct adouble *ad, char *name)
1132 #if AD_VERSION == AD_VERSION2
1134 if ( (ret = ad_convert(ad, name)) < 0 || (ret = ad_update(ad, name) < 0)) {
1141 /* --------------------------- */
1142 static int ad_header_upgrade_none(struct adouble *ad _U_, char *name _U_)
1147 /* --------------------------- */
1148 static struct adouble_fops ad_osx = {
1151 &ad_rebuild_adouble_header,
1158 static struct adouble_fops ad_sfm = {
1161 &ad_rebuild_sfm_header,
1164 &ad_header_sfm_read,
1165 &ad_header_upgrade_none,
1168 static struct adouble_fops ad_adouble = {
1171 &ad_rebuild_adouble_header,
1179 void ad_init(struct adouble *ad, int flags, int options)
1182 ad->ad_flags = flags;
1183 if (flags == AD_VERSION2_OSX) {
1184 ad->ad_ops = &ad_osx;
1185 ad->ad_md = &ad->ad_resource_fork;
1187 else if (flags == AD_VERSION1_SFM) {
1188 ad->ad_ops = &ad_sfm;
1189 ad->ad_md = &ad->ad_metadata_fork;
1192 ad->ad_ops = &ad_adouble;
1193 ad->ad_md = &ad->ad_resource_fork;
1195 ad->ad_options = options;
1197 ad_data_fileno(ad) = -1;
1198 ad_reso_fileno(ad) = -1;
1199 ad_meta_fileno(ad) = -1;
1200 /* following can be read even if there's no
1203 memset(ad->ad_eid, 0, sizeof( ad->ad_eid ));
1207 /* -------------------
1208 * It's not possible to open the header file O_RDONLY -- the read
1209 * will fail and return an error. this refcounts things now.
1211 int ad_open( const char *path, int adflags, int oflags, int mode, struct adouble *ad)
1214 struct stat st_meta;
1215 struct stat st_link;
1216 struct stat *pst = NULL;
1218 int hoflags, admode;
1219 int st_invalid = -1;
1222 if (ad->ad_inited != AD_INITED) {
1223 ad->ad_inited = AD_INITED;
1224 ad->ad_refcount = 1;
1225 ad->ad_open_forks = 0;
1226 ad->ad_adflags = adflags;
1227 ad->ad_resource_fork.adf_refcount = 0;
1228 ad->ad_data_fork.adf_refcount = 0;
1229 ad->ad_data_fork.adf_syml=0;
1232 ad->ad_open_forks = ((ad->ad_data_fork.adf_refcount > 0) ? ATTRBIT_DOPEN : 0);
1233 /* XXX not true if we have a meta data fork ? */
1234 if ((ad->ad_resource_fork.adf_refcount > ad->ad_data_fork.adf_refcount))
1235 ad->ad_open_forks |= ATTRBIT_ROPEN;
1238 if ((adflags & ADFLAGS_DF)) {
1239 if (ad_data_fileno(ad) == -1) {
1240 hoflags = (oflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
1242 if ((oflags & O_CREAT)) {
1243 st_invalid = ad_mode_st(path, &admode, &st_dir);
1244 if ((ad->ad_options & ADVOL_UNIXPRIV)) {
1248 lstat(path,&st_link);
1249 if (S_ISLNK(st_link.st_mode) && (oflags == O_RDONLY)) {
1251 ad->ad_data_fork.adf_syml=(char *)malloc(PATH_MAX+1);
1252 lsz=readlink(path,ad->ad_data_fork.adf_syml,PATH_MAX);
1254 free(ad->ad_data_fork.adf_syml);
1257 ad->ad_data_fork.adf_syml[lsz]=0;
1258 ad->ad_data_fork.adf_syml=(char *)realloc(ad->ad_data_fork.adf_syml,lsz+1);
1259 ad->ad_data_fork.adf_fd=0;
1262 ad->ad_data_fork.adf_fd =open( path, hoflags | O_NOFOLLOW, admode );
1264 if (ad->ad_data_fork.adf_fd < 0 ) {
1265 if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) {
1267 ad->ad_data_fork.adf_fd = open( path, hoflags | O_NOFOLLOW, admode );
1271 if ( ad->ad_data_fork.adf_fd < 0)
1274 AD_SET(ad->ad_data_fork.adf_off);
1275 ad->ad_data_fork.adf_flags = hoflags;
1277 /* just created, set owner if admin (root) */
1278 ad_chown(path, &st_dir);
1280 adf_lock_init(&ad->ad_data_fork);
1283 /* the file is already open... but */
1284 if ((oflags & ( O_RDWR | O_WRONLY)) && /* we want write access */
1285 !(ad->ad_data_fork.adf_flags & ( O_RDWR | O_WRONLY))) /* and it was denied the first time */
1291 * for now ad_open is never called with O_TRUNC or O_EXCL if the file is
1292 * already open. Should we check for it? ie
1294 * O_TRUNC --> truncate the fork.
1295 * idem for ressource fork.
1298 open_df = ADFLAGS_DF;
1299 ad->ad_data_fork.adf_refcount++;
1302 if (!(adflags & ADFLAGS_HF))
1305 /* ****************************************** */
1307 if (ad_meta_fileno(ad) != -1) { /* the file is already open */
1308 if ((oflags & ( O_RDWR | O_WRONLY)) &&
1309 !(ad->ad_md->adf_flags & ( O_RDWR | O_WRONLY))) {
1311 /* don't call with ADFLAGS_HF because we didn't open ressource fork */
1312 ad_close( ad, open_df );
1318 ad->ad_md->adf_refcount++;
1322 memset(ad->ad_eid, 0, sizeof( ad->ad_eid ));
1324 ad_p = ad->ad_ops->ad_path( path, adflags );
1326 hoflags = oflags & ~(O_CREAT | O_EXCL);
1327 if (!(adflags & ADFLAGS_RDONLY)) {
1328 hoflags = (hoflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
1330 ad->ad_md->adf_fd = open( ad_p, hoflags | O_NOFOLLOW, 0 );
1331 if (ad->ad_md->adf_fd < 0 ) {
1332 if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) {
1333 hoflags = oflags & ~(O_CREAT | O_EXCL);
1334 ad->ad_md->adf_fd = open( ad_p, hoflags | O_NOFOLLOW, 0 );
1338 if ( ad->ad_md->adf_fd < 0 ) {
1339 if (errno == ENOENT && (oflags & O_CREAT) ) {
1341 * We're expecting to create a new adouble header file,
1343 * if ((oflags & O_CREAT) ==> (oflags & O_RDWR)
1347 st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
1348 if ((ad->ad_options & ADVOL_UNIXPRIV)) {
1351 admode = ad_hf_mode(admode);
1352 if ( errno == ENOENT && !(adflags & ADFLAGS_NOADOUBLE) && ad->ad_flags != AD_VERSION2_OSX) {
1353 if (ad->ad_ops->ad_mkrf( ad_p) < 0) {
1354 return ad_error(ad, adflags);
1357 st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
1358 if ((ad->ad_options & ADVOL_UNIXPRIV)) {
1361 admode = ad_hf_mode(admode);
1363 /* retry with O_CREAT */
1364 ad->ad_md->adf_fd = open( ad_p, oflags,admode );
1365 if ( ad->ad_md->adf_fd < 0 ) {
1366 return ad_error(ad, adflags);
1368 ad->ad_md->adf_flags = oflags;
1369 /* just created, set owner if admin owner (root) */
1371 ad_chown(ad_p, &st_dir);
1375 return ad_error(ad, adflags);
1378 ad->ad_md->adf_flags = hoflags;
1379 if (fstat(ad->ad_md->adf_fd, &st_meta) == 0 && st_meta.st_size == 0) {
1380 /* for 0 length files, treat them as new. */
1381 ad->ad_md->adf_flags |= O_TRUNC;
1384 /* we have valid data in st_meta stat structure, reused it
1390 AD_SET(ad->ad_md->adf_off);
1392 ad->ad_md->adf_refcount = 1;
1393 adf_lock_init(ad->ad_md);
1394 if ((ad->ad_md->adf_flags & ( O_TRUNC | O_CREAT ))) {
1396 * This is a new adouble header file. Initialize the structure,
1397 * instead of reading it.
1399 if (new_rfork(path, ad, adflags) < 0) {
1401 /* the file is already deleted, perm, whatever, so return an error*/
1402 ad_close(ad, adflags);
1408 /* Read the adouble header in and parse it.*/
1409 if (ad->ad_ops->ad_header_read( ad , pst) < 0
1410 || ad->ad_ops->ad_header_upgrade(ad, ad_p) < 0)
1414 ad_close( ad, adflags );
1420 /* ****************************************** */
1421 /* open the resource fork if SFM */
1423 if (ad->ad_flags != AD_VERSION1_SFM) {
1427 if ((adflags & ADFLAGS_DIR)) {
1428 /* no resource fork for directories / volumes XXX it's false! */
1432 /* untrue yet but ad_close will decremente it*/
1433 ad->ad_resource_fork.adf_refcount++;
1435 if (ad_reso_fileno(ad) != -1) { /* the file is already open */
1436 if ((oflags & ( O_RDWR | O_WRONLY)) &&
1437 !(ad->ad_resource_fork.adf_flags & ( O_RDWR | O_WRONLY))) {
1439 ad_close( ad, open_df | ADFLAGS_HF);
1446 ad_p = ad->ad_ops->ad_path( path, ADFLAGS_RF );
1449 st_invalid = ad_mode_st(ad_p, &admode, &st_dir);
1451 if ((ad->ad_options & ADVOL_UNIXPRIV)) {
1455 hoflags = (oflags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
1456 ad->ad_resource_fork.adf_fd = open( ad_p, hoflags, admode );
1458 if (ad->ad_resource_fork.adf_fd < 0 ) {
1459 if ((errno == EACCES || errno == EROFS) && !(oflags & O_RDWR)) {
1461 ad->ad_resource_fork.adf_fd =open( ad_p, hoflags, admode );
1465 if ( ad->ad_resource_fork.adf_fd < 0) {
1468 ad_close( ad, adflags );
1472 adf_lock_init(&ad->ad_resource_fork);
1473 AD_SET(ad->ad_resource_fork.adf_off);
1474 ad->ad_resource_fork.adf_flags = hoflags;
1475 if ((oflags & O_CREAT) && !st_invalid) {
1476 /* just created, set owner if admin (root) */
1477 ad_chown(ad_p, &st_dir);
1479 else if (!fstat(ad->ad_resource_fork.adf_fd, &st_meta)) {
1480 ad->ad_rlen = st_meta.st_size;
1485 /* -----------------------------------
1486 * return only metadata but try very hard
1488 int ad_metadata(const char *name, int flags, struct adouble *adp)
1492 int dir = flags & ADFLAGS_DIR;
1495 if (!(flags & ADFLAGS_NOADOUBLE)) {
1499 /* Open with O_CREAT, thus enumarating a dir will create missing adouble files, see: */
1500 /* http://marc.info/?l=netatalk-devel&m=124039156832408&w=2 */
1501 if ((ret = ad_open(name, ADFLAGS_HF | dir, O_RDWR | adouble, 0666, adp)) < 0 && errno == EACCES) {
1504 LOG(log_error, logtype_default, "ad_metadata(%s): seteuid failed %s", name, strerror(errno));
1508 /* we are root open read only */
1509 ret = ad_open(name, ADFLAGS_HF|ADFLAGS_RDONLY| dir, O_RDONLY, 0, adp);
1511 if ( seteuid(uid) < 0) {
1512 LOG(log_error, logtype_default, "ad_metadata: can't seteuid back");
1518 if (!ret && (ADFLAGS_OPENFORKS & flags)) {
1520 we need to check if the file is open by another process.
1521 it's slow so we only do it if we have to:
1523 - we don't already have the answer!
1525 adp->ad_open_forks |= ad_openforks(adp, adp->ad_open_forks);
1530 /* ----------------------------------- */
1531 static int new_rfork(const char *path, struct adouble *ad, int adflags)
1533 const struct entry *eid;
1537 ad->ad_magic = AD_MAGIC;
1538 ad->ad_version = ad->ad_flags & 0x0f0000;
1539 if (!ad->ad_version) {
1540 ad->ad_version = AD_VERSION;
1543 memset(ad->ad_filler, 0, sizeof( ad->ad_filler ));
1544 memset(ad->ad_data, 0, sizeof(ad->ad_data));
1546 #if AD_VERSION == AD_VERSION2
1547 if (ad->ad_flags == AD_VERSION2)
1549 else if (ad->ad_flags == AD_VERSION2_OSX)
1550 eid = entry_order_osx;
1551 else if (ad->ad_flags == AD_VERSION1_SFM) {
1552 ad->ad_magic = SFM_MAGIC;
1553 eid = entry_order_sfm;
1560 ad->ad_eid[eid->id].ade_off = eid->offset;
1561 ad->ad_eid[eid->id].ade_len = eid->len;
1565 /* put something sane in the directory finderinfo */
1566 if ((adflags & ADFLAGS_DIR)) {
1567 /* set default view */
1568 ashort = htons(FINDERINFO_CLOSEDVIEW);
1569 memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRVIEWOFF,
1570 &ashort, sizeof(ashort));
1572 /* set default creator/type fields */
1573 memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRTYPEOFF,"\0\0\0\0", 4);
1574 memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRCREATOFF,"\0\0\0\0", 4);
1577 /* make things invisible */
1578 if ((ad->ad_options & ADVOL_INVDOTS) && !(adflags & ADFLAGS_CREATE) &&
1579 (*path == '.') && strcmp(path, ".") && strcmp(path, ".."))
1581 ashort = htons(ATTRBIT_INVISIBLE);
1582 ad_setattr(ad, ashort);
1583 ashort = htons(FINDERINFO_INVISIBLE);
1584 memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, &ashort, sizeof(ashort));
1587 if (lstat(path, &st) < 0) {
1591 /* put something sane in the date fields */
1592 ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, st.st_mtime);
1593 ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, st.st_mtime);
1594 ad_setdate(ad, AD_DATE_ACCESS | AD_DATE_UNIX, st.st_mtime);
1595 ad_setdate(ad, AD_DATE_BACKUP, AD_DATE_START);
1599 /* to do this with mmap, we need the hfs fs to understand how to mmap
1601 int ad_refresh(struct adouble *ad)
1604 if (ad_meta_fileno(ad) < 0)
1607 return ad->ad_ops->ad_header_read(ad, NULL);