1(* Ulm's Oberon Library 2 Copyright (C) 1989-1994 by University of Ulm, SAI, D-89069 Ulm, Germany 3 ---------------------------------------------------------------------------- 4 Ulm's Oberon Library is free software; you can redistribute it 5 and/or modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either version 7 2 of the License, or (at your option) any later version. 8 9 Ulm's Oberon Library is distributed in the hope that it will be 10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 11 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 ---------------------------------------------------------------------------- 18 E-mail contact: oberon@mathematik.uni-ulm.de 19 ---------------------------------------------------------------------------- 20 $Id: SysStat.om,v 1.3 2000/11/12 13:02:09 borchert Exp $ 21 ---------------------------------------------------------------------------- 22 $Log: SysStat.om,v $ 23 Revision 1.3 2000/11/12 13:02:09 borchert 24 door file type added 25 26 Revision 1.2 2000/11/12 12:48:07 borchert 27 - conversion adapted to Solaris 2.x 28 - Lstat added 29 30 Revision 1.1 1994/02/23 08:00:48 borchert 31 Initial revision 32 33 ---------------------------------------------------------------------------- 34 AFB 9/89 35 ---------------------------------------------------------------------------- 36*) 37 38MODULE ulmSysStat; 39 40 (* examine inode: stat(2) and fstat(2) *) 41 42 IMPORT RelatedEvents := ulmRelatedEvents, Sys := ulmSys, SYS := SYSTEM, uSYS := ulmSYSTEM, SysConversions := ulmSysConversions, SysErrors := ulmSysErrors, 43 SysTypes := ulmSysTypes, Types := ulmTypes; 44 45 CONST 46 (* file mode: 47 bit 0 = 1<<0 bit 31 = 1<<31 48 49 user group other 50 3 1 1111 11 51 1 ... 6 5432 109 876 543 210 52 +--------+------+-----+-----+-----+-----+ 53 | unused | type | sst | rwx | rwx | rwx | 54 +--------+------+-----+-----+-----+-----+ 55 *) 56 57 type* = {12..15}; 58 prot* = {0..8}; 59 60 (* file types; example: (stat.mode * type = dir) *) 61 reg* = {15}; (* regular *) 62 dir* = {14}; (* directory *) 63 chr* = {13}; (* character special *) 64 fifo* = {12}; (* fifo *) 65 blk* = {13..14}; (* block special *) 66 symlink* = {13, 15}; (* symbolic link *) 67 socket* = {14, 15}; (* socket *) 68 69 (* special *) 70 setuid* = 11; (* set user id on execution *) 71 setgid* = 10; (* set group id on execution *) 72 savetext* = 9; (* save swapped text even after use *) 73 74 (* protection *) 75 uread* = 8; (* read permission owner *) 76 uwrite* = 7; (* write permission owner *) 77 uexec* = 6; (* execute/search permission owner *) 78 gread* = 5; (* read permission group *) 79 gwrite* = 4; (* write permission group *) 80 gexec* = 3; (* execute/search permission group *) 81 oread* = 2; (* read permission other *) 82 owrite* = 1; (* write permission other *) 83 oexec* = 0; (* execute/search permission other *) 84 85 (* example for "r-xr-x---": (read + exec) * (owner + group) *) 86 owner* = {uread, uwrite, uexec}; 87 group* = {gread, gwrite, gexec}; 88 other* = {oread, owrite, oexec}; 89 read* = {uread, gread, oread}; 90 write* = {uwrite, gwrite, owrite}; 91 exec* = {uexec, gexec, oexec}; 92 rwx* = prot; 93 94 TYPE 95 StatRec* = RECORD (* result of stat(2) and fstat(2) *) 96 device*: SysTypes.Device; (* ID of device containing a directory entry 97 for this file *) 98 inode*: SysTypes.Inode; (* inode number *) 99 mode*: Types.Set; (* file mode; see mknod(2) *) 100 nlinks*: Types.Int32; (* number of links *) 101 uid*: Types.Int32; (* user id of the file's owner *) 102 gid*: Types.Int32; (* group id of the file's group *) 103 rdev*: SysTypes.Device; (* ID of device. this entry is defined only for 104 character special or block special files *) 105 size*: SysTypes.Offset; (* file size in bytes *) 106 107 (* Blocks and blksize are not available on all platforms. 108 blksize*: Types.Int32; (* preferred blocksize *) 109 blocks*: Types.Int32; (* # of blocks allocated *) 110 *) 111 112 atime*: SysTypes.Time; (* time of last access *) 113 mtime*: SysTypes.Time; (* time of last data modification *) 114 ctime*: SysTypes.Time; (* time of last file status change *) 115 END; 116 117 118 PROCEDURE -Aincludesysstat '#include <sys/stat.h>'; 119 PROCEDURE -Aerrno '#include <errno.h>'; 120 121 PROCEDURE -structstats "struct stat s"; 122 PROCEDURE -statdev(): Types.Int32 "(INT32)s.st_dev"; 123 PROCEDURE -statino(): Types.Int32 "(INT32)s.st_ino"; 124 PROCEDURE -statmode(): Types.Int32 "(INT32)s.st_mode"; 125 PROCEDURE -statnlink(): Types.Int32 "(INT32)s.st_nlink"; 126 PROCEDURE -statuid(): Types.Int32 "(INT32)s.st_uid"; 127 PROCEDURE -statgid(): Types.Int32 "(INT32)s.st_gid"; 128 PROCEDURE -statrdev(): Types.Int32 "(INT32)s.st_rdev"; 129 PROCEDURE -statsize(): Types.Int32 "(INT32)s.st_size"; 130 PROCEDURE -statatime(): Types.Int32 "(INT32)s.st_atime"; 131 PROCEDURE -statmtime(): Types.Int32 "(INT32)s.st_mtime"; 132 PROCEDURE -statctime(): Types.Int32 "(INT32)s.st_ctime"; 133 134 (* Blocks and blksize are not available on all platforms. 135 PROCEDURE -statblksize(): Types.Int32 "(Types.Int32)s.st_blksize"; 136 PROCEDURE -statblocks(): Types.Int32 "(Types.Int32)s.st_blocks"; 137 *) 138 139 PROCEDURE -fstat(fd: Types.Int32): Types.Int32 "fstat(fd, &s)"; 140 PROCEDURE -stat (n: ARRAY OF CHAR): Types.Int32 "stat((char*)n, &s)"; 141 142 PROCEDURE -err(): Types.Int32 "errno"; 143 144 PROCEDURE Stat*(path: ARRAY OF CHAR; VAR buf: StatRec; errors: RelatedEvents.Object): BOOLEAN; 145 BEGIN 146 structstats; 147 IF stat(path) < 0 THEN SysErrors.Raise(errors, err(), Sys.newstat, path); RETURN FALSE END; 148 buf.device := SYS.VAL(SysTypes.Device, statdev()); 149 buf.inode := SYS.VAL(SysTypes.Inode, statino()); 150 buf.mode := SYS.VAL(Types.Set, statmode()); 151 buf.nlinks := statnlink(); 152 buf.uid := statuid(); 153 buf.gid := statgid(); 154 buf.rdev := SYS.VAL(SysTypes.Device, statrdev()); 155 buf.size := SYS.VAL(SysTypes.Offset, statsize()); 156 (* Blocks and blksize are not available on all platforms. 157 buf.blksize := statblksize(); 158 buf.blocks := statblocks(); 159 *) 160 buf.atime := SYS.VAL(SysTypes.Time, statatime()); 161 buf.mtime := SYS.VAL(SysTypes.Time, statmtime()); 162 buf.ctime := SYS.VAL(SysTypes.Time, statctime()); 163 RETURN TRUE; 164 END Stat; 165 166 PROCEDURE Fstat*(fd: SysTypes.File; VAR buf: StatRec; errors: RelatedEvents.Object): BOOLEAN; 167 BEGIN 168 structstats; 169 IF fstat(SYS.VAL(Types.Int32, fd)) < 0 THEN SysErrors.Raise(errors, err(), Sys.newfstat, ""); RETURN FALSE END; 170 buf.device := SYS.VAL(SysTypes.Device, statdev()); 171 buf.inode := SYS.VAL(SysTypes.Inode, statino()); 172 buf.mode := SYS.VAL(Types.Set, statmode()); 173 buf.nlinks := statnlink(); 174 buf.uid := statuid(); 175 buf.gid := statgid(); 176 buf.rdev := SYS.VAL(SysTypes.Device, statrdev()); 177 buf.size := SYS.VAL(SysTypes.Offset, statsize()); 178 (* Blocks and blksize are not available on all platforms. 179 buf.blksize := statblksize(); 180 buf.blocks := statblocks(); 181 *) 182 buf.atime := SYS.VAL(SysTypes.Time, statatime()); 183 buf.mtime := SYS.VAL(SysTypes.Time, statmtime()); 184 buf.ctime := SYS.VAL(SysTypes.Time, statctime()); 185 RETURN TRUE; 186 END Fstat; 187 188 189END ulmSysStat. 190