1/*
2 * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#include "webdav_utils.h"
25
26/*****************************************************************************/
27/*
28 * Lock a webdavnode
29 */
30__private_extern__ int webdav_lock(struct webdavnode *pt, enum webdavlocktype locktype)
31{
32	if (locktype == WEBDAV_SHARED_LOCK)
33		lck_rw_lock_shared(&pt->pt_rwlock);
34	else
35		lck_rw_lock_exclusive(&pt->pt_rwlock);
36
37	pt->pt_lockState = locktype;
38
39#if 0
40	/* For Debugging... */
41	if (locktype != WEBDAV_SHARED_LOCK) {
42		pt->pt_activation = (void *) current_thread();
43	}
44#endif
45
46	return (0);
47}
48
49/*****************************************************************************/
50/*
51 * Unlock a webdavnode
52 */
53__private_extern__ void webdav_unlock(struct webdavnode *pt)
54{
55	lck_rw_done(&pt->pt_rwlock);
56	pt->pt_lockState = 0;
57}
58
59void timespec_to_webdav_timespec64(struct timespec ts, struct webdav_timespec64 *wts)
60{
61	wts->tv_sec = ts.tv_sec;
62	wts->tv_nsec = ts.tv_nsec;
63}
64
65void webdav_timespec64_to_timespec(struct webdav_timespec64 wts, struct timespec *ts)
66{
67#ifdef __LP64__
68	ts->tv_sec = wts.tv_sec;
69	ts->tv_nsec = wts.tv_nsec;
70#else
71	ts->tv_sec = (uint32_t)wts.tv_sec;
72	ts->tv_nsec = (uint32_t)wts.tv_nsec;
73#endif
74}