3 #endif /* HAVE_CONFIG_H */
6 #include <atalk/adouble.h>
8 #define FILEIOFF_ATTR 14
9 #define AFPFILEIOFF_ATTR 2
13 the "shared" and "invisible" attributes are opaque and stored and
14 retrieved from the FinderFlags. This fixes Bug #2802236:
15 <https://sourceforge.net/tracker/?func=detail&aid=2802236&group_id=8642&atid=108642>
17 int ad_getattr(const struct adouble *ad, u_int16_t *attr)
22 if (ad->ad_version == AD_VERSION2) {
23 if (ad_getentryoff(ad, ADEID_AFPFILEI)) {
24 memcpy(attr, ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, 2);
26 /* Now get opaque flags from FinderInfo */
27 memcpy(&fflags, ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, 2);
28 if (fflags & htons(FINDERINFO_INVISIBLE))
29 *attr |= htons(ATTRBIT_INVISIBLE);
31 *attr &= htons(~ATTRBIT_INVISIBLE);
33 This one is tricky, I actually got it wrong the first time:
34 for directories bit 1<<1 is ATTRBIT_EXPFLDR and is NOT opaque !
36 if ( ! (ad->ad_adflags & ADFLAGS_DIR)) {
37 if (fflags & htons(FINDERINFO_ISHARED))
38 *attr |= htons(ATTRBIT_MULTIUSER);
40 *attr &= htons(~ATTRBIT_MULTIUSER);
45 *attr |= htons(ad->ad_open_forks);
50 /* ----------------- */
51 int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
55 /* we don't save open forks indicator */
56 u_int16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
58 /* Proactively (10.4 does indeed try to set ATTRBIT_MULTIUSER (=ATTRBIT_EXPFLDR)
59 for dirs with SetFile -a M <dir> ) disable all flags not defined for dirs. */
60 if (ad->ad_adflags & ADFLAGS_DIR)
61 attr &= ~(ATTRBIT_MULTIUSER | ATTRBIT_NOWRITE | ATTRBIT_NOCOPY);
63 if (ad->ad_version == AD_VERSION2) {
64 if (ad_getentryoff(ad, ADEID_AFPFILEI) && ad_getentryoff(ad, ADEID_FINDERI)) {
65 memcpy(ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, &attr, sizeof(attr));
67 /* Now set opaque flags in FinderInfo too */
68 memcpy(&fflags, ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, 2);
69 if (attr & htons(ATTRBIT_INVISIBLE))
70 fflags |= htons(FINDERINFO_INVISIBLE);
72 fflags &= htons(~FINDERINFO_INVISIBLE);
74 /* See above comment in ad_getattr() */
75 if (attr & htons(ATTRBIT_MULTIUSER)) {
76 if ( ! (ad->ad_adflags & ADFLAGS_DIR) )
77 fflags |= htons(FINDERINFO_ISHARED);
79 fflags &= htons(~FINDERINFO_ISHARED);
81 memcpy(ad_entry(ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, &fflags, 2);
89 * save file/folder ID in AppleDoubleV2 netatalk private parameters
90 * return 1 if resource fork has been modified
92 int ad_setid (struct adouble *adp, const dev_t dev, const ino_t ino , const u_int32_t id, const cnid_t did, const void *stamp)
94 if ((adp->ad_flags == AD_VERSION2) && (adp->ad_options & ADVOL_CACHE)) {
96 /* ad_getid depends on this to detect presence of ALL entries */
97 ad_setentrylen( adp, ADEID_PRIVID, sizeof(id));
98 memcpy(ad_entry( adp, ADEID_PRIVID ), &id, sizeof(id));
100 ad_setentrylen( adp, ADEID_PRIVDEV, sizeof(dev_t));
101 if ((adp->ad_options & ADVOL_NODEV)) {
102 memset(ad_entry( adp, ADEID_PRIVDEV ), 0, sizeof(dev_t));
104 memcpy(ad_entry( adp, ADEID_PRIVDEV ), &dev, sizeof(dev_t));
107 ad_setentrylen( adp, ADEID_PRIVINO, sizeof(ino_t));
108 memcpy(ad_entry( adp, ADEID_PRIVINO ), &ino, sizeof(ino_t));
110 ad_setentrylen( adp, ADEID_DID, sizeof(did));
111 memcpy(ad_entry( adp, ADEID_DID ), &did, sizeof(did));
113 ad_setentrylen( adp, ADEID_PRIVSYN, ADEDLEN_PRIVSYN);
114 memcpy(ad_entry( adp, ADEID_PRIVSYN ), stamp, ADEDLEN_PRIVSYN);
120 /* ----------------------------- */
121 u_int32_t ad_getid (struct adouble *adp, const dev_t st_dev, const ino_t st_ino , const cnid_t did, const void *stamp)
127 char temp[ADEDLEN_PRIVSYN];
129 /* look in AD v2 header
130 * note inode and device are opaques and not in network order
131 * only use the ID if adouble is writable for us.
134 && (adp->ad_options & ADVOL_CACHE)
135 && (adp->ad_md->adf_flags & O_RDWR )
136 && (sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)) /* One check to ensure ALL values are there */
138 memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
139 memcpy(&ino, ad_entry(adp, ADEID_PRIVINO), sizeof(ino_t));
140 memcpy(temp, ad_entry(adp, ADEID_PRIVSYN), sizeof(temp));
141 memcpy(&a_did, ad_entry(adp, ADEID_DID), sizeof(cnid_t));
143 if ( ((adp->ad_options & ADVOL_NODEV) || dev == st_dev)
145 && (!did || a_did == did)
146 && (memcmp(stamp, temp, sizeof(temp)) == 0) ) {
147 memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
154 /* ----------------------------- */
155 u_int32_t ad_forcegetid (struct adouble *adp)
159 if (adp && (adp->ad_options & ADVOL_CACHE)) {
160 memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
167 * set resource fork filename attribute.
169 int ad_setname(struct adouble *ad, const char *path)
171 if (path && ad_getentryoff(ad, ADEID_NAME)) {
172 ad_setentrylen( ad, ADEID_NAME, strlen( path ));
173 memcpy(ad_entry( ad, ADEID_NAME ), path, ad_getentrylen( ad, ADEID_NAME ));