flabel.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
immutable class USER < $REFERENCE, $IS_EQ, $STR
immutable class USER < $REFERENCE, $IS_EQ, $STR is
-- This class provides for manipulation of user identities as
-- provided by an underlying operating system.
-- Version 1.2 Apr 97. Copyright K Hopper,U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 10 Jun 96 kh Original
-- 19 Feb 97 kh Additions for string/char portability.
-- 10 Apr 97 kh Modified for INT to CARD, etc
include NUM_CODE
maxval ->,
minval ->,
build ->,
is_lt -> ; -- meaningless here!
build(
cursor : BIN_CURSOR
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine builds a user from the binary string indicated.
return create(cursor.card)
end ;
user : SAME is
-- This routine returns the user of the executing program as known to
-- the operating system. Where the operating system provides for a program
-- to be run by someone other than the user who started the program
-- execution, it is this user who is returned.
return OPSYS::get_effective_user_id
end ;
real_user : SAME is
-- This routine returns the real user identity who started the
-- execution of the program as known to the operating system.
return OPSYS::get_user_id
end ;
str(
lib : LIBCHARS
) : STR
pre ~void(lib)
post ~void(result)
is
-- This routine returns a string representation of the code used
-- to represent a particular user identity in the given repertoire and
-- encoding.
return card.hex_str(lib)
end ;
str : STR
pre true
post ~void(result)
is
-- This routine returns a string representation of the code used
-- to represent a particular user identity using the default repertoire and
-- encoding.
return str(LIBCHARS::default)
end ;
end ; -- USER
immutable class GROUP < $REFERENCE, $IS_EQ, $STR
immutable class GROUP < $REFERENCE, $IS_EQ, $STR is
-- This class provides for manipulation of user identities as
-- provided by an underlying operating system.
-- Version 1.2 Apr 97. Copyright K Hopper,U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 10 Jun 96 kh Original
-- 19 Feb 97 kh Additions for string/char portability.
-- 10 Apr 97 kh Modified for INT to CARD, etc
include NUM_CODE
maxval ->,
minval ->,
build ->,
is_lt -> ; -- meaningless here!
build(
cursor : BIN_CURSOR
) : SAME
pre ~void(cursor)
and ~cursor.is_done
post true
is
-- This routine builds a group from the binary string indicated.
return create(cursor.card)
end ;
group : SAME is
-- This creation routine returns the group of the executing program
-- as known to the operating system. Where an operating system provides for
-- a program to be run by someone from a group different from that of the
-- user who started the program execution, it is this group which is returned.
return OPSYS::get_effective_project_id
end ;
real_group : SAME is
-- This routine returns the real group identity who started the
-- execution of the program.
return OPSYS::get_project_id
end ;
str(
lib : LIBCHARS
) : STR
pre ~void(lib)
post ~void(result)
is
-- This routine returns a string representation of the code used
-- to represent a particular group identity in the given repertoire and
-- encoding.
return card.hex_str(lib)
end ;
str : STR
pre true
post ~void(result)
is
-- This routine returns a string representation of the code used
-- to represent a particular group identity in the given repertoire and
-- encoding.
return str(LIBCHARS::default)
end ;
end ; -- GROUP
class FILE_LABEL
class FILE_LABEL is
-- Considering that a file consists of a label (indicating various
-- properties which it may have) and also a contents, this class provides
-- access to the label for obtaining property values and, where permitted,
-- for altering them.
-- Version 1.2 Apr 97. Copyright K Hopper,U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 10 Jun 96 kh Original
-- 19 Feb 97 kh Additions for string/char portability.
-- 10 Apr 97 kh Modified for INT to CARD, etc
private const FS_Kind_Length : CARD := FILE_SYS::Kind_Length ;
-- The following constant is used to convert from file system
-- time units to clock time units.
private const Ticks_per_Unit : CARD := OS_TIME::Ticks_per_Second /
OS_FLABEL::Units_per_Second ;
readonly attr name : STR ;
private attr label : OS_FLABEL ;
create(
name : STR
) : SAME is
-- This routine returns the label for the file indicated by a
-- possibly full pathname name. If the name does not exist then
-- void will be returned.
if void(FILE_PATH::create(name)) then
return void
end ;
me : SAME := new ;
me.name := name ;
loc_label : OS_FLABEL := OS_FLABEL::create ;
if ~FILE_SYS::exists(name)
or ~FILE_SYS::get_label(me.name,loc_label.array_ptr) then
-- doesn't exist or no permission
return void
end ;
me.label := loc_label ;
return me
end ;
-- The following routines provide read access to the
-- individual label components.
device_code : NUM_BITS
pre ~void(self)
post (result = label.device_code.code_val)
is
return label.device_code.code_val
end ;
file_code : CARD
pre ~void(self)
post (result = label.file_code.card)
is
return label.file_code.card
end ;
private modes : NUM_BITS -- kind, permissions, etc
pre ~void(self)
post (result = label.mode)
is
return label.mode
end ;
owner : USER
pre ~void(self)
post (result = label.user_id.user)
is
return label.user_id.user
end ;
project : GROUP
pre ~void(self)
post (result = label.group_id.group)
is
return label.group_id.group
end ;
size : CARD
pre ~void(self)
post (result = label.file_size)
is
return label.file_size
end ;
created_at : TIME_STAMP
pre ~void(self)
post ~void(result)
is
-- This routine returns the creation date as a standard time-stamp
-- using an OS dependent conversion routine.
loc_os_time : OS_TIME := OS_TIME::convert(label.created_time,
Ticks_per_Unit) ;
return TIME_STAMP::create(loc_os_time.days,loc_os_time.millisecs) ;
end ;
altered_at : TIME_STAMP
pre ~void(self)
post ~void(result)
is
-- This routine returns the date of latest modification as a standard
-- time-stamp using an OS dependent conversion routine.
loc_os_time : OS_TIME := OS_TIME::convert(label.modify_time,
Ticks_per_Unit) ;
return TIME_STAMP::create(loc_os_time.days,loc_os_time.millisecs)
end ;
used_at : TIME_STAMP
pre ~void(self)
post ~void(result)
is
loc_os_time : OS_TIME := OS_TIME::convert(label.access_time,
Ticks_per_Unit) ;
return TIME_STAMP::create(loc_os_time.days,loc_os_time.millisecs)
end ;
block_size : CARD
pre ~void(self)
post (result = label.block_size)
is
return label.block_size
end ;
allocated : CARD
pre ~void(self)
post (result = label.block_count)
is
return label.block_count
end ;
private const Kind_Shift : CARD := 12 ;
private const Kind_Mask : NUM_BITS := NUM_BITS::create(0x0000F000) ;
kind : FILE_KINDS is
-- This routine returns the file kind indicated on the label.
val : CARD := label.mode.bit_and(Kind_Mask).right(Kind_Shift).card ;
return FILE_SYS::kind(val)
end ;
used_at(
utime : TIME_STAMP,
mtime : TIME_STAMP
)
pre ~void(self)
and (utime >= created_at)
and (mtime >= created_at)
and (utime >= mtime)
post (altered_at = mtime)
and (used_at = utime)
is
-- This routine enables the access and modification times for the file
-- to be set -- provided that the user has permission to do this!
if ~FILE_SYS::set_times(name,utime,mtime) then
SYS_ERROR::create.error(self,SYS_EXCEPT::Access_Error,name)
end ;
label.modify_time(OS_TIME::create_fstime(
mtime.num_days,mtime.num_milliseconds,Ticks_per_Unit)) ;
label.access_time(OS_TIME::create_fstime(
utime.num_days,utime.num_milliseconds,Ticks_per_Unit))
end ;
owner(
who : USER
)
pre ~void(self)
post true -- and changed - if permitted to do so!
is
-- This routine attempts to change ownership of the labelled file to
-- the user 'who'. If this has not been possible then ownership remains
-- the same as before.
if FILE_SYS::change_owner(name,who,label.group_id.group) then
label.user_id(OS_IDENT::create(who))
end
end ;
project(
which : GROUP
)
pre ~void(self)
post true -- and changed - if permitted to do so!
is
-- This procedure attempts to change the group of the labelled file to
-- the group 'which'. If this has not been possible then the group remains
-- the same as before.
if FILE_SYS::change_owner(name,label.user_id.user,which) then
label.group_id(OS_IDENT::create(which))
end
end ;
private const Owner_Mask : NUM_BITS := NUM_BITS::create(0x000001C0) ;
private const Group_Mask : NUM_BITS := NUM_BITS::create(0x00000038) ;
private const World_Mask : NUM_BITS := NUM_BITS::create(0x00000007) ;
owner_access(
val : ACCESS_SET
)
pre ~void(self)
post true
is
-- This routine provides the facility to set the owner access to
-- the labelled file.
new_access : ACCESS_SET := (ACCESS_SET::create(label.mode) *
ACCESS_SET::owner_mask) + val ;
if ~FILE_SYS::change_access(name,new_access) then -- failed!
return
end ;
loc_old : NUM_BITS := label.mode.bit_and(Kind_Mask).bit_or(
label.mode.bit_and(Group_Mask).bit_or(
label.mode.bit_and(World_Mask))) ;
label.mode(loc_old.bit_or(new_access.num_bits))
end ;
owner_access : ACCESS_SET
pre ~void(self)
post (result = ACCESS_SET::create(label.mode) * ACCESS_SET::owner)
is
-- This routine returns the set of permissions held by the owner of
-- the labelled file.
return ACCESS_SET::create(label.mode) * ACCESS_SET::owner
end ;
group_access(
val : ACCESS_SET
)
pre ~void(self)
post true
is
-- This routine provides the facility to set the group access to
-- the labelled file.
new_access : ACCESS_SET := (ACCESS_SET::create(label.mode) *
ACCESS_SET::group_mask) + val ;
if ~FILE_SYS::change_access(name,new_access) then -- failed!
return
end ;
loc_old : NUM_BITS := label.mode.bit_and(Kind_Mask).bit_or(
label.mode.bit_and(Owner_Mask).bit_or(
label.mode.bit_and(World_Mask))) ;
label.mode(loc_old.bit_or(new_access.num_bits))
end ;
group_access : ACCESS_SET
pre ~void(self)
post (result = ACCESS_SET::create(label.mode) * ACCESS_SET::group)
is
-- This routine returns the set of all of the access rights available
-- to the project group.
return ACCESS_SET::create(label.mode) * ACCESS_SET::group
end ;
public_access(
val : ACCESS_SET
)
pre ~void(self)
post true
is
-- This routine provides the facility to set the public access on
-- the file label.
new_access : ACCESS_SET := (ACCESS_SET::create(label.mode) *
ACCESS_SET::world_mask) + val ;
if ~FILE_SYS::change_access(name,new_access) then -- failed!
return
end ;
loc_old : NUM_BITS := label.mode.bit_and(Kind_Mask).bit_or(
label.mode.bit_and(Owner_Mask).bit_or(
label.mode.bit_and(Group_Mask))) ;
label.mode(loc_old.bit_or(new_access.num_bits))
end ;
public_access : ACCESS_SET
pre ~void(self)
post (result = ACCESS_SET::create(label.mode) * ACCESS_SET::world)
is
-- This routine returns the set of access permissions available to anyone.
return ACCESS_SET::create(label.mode) * ACCESS_SET::world
end ;
is_directory : BOOL is
-- This predicate returns true iff the label indicates that this
-- is actually a directory, otherwise false.
return kind = FILE_KINDS::Directory
end ;
is_file : BOOL is
-- This predicate returns true iff the label indicates that this
-- is actually a file, otherwise false.
return kind = FILE_KINDS::Normal
end ;
is_pipe : BOOL is
-- This predicate returns true iff the label indicates that this
-- is actually a named pipe, otherwise false.
return kind = FILE_KINDS::Pipe
end ;
is_device : BOOL is
-- This predicate returns true iff the label indicates that this
-- is one of the device types, otherwise false.
return (kind = FILE_KINDS::Char_Device)
or (kind = FILE_KINDS::Block_Device)
or (kind = FILE_KINDS::Network_Device)
end ;
is_special : BOOL is
-- This predicate returns true iff the label indicates that this
-- is actually a system file, otherwise false.
return kind = FILE_KINDS::System_Special
end ;
end ; -- FILE_LABEL