2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Implementation of the volume operations used by the AFS user
16 * --------------------- Required definitions ---------------------
18 #include <afs/param.h>
19 #include <afsconfig.h>
23 #include "uss_vol.h" /*Interface to this module*/
24 #include "uss_common.h" /*Common definitions*/
25 #include "uss_procs.h" /*Defs from procs module*/
26 #include "uss_fs.h" /*CacheManager ops*/
30 #include <sys/errno.h>
31 #include <afs/vlserver.h>
33 #include <afs/cellconfig.h>
35 #include <rx/rx_globals.h>
36 #include <afs/volser.h>
37 #include <afs/volint.h>
42 extern struct rx_connection *UV_Bind();
43 extern struct rx_securityClass *rxnull_NewClientSecurityObject();
45 extern int VL_GetEntryByID();
46 extern char *hostutil_GetNameByINet();
50 * ---------------------- Private definitions ---------------------
53 #undef USS_VOL_DB_SHOW_OVERRIDES
57 * --------------------- Exported definitions ---------------------
60 * The Volume Server interface imports the Ubik connection
61 * structure to use, expecting it to be named "cstruct". This
62 * is why we have two names here. Thus, the UV_CreateVolume()
63 * will work and we can avoid nasty little core dumps.
65 struct ubik_client *uconn_vldbP; /*Ubik connection struct*/
66 struct ubik_client *cstruct; /*Required name for above*/
69 * ------------------------ Private globals -----------------------
71 static int initDone = 0; /*Module initialized?*/
72 static int NoAuthFlag = 0; /*Use -noauth?*/
73 static struct rx_connection
74 *serverconns[VLDB_MAXSERVERS]; /*Connection(s) to VLDB
78 /*-----------------------------------------------------------------------
79 * static InitThisModule
82 * Set up this module, namely set up all the client state for
83 * dealing with the Volume Location Server(s), including
84 * network connections.
87 * a_noAuthFlag : Do we need authentication?
88 * a_confDir : Configuration directory to use.
89 * a_cellName : Cell we want to talk to.
92 * 0 if everything went fine, or
93 * lower-level error code otherwise.
96 * This routine will only be called once.
100 *------------------------------------------------------------------------*/
102 static afs_int32 InitThisModule(a_noAuthFlag, a_confDir, a_cellName)
109 static char rn[] = "uss_vol:InitThisModule";
110 register afs_int32 code; /*Return code*/
111 struct afsconf_dir *tdir; /*Ptr to conf dir info*/
112 struct afsconf_cell info; /*Info about chosen cell*/
113 struct ktc_principal sname; /*Service name*/
114 struct ktc_token ttoken; /*Service ticket*/
115 afs_int32 scIndex; /*Chosen security index*/
116 struct rx_securityClass *sc; /*Generated security object*/
117 afs_int32 i; /*Loop index*/
120 * Only once, guys, will 'ya?
124 printf("[%s] Called multiple times!\n", rn);
125 #endif /* USS_VOL_DB */
130 * Set up our Rx environment.
133 printf("[%s] Initializing Rx environment\n", rn);
134 #endif /* USS_VOL_DB */
137 fprintf(stderr,"%s: Couldn't initialize Rx.\n", uss_whoami);
140 rx_SetRxDeadTime(50);
143 * Find out all about our configuration.
146 printf("[%s] Handling configuration info\n", rn);
147 #endif /* USS_VOL_DB */
148 tdir = afsconf_Open(a_confDir);
150 fprintf(stderr, "%s: Couldn't open configuration directory (%s).\n",
151 uss_whoami, a_confDir);
154 code = afsconf_GetCellInfo(tdir, a_cellName, AFSCONF_VLDBSERVICE, &info);
156 printf("%s: Can't find VLDB server(s) for cell %s\n",
157 uss_whoami, a_cellName);
162 printf("[%s] Getting tickets if needed\n", rn);
163 #endif /* USS_VOL_DB */
166 * We don't need tickets for unauthenticated connections.
168 strcpy(sname.cell, info.name);
169 sname.instance[0] = 0;
170 strcpy(sname.name, "afs");
171 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
174 "%s: Couldn't get AFS tokens, running unauthenticated.\n",
180 * We got a ticket, go for an authenticated connection.
182 if (ttoken.kvno >= 0 && ttoken.kvno <= 255)
183 scIndex = 2; /*Kerberos*/
185 fprintf(stderr, "%s: Funny kvno (%d) in ticket, proceeding\n",
186 uss_whoami, ttoken.kvno);
190 } /*Authentication desired*/
195 * Generate the appropriate security object for the connection.
198 printf("[%s] Generating Rx security object\n", rn);
199 #endif /* USS_VOL_DB */
202 sc = (struct rx_securityClass *)
203 rxnull_NewClientSecurityObject();
210 sc = (struct rx_securityClass *)
211 rxkad_NewClientSecurityObject(rxkad_clear,
220 * Tell UV module about default authentication.
223 printf("[%s] Setting UV security: obj 0x%x, index %d\n",
225 #endif /* USS_VOL_DB */
226 UV_SetSecurity(sc, scIndex);
227 if (info.numServers > VLDB_MAXSERVERS) {
228 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
229 uss_whoami, info.numServers, VLDB_MAXSERVERS);
234 * Connect to each VLDB server for the chosen cell.
236 for (i = 0; i < info.numServers; i++) {
238 printf("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n",
239 rn, info.hostAddr[i].sin_addr.s_addr,
240 info.hostAddr[i].sin_port,
242 #endif /* USS_VOL_DB */
243 serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
244 info.hostAddr[i].sin_port,
251 * Set up to execute Ubik transactions on the VLDB.
254 printf("[%s] Initializing Ubik interface\n", rn);
255 #endif /* USS_VOL_DB */
256 code = ubik_ClientInit(serverconns, &uconn_vldbP);
258 fprintf(stderr, "%s: Ubik client init failed.\n", uss_whoami);
262 printf("[%s] VLDB ubik connection structure at 0x%x\n",
264 #endif /* USS_VOL_DB */
267 * Place the ubik VLDB connection structure in its advertised
270 cstruct = uconn_vldbP;
281 /*-----------------------------------------------------------------------
282 * static HostIDToHostName
285 * Given a host ID (in network byte order), figure out the
286 * corresponding host name.
289 * a_hostID : Host ID in network byte order.
290 * a_hostName : Ptr to host name buffer.
296 * This routine simply calls the hostutil_GetNameByINet()
297 * function exported by the utility library (util.a).
301 *------------------------------------------------------------------------*/
303 char *hostutil_GetNameByINet();
305 static void HostIDToHostName(a_hostID, a_hostName)
309 { /*HostIDToHostName*/
311 strcpy(a_hostName, hostutil_GetNameByINet(a_hostID));
313 } /*HostIDToHostName*/
316 /*-----------------------------------------------------------------------
317 * static PartIDToPartName
320 * Given a partition ID (in network byte order), figure out the
321 * corresponding partition name.
324 * a_partID : Partition ID in network byte order.
325 * a_partName : Ptr to partition name buffer.
328 * 0 if everything went well, or
329 * -1 if the given partition ID couldn't be translated.
332 * Nothing interesting.
336 *------------------------------------------------------------------------*/
338 static afs_int32 PartIDToPartName(a_partID, a_partName)
342 { /*PartIDToPartName*/
344 static char rn[] = "PartIDToPartName";
347 printf("[%s] Translating partition id %d to its name\n",
349 #endif /* USS_VOL_DB */
351 if ((a_partID < 0) || (a_partID > VOLMAXPARTS))
355 strcpy(a_partName,"/vicep");
356 a_partName[6] = a_partID + 'a';
357 a_partName[7] = '\0';
359 strcpy(a_partName,"/vicep");
361 a_partName[6] = 'a' + (a_partID/26);
362 a_partName[7] = 'a' + (a_partID%26);
363 a_partName[8] = '\0';
367 printf("[%s] Translation for part ID %d is '%s'\n",
368 rn, a_partID, a_partName);
369 #endif /* USS_VOL_DB */
372 } /*PartIDToPartName*/
375 /*------------------------------------------------------------------------
376 * EXPORTED uss_Vol_GetServer
379 * Nothing interesting.
383 *------------------------------------------------------------------------*/
385 afs_int32 uss_vol_GetServer(a_name)
388 { /*uss_vol_GetServer*/
390 register struct hostent *th;
393 register afs_int32 code;
395 code = sscanf(a_name, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
398 * Parsed as 128.2.9.4, or similar; return it in network
399 * byte order (128 in byte 0).
401 addr = (((afs_int32)b1)<<24) | (((afs_int32)b2)<<16) | (((afs_int32)b3)<<8) | (afs_int32)b4;
405 th = gethostbyname(a_name);
408 bcopy(th->h_addr, &addr, sizeof(addr));
411 } /*uss_vol_GetServer*/
413 /*------------------------------------------------------------------------
414 * static GetVolumeType
417 * Translate the given char string representing a volume type to the
418 * numeric representation.
421 * a_type : Char string volume type.
424 * One of ROVOL, RWVOL, BACKVOL, or -1 on failure.
427 * Nothing interesting.
431 *------------------------------------------------------------------------*/
433 static afs_int32 GetVolumeType(a_type)
438 if(!strcmp(a_type,"ro"))
441 if(!strcmp(a_type, "rw"))
444 if(!strcmp(a_type,"bk"))
452 /*------------------------------------------------------------------------
453 * EXPORTED uss_Vol_GetPartitionID
456 * It is assumed that partition names may begin with ``/vicep''.
460 *------------------------------------------------------------------------*/
462 afs_int32 uss_vol_GetPartitionID(a_name)
465 { /*uss_vol_GetPartitionID*/
475 * Numbers go straight through.
477 if (tc >= '0' && tc <= '9') {
478 return(atoi(a_name));
482 * Otherwise, check for vicepa or /vicepa, or just plain "a"
485 if (strlen(a_name) <= 2) {
486 strcpy(ascii, a_name);
487 } else if (!strncmp(a_name, "/vicep", 6)) {
488 strncpy(ascii, a_name+6, 2);
490 else if (!strncmp(a_name, "vicep", 5)) {
491 strncpy(ascii, a_name+5, 2);
497 * Now, partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
498 * .../vicepzz, and are numbered from 0. Do the appropriate conversion.
502 * Single-char name, 0..25
504 if (ascii[0] < 'a' || ascii[0] > 'z')
505 return(-1); /* wrongo */
506 return(ascii[0] - 'a');
510 * Two-char name, 26 .. <whatever>
512 if (ascii[0] < 'a' || ascii[0] > 'z')
514 if (ascii[1] < 'a' || ascii[1] > 'z')
516 return((ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26);
518 } /*uss_vol_GetPartitionID*/
521 /*-----------------------------------------------------------------------
522 * static CheckDoubleMount
525 * Make sure we're not trying to mount a volume in the same place
529 * a_mp : Mountpoint pathname to check.
530 * a_oldmp : Ptr to buffer into which the old value of the
531 * mountpoint is placed (if any).
534 * 0 if the volume was not previously mounted.
535 * uss_procs_ANCIENT if there was already a mountpoint AND the
536 * user was already recorded in the password
538 * uss_procs_YOUNG if there was a mountpoint for the user taken
539 * from the directory pool, yet the user was not
540 * yet in the password file.
543 * Nothing interesting.
546 * May fill in the a_oldmp buffer with the value of the old
548 *------------------------------------------------------------------------*/
550 static int CheckDoubleMount(a_mp, a_oldmp)
554 { /*CheckDoubleMount*/
556 static char rn[] = "uss_vol:CheckDoubleMount";
557 int start, len, mlen, tlen;
562 pws = getpwuid(atoi(uss_Uid));
563 if (pws != (struct passwd *)0) {
565 * User exists in the password file, so they've been fully
566 * created and integrated. Return the ``ancient'' mountpoint.
568 strcpy(a_oldmp, pws->pw_dir);
569 return(uss_procs_ANCIENT);
574 * $AUTO used. Search among the possible directories.
576 len = strlen(uss_Auto);
578 while(strncmp(&a_mp[i], uss_Auto, len)) {
579 a_oldmp[i] = a_mp[i];
580 if (++i > (mlen - len)) {
585 if ((start = i) != -1) {
587 * $AUTO used in mountpoint.
589 for (i = 0; i < uss_NumGroups; i++) {
591 * Copy in the base and tail components.
593 tlen = strlen(uss_DirPool[i]);
594 strncpy(&a_oldmp[start], uss_DirPool[i], tlen);
595 strcpy(&a_oldmp[start+tlen], &a_mp[start+len]);
597 printf("%s: Checking '%s' for mount point\n",
599 #endif /* USS_VOL_DB */
600 if(lstat(a_oldmp, &stbuf) == 0) /*mp exists*/
601 if (strcmp(a_oldmp, a_mp)) /* and is different */
603 * The old mount point exists and is different
604 * from the current one, so return the fact
605 * that we have a ``young'' mountpoint.
607 return(uss_procs_YOUNG);
608 } /*Check each $AUTO directory*/
610 } /*$AUTO has been used*/
613 * No luck finding the old mount point, so we just return that
614 * this is the first time we've seen this volume.
618 } /*CheckDoubleMount*/
621 /*------------------------------------------------------------------------
622 * EXPORTED uss_vol_CreateVol
625 * Called from the code generated by the uss grammar.
629 *------------------------------------------------------------------------*/
631 afs_int32 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint, a_owner, a_acl)
640 { /*uss_vol_CreateVol*/
643 "uss_vol_CreateVol"; /*Routine name*/
644 afs_int32 pname; /*Partition name*/
645 afs_int32 volid, code; /*Volume ID, return code*/
646 afs_int32 saddr; /*Socket info for server*/
647 int VolExistFlag = 0; /*Does the volume exist?*/
648 int mpExistFlag = 0; /*Does the mountpoint exist?*/
649 char *Oldmpoint = NULL; /*Old mountpoint name, if any*/
650 char tmp_str[uss_MAX_SIZE]; /*Useful string buffer*/
651 int o; /*Owner's user id*/
652 char userinput[64]; /*User's input*/
653 struct uss_subdir *new_dir; /*Used to remember original ACL*/
656 * Don't do anything if there's already a problem.
662 fprintf(stderr, "%s:uss_vol_CreateVol params:\n", rn);
663 fprintf(stderr, "%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
664 rn, a_volname, a_server, a_partition, a_quota, a_mpoint,
666 #endif /* USS_VOL_DB */
669 * All of the parameters passed in are taken from the template
670 * file. Override these values if the user has explicitly set
671 * them, namely if the uss commons have non-null strings.
673 if (uss_Server[0] != '\0') {
674 #ifdef USS_VOL_DB_SHOW_OVERRIDES
677 "%s: Overriding server field: template value is '%s', overridden to '%s'\n",
678 rn, a_server, uss_Server);
679 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
680 a_server = uss_Server;
683 if (uss_Partition[0] != '\0') {
684 #ifdef USS_VOL_DB_SHOW_OVERRIDES
686 fprintf(stderr, "%s: Overriding partition field: template value is '%s', overridden to '%s'\n",
687 rn, a_partition, uss_Partition);
688 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
689 a_partition = uss_Partition;
692 if (uss_MountPoint[0] != '\0') {
693 #ifdef USS_VOL_DB_SHOW_OVERRIDES
695 fprintf(stderr, "%s: overriding mountpoint field: template value is '%s', overridden to '%s'\n",
696 rn, a_mpoint, uss_MountPoint);
697 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
698 a_mpoint = uss_MountPoint;
701 #ifdef USS_VOL_DB_SHOW_OVERRIDES
702 printf("%s: Params after overrides:\n", uss_whoami);
703 printf("%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
704 uss_whoami, a_volname, a_server, a_partition, a_quota,
705 a_mpoint, a_owner, a_acl);
706 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
710 "Creating volume '%s' on server '%s', partition '%s'\n",
711 a_volname, a_server, a_partition);
713 saddr = uss_vol_GetServer(a_server);
715 uss_procs_PrintErr(line,
716 "File server '%s' not found in config info\n",
720 pname = uss_vol_GetPartitionID(a_partition);
722 uss_procs_PrintErr(line,
723 "Couldn't interpret partition name '%s'\n",
729 * Make sure our VLDB connection(s) is/are set up before actually
730 * trying to perform a volume creation creation.
733 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
735 com_err(uss_whoami, code,
736 "while inititializing VLDB connection(s)\n");
739 } /*Initialize VLDB connection(s)*/
743 printf("%s: Creating volume on srv 0x%x, part %d, vol name '%s'\n",
744 rn, saddr, pname, a_volname);
745 #endif /* USS_VOL_DB */
746 code = UV_CreateVolume(saddr, pname, a_volname, &volid);
748 if (code == VL_NAMEEXIST){
751 "%s: Warning; Volume '%s' exists, using existing one.\n",
752 uss_whoami, a_volname);
755 * We should get the volid here if we want to use it, but
756 * we don't need it right now. What we DO need, though, is
757 * to ask our caller if it's OK to overwrite the user's files
758 * if they're pre-existing.
760 if (!uss_OverwriteThisOne) {
761 printf("Overwrite files in pre-existing '%s' volume? [y, n]: ",
763 scanf("%s", userinput);
764 if ((userinput[0] == 'y') || (userinput[0] == 'Y')) {
765 printf("\t[Overwriting allowed]\n");
766 uss_OverwriteThisOne = 1;
769 printf("\t[Overwriting not permitted]\n");
770 } /*Overwriting not previously allowed*/
771 } /*Volume already existed*/
773 uss_procs_PrintErr(line,
774 "Couldn't create volume '%s' [error %d]: %s\n",
775 a_volname, code, sys_errlist[errno]);
777 } /*Failure was NOT because it already existed*/
778 } /*UV_CreateVolume failed*/
782 "\t[Dry run: Creating volume '%s' on '%s', partition '%s']\n",
783 a_volname, a_server, a_partition);
786 /* OK, we want to make sure we don't double-mount the volume.
787 * If the volume existed, it can be the case that it is
788 * already mounted somewhere else (because of $AUTO or others).
789 * Let's check for that. Note: we never enter this portion of
790 * the code if we're doing a dry run.
793 if ((Oldmpoint = (char *) malloc(strlen(a_mpoint)+50)) == NULL){
794 fprintf(stderr, "%s: No more memory!\n", uss_whoami);
798 mpExistFlag = CheckDoubleMount(a_mpoint, Oldmpoint);
799 if(mpExistFlag == uss_procs_ANCIENT) {
801 "%s:\t*** WARNING ***; This user (%s) is already in passwd file (or equivalent). IGNORED.\n", uss_whoami, uss_User);
803 uss_syntax_err = 1; /*I know, I know, it's not a SYNTAX error*/
807 if (mpExistFlag == uss_procs_YOUNG) {
809 "%s: Warning; Volume '%s' is already mounted on %s. Using the existing one.\n",
810 uss_whoami, a_volname, Oldmpoint);
811 a_mpoint = Oldmpoint;
815 if (mpExistFlag == 0) {
816 extern int local_Cell;
821 sprintf(tmp_str, "#%s.", a_volname);
823 sprintf(tmp_str, "#%s:%s.", uss_Cell, a_volname);
825 if (symlink(tmp_str, a_mpoint)) {
826 if (errno == EEXIST) {
828 "%s: Warning: Mount point '%s' already exists.\n",
829 uss_whoami, a_mpoint);
832 fprintf(stderr,"%s: Can't mount volume '%s' on '%s': %s\n",
833 uss_whoami, a_volname, a_mpoint, sys_errlist[errno]);
837 } /*There was already something mounted there*/
841 fprintf(stderr, "\t[Dry run: Mounting '%s' at '%s']\n",
844 } /*Mount point didn't already exist*/
847 * Set the volume disk quota.
850 if (code = uss_acl_SetDiskQuota(a_mpoint, atoi(a_quota)))
855 "\t[Dry run: Setting disk quota for '%s' to %s blocks]\n",
859 /*Copy mpoint into $MTPT for others to use*/
860 strcpy(uss_MountPoint, a_mpoint);
862 o = uss_procs_GetOwner(a_owner);
864 if (chown(a_mpoint, o, -1)) {
866 "%s: Can't chown() mountpoint '%s' to owner '%s' (uid %d): %s\n",
867 uss_whoami, a_mpoint, a_owner, o, sys_errlist[errno]);
875 "\t[Dry run: chown() mountpoint '%s' to be owned by user]\n",
880 * Set the ACL on the user's home directory so that, for the duration of
881 * the account creation, only the uss_AccountCreator has any rights on the
882 * files therein. Make sure to clear this ACL to remove anyone that might
883 * already be there due to volume creation defaults. We will set this ACL
884 * properly, as well as all ACLs of future subdirectories,as the very last
885 * thing we do to the new account.
887 new_dir = (struct uss_subdir *) malloc(sizeof(struct uss_subdir));
888 new_dir->previous = uss_currentDir;
889 new_dir->path = (char *) malloc(strlen(a_mpoint)+1);
890 strcpy(new_dir->path, a_mpoint);
891 new_dir->finalACL = (char *) malloc(strlen(a_acl)+1);
892 strcpy(new_dir->finalACL, a_acl);
893 uss_currentDir = new_dir;
894 sprintf(tmp_str, "%s %s all", a_mpoint, uss_AccountCreator);
901 fprintf(stderr, "Setting ACL: '%s'\n",
903 if (uss_acl_SetAccess(tmp_str, 1, 0))
907 fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s)]\n", tmp_str);
910 } /*uss_vol_CreateVol*/
913 /*------------------------------------------------------------------------
914 * EXPORTED uss_vol_DeleteVol
917 * Nothing interesting.
921 *------------------------------------------------------------------------*/
923 afs_int32 uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName, a_partID)
931 { /*uss_vol_DeleteVol*/
933 static char rn[] = "uss_vol_DeleteVol"; /*Routine name*/
934 register afs_int32 code; /*Return code*/
937 * Make sure we've initialized our VLDB connection(s) before
941 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
948 * Go for the deletion.
951 printf("%s: Deleting volume '%s' (ID %d) on FileServer '%s' (0x%x), partition '%s' (%d)\n",
952 rn, a_volName, a_volID, a_servName, a_servID,
953 a_partName, a_partID);
954 #endif /* USS_VOL_DB */
956 code = UV_DeleteVolume(a_servID, a_partID, a_volID);
958 printf("%s: Can't delete volume '%s'\n",
959 uss_whoami, a_volName);
961 printf("\t[Dry run - volume '%s' NOT removed]\n", a_volName);
965 } /*uss_vol_DeleteVol*/
968 /*------------------------------------------------------------------------
969 * static GetServerAndPart
972 * Given a VLDB entry, return the server and partition IDs for
973 * the read/write volume.
976 * a_vldbEntryP : Ptr to VLDB entry.
977 * a_servIDP : Ptr to server ID to set.
978 * a_partIDP : Ptr to partition ID to set.
981 * 0 if everything went well, or
985 * Nothing interesting.
989 *------------------------------------------------------------------------*/
991 static afs_int32 GetServerAndPart(a_vldbEntryP, a_servIDP, a_partIDP)
992 struct vldbentry *a_vldbEntryP;
993 afs_int32 *a_servIDP;
994 afs_int32 *a_partIDP;
996 { /*GetServerAndPart*/
999 * It really looks like all we need to do is pull off the
1000 * first entry's info.
1002 *a_servIDP = a_vldbEntryP->serverNumber[0];
1003 *a_partIDP = a_vldbEntryP->serverPartition[0];
1006 } /*GetServerAndPart*/
1009 /*------------------------------------------------------------------------
1010 * EXPORTED uss_vol_GetVolInfoFromMountPoint
1013 * If the mountpoint path provided is not
1017 *------------------------------------------------------------------------*/
1019 afs_int32 uss_vol_GetVolInfoFromMountPoint(a_mountpoint)
1022 { /*uss_vol_GetVolInfoFromMountPoint*/
1024 static char rn[] = "uss_vol_GetVolInfoFromMountPoint";
1025 register afs_int32 code; /*Return code*/
1026 uss_VolumeStatus_t *statusP; /*Ptr to returned status*/
1027 afs_int32 volID; /*Volume ID*/
1028 struct vldbentry vldbEntry; /*VLDB entry for volume*/
1029 afs_int32 serverID; /*Addr of host FileServer*/
1030 afs_int32 partID; /*Volume's partition ID*/
1033 * Set up to ask the CacheManager to give us all the info
1034 * it has about the given mountpoint.
1036 code = uss_fs_GetVolStat(a_mountpoint,
1040 printf("[%s] Result of uss_fs_GetVolStat: code = %d, errno = %d\n",
1042 #endif /* USS_VOL_DB */
1044 if (errno == EINVAL ||
1048 * We were given a mountpoint pathname that doesn't
1049 * point to a volume, or a mountpoint that has already
1050 * been deleted. This means that there is no info
1051 * to get from this pathname. Zero out the volume,
1052 * server & partition info and return successfully.
1054 uss_Volume[0] = '\0';
1055 uss_Server[0] = '\0';
1056 uss_Partition[0] = '\0';
1059 uss_PartitionID = 0;
1061 printf("%s: Warning: Mountpoint pathname '%s': ",
1062 uss_whoami, a_mountpoint);
1063 if (errno == EINVAL)
1064 printf("Volume not reachable\n");
1065 else if (errno == ENODEV)
1066 printf("No such device\n");
1068 printf("Not found\n");
1073 printf("%s: Can't get volume information from mountpoint '%s'\n",
1074 uss_whoami, a_mountpoint);
1077 } /*Can't get volume status*/
1080 * Pull out the volume name from the returned information and store
1081 * it in the common area. It resides right after the basic volume
1084 statusP = (uss_VolumeStatus_t *)uss_fs_OutBuff;
1085 strcpy(uss_Volume, (((char *)statusP) + sizeof(*statusP)));
1086 volID = statusP->Vid;
1087 uss_VolumeID = volID;
1089 printf("%s: Illegal volume ID: %d\n",
1095 * With the volume name in hand, find out where that volume
1096 * lives. Make sure our VLDB stuff has been initialized first.
1099 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
1103 code = ubik_Call(VL_GetEntryByID, uconn_vldbP, 0, volID, -1, &vldbEntry);
1105 printf("%s: Can't fetch VLDB entry for volume ID %d\n",
1111 * Translate the given VLDB entry from network to host format, then
1112 * checking on the volume's validity. Specifically, it must be a
1113 * read/write volume and must only exist on one server.
1115 MapHostToNetwork(&vldbEntry);
1116 if (vldbEntry.volumeId[RWVOL] != volID) {
1117 printf("s: Volume '%s' (ID %d) is not a read/write volume!!\n",
1118 uss_whoami, uss_Volume, volID);
1121 if (vldbEntry.nServers != 1) {
1122 printf("s: Volume '%s' (ID %d) exists on multiple servers!!\n",
1123 uss_whoami, uss_Volume, volID);
1128 * Pull out the int32words containing the server and partition info
1129 * for the read/write volume.
1131 code = GetServerAndPart(&vldbEntry, &serverID, &partID);
1133 printf("%s: Can't get server/partition info from VLDB entry for volume '%s' (ID %d)\n",
1134 uss_whoami, uss_Volume, volID);
1139 * Store the raw data, then translate the FileServer address to a
1140 * host name, and the partition ID to a partition name.
1142 uss_ServerID = serverID;
1143 uss_PartitionID = partID;
1144 HostIDToHostName(serverID, uss_Server);
1146 printf("[%s] Server ID 0x%x translated to '%s'\n",
1147 rn, serverID, uss_Server);
1148 #endif /* USS_VOL_DB */
1149 code = PartIDToPartName(partID, uss_Partition);
1151 printf("%s: Error translating partition ID %d to partition name\n",
1152 uss_whoami, partID);
1157 * We got it, home boy.
1161 } /*uss_vol_GetVolInfoFromMountPoint*/