/*
- * $Id: adouble.h,v 1.11 2002-10-11 14:18:35 didg Exp $
+ * $Id: adouble.h,v 1.12 2002-11-14 17:15:22 srittau Exp $
* Copyright (c) 1990,1991 Regents of The University of Michigan.
* All Rights Reserved.
*
#include <unistd.h>
#endif
-#ifdef HAVE_FLOCK
-#include <sys/file.h>
-#else
-#define LOCK_SH 1
-#define LOCK_EX 2
-#define LOCK_NB 4
-#define LOCK_UN 8
-extern int flock (int /*fd*/, int /*operation*/);
-#endif
-
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
extern int ad_close __P((struct adouble *, int));
/* ad_lock.c */
-extern int ad_flock_lock __P((struct adouble *, const u_int32_t /*eid*/,
- const int /*type*/, const off_t /*offset*/,
- const size_t /*len*/, const int /*user*/));
extern int ad_fcntl_lock __P((struct adouble *, const u_int32_t /*eid*/,
const int /*type*/, const off_t /*offset*/,
const size_t /*len*/, const int /*user*/));
extern void ad_fcntl_unlock __P((struct adouble *, const int /*user*/));
-extern int ad_flock_tmplock __P((struct adouble *, const u_int32_t /*eid*/,
- const int /*type*/, const off_t /*offset*/,
- const size_t /*len*/));
extern int ad_fcntl_tmplock __P((struct adouble *, const u_int32_t /*eid*/,
const int /*type*/, const off_t /*offset*/,
const size_t /*len*/));
-#ifdef USE_FLOCK_LOCKS
-#define ad_lock ad_flock_lock
-#define ad_tmplock ad_flock_tmplock
-#define ad_unlock(a,b)
-#else
#define ad_lock ad_fcntl_lock
#define ad_tmplock ad_fcntl_tmplock
#define ad_unlock ad_fcntl_unlock
-#endif
/* ad_open.c */
extern char *ad_dir __P((const char *));
#ifndef ATACC
static __inline__ mode_t ad_hf_mode (mode_t mode)
{
-#ifndef USE_FLOCK_LOCKS
/* fnctl lock need write access */
if ((mode & S_IRUSR))
mode |= S_IWUSR;
mode |= S_IWGRP;
if ((mode & S_IROTH))
mode |= S_IWOTH;
-#endif
+
/* if write mode set add read mode */
if ((mode & S_IWUSR))
mode |= S_IRUSR;
/*
- * $Id: ad_lock.c,v 1.5 2002-07-01 23:25:00 didg Exp $
+ * $Id: ad_lock.c,v 1.6 2002-11-14 17:15:22 srittau Exp $
*
* Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT for more information.
struct ad_fd *adf;
adf_lock_t *plock;
int i;
- int lockmode;
-
+
lock.l_start = off;
if (eid == ADEID_DFORK) {
adf = &ad->ad_df;
adf_unlock(&ad->ad_hf, ad->ad_hf.adf_fd, user);
}
}
-
-/* byte-range locks. ad_lock is used by afp_bytelock and afp_openfork
- * to establish locks. both ad_lock and ad_tmplock take 0, 0, 0 to
- * signify locking of the entire file. in the absence of working
- * byte-range locks, this will default to file-wide flock-style locks.
- */
-int ad_flock_lock(struct adouble *ad, const u_int32_t eid, const int type,
- const off_t off, const size_t len, const int user)
-{
- int err, lock_type;
-
- lock_type = XLATE_FLOCK(type & ADLOCK_MASK);
- if (eid == ADEID_DFORK) {
- if ((err = flock(ad_dfileno(ad), lock_type | LOCK_NB)) == 0)
- ad->ad_df.adf_lockcount = lock_type;
- } else if ((err = flock(ad_hfileno(ad), lock_type | LOCK_NB)) == 0)
- ad->ad_hf.adf_lockcount = lock_type;
-
- if (err) {
- if ((EWOULDBLOCK != EAGAIN) && (errno == EWOULDBLOCK))
- errno = EAGAIN;
- return -1;
- }
-
- return 0;
-}
-
-/* ad_tmplock is used by afpd to lock actual read/write operations.
- * it saves the current lock state before attempting to lock to prevent
- * mixups. if byte-locks don't exist, it will lock the entire file with
- * an flock. we can be a little smart here by just upgrading/downgrading
- * locks. */
-int ad_flock_tmplock(struct adouble *ad, const u_int32_t eid, const int type,
- const off_t off, const size_t len)
-{
- int fd, oldlock, lock_type;
-
- if (eid == ADEID_DFORK) {
- oldlock = ad->ad_df.adf_lockcount;
- fd = ad_dfileno(ad);
- } else {
- oldlock = ad->ad_hf.adf_lockcount;
- fd = ad_hfileno(ad);
- }
-
- /* if we already have a write lock, we don't need to do anything */
- if (oldlock == LOCK_EX) {
- return 0;
- }
-
- /* if we have a read lock, upgrade it if necessary */
- lock_type = XLATE_FLOCK(type & ADLOCK_MASK);
- if (oldlock == LOCK_SH) {
- if (lock_type == LOCK_EX)
- return flock(fd, LOCK_EX | LOCK_NB);
- else if (lock_type == LOCK_UN) /* reset it */
- return flock(fd, LOCK_SH | LOCK_NB);
- else /* do nothing */
- return 0;
- }
-
- /* if we don't already have a lock, just do it. */
- return flock(fd, lock_type | LOCK_NB);
-}
-
-
/*
- * $Id: ad_private.h,v 1.3 2002-08-16 08:07:57 didg Exp $
+ * $Id: ad_private.h,v 1.4 2002-11-14 17:15:23 srittau Exp $
*/
#ifndef LIBATALK_ADOUBLE_AD_PRIVATE_H
/* this is so that we can keep lists of fds referencing the same file
* around. that way, we can honor locks created by the same process
* with the same file. */
-#ifdef USE_FLOCK_LOCKS
-#define adf_lock_init(a)
-#define adf_lock_free(a)
-#else /* USE_FLOCK_LOCKS */
#define adf_lock_init(a) do { \
(a)->adf_lockmax = (a)->adf_lockcount = 0; \
free((a)->adf_lock); \
adf_lock_init(a); \
} while (0)
-#endif /* USE_FLOCK_LOCKS */
#endif /* libatalk/adouble/ad_private.h */
strdup.c \
inet_aton.c \
rquota_xdr.c \
- flock.c \
snprintf.c
+++ /dev/null
-/*
- * $Id: flock.c,v 1.4 2001-06-29 14:14:46 rufustfirefly Exp $
- *
- * Copyright (c) 1996 Regents of The University of Michigan.
- * All Rights Reserved. See COPYRIGHT.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-static int _flock_dummy;
-
-#ifndef HAVE_FLOCK
-
-#include <sys/types.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
-#include <errno.h>
-
-#define LOCK_SH 1
-#define LOCK_EX 2
-#define LOCK_NB 4
-#define LOCK_UN 8
-
-int flock( fd, operation )
- int fd;
- int operation;
-{
- struct flock l;
- int rc, op;
-
- if ( operation & LOCK_NB ) {
- op = F_SETLK;
- } else {
- op = F_SETLKW;
- }
-
- if ( operation & LOCK_EX ) {
- l.l_type = F_WRLCK;
- }
-
- if ( operation & LOCK_SH ) {
- l.l_type = F_RDLCK;
- }
-
- if ( operation & LOCK_UN ) {
- l.l_type = F_UNLCK;
- }
-
- l.l_whence = 0;
- l.l_start = 0;
- l.l_len = 0;
-
- if (( rc = fcntl( fd, F_SETLK, &l )) < 0 ) {
- if ( errno == EAGAIN || errno == EACCES ) {
- errno = EWOULDBLOCK;
- }
- }
- return( rc );
-}
-#endif /* !HAVE_FLOCK */