/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* Glenn Fowler25* AT&T Bell Laboratories26*27* return fs type string given stat28*/2930#include <ast.h>31#include <ls.h>32#include <mnt.h>3334#include "FEATURE/fs"3536#if _str_st_fstype3738char*39fmtfs(struct stat* st)40{41return st->st_fstype;42}4344#else4546#include <cdt.h>4748typedef struct Id_s49{50Dtlink_t link;51dev_t id;52char name[1];53} Id_t;5455char*56fmtfs(struct stat* st)57{58register Id_t* ip;59register void* mp;60register Mnt_t* mnt;61register char* s;62struct stat rt;63char* buf;6465static Dt_t* dict;66static Dtdisc_t disc;6768if (!dict)69{70disc.key = offsetof(Id_t, id);71disc.size = sizeof(dev_t);72dict = dtopen(&disc, Dtset);73}74else if (ip = (Id_t*)dtmatch(dict, &st->st_dev))75return ip->name;76s = FS_default;77if (mp = mntopen(NiL, "r"))78{79while ((mnt = mntread(mp)) && (stat(mnt->dir, &rt) || rt.st_dev != st->st_dev));80if (mnt && mnt->type)81s = mnt->type;82}83if (!dict || !(ip = newof(0, Id_t, 1, strlen(s))))84{85if (!mp)86return s;87buf = fmtbuf(strlen(s) + 1);88strcpy(buf, s);89mntclose(mp);90return buf;91}92strcpy(ip->name, s);93if (mp)94mntclose(mp);95dtinsert(dict, ip);96return ip->name;97}9899#endif100101102