map.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1989-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Eduardo Krell <ekrell@adexus.cl> *
* *
***********************************************************************/
#pragma prototyped
/*
* 3d mount map support
*/
#include "3d.h"
/*
* visit a mapping and compute its size or copy mapping
*/
int
{
register char* p;
register int z;
register char* v;
register int n;
#if FS
#endif
{
#if FS
case T_MOUNT:
return 0;
break;
#endif
case 0:
/*FALLTHROUGH*/
default:
break;
}
if (p = buf)
{
p += n;
*p++ = ' ';
if (
#if FS
mp ||
#endif
{
*p++ = '/';
*p++ = '#';
#if FS
if (!mp)
#endif
{
*p++ = '/';
if (*v == '/')
*p++ = '#';
}
}
strncpy(p, v, z);
p += z;
#if FS
if (mp)
{
p += sfsprintf(p, 0, "%-*s", mp->physicalsize ? mp->physicalsize : strlen(mp->physical), mp->physical);
}
#endif
*p++ = ' ';
n = p - buf;
}
else
#if FS
+ (mp ? ((mp->channel ? 16 : 0) + (mp->physical ? (mp->physicalsize ? mp->physicalsize : strlen(mp->physical)) : 0) + getattr(mp->attr, NiL)) : 0)
#endif
+ 6;
return n;
}
/*
* dump table mappings into buf
* the mapping size is returned
* if tab==0 then all 3d mappings are processed
* if buf==0 then the size is just computed
*/
int
{
register int n;
register int sum = 0;
register char* p = buf;
{
{
if (p)
*p = 0;
return 1;
}
if (p)
{
p += n;
}
else
n = sizeof(TABLE_PREFIX) - 1;
sum += n;
}
if (!tab)
{
{
if (p)
p += n;
sum += n;
}
}
else
{
if (p)
p += n;
sum += n;
}
if (p)
{
if (p > buf)
{
p--;
p = buf;
else
*(p - 1) = '\n';
}
*p = 0;
}
return sum;
}
#if LICENSED
/*
* check fs license
*/
static int
{
{
{
{
else
}
else
{
}
}
return 0;
}
return 1;
}
#else
#define licensed(p) (1)
#endif
#if FS
/*
* copy attributes into table buf
*/
int
{
register char* a = (char*)attr;
register char* b = buf;
register int c;
if (b)
{
while (c = *b++ = *a++)
if (c == ' ')
*(b - 1) = '/';
return b - buf - 1;
}
return strlen(a);
}
/*
* attributes stored as
*
* (<space>name=value)*
*/
const char*
{
register const char* s;
register const char* v;
register char* a;
register char* x;
register int n;
int k;
int m;
if (s = op)
{
for (;;)
{
if (s >= oe || *s == '/')
return op;
if (*s++ == '=')
{
v = s - 1;
n = v - op;
while (s < oe && *s != '/')
s++;
k = s - v - 1;
m = s - op;
a = attr;
while (*a)
{
a++;
{
{
if (!(x = strchr(a, ' ')))
{
if (a > attr)
a--;
*a = 0;
}
else
while (*a++ = *++x);
}
else
k = 0;
break;
}
if (!(a = strchr(a, ' ')))
break;
}
{
a = attr + k;
*a++ = ' ';
a[m] = 0;
}
if (s++ >= oe)
return 0;
op = s;
}
}
}
return op;
}
#endif
/*
* handle `arg /#<op>'
*/
static int
{
register const char* oe;
const char* ov;
const char* org;
int arglen;
unsigned long x;
#if FS
#endif
{
if (arglen)
{
return -1;
}
return 0;
}
{
return -1;
}
{
return -1;
}
{
return 0;
#if FS
{
{
{
return -1;
}
message((-2, "mount: old fs=%s map=%-*s arg=%-*s op=%-*s", fs->special, map->keysize, map->key, arglen, arg, ov ? (oe - ov) : 6, ov));
{
return -1;
}
}
{
if (arglen)
{
{
return -1;
break;
}
{
message((-2, "mount: new fs=%s map=%-*s arg=%-*s op=%-*s", fs->special, map->keysize, map->key, arglen, arg, ov ? (oe - ov) : 6, ov));
if (ov)
{
{
ov = 0;
}
{
if (opsize)
{
}
else
{
mp->physicalsize = 0;
}
}
}
}
}
{
return -1;
}
}
}
else
#endif
{
if (ov)
{
return -1;
}
else if (arglen)
{
return -1;
}
return -1;
}
break;
}
{
return -1;
}
return 0;
}
/*
* set a single 3d table mapping
* size==0 for volatile args
* from="-" maps to from=""
* to="-" maps to to=""
*/
int
{
register int n;
int x;
{
return -1;
}
if (!fromsize && (!from || !from[0] || from[0] == '-' && !from[1]) || fromsize == 1 && from[0] == '-')
{
fromsize = 0;
}
{
tosize = 0;
}
message((-2, "mount: %-*s %-*s", from == state.null ? 1 : fromsize ? fromsize : strlen(from), from == state.null ? "-" : from, to == state.null ? 1 : tosize ? tosize : strlen(to), to == state.null ? "-" : to));
{
to += 2;
if (tosize)
tosize -= 2;
}
if (!*from)
{
if (!*to)
return 0;
}
if (fromsize)
{
{
/*
* no malloc during initialization
* so we have to believe from and to here
*/
}
}
return 0;
{
return -1;
if (fromsize)
{
fromsize = 0;
}
}
if (!fromsize)
if (!*to)
{
return 0;
}
{
if (old)
{
else
}
else
}
else if (old)
{
/*
* ok if previous mapping matched
*/
return -1;
return 0;
/*
* already have different mapping
*/
return -1;
}
else
{
if (x)
{
return -1;
}
}
return 0;
}
/*
* initialize mappings from space separated pairs in buf
* if readonly!=0 then buf must not be changed after this call
*/
int
{
register char* from;
register char* to;
int fromsize;
int tosize;
#if DEBUG_TABLE
if (!error_info.trace)
#endif
#if DEBUG_TABLE
#endif
if (!readonly)
while (*bp)
{
if (readonly)
{
if (*bp)
bp++;
}
else if (*bp)
*bp++ = 0;
if (readonly)
else if (*bp)
*bp++ = 0;
#if DEBUG_TABLE
{
if (readonly)
else
return -1;
}
{
message((-1, "TABLE state.table.version=%d != TABLE_VERSION=%d", state.table.version, TABLE_VERSION));
return -1;
}
#else
return -1;
#endif
if (*bp)
bp++;
}
return 0;
}