#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: adutil.c,v 1.17 2014/08/05 08:50:54 hannken Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <sys/buf.h>
#include <fs/adosfs/adosfs.h>
static int CapitalChar(int, int);
int
adosfs_getblktype(struct adosfsmount *amp, struct buf *bp)
{
if (adoscksum(bp, amp->nwords)) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: cksum of blk %" PRId64 " failed\n",
bp->b_blkno / (amp->bsize / DEV_BSIZE));
#endif
return (-1);
}
if (adoswordn(bp, 0) != BPT_SHORT) {
#ifdef DIAGNOSTIC
printf("adosfs: aget: bad primary type blk %" PRId64 " (type = %d)\n",
bp->b_blkno / (amp->bsize / DEV_BSIZE), adoswordn(bp,0));
#endif
return (-1);
}
switch (adoswordn(bp, amp->nwords - 1)) {
case BST_RDIR:
return (AROOT);
case BST_LDIR:
return (ALDIR);
case BST_UDIR:
return (ADIR);
case BST_LFILE:
return (ALFILE);
case BST_FILE:
return (AFILE);
case BST_SLINK:
return (ASLINK);
}
#ifdef DIAGNOSTIC
printf("adosfs: aget: bad secondary type blk %" PRId64 " (type = %d)\n",
bp->b_blkno / (amp->bsize / DEV_BSIZE), adoswordn(bp, amp->nwords - 1));
#endif
return (-1);
}
int
adunixprot(int adprot)
{
if (adprot & 0xc000ee00) {
adprot = (adprot & 0xee0e) >> 1;
return (((adprot & 0x7) << 6) |
((adprot & 0x700) >> 5) |
((adprot & 0x7000) >> 12));
}
else {
adprot = (adprot >> 1) & 0x7;
return((adprot << 6) | (adprot << 3) | adprot);
}
}
static int
CapitalChar(int ch, int inter)
{
if ((ch >= 'a' && ch <= 'z') ||
(inter && ch >= 0xe0 && ch <= 0xfe && ch != 0xf7))
return(ch - ('a' - 'A'));
return(ch);
}
u_int32_t
adoscksum(struct buf *bp, int n)
{
u_int32_t sum, *lp;
lp = (u_int32_t *)bp->b_data;
sum = 0;
while (n--)
sum += ntohl(*lp++);
return(sum);
}
int
adoscaseequ(const u_char *name1, const u_char *name2, int len, int inter)
{
while (len-- > 0)
if (CapitalChar(*name1++, inter) !=
CapitalChar(*name2++, inter))
return 0;
return 1;
}
int
adoshash(const u_char *nam, int namlen, int nelt, int inter)
{
int val;
val = namlen;
while (namlen--)
val = ((val * 13) + CapitalChar(*nam++, inter)) & 0x7ff;
return(val % nelt);
}
#ifdef notyet
int
dstotv(struct datestamp *dsp, struct timeval *tvp)
{
}
int
tvtods(struct timeval *tvp, struct datestamp *dsp)
{
}
#endif
#if BYTE_ORDER != BIG_ENDIAN
u_int32_t
adoswordn(struct buf *bp, int wn)
{
return(ntohl(*((u_int32_t *)bp->b_data + wn)));
}
#endif