2 # Copyright (c) 1996, Carnegie Mellon University
5 # See CMUCS/CMU_copyright.pm for use and distribution information
7 package OpenAFS::afsconf;
11 OpenAFS::afsconf - Access to AFS config info
17 $cell = AFS_conf_localcell();
18 $cell = AFS_conf_canoncell($cellname);
19 @servers = AFS_conf_cellservers($cellname);
20 @cells = AFS_conf_listcells();
21 %info = AFS_conf_cacheinfo();
25 This module provides access to information about the local workstation's
26 AFS configuration. This includes information like the name of the
27 local cell, where AFS is mounted, and access to information in the
28 F<CellServDB>. All information returned by this module is based on the
29 configuration files, and does not necessarily reflect changes made
30 on the afsd command line or using B<fs> commands.
34 use OpenAFS::CMU_copyright;
36 use OpenAFS::util qw(:DEFAULT :afs_internal);
42 @EXPORT = qw(&AFS_conf_localcell
49 # _confpath($file) - Return path to a configuration file
53 if ($conf_paths{$file}) {
55 } elsif ($AFS_Parms{confdir} && -r "$AFS_Parms{confdir}/$file") {
56 $conf_paths{$file} = "$AFS_Parms{confdir}/$file";
57 } elsif (-r "$def_ConfDir/$file") {
58 $conf_paths{$file} = "$def_ConfDir/$file";
60 die "Unable to locate $file\n";
64 =head2 AFS_conf_localcell()
66 Return the canonical name of the local cell. This depends on the contents
67 of the F<ThisCell> file in the AFS configuration directory.
71 $AFS_Help{conf_localcell} = '=> $lclcell';
72 sub AFS_conf_localcell {
73 my($path) = _confpath(ThisCell);
76 return '' if (!$path);
77 if (open(THISCELL, $path)) {
78 chomp($result = <THISCELL>);
82 die "Unable to open $path: $!\n";
86 =head2 AFS_conf_canoncell($cellname)
88 Return the canonical name of the specified cell, as found in F<CellServDB>.
89 I<$cellname> may be any unique prefix of a cell name, as with various AFS
90 commands that take cell names as arguments.
92 =head2 AFS_conf_cellservers($cellname)
94 Return a list of servers in the specified cell. As with B<AFS_conf_canoncell>,
95 I<$cellname> may be any unique prefix of a cell name. The resulting list
96 contains server hostnames, as found in F<CellServDB>.
100 $AFS_Help{conf_canoncell} = '$cellname => $canon';
101 $AFS_Help{conf_cellservers} = '$cellname => @servers';
103 sub AFS_conf_canoncell { &_findcell($_[0], 0); }
104 sub AFS_conf_cellservers { &_findcell($_[0], 1); }
107 my($cellname, $doservers) = @_;
108 my($path, $found, @servers, $looking);
110 return $canon_name{$cellname} if (!$doservers && $canon_name{$cellname});
111 $path = _confpath(CellServDB) || die "Unable to locate CellServDB\n";
113 if (open(CELLSERVDB, $path)) {
114 my($cellpat) = $cellname;
115 $cellpat =~ s/(\W)/\\$1/g;
116 while (<CELLSERVDB>) {
117 $looking = 0 if (/^\>/);
121 die "Cell name $cellname is not unique\n";
124 $found =~ s/^\>(\S+).*/$1/;
125 $looking = 1 if ($doservers);
127 } elsif ($looking && (/^[\.\d]+\s*\#\s*(.*\S+)/ || /^([\.\d]+)/)) {
133 $canon_name{$cellname} = $found;
134 $doservers ? @servers : ($found);
136 die "Cell $cellname not in CellServDB\n";
139 die "Unable to open $path: $!\n";
143 =head2 AFS_conf_listcells()
145 Return a list of canonical names (as found in F<CellServDB>) of all
150 $AFS_Help{conf_listcells} = '=> @cells';
151 sub AFS_conf_listcells {
154 $path = _confpath(CellServDB) || die "Unable to locate CellServDB!\n";
156 if (open(CELLSERVDB, $path)) {
157 while (<CELLSERVDB>) {
165 die "Unable to open $path: $!\n";
169 =head2 AFS_conf_cacheinfo()
171 Return a table of information about the local workstation's cache
172 configuration. This table may contain any or all of the following elements:
178 Mount point for the AFS root volume
182 Location of the AFS cache directory
190 Hard limit on AFS cache size (if specified; probably Mach-specific)
194 Name of AFS/NFS translator server (if set)
200 $AFS_Help{conf_cacheinfo} = '=> %info';
201 sub AFS_conf_cacheinfo {
202 my($path) = _confpath('cacheinfo');
203 my(%result, $line, $hcs);
206 if (open(CACHEINFO, $path)) {
207 chop($line = <CACHEINFO>);
209 (@result{'afsroot', 'cachedir', 'cachesize'} , $hcs) = split(/:/, $line);
210 $result{'hardcachesize'} = $hcs if ($hcs);
212 die "Unable to open $path: $!\n";
215 if ($ENV{'AFSSERVER'}) {
216 $result{'translator'} = $ENV{'AFSSERVER'};
217 } elsif (open(SRVFILE, "$ENV{HOME}/.AFSSERVER")
218 || open(SRVFILE, "/.AFSSERVER")) {
219 $result{'translator'} = <SRVFILE>;
230 The CMUCS AFStools, including this module are
231 Copyright (c) 1996, Carnegie Mellon University. All rights reserved.
232 For use and redistribution information, see CMUCS/CMU_copyright.pm