+
+ return buf;
+}
+
+/******************************************************************************
+ * Public functions
+ ******************************************************************************/
+
+int ad_lock(struct adouble *ad, uint32_t eid, int locktype, off_t off, off_t len, int fork)
+{
+ struct flock lock;
+ struct ad_fd *adf;
+ adf_lock_t *adflock;
+ int oldlock;
+ int i;
+ int type;
+ int ret = 0, fcntl_lock_err = 0;
+
+ LOG(log_debug, logtype_default, "ad_lock(%s, %s, off: %jd (%s), len: %jd): BEGIN",
+ eid == ADEID_DFORK ? "data" : "reso",
+ locktypetostr(locktype),
+ (intmax_t)off,
+ shmdstrfromoff(off),
+ (intmax_t)len);
+
+ if ((locktype & ADLOCK_FILELOCK) && (len != 1))
+ AFP_PANIC("lock API error");
+
+ type = locktype;
+
+ if (eid == ADEID_DFORK) {
+ adf = &ad->ad_data_fork;
+ lock.l_start = off;
+ } else { /* rfork */
+ if (type & ADLOCK_FILELOCK) {
+ adf = &ad->ad_data_fork;
+ lock.l_start = rf2off(off);
+ } else {
+ adf = ad->ad_rfp;
+ lock.l_start = off + ad_getentryoff(ad, ADEID_RFORK);
+ }
+ }
+
+ /* NOTE: we can't write lock a read-only file. on those, we just
+ * make sure that we have a read lock set. that way, we at least prevent
+ * someone else from really setting a deny read/write on the file.
+ */
+ if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) {
+ type = (type & ~ADLOCK_WR) | ADLOCK_RD;