2 * $Id: ad_attr.c,v 1.4.8.7.2.3 2005-04-27 01:36:21 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,
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)
74 ad_setentrylen( adp, ADEID_PRIVDEV, sizeof(dev_t));
75 if ((adp->ad_options & ADVOL_NODEV)) {
76 memset(ad_entry( adp, ADEID_PRIVDEV ), 0, sizeof(dev_t));
79 memcpy(ad_entry( adp, ADEID_PRIVDEV ), &dev, sizeof(dev_t));
82 ad_setentrylen( adp, ADEID_PRIVINO, sizeof(ino_t));
83 memcpy(ad_entry( adp, ADEID_PRIVINO ), &ino, sizeof(ino_t));
85 ad_setentrylen( adp, ADEID_PRIVID, sizeof(id));
86 memcpy(ad_entry( adp, ADEID_PRIVID ), &id, sizeof(id));
88 ad_setentrylen( adp, ADEID_DID, sizeof(did));
89 memcpy(ad_entry( adp, ADEID_DID ), &did, sizeof(did));
91 ad_setentrylen( adp, ADEID_PRIVSYN, ADEDLEN_PRIVSYN);
92 memcpy(ad_entry( adp, ADEID_PRIVSYN ), stamp, ADEDLEN_PRIVSYN);
98 /* ----------------------------- */
99 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)
105 char temp[ADEDLEN_PRIVSYN];
107 /* look in AD v2 header
108 * note inode and device are opaques and not in network order
109 * only use the ID if adouble is writable for us.
111 if (adp && ( adp->ad_options & ADVOL_CACHE) && ( adp->ad_hf.adf_flags & O_RDWR )
112 && sizeof(dev_t) == ad_getentrylen(adp, ADEID_PRIVDEV)
113 && sizeof(ino_t) == ad_getentrylen(adp,ADEID_PRIVINO)
114 && sizeof(temp) == ad_getentrylen(adp,ADEID_PRIVSYN)
115 && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_DID)
116 && sizeof(cnid_t) == ad_getentrylen(adp, ADEID_PRIVID)
118 memcpy(&dev, ad_entry(adp, ADEID_PRIVDEV), sizeof(dev_t));
119 memcpy(&ino, ad_entry(adp, ADEID_PRIVINO), sizeof(ino_t));
120 memcpy(temp, ad_entry(adp, ADEID_PRIVSYN), sizeof(temp));
121 memcpy(&a_did, ad_entry(adp, ADEID_DID), sizeof(cnid_t));
123 if ( ((adp->ad_options & ADVOL_NODEV) || dev == st_dev)
124 && ino == st_ino && a_did == did
125 && !memcmp(stamp, temp, sizeof(temp))) {
126 memcpy(&aint, ad_entry(adp, ADEID_PRIVID), sizeof(aint));
136 * set resource fork filename attribute.
138 int ad_setname(struct adouble *ad, const char *path)
140 if (ad_getentryoff(ad, ADEID_NAME)) {
141 ad_setentrylen( ad, ADEID_NAME, strlen( path ));
142 memcpy(ad_entry( ad, ADEID_NAME ), path, ad_getentrylen( ad, ADEID_NAME ));