Index: arladeb.c =================================================================== RCS file: /afs/stacken.kth.se/src/SourceRepository/arla/arlad/arladeb.c,v retrieving revision 1.24 diff -u -w -r1.24 arladeb.c --- arladeb.c 2000/10/02 22:30:28 1.24 +++ arladeb.c 2001/02/03 08:34:04 @@ -193,14 +193,14 @@ { char *s; const char *cellname; - const char *volname; + char volname[VLDB_MAXNAMELEN]; cellname = cell_num2name (fid->Cell); if (cellname == NULL) cellname = ""; - volname = volcache_getname (fid->fid.Volume, fid->Cell); - if (volname == NULL) - volname = ""; + if (volcache_getname (fid->fid.Volume, fid->Cell, + volname, sizeof(volname)) != 0) + strlcpy(volname, "", sizeof(volname)); vasprintf (&s, fmt, args); if (s == NULL) { Index: fcache.c =================================================================== RCS file: /afs/stacken.kth.se/src/SourceRepository/arla/arlad/fcache.c,v retrieving revision 1.315 diff -u -w -r1.315 fcache.c --- fcache.c 2001/01/31 15:32:59 1.315 +++ fcache.c 2001/02/03 08:35:30 @@ -4288,9 +4288,9 @@ if (host_downp(ret)) ret = ENETDOWN; if (ret == 0 && volumename[0] == '\0') { - const char *tmp = volcache_getname (fid.fid.Volume, fid.Cell); - if (tmp != NULL) - strlcpy (volumename, tmp, AFSNAMEMAX); + volumename[0] = '\0'; + volcache_getname (fid.fid.Volume, fid.Cell, + volumename, sizeof(volumename)); } fcache_release (dire); Index: volcache.c =================================================================== RCS file: /afs/stacken.kth.se/src/SourceRepository/arla/arlad/volcache.c,v retrieving revision 1.96 diff -u -w -r1.96 volcache.c --- volcache.c 2001/01/09 02:57:44 1.96 +++ volcache.c 2001/02/03 08:42:41 @@ -43,9 +43,9 @@ */ static char *volsuffixes[] = { -"", -ROSUFFIX, -BACKSUFFIX +"", /* RWVOL */ +".readonly", /* ROVOL */ +".backup" /* BACKVOL */ }; static const char *root_volume_name = "root.afs"; @@ -234,12 +234,11 @@ assert (e->refcount == 0 && e->vol_refs == 0); - for (i = 0; i < MAXTYPES; ++i) { + for (i = 0; i < MAXTYPES; ++i) if (e->num_ptr[i].ptr != NULL) hashtabdel (volidhashtab, &e->num_ptr[i]); - if (e->name_ptr[i].ptr != NULL) - hashtabdel (volnamehashtab, &e->name_ptr[i]); - } + if (e->name_ptr.ptr != NULL) + hashtabdel (volnamehashtab, &e->name_ptr); if (e->parent) { volcache_volfree (e->parent); e->parent = NULL; @@ -336,8 +335,6 @@ n = (struct name_ptr *)hashtabsearch (volnamehashtab, (void *)&key); if (n == NULL) return NULL; - if (type != NULL) - *type = n->type; return n->ptr; } @@ -388,13 +385,15 @@ e->mp_fid = tmp.mp_fid; e->parent_fid = tmp.parent_fid; e->parent = NULL; - for (i = 0; i < MAXTYPES; ++i) { - if (tmp.name_ptr[i].ptr != NULL) { - e->name_ptr[i].cell = tmp.name_ptr[i].cell; - strcpy (e->name_ptr[i].name, tmp.name_ptr[i].name); - e->name_ptr[i].ptr = e; - hashtabadd (volnamehashtab, (void *)&e->name_ptr[i]); + if (tmp.name_ptr.ptr != NULL) { + e->name_ptr.cell = tmp.name_ptr.cell; + strlcpy (e->name_ptr.name, tmp.name_ptr.name, + sizeof(e->name_ptr.name)); + e->name_ptr.ptr = e; + hashtabadd (volnamehashtab, (void *)&e->name_ptr); } + + for (i = 0; i < MAXTYPES; ++i) { if (tmp.num_ptr[i].ptr != NULL) { e->num_ptr[i].cell = tmp.num_ptr[i].cell; e->num_ptr[i].vol = tmp.num_ptr[i].vol; @@ -502,7 +501,6 @@ add_clone (VolCacheEntry *e, int type, int suffix_type) { struct num_ptr *num_ptr = &e->num_ptr[type]; - struct name_ptr *name_ptr = &e->name_ptr[suffix_type]; if (type == suffix_type) { num_ptr->cell = e->cell; @@ -511,13 +509,6 @@ num_ptr->type = type; hashtabadd (volidhashtab, (void *) num_ptr); } - - name_ptr->cell = e->cell; - snprintf (name_ptr->name, VLDB_MAXNAMELEN, - "%s%s", e->entry.name, volsuffixes[suffix_type]); - name_ptr->ptr = e; - name_ptr->type = type; - hashtabadd (volnamehashtab, (void *) name_ptr); } /* @@ -527,6 +518,11 @@ static void add_to_hashtab (VolCacheEntry *e) { + e->name_ptr.cell = e->cell; + strlcpy (e->name_ptr.name, e->entry.name, sizeof(e->name_ptr.name)); + e->name_ptr.ptr = e; + hashtabadd (volnamehashtab, (void *)&e->name_ptr); + if (e->entry.flags & VLF_RWEXISTS) add_clone (e, RWVOL, RWVOL); else @@ -727,53 +723,29 @@ CredCacheEntry *ce) { int error; - int i; - size_t entry_name_len; - int name_matched; error = get_info_loop (e, volname, cell, ce); if (error) return error; - entry_name_len = strlen(e->entry.name); - name_matched = FALSE; - - for (i = 0; i < MAXTYPES; ++i) { - if (strncmp (volname, e->entry.name, entry_name_len) == 0 - && strcmp (volname + entry_name_len, volsuffixes[i]) == 0) { - name_matched = TRUE; - break; - } - } - /* * If the name we looked up is different from the one we got back, * replace that one with the canonical looked up name. Otherwise, * we're not going to be able to find the volume in question. */ - if (!name_matched) { - size_t volname_len = strlen(volname); - + if (strcmp(volname, e->entry.name) != 0) { arla_warnx (ADEBWARN, "get_info: different volnames: %s - %s", volname, e->entry.name); - - for (i = MAXTYPES - 1; i >= 0; --i) - if (strcmp (volname + volname_len - strlen(volsuffixes[i]), - volsuffixes[i]) == 0) { - volname_len -= strlen(volsuffixes[i]); - break; - } - if (volname_len >= sizeof(e->entry.name)) { + if (strlcpy (e->entry.name, volname, + sizeof(e->entry.name)) >= sizeof(e->entry.name)) { arla_warnx (ADEBWARN, "get_info: too long volume (%.*s)", - (int)volname_len, volname); + (int)strlen(volname), volname); return ENAMETOOLONG; } - memmove (e->entry.name, volname, volname_len); - e->entry.name[volname_len] = '\0'; } return get_info_common (e); @@ -839,11 +811,25 @@ VolCacheEntry **e, int *type) { int error = 0; + char real_volname[VLDB_MAXNAMELEN]; + int i; + + strlcpy (real_volname, volname, sizeof(real_volname)); + *type = RWVOL; + + for (i = 0; i < MAXTYPES; ++i) { + char *p = strrchr (real_volname, '.'); + if (p != NULL && strcmp(p, volsuffixes[i]) == 0) { + *p = '\0'; + *type = i; + break; + } + } for(;;) { - *e = getbyname (volname, cell, type); + *e = getbyname (real_volname, cell, type); if (*e == NULL) { - error = add_entry_byname (e, volname, cell, ce); + error = add_entry_byname (e, real_volname, cell, ce); if (error) return error; continue; @@ -856,7 +842,7 @@ } else { VolCacheEntry tmp_ve; - error = get_info_byname (&tmp_ve, volname, cell, ce); + error = get_info_byname (&tmp_ve, real_volname, cell, ce); if (error) { --(*e)->refcount; try_reuse (*e); @@ -1090,18 +1076,21 @@ } /* - * Return a name for a volume (or NULL if it doesn't seem to exist). + * Get a name for a volume in (name, name_sz). + * Return 0 if succesful */ -const char * -volcache_getname (u_int32_t id, int32_t cell) +int +volcache_getname (u_int32_t id, int32_t cell, + char *name, size_t name_sz) { int type; VolCacheEntry *e = getbyid (id, cell, &type); if (e == NULL) - return NULL; - return e->name_ptr[type].name; + return -1; + snprintf (name, name_sz, "%s%s", e->name_ptr.name, volsuffixes[type]); + return 0; } /* Index: volcache.h =================================================================== RCS file: /afs/stacken.kth.se/src/SourceRepository/arla/arlad/volcache.h,v retrieving revision 1.29 diff -u -w -r1.29 volcache.h --- volcache.h 2001/01/09 03:01:00 1.29 +++ volcache.h 2001/02/03 08:27:13 @@ -45,9 +45,6 @@ #include #include "vldb.h" -#define BACKSUFFIX ".backup" -#define ROSUFFIX ".readonly" - /* * index for number into a VolCacheEntry */ @@ -67,7 +64,6 @@ int32_t cell; char name[VLDB_MAXNAMELEN]; struct volcacheentry *ptr; - int32_t type; }; struct volcacheentry { @@ -85,7 +81,7 @@ unsigned validp : 1; unsigned stablep : 1; } flags; - struct name_ptr name_ptr[MAXTYPES]; + struct name_ptr name_ptr; struct num_ptr num_ptr[MAXTYPES]; }; @@ -103,7 +99,7 @@ * current version number of the dump file */ -#define VOLCACHE_VERSION 0x2 +#define VOLCACHE_VERSION 0x3 const char *volcache_get_rootvolume (void); @@ -141,7 +137,7 @@ Bool volcache_reliable (u_int32_t id, int32_t cell); -const char *volcache_getname (u_int32_t id, int32_t cell); +int volcache_getname (u_int32_t id, int32_t cell, char *, size_t); void volcache_status (void);