2 * $Id: ad_attr.c,v 1.5 2005-04-28 20:49:51 bfernhomberg 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,
39 /* ----------------- */
40 int ad_setattr(const struct adouble *ad, const u_int16_t attr)
42 if (ad->ad_version == AD_VERSION1) {
43 if (ad_getentryoff(ad, ADEID_FILEI)) {
44 memcpy(ad_entry(ad, ADEID_FILEI) + FILEIOFF_ATTR, &attr,
48 #if AD_VERSION == AD_VERSION2
49 else if (ad->ad_version == AD_VERSION2) {
50 if (ad_getentryoff(ad, ADEID_AFPFILEI)) {
51 memcpy(ad_entry(ad, ADEID_AFPFILEI) + AFPFILEIOFF_ATTR, &attr,
63 * save file/folder ID in AppleDoubleV2 netatalk private parameters
64 * return 1 if resource fork has been modified
66 #if AD_VERSION == AD_VERSION2
67 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)
69 if (adp->ad_flags == AD_VERSION2 && ( adp->ad_options & ADVOL_CACHE) &&
70 ad_getentryoff(adp, ADEID_PRIVDEV) &&
71 sizeof(dev_t) == ADEDLEN_PRIVDEV && sizeof(ino_t) == ADEDLEN_PRIVINO)
73 ad_setentrylen( adp, ADEID_PRIVDEV, sizeof(dev_t));
74 if ((adp->ad_options & ADVOL_NODEV)) {
75 memset(ad_entry( adp, ADEID_PRIVDEV ), 0, sizeof(dev_t));
78 memcpy(ad_entry( adp, ADEID_PRIVDEV ), &dev, sizeof(dev_t));
81 ad_setentrylen( adp, ADEID_PRIVINO, sizeof(ino_t));
82 memcpy(ad_entry( adp, ADEID_PRIVINO ), &ino, sizeof(ino_t));
84 ad_setentrylen( adp, ADEID_PRIVID, sizeof(id));
85 memcpy(ad_entry( adp, ADEID_PRIVID ), &id, sizeof(id));
87 ad_setentrylen( adp, ADEID_DID, sizeof(did));
88 memcpy(ad_entry( adp, ADEID_DID ), &did, sizeof(did));
90 ad_setentrylen( adp, ADEID_PRIVSYN, ADEDLEN_PRIVSYN);
91 memcpy(ad_entry( adp, ADEID_PRIVSYN ), stamp, ADEDLEN_PRIVSYN);
97 /* ----------------------------- */
98 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)
104 char temp[ADEDLEN_PRIVSYN];
106 /* look in AD v2 header
107 * note inode and device are opaques and not in network order
108 * only use the ID if adouble is writable for us.
110 if (adp && ( adp->ad_options & ADVOL_CACHE) && ( adp->ad_hf.adf_flags & O_RDWR )
111 && sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)
112 && sizeof(ino_t) == ad_getentrylen(adp,ADEID_PRIVINO)
113 && sizeof(temp) == ad_getentrylen(adp,ADEID_PRIVSYN)
114 && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_DID)
115 && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_PRIVID)
117 memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
118 memcpy(&ino, ad_entry(adp, ADEID_PRIVINO), sizeof(ino_t));
119 memcpy(temp, ad_entry(adp, ADEID_PRIVSYN), sizeof(temp));
120 memcpy(&a_did, ad_entry(adp, ADEID_DID), sizeof(cnid_t));
122 if ( ((adp->ad_options & ADVOL_NODEV) || dev == st_dev)
123 && ino == st_ino && a_did == did
124 && !memcmp(stamp, temp, sizeof(temp))) {
125 memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
135 * set resource fork filename attribute.
137 int ad_setname(struct adouble *ad, const char *path)
139 if (ad_getentryoff(ad, ADEID_NAME)) {
140 ad_setentrylen( ad, ADEID_NAME, strlen( path ));
141 memcpy(ad_entry( ad, ADEID_NAME ), path, ad_getentrylen( ad, ADEID_NAME ));