[Top] [Prev] [Next] [Bottom]


[Contents] [Index]

stat, fstat, fwstat, wstat -
get and put file status

fstat:  fn(fd: ref FD)          : (int, Dir);
fwstat: fn(fd: ref FD;  d: Dir) : int;
stat:   fn(name: string)        : (int, Dir);
wstat:  fn(name: string, d: Dir): int;

Description

stat and fstat

stat:   fn(name: string) :(int, Dir);
fstat:  fn(fd: ref FD) 	:(int, Dir);

## returns (int, Dir). The int member will be zero if call 
is successful, -1 if call fails.
Given a file's name, or an open file descriptor fd, these routines return information about the file into the Dir member of the returned tuple. The int member will be zero for success and -1 for failure.

Example

file := hd tl argv;
(ok, d) := sys->stat(file);
if( ok == -1 ) {
	sys->print("stat failed: %r\n");
	return;
}

wstat (name, d) and fwstat (fd, d)

wstat:  fn(name: string, d: Dir): int;
fwstat: fn(fd: ref FD;  d: Dir) : int;

## returns 0 for success, -1 for failure.
The wstat and fwstat functions apply the file attributes of d to the file. Only certain attributes can be modified. See the section Modifying file attributes. Both functions return zero for success and -1 for failure.

Example

if( sys->wstat(name, d) == -1) 
    	sys->print("wstat failed: %r\n");

The Dir abstract data type

File status is managed via the Dir abstract data type:

Qid: adt 
{   
	path:  int;   
	vers:  int; 
}; 

Dir: adt 
{   
	name:   string;   
	uid:    string;   
	gid:    string;   
	qid:    Qid;   
	mode:   int;   
	atime:  int;   
	mtime:  int;   
	length: int;   
	dtype:  int;   
	dev:    int; 
};
 
length If the file resides on permanent storage and is not a directory, the length returned by stat is the number of bytes in the file. For directories, the length returned is zero. Some devices report a length that is the number of bytes that may be read from the device without blocking.
dtype and dev Each file is the responsibility of some server: it could be a file server, a kernel device, or a user process. The dtype member identifies the server type, and the dev member says which of a group of servers of the same type is responsible for the file.
Qid The Qid abstract data type contains two members: path and vers members, each an integer. The path member is guaranteed to be unique among all path names currently on the file server, and vers changes each time the file is modified. If two files have the same dtype, dev, and qid, they are the same file
mode The bits in mode are defined below.
mtime and atime The two time fields are measured in seconds since the epoch (Jan 1 00:00 1970 GMT). The mtime member is the time of the last change of content. Similarly, the atime member is set whenever the contents are accessed; also, it is set whenever mtime is set.
uid and gid The uid and gid members are the names of the owner and group (of owners) of the file. When an initial attachment is made to a server, the user string in the process group is communicated to the server. Thus, for each file access, the server knows if the process is the owner of the file, or in the group of the file. This determines which sets of three bits in mode to use when checking permissions.

File mode bits
16r80000000 Directory. The Sys module defines this as CHDIR.
8r400 Read permission by owner.
8r200 Write permission by owner.
8r100 Execute permission (search on directory) by owner
8r070 Read, write, execute (search) by group.
8r007 Read, write, execute (search) by others.

Modifying file attributes

Only some of the fields may be changed by wstat calls.
name The name can be changed by anyone with write permission in the parent directory.
mode and mtime The mode and mtime can be changed by the owner or the group leader of the file's current group.
gid The gid can be changed by the owner.

See Also

System Module Overview
dirread - read directory
open, create - open/create a file for reading or writing
stat, wstat - inquire or change file attributes in Chapter 3

Notes

The following behaviors apply when Inferno is hosted on Windows-based systems.

FAT file system (Windows 95 and Windows NT)

The values of uid and gid are Everyone.

Files and directories always have read and execute permission. They cannot be changed. Files without write permission cannot be removed.

NTFS file system (Windows NT)

Permissions for read, write, and execute operate as described above.

The uid attribute is supported.

The gid attribute is interpreted always to mean the special group InfernoGroup, even if the underlying Windows system maintains other groups for the file. Special group Everyone is used to represent `other' for permissions.



[Top] [Prev] [Next] [Bottom]

infernosupport@lucent.com
Copyright © 1997, Lucent Technologies, Inc.. All rights reserved.