10Sstevel@tonic-gate# 2*12388SJohn.Sonnenschein@Sun.COM# Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 30Sstevel@tonic-gate# 4*12388SJohn.Sonnenschein@Sun.COM 50Sstevel@tonic-gate# 60Sstevel@tonic-gate# Sun::Solaris::Exacct::File documentation. 70Sstevel@tonic-gate# 80Sstevel@tonic-gate 90Sstevel@tonic-gate=head1 NAME 100Sstevel@tonic-gate 110Sstevel@tonic-gateSun::Solaris::Exacct::File - exacct file manipulation 120Sstevel@tonic-gate 130Sstevel@tonic-gate=head1 SYNOPSIS 140Sstevel@tonic-gate 150Sstevel@tonic-gate use Sun::Solaris::Exacct::File qw(:ALL); 160Sstevel@tonic-gate my $ea_file = Sun::Solaris::Exacct::File->new($myfile, &O_RDONLY); 170Sstevel@tonic-gate my $ea_obj = $ea_file->get(); 180Sstevel@tonic-gate 190Sstevel@tonic-gateThis module provides access to the C<libexacct(3LIB)> functions that 200Sstevel@tonic-gatemanipulate accounting files. The interface is object-oriented and allows the 210Sstevel@tonic-gatecreation and reading of libexacct files. The C library calls wrapped by this 220Sstevel@tonic-gatemodule are C<ea_open(3EAXACCT)>, C<ea_close(3EAXACCT)>, 230Sstevel@tonic-gateC<ea_next_object(3EAXACCT)>, C<ea_previous_object(3EAXACCT)>, 240Sstevel@tonic-gateC<ea_write_object(3EAXACCT)>, C<ea_get_object(3EAXACCT)>, 250Sstevel@tonic-gateC<ea_get_creator(3EAXACCT)>, and C<ea_get_hostname(3EAXACCT)>. The file read 260Sstevel@tonic-gateand write methods all operate on C<Sun::Solaris::Exacct::Object> objects and 270Sstevel@tonic-gateperform all the necessary memory management, packing, unpacking, and structure 280Sstevel@tonic-gateconversions that are required. 290Sstevel@tonic-gate 300Sstevel@tonic-gate=head2 Constants 310Sstevel@tonic-gate 320Sstevel@tonic-gateC<EO_HEAD>, C<EO_TAIL>, C<EO_NO_VALID_HDR>, C<EO_POSN_MSK>, and 330Sstevel@tonic-gateC<EO_VALIDATE_MSK>. Other constants needed by the C<new()> method below are in 340Sstevel@tonic-gatethe standard Perl C<Fcntl> module. 350Sstevel@tonic-gate 360Sstevel@tonic-gate=head2 Functions 370Sstevel@tonic-gate 380Sstevel@tonic-gateNone. 390Sstevel@tonic-gate 400Sstevel@tonic-gate=head2 Class methods 410Sstevel@tonic-gate 420Sstevel@tonic-gateB<C<< new($name, $oflags, creator => $creator, 430Sstevel@tonic-gate aflags => $aflags, mode => $mode) >>> 440Sstevel@tonic-gate 450Sstevel@tonic-gateThis method opens a libexacct file as specified by the mandatory parameters 460Sstevel@tonic-gateC<$name> and C<$oflags>, and returns a C<Sun::Solaris::Exacct::File> object, 470Sstevel@tonic-gateor C<undef> if an error occurs. The parameters C<$creator>, C<$aflags>, and 480Sstevel@tonic-gateC<$mode> are optional and are passed as C<(name => value)> pairs. The only 490Sstevel@tonic-gatevalid values for C<$oflags> are the combinations of C<O_RDONLY>, C<O_WRONLY>, 500Sstevel@tonic-gateC<O_RDWR>, and C<O_CREAT> described below. 510Sstevel@tonic-gate 520Sstevel@tonic-gateThe C<$creator> parameter is a string describing the creator of the file. If 530Sstevel@tonic-gateit is required (for instance, when writing to a file) but absent, it is set to 540Sstevel@tonic-gatethe string representation of the caller's UID. The C<$aflags> parameter 550Sstevel@tonic-gatedescribes the required positioning in the file for C<O_RDONLY> access: either 560Sstevel@tonic-gateC<EO_HEAD> or C<EO_TAIL> are allowed. If absent, C<EO_HEAD> is assumed. The 570Sstevel@tonic-gateC<$mode> parameter is the file creation mode and is ignored unless C<O_CREAT> 580Sstevel@tonic-gateis specified in C<$oflags>. If C<$mode> is unspecified, the file creation mode 590Sstevel@tonic-gateis set to C<0666> (octal). If an error occurs, it can be retrieved with the 600Sstevel@tonic-gateC<Sun::Solaris::Exacct::ea_error()> function. 610Sstevel@tonic-gate(See C<Sun::Solaris::Exacct(3)>). 620Sstevel@tonic-gate 630Sstevel@tonic-gateB<C< $oflags $aflags Action>> 640Sstevel@tonic-gate 650Sstevel@tonic-gate O_RDONLY Absent or EO_HEAD Open for reading 660Sstevel@tonic-gate at the start of 670Sstevel@tonic-gate the file. 680Sstevel@tonic-gate 690Sstevel@tonic-gate O_RDONLY EO_TAIL Open for reading 700Sstevel@tonic-gate at the end of the 710Sstevel@tonic-gate file. 720Sstevel@tonic-gate 730Sstevel@tonic-gate O_WRONLY Ignored File must exist, 740Sstevel@tonic-gate open for writing 750Sstevel@tonic-gate at the end of the 760Sstevel@tonic-gate file. 770Sstevel@tonic-gate 780Sstevel@tonic-gate O_WRONLY | O_CREAT Ignored Create file if it 790Sstevel@tonic-gate does not exist, 800Sstevel@tonic-gate otherwise truncate 810Sstevel@tonic-gate and open for writing. 820Sstevel@tonic-gate 830Sstevel@tonic-gate O_RDWR Ignored File must exist, 840Sstevel@tonic-gate open for 850Sstevel@tonic-gate reading/writing, 860Sstevel@tonic-gate positioned at the 870Sstevel@tonic-gate end of the file. 880Sstevel@tonic-gate 890Sstevel@tonic-gate O_RDWR | O_CREAT Ignored Create file if it 900Sstevel@tonic-gate does not exist, 910Sstevel@tonic-gate otherwise truncate 920Sstevel@tonic-gate and open for 930Sstevel@tonic-gate reading/writing. 940Sstevel@tonic-gate 950Sstevel@tonic-gate=head2 Object methods 960Sstevel@tonic-gate 970Sstevel@tonic-gateB<Note:> Closing a C<Sun::Solaris::Exacct::File> 980Sstevel@tonic-gate 990Sstevel@tonic-gateThere is no explicit C<close()> method for a C<Sun::Solaris::Exacct::File>. 1000Sstevel@tonic-gateThe file is closed when the file handle object is undefined or reassigned. 1010Sstevel@tonic-gate 1020Sstevel@tonic-gateB<C<creator()>> 1030Sstevel@tonic-gate 1040Sstevel@tonic-gateThis method returns a string containing the creator of the file or C<undef> if 1050Sstevel@tonic-gatethe file does not contain the information. 1060Sstevel@tonic-gate 1070Sstevel@tonic-gateB<C<hostname()>> 1080Sstevel@tonic-gate 1090Sstevel@tonic-gateThis method returns a string containing the hostname on which the file was 1100Sstevel@tonic-gatecreated, or C<undef> if the file does not contain the information. 1110Sstevel@tonic-gate 1120Sstevel@tonic-gateB<C<next()>> 1130Sstevel@tonic-gate 1140Sstevel@tonic-gateThis method reads the header information of the next record in the file. In a 1150Sstevel@tonic-gatescalar context the value of the type field is returned as a dual-typed scalar 1160Sstevel@tonic-gatethat will be one of C<EO_ITEM>, C<EO_GROUP>, or C<EO_NONE>. In a list context 1170Sstevel@tonic-gateit returns a two-element list containing the values of the type and catalog 1180Sstevel@tonic-gatefields. The type element is a dual-typed scalar. The catalog element is 1190Sstevel@tonic-gateblessed into the C<Sun::Solaris::Exacct::Catalog> class. If an error occurs, 1200Sstevel@tonic-gateC<undef> or C<(undef, undef)> is returned depending upon context. The status 1210Sstevel@tonic-gatecan be accessed with the C<Sun::Solaris::Exacct::ea_error()> function. (See 1220Sstevel@tonic-gateC<Sun::Solaris::Exacct(3)>). 1230Sstevel@tonic-gate 1240Sstevel@tonic-gateB<C<previous()>> 1250Sstevel@tonic-gate 1260Sstevel@tonic-gateThis method reads the header information of the previous record in the file. 1270Sstevel@tonic-gateIn a scalar context it returns the type field. In a list context it returns 1280Sstevel@tonic-gatethe two element list containing the values of the type and catalog fields, in 1290Sstevel@tonic-gatethe same manner as the C<next()> method. Error are also returned in the same 1300Sstevel@tonic-gatemanner as the C<next()> method. 1310Sstevel@tonic-gate 1320Sstevel@tonic-gateB<C<get()>> 1330Sstevel@tonic-gate 1340Sstevel@tonic-gateThis method reads in the libexacct record at the current position in the file 1350Sstevel@tonic-gateand returns a C<Sun::Solaris::Exacct::Object> containing the unpacked data 1360Sstevel@tonic-gatefrom the file. This object can then be further manipulated using its methods. 1370Sstevel@tonic-gateIn case of error C<undef> is returned and the error status is made available 1380Sstevel@tonic-gatewith the C<Sun::Solaris::Exacct::ea_error()> function. After this operation, 1390Sstevel@tonic-gatethe position in the file is set to the start of the next record in the file. 1400Sstevel@tonic-gate 1410Sstevel@tonic-gateB<C<write(@ea_obj)>> 1420Sstevel@tonic-gate 1430Sstevel@tonic-gateThis method converts the passed list of C<Sun::Solaris::Exacct::Object>s into 1440Sstevel@tonic-gatelibexacct file format and appends them to the libexacct file, which must be 1450Sstevel@tonic-gateopen for writing. This method returns C<true> if successful and C<false> 1460Sstevel@tonic-gateotherwise. On failure the error can be examined with the 1470Sstevel@tonic-gateC<Sun::Solaris::Exacct::ea_error()> function. 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate=head2 Exports 1500Sstevel@tonic-gate 1510Sstevel@tonic-gateBy default nothing is exported from this module. The following tags can be 1520Sstevel@tonic-gateused to selectively import constants defined in this module: 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate :CONSTANTS EO_HEAD, EO_TAIL, EO_NO_VALID_HDR, EO_POSN_MSK, and 1550Sstevel@tonic-gate EO_VALIDATE_MSK 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate :ALL :CONSTANTS, Fcntl(:DEFAULT). 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate=head1 ATTRIBUTES 1600Sstevel@tonic-gate 1610Sstevel@tonic-gateSee C<attributes(5)> for descriptions of the following attributes: 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate ___________________________________________________________ 1640Sstevel@tonic-gate | ATTRIBUTE TYPE | ATTRIBUTE VALUE | 1650Sstevel@tonic-gate |_____________________________|_____________________________| 1660Sstevel@tonic-gate | Availability | SUNWpl5u | 1670Sstevel@tonic-gate |_____________________________|_____________________________| 1680Sstevel@tonic-gate | Interface Stability | CPAN (http://www.cpan.org) | 1690Sstevel@tonic-gate |_____________________________|_____________________________| 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate=head1 SEE ALSO 1720Sstevel@tonic-gate 1730Sstevel@tonic-gateC<ea_close(3EXACCT)>, C<ea_get_creator(3EXACCT)>, C<ea_get_hostname(3EXACCT)>, 1740Sstevel@tonic-gateC<ea_get_object(3EXACCT)>, C<ea_next_object(3EXACCT)>, C<ea_open(3EXACCT)>, 1750Sstevel@tonic-gateC<ea_previous_object(3EXACCT)>, C<ea_write_object(3EXACCT)>, 1760Sstevel@tonic-gateC<Sun::Solaris::Exacct(3)>, C<Sun::Solaris::Exacct::Catalog(3)>, 1770Sstevel@tonic-gateC<Sun::Solaris::Exacct::Object(3)>, C<Sun::Solaris::Exacct::Object::Group(3)>, 1780Sstevel@tonic-gateC<Sun::Solaris::Exacct::Object::Item(3)>, C<libexacct(3LIB)>, C<attributes(5)> 179