Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: How do I read an inode? Keywords: unix,inodes Message-ID: <3784@auspex.auspex.com> Date: 28 Jul 90 18:51:22 GMT References: <114837@linus.mitre.org> <1990Jul27.010549.2567@athena.mit.edu> Organization: Auspex Systems, Santa Clara Lines: 32 > In particular, the st_mode field of the stat structure tells you >whether it's a character or block special device (S_IFCHR and S_IFBLK on >BSD, I don't know what it is on others), It's the same on others. WARNING: S_IFCHR, S_IFBLK, and the like are *NOT* bit flags (you probably already knew this, but plenty of other folks seem to to); they are bit-field values. Do *not* test whether something is a character special file by doing if (statb.st_mode & S_IFCHR) The correct test in UNIX is if ((statb.st_mode & S_IFMT) == S_IFCHR) or, if you have a POSIX-compliant system, if (S_ISCHR(statb.st_mode)) >and the st_rdev field tells you the major and minor device numbers (the >first two bytes are the major number, and the second two bytes are the >minor number). You must have System V Release 4. :-) S5R4 was going to (and I think it did) expand a "dev_t" to 32 bits; other UNIX systems have 16-bit "dev_t"s - the first two bytes are the *only* two bytes. The upper byte is the major number, and the lower byte is the minor number. The *right* way to get the major and minor device numbers out of a "dev_t" such as "st_rdev" is to use the "major()" and "minor()" macros, found in on some systems and on others. This insulates you from changes like the ones made in S5R4.