#include "lf_hfs_utils.h"
#include "lf_hfs_vfsutils.h"
void *
hashinit(int elements, u_long *hashmask)
{
int hashsize = 0;
LIST_HEAD(generic, generic) *hashtbl;
int i;
if (elements <= 0)
return NULL;
for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
{
continue;
}
hashsize >>= 1;
hashtbl = hfs_malloc(hashsize * sizeof(*hashtbl));
if (hashtbl != NULL)
{
for (i = 0; i < hashsize; i++)
{
LIST_INIT(&hashtbl[i]);
}
*hashmask = hashsize - 1;
}
return (hashtbl);
}
void
hashDeinit(void* pvHashTbl)
{
LIST_HEAD(generic, generic) *hashtbl = pvHashTbl;
hfs_free(hashtbl);
}
time_t
to_bsd_time(u_int32_t hfs_time)
{
u_int32_t gmt = hfs_time;
if (gmt > MAC_GMT_FACTOR)
gmt -= MAC_GMT_FACTOR;
else
gmt = 0;
return (time_t)gmt;
}
u_int32_t
to_hfs_time(time_t bsd_time)
{
u_int32_t hfs_time = (u_int32_t)bsd_time;
if (hfs_time != 0)
hfs_time += MAC_GMT_FACTOR;
return (hfs_time);
}
void
microuptime(struct timeval *tvp)
{
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC, &ts );
TIMESPEC_TO_TIMEVAL(tvp, &ts);
}
void
microtime(struct timeval *tvp)
{
struct timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
TIMESPEC_TO_TIMEVAL(tvp, &ts);
}
void* lf_hfs_utils_allocate_and_copy_string( char *pcName, size_t uLen )
{
if (uLen > kHFSPlusMaxFileNameChars) {
return NULL;
}
if (strlen(pcName) != uLen) {
return NULL;
}
void *pvTmp = hfs_malloc( uLen+1 );
if ( pvTmp == NULL ) {
return NULL;
}
memcpy(pvTmp, pcName, uLen);
char *pcLastChar = pvTmp + uLen;
*pcLastChar = '\0';
return pvTmp;
}
off_t
blk_to_bytes(uint32_t blk, uint32_t blk_size)
{
return (off_t)blk * blk_size; }