Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.unix.wizards Subject: Re: given inode and fs, determine if dir or not? Message-ID: <505@auspex.UUCP> Date: 25 Nov 88 00:27:42 GMT References: <25943@teknowledge-vaxc.ARPA> Reply-To: guy@auspex.UUCP (Guy Harris) Distribution: na Organization: Auspex Systems, Santa Clara Lines: 25 >If I have an inode (and fs root) on hand, how do I tell whether that >inode is a directory or not? The definition of struct inode suggests >that it's possible, but I can't find a man entry that says how. > >If it matters, this would be for SunOS 3.x and Ultrix 2.x It doesn't matter greatly; both those systems use the 4.2BSD file system, but Berkeley pretty much left the part of the inode that comes into play here alone, so the same technique can be used on V7/4.1BSD/S5 file systems. I presume (since you refer to "struct inode") by "inode" you mean "inode structure", either on disk or in core, rather than inumber. If you have an inumber, you have to get the inode structure first.... The "i_mode" field of the inode is laid out the exact same way the "st_mode" field of a "stat" structure is. Even the bits used in that field are the same in most UNIX implementations; you shouldn't, and don't have to, rely on this, however. Just check whether (i_mode & IFMT) == IFDIR (the analogy of checking whether "(st_mode & S_IFMT) == S_IFDIR)" for a "stat" structure).