119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/*
219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * feature.c --- convert between features and strings
33984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt *
419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * Copyright (C) 1999  Theodore Ts'o <tytso@mit.edu>
53984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt *
68558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall * %Begin-Header%
78558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall * This file may be redistributed under the terms of the GNU Library
88558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall * General Public License, version 2.
98558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall * %End-Header%
1019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project */
1119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include <stdio.h>
1319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include <stdlib.h>
1419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include <string.h>
1519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include <ctype.h>
1619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include <errno.h>
1719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#include "e2p.h"
1919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
2019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstruct hash {
2119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		num;
2219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	const char	*string;
2319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project};
2419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
2519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstatic struct hash hash_list[] = {
2619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	{	EXT2_HASH_LEGACY, 	"legacy" },
2719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	{	EXT2_HASH_HALF_MD4, 	"half_md4" },
2819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	{	EXT2_HASH_TEA, 		"tea" },
2919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	{	0, 0 },
3019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project};
3119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectconst char *e2p_hash2string(int num)
3319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
3419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct hash  *p;
3519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	static char buf[20];
3619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (p = hash_list; p->string; p++) {
3819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (num == p->num)
3919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			return p->string;
4019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
4119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	sprintf(buf, "HASHALG_%d", num);
4219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	return buf;
4319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
4419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
4519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/*
4619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * Returns the hash algorithm, or -1 on error
4719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project */
4819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectint e2p_string2hash(char *string)
4919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project{
5019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	struct hash	*p;
5119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	char		*eptr;
5219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		num;
5319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
5419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	for (p = hash_list; p->string; p++) {
5519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		if (!strcasecmp(string, p->string)) {
5619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			return p->num;
5719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		}
5819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	}
5919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (strncasecmp(string, "HASHALG_", 8))
6019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return -1;
6119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
6219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (string[8] == 0)
6319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return -1;
6419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	num = strtol(string+8, &eptr, 10);
6519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (num > 255 || num < 0)
6619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return -1;
6719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	if (*eptr)
6819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project		return -1;
6919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	return num;
7019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project}
7119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
72