2 * $Id: ad_attr.c,v 1.6 2006-09-29 09:39:16 didg Exp $
7 #endif /* HAVE_CONFIG_H */
10 #include <atalk/adouble.h>
12 #define FILEIOFF_ATTR 14
13 #define AFPFILEIOFF_ATTR 2
15 int ad_getattr(const struct adouble *ad, u_int16_t *attr)
19 if (ad->ad_version == AD_VERSION1) {
20 if (ad_getentryoff(ad, ADEID_FILEI)) {
21 memcpy(attr, ad_entry(ad, ADEID_FILEI) + FILEIOFF_ATTR,
25 #if AD_VERSION == AD_VERSION2
26 else if (ad->ad_version == AD_VERSION2) {
27 if (ad_getentryoff(ad, ADEID_AFPFILEI)) {
28 memcpy(attr, ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR,
36 *attr |= htons(ad->ad_open_forks);
41 /* ----------------- */
42 int ad_setattr(const struct adouble *ad, const u_int16_t attribute)
44 /* we don't save open forks indicator */
45 u_int16_t attr = attribute & ~htons(ATTRBIT_DOPEN | ATTRBIT_ROPEN);
47 if (ad->ad_version == AD_VERSION1) {
48 if (ad_getentryoff(ad, ADEID_FILEI)) {
49 memcpy(ad_entry(ad, ADEID_FILEI) + FILEIOFF_ATTR, &attr,
53 #if AD_VERSION == AD_VERSION2
54 else if (ad->ad_version == AD_VERSION2) {
55 if (ad_getentryoff(ad, ADEID_AFPFILEI)) {
56 memcpy(ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, &attr,
68 * save file/folder ID in AppleDoubleV2 netatalk private parameters
69 * return 1 if resource fork has been modified
71 #if AD_VERSION == AD_VERSION2
72 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)
74 if (adp->ad_flags == AD_VERSION2 && ( adp->ad_options & ADVOL_CACHE) &&
75 ad_getentryoff(adp, ADEID_PRIVDEV) &&
76 sizeof(dev_t) == ADEDLEN_PRIVDEV && sizeof(ino_t) == ADEDLEN_PRIVINO)
78 ad_setentrylen( adp, ADEID_PRIVDEV, sizeof(dev_t));
79 if ((adp->ad_options & ADVOL_NODEV)) {
80 memset(ad_entry( adp, ADEID_PRIVDEV ), 0, sizeof(dev_t));
83 memcpy(ad_entry( adp, ADEID_PRIVDEV ), &dev, sizeof(dev_t));
86 ad_setentrylen( adp, ADEID_PRIVINO, sizeof(ino_t));
87 memcpy(ad_entry( adp, ADEID_PRIVINO ), &ino, sizeof(ino_t));
89 ad_setentrylen( adp, ADEID_PRIVID, sizeof(id));
90 memcpy(ad_entry( adp, ADEID_PRIVID ), &id, sizeof(id));
92 ad_setentrylen( adp, ADEID_DID, sizeof(did));
93 memcpy(ad_entry( adp, ADEID_DID ), &did, sizeof(did));
95 ad_setentrylen( adp, ADEID_PRIVSYN, ADEDLEN_PRIVSYN);
96 memcpy(ad_entry( adp, ADEID_PRIVSYN ), stamp, ADEDLEN_PRIVSYN);
102 /* ----------------------------- */
103 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)
109 char temp[ADEDLEN_PRIVSYN];
111 /* look in AD v2 header
112 * note inode and device are opaques and not in network order
113 * only use the ID if adouble is writable for us.
115 if (adp && ( adp->ad_options & ADVOL_CACHE) && ( adp->ad_md->adf_flags & O_RDWR )
116 && sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)
117 && sizeof(ino_t) == ad_getentrylen(adp,ADEID_PRIVINO)
118 && sizeof(temp) == ad_getentrylen(adp,ADEID_PRIVSYN)
119 && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_DID)
120 && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_PRIVID)
122 memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
123 memcpy(&ino, ad_entry(adp, ADEID_PRIVINO), sizeof(ino_t));
124 memcpy(temp, ad_entry(adp, ADEID_PRIVSYN), sizeof(temp));
125 memcpy(&a_did, ad_entry(adp, ADEID_DID), sizeof(cnid_t));
127 if ( ((adp->ad_options & ADVOL_NODEV) || dev == st_dev)
128 && ino == st_ino && a_did == did
129 && !memcmp(stamp, temp, sizeof(temp))) {
130 memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
140 * set resource fork filename attribute.
142 int ad_setname(struct adouble *ad, const char *path)
144 if (ad_getentryoff(ad, ADEID_NAME)) {
145 ad_setentrylen( ad, ADEID_NAME, strlen( path ));
146 memcpy(ad_entry( ad, ADEID_NAME ), path, ad_getentrylen( ad, ADEID_NAME ));