#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/queue.h>
#include <sys/utfconv.h>
#include "hfs.h"
+lck_grp_t * encodinglst_lck_grp;
+lck_grp_attr_t * encodinglst_lck_grp_attr;
+lck_attr_t * encodinglst_lck_attr;
+
+
/* hfs encoding converter list */
SLIST_HEAD(encodinglst, hfs_encoding) hfs_encoding_list = {0};
-decl_simple_lock_data(,hfs_encoding_list_slock);
+
+lck_mtx_t encodinglst_mutex;
+
/* hfs encoding converter entry */
#define MAX_HFS_UNICODE_CHARS (15*5)
-int mac_roman_to_unicode(Str31 hfs_str, UniChar *uni_str, UInt32 maxCharLen, UInt32 *usedCharLen);
+int mac_roman_to_unicode(const Str31 hfs_str, UniChar *uni_str, UInt32 maxCharLen, UInt32 *usedCharLen);
static int unicode_to_mac_roman(UniChar *uni_str, UInt32 unicodeChars, Str31 hfs_str);
hfs_converterinit(void)
{
SLIST_INIT(&hfs_encoding_list);
- simple_lock_init(&hfs_encoding_list_slock);
+
+ encodinglst_lck_grp_attr= lck_grp_attr_alloc_init();
+ lck_grp_attr_setstat(encodinglst_lck_grp_attr);
+ encodinglst_lck_grp = lck_grp_alloc_init("cnode_hash", encodinglst_lck_grp_attr);
+
+ encodinglst_lck_attr = lck_attr_alloc_init();
+ //lck_attr_setdebug(encodinglst_lck_attr);
+
+ lck_mtx_init(&encodinglst_mutex, encodinglst_lck_grp, encodinglst_lck_attr);
/*
* add resident MacRoman converter and take a reference
MALLOC(encp, struct hfs_encoding *, sizeof(struct hfs_encoding), M_TEMP, M_WAITOK);
- simple_lock(&hfs_encoding_list_slock);
+ lck_mtx_lock(&encodinglst_mutex);
encp->link.sle_next = NULL;
encp->refcount = 0;
encp->kmod_id = id;
SLIST_INSERT_HEAD(&hfs_encoding_list, encp, link);
- simple_unlock(&hfs_encoding_list_slock);
+ lck_mtx_unlock(&encodinglst_mutex);
return (0);
}
hfs_remconverter(int id, UInt32 encoding)
{
struct hfs_encoding *encp;
- int busy = 0;
- simple_lock(&hfs_encoding_list_slock);
+ lck_mtx_lock(&encodinglst_mutex);
SLIST_FOREACH(encp, &hfs_encoding_list, link) {
if (encp->encoding == encoding && encp->kmod_id == id) {
encp->refcount--;
/* if converter is no longer in use, release it */
if (encp->refcount <= 0 && encp->kmod_id != 0) {
SLIST_REMOVE(&hfs_encoding_list, encp, hfs_encoding, link);
+ lck_mtx_unlock(&encodinglst_mutex);
FREE(encp, M_TEMP);
+ return (0);
} else {
- busy = 1;
+ lck_mtx_unlock(&encodinglst_mutex);
+ return (1); /* busy */
}
break;
}
}
- simple_unlock(&hfs_encoding_list_slock);
+ lck_mtx_unlock(&encodinglst_mutex);
- return (busy);
+ return (0);
}
struct hfs_encoding *encp;
int found = 0;
- simple_lock(&hfs_encoding_list_slock);
+ lck_mtx_lock(&encodinglst_mutex);
SLIST_FOREACH(encp, &hfs_encoding_list, link) {
if (encp->encoding == encoding) {
found = 1;
break;
}
}
- simple_unlock(&hfs_encoding_list_slock);
+ lck_mtx_unlock(&encodinglst_mutex);
if (!found) {
*get_unicode = NULL;
hfs_relconverter(UInt32 encoding)
{
struct hfs_encoding *encp;
- int found = 0;
- simple_lock(&hfs_encoding_list_slock);
+ lck_mtx_lock(&encodinglst_mutex);
SLIST_FOREACH(encp, &hfs_encoding_list, link) {
if (encp->encoding == encoding) {
- found = 1;
encp->refcount--;
/* if converter is no longer in use, release it */
int id = encp->kmod_id;
SLIST_REMOVE(&hfs_encoding_list, encp, hfs_encoding, link);
- FREE(encp, M_TEMP);
- encp = NULL;
-
- simple_unlock(&hfs_encoding_list_slock);
- kmod_destroy(host_priv_self(), id);
- simple_lock(&hfs_encoding_list_slock);
+ lck_mtx_unlock(&encodinglst_mutex);
+
+ FREE(encp, M_TEMP);
+ kmod_destroy((host_priv_t) host_priv_self(), id);
+ return (0);
}
- break;
+ lck_mtx_unlock(&encodinglst_mutex);
+ return (0);
}
}
- simple_unlock(&hfs_encoding_list_slock);
+ lck_mtx_unlock(&encodinglst_mutex);
- return (found ? 0 : EINVAL);
+ return (EINVAL);
}
* Unicode output is fully decomposed
*/
int
-mac_roman_to_unicode(Str31 hfs_str, UniChar *uni_str,
+mac_roman_to_unicode(const Str31 hfs_str, UniChar *uni_str,
UInt32 maxCharLen, UInt32 *unicodeChars)
{
const UInt8 *p;