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 <afsconfig.h>
19 #include <afs/param.h>
24 #include "uss_vol.h" /*Interface to this module */
25 #include "uss_common.h" /*Common definitions */
26 #include "uss_procs.h" /*Defs from procs module */
27 #include "uss_fs.h" /*CacheManager ops */
36 #include <afs/com_err.h>
37 #include <afs/vlserver.h>
38 #include <afs/vldbint.h>
40 #include <afs/cellconfig.h>
41 #include <rx/rx_globals.h>
42 #include <afs/volser.h>
43 #include <afs/volint.h>
45 #include <afs/afsutil.h>
51 * ---------------------- Private definitions ---------------------
54 #undef USS_VOL_DB_SHOW_OVERRIDES
58 * --------------------- Exported definitions ---------------------
61 * The Volume Server interface imports the Ubik connection
62 * structure to use, expecting it to be named "cstruct". This
63 * is why we have two names here. Thus, the UV_CreateVolume()
64 * will work and we can avoid nasty little core dumps.
66 struct ubik_client *uconn_vldbP; /*Ubik connection struct */
67 struct ubik_client *cstruct; /*Required name for above */
70 * ------------------------ Private globals -----------------------
72 static int initDone = 0; /*Module initialized? */
73 static int NoAuthFlag = 0; /*Use -noauth? */
74 static struct rx_connection
75 *serverconns[VLDB_MAXSERVERS]; /*Connection(s) to VLDB
79 /*-----------------------------------------------------------------------
80 * static InitThisModule
83 * Set up this module, namely set up all the client state for
84 * dealing with the Volume Location Server(s), including
85 * network connections.
88 * a_noAuthFlag : Do we need authentication?
89 * a_confDir : Configuration directory to use.
90 * a_cellName : Cell we want to talk to.
93 * 0 if everything went fine, or
94 * lower-level error code otherwise.
97 * This routine will only be called once.
101 *------------------------------------------------------------------------*/
104 InitThisModule(int a_noAuthFlag, char *a_confDir, char *a_cellName)
105 { /*InitThisModule */
107 static char rn[] = "uss_vol:InitThisModule";
109 register afs_int32 code; /*Return code */
110 struct afsconf_dir *tdir; /*Ptr to conf dir info */
111 struct afsconf_cell info; /*Info about chosen cell */
112 struct ktc_principal sname; /*Service name */
113 struct ktc_token ttoken; /*Service ticket */
114 afs_int32 scIndex; /*Chosen security index */
115 struct rx_securityClass *sc; /*Generated security object */
116 afs_int32 i; /*Loop index */
119 * Only once, guys, will 'ya?
123 printf("[%s] Called multiple times!\n", rn);
124 #endif /* USS_VOL_DB */
129 * Set up our Rx environment.
132 printf("[%s] Initializing Rx environment\n", rn);
133 #endif /* USS_VOL_DB */
136 fprintf(stderr, "%s: Couldn't initialize Rx.\n", uss_whoami);
139 rx_SetRxDeadTime(50);
142 * Find out all about our configuration.
145 printf("[%s] Handling configuration info\n", rn);
146 #endif /* USS_VOL_DB */
147 tdir = afsconf_Open(a_confDir);
149 fprintf(stderr, "%s: Couldn't open configuration directory (%s).\n",
150 uss_whoami, a_confDir);
153 code = afsconf_GetCellInfo(tdir, a_cellName, AFSCONF_VLDBSERVICE, &info);
155 printf("%s: Can't find VLDB server(s) for cell %s\n", uss_whoami,
160 printf("[%s] Getting tickets if needed\n", rn);
161 #endif /* USS_VOL_DB */
164 * We don't need tickets for unauthenticated connections.
166 strcpy(sname.cell, info.name);
167 sname.instance[0] = 0;
168 strcpy(sname.name, "afs");
169 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
172 "%s: Couldn't get AFS tokens, running unauthenticated.\n",
177 * We got a ticket, go for an authenticated connection.
179 if (ttoken.kvno >= 0 && ttoken.kvno <= 256)
180 scIndex = 2; /*Kerberos */
182 fprintf(stderr, "%s: Funny kvno (%d) in ticket, proceeding\n",
183 uss_whoami, ttoken.kvno);
187 } /*Authentication desired */
192 * Generate the appropriate security object for the connection.
195 printf("[%s] Generating Rx security object\n", rn);
196 #endif /* USS_VOL_DB */
199 sc = (struct rx_securityClass *)
200 rxnull_NewClientSecurityObject();
207 sc = (struct rx_securityClass *)
208 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
209 ttoken.kvno, ttoken.ticketLen,
215 * Tell UV module about default authentication.
218 printf("[%s] Setting UV security: obj 0x%x, index %d\n", rn, sc, scIndex);
219 #endif /* USS_VOL_DB */
220 UV_SetSecurity(sc, scIndex);
221 if (info.numServers > VLDB_MAXSERVERS) {
222 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
223 uss_whoami, info.numServers, VLDB_MAXSERVERS);
228 * Connect to each VLDB server for the chosen cell.
230 for (i = 0; i < info.numServers; i++) {
233 ("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n",
234 rn, info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port,
236 #endif /* USS_VOL_DB */
238 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
239 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
244 * Set up to execute Ubik transactions on the VLDB.
247 printf("[%s] Initializing Ubik interface\n", rn);
248 #endif /* USS_VOL_DB */
249 code = ubik_ClientInit(serverconns, &uconn_vldbP);
251 fprintf(stderr, "%s: Ubik client init failed.\n", uss_whoami);
255 printf("[%s] VLDB ubik connection structure at 0x%x\n", rn, uconn_vldbP);
256 #endif /* USS_VOL_DB */
259 * Place the ubik VLDB connection structure in its advertised
262 cstruct = uconn_vldbP;
270 } /*InitThisModule */
273 /*-----------------------------------------------------------------------
274 * static HostIDToHostName
277 * Given a host ID (in network byte order), figure out the
278 * corresponding host name.
281 * a_hostID : Host ID in network byte order.
282 * a_hostName : Ptr to host name buffer.
288 * This routine simply calls the hostutil_GetNameByINet()
289 * function exported by the utility library (util.a).
293 *------------------------------------------------------------------------*/
296 HostIDToHostName(afs_int32 a_hostID, char *a_hostName)
297 { /*HostIDToHostName */
299 strcpy(a_hostName, hostutil_GetNameByINet(a_hostID));
301 } /*HostIDToHostName */
304 /*-----------------------------------------------------------------------
305 * static PartIDToPartName
308 * Given a partition ID (in network byte order), figure out the
309 * corresponding partition name.
312 * a_partID : Partition ID in network byte order.
313 * a_partName : Ptr to partition name buffer.
316 * 0 if everything went well, or
317 * -1 if the given partition ID couldn't be translated.
320 * Nothing interesting.
324 *------------------------------------------------------------------------*/
327 PartIDToPartName(afs_int32 a_partID, char *a_partName)
328 { /*PartIDToPartName */
330 static char rn[] = "PartIDToPartName";
333 printf("[%s] Translating partition id %d to its name\n", rn, a_partID);
334 #endif /* USS_VOL_DB */
336 if ((a_partID < 0) || (a_partID > VOLMAXPARTS))
340 strcpy(a_partName, "/vicep");
341 a_partName[6] = a_partID + 'a';
342 a_partName[7] = '\0';
344 strcpy(a_partName, "/vicep");
346 a_partName[6] = 'a' + (a_partID / 26);
347 a_partName[7] = 'a' + (a_partID % 26);
348 a_partName[8] = '\0';
352 printf("[%s] Translation for part ID %d is '%s'\n", rn, a_partID,
354 #endif /* USS_VOL_DB */
357 } /*PartIDToPartName */
360 /*------------------------------------------------------------------------
361 * EXPORTED uss_Vol_GetServer
364 * Nothing interesting.
368 *------------------------------------------------------------------------*/
371 uss_vol_GetServer(char *a_name)
372 { /*uss_vol_GetServer */
374 register struct hostent *th;
377 register afs_int32 code;
379 code = sscanf(a_name, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
382 * Parsed as 128.2.9.4, or similar; return it in network
383 * byte order (128 in byte 0).
386 (((afs_int32) b1) << 24) | (((afs_int32) b2) << 16) |
387 (((afs_int32) b3) << 8) | (afs_int32) b4;
391 th = gethostbyname(a_name);
394 memcpy(&addr, th->h_addr, sizeof(addr));
397 } /*uss_vol_GetServer */
399 /* XXX - This function is unused, and could be deleted */
401 /*------------------------------------------------------------------------
402 * static GetVolumeType
405 * Translate the given char string representing a volume type to the
406 * numeric representation.
409 * a_type : Char string volume type.
412 * One of ROVOL, RWVOL, BACKVOL, or -1 on failure.
415 * Nothing interesting.
419 *------------------------------------------------------------------------*/
422 GetVolumeType(char *a_type)
425 if (!strcmp(a_type, "ro"))
427 else if (!strcmp(a_type, "rw"))
429 else if (!strcmp(a_type, "bk"))
437 /*------------------------------------------------------------------------
438 * EXPORTED uss_Vol_GetPartitionID
441 * It is assumed that partition names may begin with ``/vicep''.
445 *------------------------------------------------------------------------*/
448 uss_vol_GetPartitionID(char *a_name)
449 { /*uss_vol_GetPartitionID */
459 * Numbers go straight through.
461 if (tc >= '0' && tc <= '9') {
462 return (atoi(a_name));
466 * Otherwise, check for vicepa or /vicepa, or just plain "a"
469 if (strlen(a_name) <= 2) {
470 strcpy(ascii, a_name);
471 } else if (!strncmp(a_name, "/vicep", 6)) {
472 strncpy(ascii, a_name + 6, 2);
473 } else if (!strncmp(a_name, "vicep", 5)) {
474 strncpy(ascii, a_name + 5, 2);
479 * Now, partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
480 * .../vicepzz, and are numbered from 0. Do the appropriate conversion.
484 * Single-char name, 0..25
486 if (ascii[0] < 'a' || ascii[0] > 'z')
487 return (-1); /* wrongo */
488 return (ascii[0] - 'a');
491 * Two-char name, 26 .. <whatever>
493 if (ascii[0] < 'a' || ascii[0] > 'z')
495 if (ascii[1] < 'a' || ascii[1] > 'z')
497 return ((ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26);
499 } /*uss_vol_GetPartitionID */
502 /*-----------------------------------------------------------------------
503 * static CheckDoubleMount
506 * Make sure we're not trying to mount a volume in the same place
510 * a_mp : Mountpoint pathname to check.
511 * a_oldmp : Ptr to buffer into which the old value of the
512 * mountpoint is placed (if any).
515 * 0 if the volume was not previously mounted.
516 * uss_procs_ANCIENT if there was already a mountpoint AND the
517 * user was already recorded in the password
519 * uss_procs_YOUNG if there was a mountpoint for the user taken
520 * from the directory pool, yet the user was not
521 * yet in the password file.
524 * Nothing interesting.
527 * May fill in the a_oldmp buffer with the value of the old
529 *------------------------------------------------------------------------*/
532 CheckDoubleMount(char *a_mp, char *a_oldmp)
533 { /*CheckDoubleMount */
536 static char rn[] = "uss_vol:CheckDoubleMount";
538 int start, len, mlen, tlen;
543 pws = getpwuid(atoi(uss_Uid));
546 * User exists in the password file, so they've been fully
547 * created and integrated. Return the ``ancient'' mountpoint.
549 strcpy(a_oldmp, pws->pw_dir);
550 return (uss_procs_ANCIENT);
555 * $AUTO used. Search among the possible directories.
557 len = strlen(uss_Auto);
559 while (strncmp(&a_mp[i], uss_Auto, len)) {
560 a_oldmp[i] = a_mp[i];
561 if (++i > (mlen - len)) {
566 if ((start = i) != -1) {
568 * $AUTO used in mountpoint.
570 for (i = 0; i < uss_NumGroups; i++) {
572 * Copy in the base and tail components.
574 tlen = strlen(uss_DirPool[i]);
575 strncpy(&a_oldmp[start], uss_DirPool[i], tlen);
576 strcpy(&a_oldmp[start + tlen], &a_mp[start + len]);
578 printf("%s: Checking '%s' for mount point\n", rn, a_oldmp);
579 #endif /* USS_VOL_DB */
580 if (lstat(a_oldmp, &stbuf) == 0) /*mp exists */
581 if (strcmp(a_oldmp, a_mp))
582 /* and is different */
584 * The old mount point exists and is different
585 * from the current one, so return the fact
586 * that we have a ``young'' mountpoint.
588 return (uss_procs_YOUNG);
589 } /*Check each $AUTO directory */
593 /*$AUTO has been used */
595 * No luck finding the old mount point, so we just return that
596 * this is the first time we've seen this volume.
600 } /*CheckDoubleMount */
603 /*------------------------------------------------------------------------
604 * EXPORTED uss_vol_CreateVol
607 * Called from the code generated by the uss grammar.
611 *------------------------------------------------------------------------*/
614 uss_vol_CreateVol(char *a_volname, char *a_server, char *a_partition,
615 char *a_quota, char *a_mpoint, char *a_owner,
617 { /*uss_vol_CreateVol */
619 static char rn[] = "uss_vol_CreateVol"; /*Routine name */
621 afs_int32 pname; /*Partition name */
622 afs_int32 volid, code; /*Volume ID, return code */
623 afs_int32 saddr; /*Socket info for server */
624 int VolExistFlag = 0; /*Does the volume exist? */
625 int mpExistFlag = 0; /*Does the mountpoint exist? */
626 char *Oldmpoint = NULL; /*Old mountpoint name, if any */
627 char tmp_str[uss_MAX_SIZE]; /*Useful string buffer */
628 int o; /*Owner's user id */
629 char userinput[64]; /*User's input */
630 struct uss_subdir *new_dir; /*Used to remember original ACL */
633 * Don't do anything if there's already a problem.
639 fprintf(stderr, "%s:uss_vol_CreateVol params:\n", rn);
641 "%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
642 rn, a_volname, a_server, a_partition, a_quota, a_mpoint, a_owner,
644 #endif /* USS_VOL_DB */
647 * All of the parameters passed in are taken from the template
648 * file. Override these values if the user has explicitly set
649 * them, namely if the uss commons have non-null strings.
651 if (uss_Server[0] != '\0') {
652 #ifdef USS_VOL_DB_SHOW_OVERRIDES
655 "%s: Overriding server field: template value is '%s', overridden to '%s'\n",
656 rn, a_server, uss_Server);
657 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
658 a_server = uss_Server;
661 if (uss_Partition[0] != '\0') {
662 #ifdef USS_VOL_DB_SHOW_OVERRIDES
665 "%s: Overriding partition field: template value is '%s', overridden to '%s'\n",
666 rn, a_partition, uss_Partition);
667 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
668 a_partition = uss_Partition;
671 if (uss_MountPoint[0] != '\0') {
672 #ifdef USS_VOL_DB_SHOW_OVERRIDES
675 "%s: overriding mountpoint field: template value is '%s', overridden to '%s'\n",
676 rn, a_mpoint, uss_MountPoint);
677 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
678 a_mpoint = uss_MountPoint;
680 #ifdef USS_VOL_DB_SHOW_OVERRIDES
681 printf("%s: Params after overrides:\n", uss_whoami);
683 ("%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
684 uss_whoami, a_volname, a_server, a_partition, a_quota, a_mpoint,
686 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
690 "Creating volume '%s' on server '%s', partition '%s'\n",
691 a_volname, a_server, a_partition);
693 saddr = uss_vol_GetServer(a_server);
695 uss_procs_PrintErr(line,
696 "File server '%s' not found in config info\n",
700 pname = uss_vol_GetPartitionID(a_partition);
702 uss_procs_PrintErr(line, "Couldn't interpret partition name '%s'\n",
708 * Make sure our VLDB connection(s) is/are set up before actually
709 * trying to perform a volume creation creation.
712 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
714 afs_com_err(uss_whoami, code,
715 "while inititializing VLDB connection(s)\n");
719 /*Initialize VLDB connection(s) */
722 printf("%s: Creating volume on srv 0x%x, part %d, vol name '%s'\n",
723 rn, saddr, pname, a_volname);
724 #endif /* USS_VOL_DB */
725 code = UV_CreateVolume(saddr, pname, a_volname, &volid);
727 if (code == VL_NAMEEXIST) {
730 "%s: Warning; Volume '%s' exists, using existing one.\n",
731 uss_whoami, a_volname);
734 * We should get the volid here if we want to use it, but
735 * we don't need it right now. What we DO need, though, is
736 * to ask our caller if it's OK to overwrite the user's files
737 * if they're pre-existing.
739 if (!uss_OverwriteThisOne) {
741 ("Overwrite files in pre-existing '%s' volume? [y, n]: ",
743 scanf("%s", userinput);
744 if ((userinput[0] == 'y') || (userinput[0] == 'Y')) {
745 printf("\t[Overwriting allowed]\n");
746 uss_OverwriteThisOne = 1;
748 printf("\t[Overwriting not permitted]\n");
749 } /*Overwriting not previously allowed */
750 } /*Volume already existed */
752 uss_procs_PrintErr(line,
753 "Couldn't create volume '%s' [error %d]: %s\n",
754 a_volname, code, strerror(errno));
756 } /*Failure was NOT because it already existed */
757 } /*UV_CreateVolume failed */
761 "\t[Dry run: Creating volume '%s' on '%s', partition '%s']\n",
762 a_volname, a_server, a_partition);
765 /* OK, we want to make sure we don't double-mount the volume.
766 * If the volume existed, it can be the case that it is
767 * already mounted somewhere else (because of $AUTO or others).
768 * Let's check for that. Note: we never enter this portion of
769 * the code if we're doing a dry run.
772 if ((Oldmpoint = (char *)malloc(strlen(a_mpoint) + 50)) == NULL) {
773 fprintf(stderr, "%s: No more memory!\n", uss_whoami);
777 mpExistFlag = CheckDoubleMount(a_mpoint, Oldmpoint);
778 if (mpExistFlag == uss_procs_ANCIENT) {
780 "%s:\t*** WARNING ***; This user (%s) is already in passwd file (or equivalent). IGNORED.\n",
781 uss_whoami, uss_User);
783 uss_syntax_err = 1; /*I know, I know, it's not a SYNTAX error */
787 if (mpExistFlag == uss_procs_YOUNG) {
789 "%s: Warning; Volume '%s' is already mounted on %s. Using the existing one.\n",
790 uss_whoami, a_volname, Oldmpoint);
791 a_mpoint = Oldmpoint;
795 if (mpExistFlag == 0) {
796 extern int local_Cell;
801 sprintf(tmp_str, "#%s.", a_volname);
803 sprintf(tmp_str, "#%s:%s.", uss_Cell, a_volname);
805 if (symlink(tmp_str, a_mpoint)) {
806 if (errno == EEXIST) {
808 "%s: Warning: Mount point '%s' already exists.\n",
809 uss_whoami, a_mpoint);
812 "%s: Can't mount volume '%s' on '%s': %s\n",
813 uss_whoami, a_volname, a_mpoint, strerror(errno));
817 } /*There was already something mounted there */
821 fprintf(stderr, "\t[Dry run: Mounting '%s' at '%s']\n", tmp_str,
826 /*Mount point didn't already exist */
828 * Set the volume disk quota.
831 if ((code = uss_acl_SetDiskQuota(a_mpoint, atoi(a_quota))))
836 "\t[Dry run: Setting disk quota for '%s' to %s blocks]\n",
840 /*Copy mpoint into $MTPT for others to use */
841 strcpy(uss_MountPoint, a_mpoint);
843 o = uss_procs_GetOwner(a_owner);
845 if (chown(a_mpoint, o, -1)) {
847 "%s: Can't chown() mountpoint '%s' to owner '%s' (uid %d): %s\n",
848 uss_whoami, a_mpoint, a_owner, o, strerror(errno));
856 "\t[Dry run: chown() mountpoint '%s' to be owned by user]\n",
861 * Set the ACL on the user's home directory so that, for the duration of
862 * the account creation, only the uss_AccountCreator has any rights on the
863 * files therein. Make sure to clear this ACL to remove anyone that might
864 * already be there due to volume creation defaults. We will set this ACL
865 * properly, as well as all ACLs of future subdirectories,as the very last
866 * thing we do to the new account.
868 new_dir = (struct uss_subdir *)malloc(sizeof(struct uss_subdir));
869 new_dir->previous = uss_currentDir;
870 new_dir->path = (char *)malloc(strlen(a_mpoint) + 1);
871 strcpy(new_dir->path, a_mpoint);
872 new_dir->finalACL = (char *)malloc(strlen(a_acl) + 1);
873 strcpy(new_dir->finalACL, a_acl);
874 uss_currentDir = new_dir;
875 sprintf(tmp_str, "%s %s all", a_mpoint, uss_AccountCreator);
882 fprintf(stderr, "Setting ACL: '%s'\n", tmp_str);
883 if (uss_acl_SetAccess(tmp_str, 1, 0))
887 fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s)]\n", tmp_str);
890 } /*uss_vol_CreateVol */
893 /*------------------------------------------------------------------------
894 * EXPORTED uss_vol_DeleteVol
897 * Nothing interesting.
901 *------------------------------------------------------------------------*/
904 uss_vol_DeleteVol(char *a_volName, afs_int32 a_volID, char *a_servName,
905 afs_int32 a_servID, char *a_partName, afs_int32 a_partID)
906 { /*uss_vol_DeleteVol */
908 static char rn[] = "uss_vol_DeleteVol"; /*Routine name */
909 register afs_int32 code = 0; /*Return code */
912 * Make sure we've initialized our VLDB connection(s) before
916 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
923 * Go for the deletion.
927 ("%s: Deleting volume '%s' (ID %d) on FileServer '%s' (0x%x), partition '%s' (%d)\n",
928 rn, a_volName, a_volID, a_servName, a_servID, a_partName,
930 #endif /* USS_VOL_DB */
932 code = UV_DeleteVolume(a_servID, a_partID, a_volID);
934 printf("%s: Can't delete volume '%s'\n", uss_whoami, a_volName);
936 printf("\t[Dry run - volume '%s' NOT removed]\n", a_volName);
940 } /*uss_vol_DeleteVol */
943 /*------------------------------------------------------------------------
944 * static GetServerAndPart
947 * Given a VLDB entry, return the server and partition IDs for
948 * the read/write volume.
951 * a_vldbEntryP : Ptr to VLDB entry.
952 * a_servIDP : Ptr to server ID to set.
953 * a_partIDP : Ptr to partition ID to set.
956 * 0 if everything went well, or
960 * Nothing interesting.
964 *------------------------------------------------------------------------*/
967 GetServerAndPart(struct vldbentry *a_vldbEntryP, afs_int32 *a_servIDP,
968 afs_int32 *a_partIDP)
969 { /*GetServerAndPart */
972 * It really looks like all we need to do is pull off the
973 * first entry's info.
975 *a_servIDP = a_vldbEntryP->serverNumber[0];
976 *a_partIDP = a_vldbEntryP->serverPartition[0];
979 } /*GetServerAndPart */
982 /*------------------------------------------------------------------------
983 * EXPORTED uss_vol_GetVolInfoFromMountPoint
986 * If the mountpoint path provided is not
990 *------------------------------------------------------------------------*/
993 uss_vol_GetVolInfoFromMountPoint(char *a_mountpoint)
994 { /*uss_vol_GetVolInfoFromMountPoint */
996 static char rn[] = "uss_vol_GetVolInfoFromMountPoint";
998 register afs_int32 code; /*Return code */
999 uss_VolumeStatus_t *statusP; /*Ptr to returned status */
1000 afs_int32 volID; /*Volume ID */
1001 struct vldbentry vldbEntry; /*VLDB entry for volume */
1002 afs_int32 serverID; /*Addr of host FileServer */
1003 afs_int32 partID; /*Volume's partition ID */
1006 * Set up to ask the CacheManager to give us all the info
1007 * it has about the given mountpoint.
1009 code = uss_fs_GetVolStat(a_mountpoint, uss_fs_OutBuff, USS_FS_MAX_SIZE);
1011 printf("[%s] Result of uss_fs_GetVolStat: code = %d, errno = %d\n", rn,
1013 #endif /* USS_VOL_DB */
1015 if (errno == EINVAL || errno == ENOENT || errno == ENODEV) {
1017 * We were given a mountpoint pathname that doesn't
1018 * point to a volume, or a mountpoint that has already
1019 * been deleted. This means that there is no info
1020 * to get from this pathname. Zero out the volume,
1021 * server & partition info and return successfully.
1023 uss_Volume[0] = '\0';
1024 uss_Server[0] = '\0';
1025 uss_Partition[0] = '\0';
1028 uss_PartitionID = 0;
1030 printf("%s: Warning: Mountpoint pathname '%s': ", uss_whoami,
1032 if (errno == EINVAL)
1033 printf("Volume not reachable\n");
1034 else if (errno == ENODEV)
1035 printf("No such device\n");
1037 printf("Not found\n");
1041 printf("%s: Can't get volume information from mountpoint '%s'\n",
1042 uss_whoami, a_mountpoint);
1047 /*Can't get volume status */
1049 * Pull out the volume name from the returned information and store
1050 * it in the common area. It resides right after the basic volume
1053 statusP = (uss_VolumeStatus_t *) uss_fs_OutBuff;
1054 strcpy(uss_Volume, (((char *)statusP) + sizeof(*statusP)));
1055 volID = statusP->Vid;
1056 uss_VolumeID = volID;
1058 printf("%s: Illegal volume ID: %d\n", uss_whoami, volID);
1063 * With the volume name in hand, find out where that volume
1064 * lives. Make sure our VLDB stuff has been initialized first.
1067 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
1071 code = ubik_VL_GetEntryByID( uconn_vldbP, 0, volID, -1, &vldbEntry);
1073 printf("%s: Can't fetch VLDB entry for volume ID %d\n", uss_whoami,
1079 * Translate the given VLDB entry from network to host format, then
1080 * checking on the volume's validity. Specifically, it must be a
1081 * read/write volume and must only exist on one server.
1083 MapHostToNetwork(&vldbEntry);
1084 if (vldbEntry.volumeId[RWVOL] != volID) {
1085 printf("%s: Volume '%s' (ID %d) is not a read/write volume!!\n",
1086 uss_whoami, uss_Volume, volID);
1089 if (vldbEntry.nServers != 1) {
1090 printf("s: Volume '%s' (ID %d) exists on multiple servers!!\n",
1091 uss_whoami, uss_Volume, volID);
1096 * Pull out the int32words containing the server and partition info
1097 * for the read/write volume.
1099 code = GetServerAndPart(&vldbEntry, &serverID, &partID);
1102 ("%s: Can't get server/partition info from VLDB entry for volume '%s' (ID %d)\n",
1103 uss_whoami, uss_Volume, volID);
1108 * Store the raw data, then translate the FileServer address to a
1109 * host name, and the partition ID to a partition name.
1111 uss_ServerID = serverID;
1112 uss_PartitionID = partID;
1113 HostIDToHostName(serverID, uss_Server);
1115 printf("[%s] Server ID 0x%x translated to '%s'\n", rn, serverID,
1117 #endif /* USS_VOL_DB */
1118 code = PartIDToPartName(partID, uss_Partition);
1120 printf("%s: Error translating partition ID %d to partition name\n",
1121 uss_whoami, partID);
1126 * We got it, home boy.
1130 } /*uss_vol_GetVolInfoFromMountPoint */