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 */
35 #include <afs/vlserver.h>
37 #include <afs/cellconfig.h>
38 #include <rx/rx_globals.h>
39 #include <afs/volser.h>
40 #include <afs/volint.h>
44 extern struct rx_connection *UV_Bind();
46 extern int VL_GetEntryByID();
47 extern char *hostutil_GetNameByINet();
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(a_noAuthFlag, a_confDir, a_cellName)
109 { /*InitThisModule */
111 static char rn[] = "uss_vol:InitThisModule";
112 register afs_int32 code; /*Return code */
113 struct afsconf_dir *tdir; /*Ptr to conf dir info */
114 struct afsconf_cell info; /*Info about chosen cell */
115 struct ktc_principal sname; /*Service name */
116 struct ktc_token ttoken; /*Service ticket */
117 afs_int32 scIndex; /*Chosen security index */
118 struct rx_securityClass *sc; /*Generated security object */
119 afs_int32 i; /*Loop index */
122 * Only once, guys, will 'ya?
126 printf("[%s] Called multiple times!\n", rn);
127 #endif /* USS_VOL_DB */
132 * Set up our Rx environment.
135 printf("[%s] Initializing Rx environment\n", rn);
136 #endif /* USS_VOL_DB */
139 fprintf(stderr, "%s: Couldn't initialize Rx.\n", uss_whoami);
142 rx_SetRxDeadTime(50);
145 * Find out all about our configuration.
148 printf("[%s] Handling configuration info\n", rn);
149 #endif /* USS_VOL_DB */
150 tdir = afsconf_Open(a_confDir);
152 fprintf(stderr, "%s: Couldn't open configuration directory (%s).\n",
153 uss_whoami, a_confDir);
156 code = afsconf_GetCellInfo(tdir, a_cellName, AFSCONF_VLDBSERVICE, &info);
158 printf("%s: Can't find VLDB server(s) for cell %s\n", uss_whoami,
163 printf("[%s] Getting tickets if needed\n", rn);
164 #endif /* USS_VOL_DB */
167 * We don't need tickets for unauthenticated connections.
169 strcpy(sname.cell, info.name);
170 sname.instance[0] = 0;
171 strcpy(sname.name, "afs");
172 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
175 "%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, &ttoken.sessionKey,
212 ttoken.kvno, ttoken.ticketLen,
218 * Tell UV module about default authentication.
221 printf("[%s] Setting UV security: obj 0x%x, index %d\n", rn, sc, scIndex);
222 #endif /* USS_VOL_DB */
223 UV_SetSecurity(sc, scIndex);
224 if (info.numServers > VLDB_MAXSERVERS) {
225 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
226 uss_whoami, info.numServers, VLDB_MAXSERVERS);
231 * Connect to each VLDB server for the chosen cell.
233 for (i = 0; i < info.numServers; i++) {
236 ("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n",
237 rn, info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port,
239 #endif /* USS_VOL_DB */
241 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
242 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
247 * Set up to execute Ubik transactions on the VLDB.
250 printf("[%s] Initializing Ubik interface\n", rn);
251 #endif /* USS_VOL_DB */
252 code = ubik_ClientInit(serverconns, &uconn_vldbP);
254 fprintf(stderr, "%s: Ubik client init failed.\n", uss_whoami);
258 printf("[%s] VLDB ubik connection structure at 0x%x\n", rn, uconn_vldbP);
259 #endif /* USS_VOL_DB */
262 * Place the ubik VLDB connection structure in its advertised
265 cstruct = uconn_vldbP;
273 } /*InitThisModule */
276 /*-----------------------------------------------------------------------
277 * static HostIDToHostName
280 * Given a host ID (in network byte order), figure out the
281 * corresponding host name.
284 * a_hostID : Host ID in network byte order.
285 * a_hostName : Ptr to host name buffer.
291 * This routine simply calls the hostutil_GetNameByINet()
292 * function exported by the utility library (util.a).
296 *------------------------------------------------------------------------*/
298 char *hostutil_GetNameByINet();
301 HostIDToHostName(a_hostID, a_hostName)
305 { /*HostIDToHostName */
307 strcpy(a_hostName, hostutil_GetNameByINet(a_hostID));
309 } /*HostIDToHostName */
312 /*-----------------------------------------------------------------------
313 * static PartIDToPartName
316 * Given a partition ID (in network byte order), figure out the
317 * corresponding partition name.
320 * a_partID : Partition ID in network byte order.
321 * a_partName : Ptr to partition name buffer.
324 * 0 if everything went well, or
325 * -1 if the given partition ID couldn't be translated.
328 * Nothing interesting.
332 *------------------------------------------------------------------------*/
335 PartIDToPartName(a_partID, a_partName)
339 { /*PartIDToPartName */
341 static char rn[] = "PartIDToPartName";
344 printf("[%s] Translating partition id %d to its name\n", rn, a_partID);
345 #endif /* USS_VOL_DB */
347 if ((a_partID < 0) || (a_partID > VOLMAXPARTS))
351 strcpy(a_partName, "/vicep");
352 a_partName[6] = a_partID + 'a';
353 a_partName[7] = '\0';
355 strcpy(a_partName, "/vicep");
357 a_partName[6] = 'a' + (a_partID / 26);
358 a_partName[7] = 'a' + (a_partID % 26);
359 a_partName[8] = '\0';
363 printf("[%s] Translation for part ID %d is '%s'\n", rn, a_partID,
365 #endif /* USS_VOL_DB */
368 } /*PartIDToPartName */
371 /*------------------------------------------------------------------------
372 * EXPORTED uss_Vol_GetServer
375 * Nothing interesting.
379 *------------------------------------------------------------------------*/
382 uss_vol_GetServer(a_name)
385 { /*uss_vol_GetServer */
387 register struct hostent *th;
390 register afs_int32 code;
392 code = sscanf(a_name, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
395 * Parsed as 128.2.9.4, or similar; return it in network
396 * byte order (128 in byte 0).
399 (((afs_int32) b1) << 24) | (((afs_int32) b2) << 16) |
400 (((afs_int32) b3) << 8) | (afs_int32) b4;
404 th = gethostbyname(a_name);
407 memcpy(&addr, th->h_addr, sizeof(addr));
410 } /*uss_vol_GetServer */
412 /*------------------------------------------------------------------------
413 * static GetVolumeType
416 * Translate the given char string representing a volume type to the
417 * numeric representation.
420 * a_type : Char string volume type.
423 * One of ROVOL, RWVOL, BACKVOL, or -1 on failure.
426 * Nothing interesting.
430 *------------------------------------------------------------------------*/
433 GetVolumeType(a_type)
438 if (!strcmp(a_type, "ro"))
440 else if (!strcmp(a_type, "rw"))
442 else if (!strcmp(a_type, "bk"))
450 /*------------------------------------------------------------------------
451 * EXPORTED uss_Vol_GetPartitionID
454 * It is assumed that partition names may begin with ``/vicep''.
458 *------------------------------------------------------------------------*/
461 uss_vol_GetPartitionID(a_name)
464 { /*uss_vol_GetPartitionID */
474 * Numbers go straight through.
476 if (tc >= '0' && tc <= '9') {
477 return (atoi(a_name));
481 * Otherwise, check for vicepa or /vicepa, or just plain "a"
484 if (strlen(a_name) <= 2) {
485 strcpy(ascii, a_name);
486 } else if (!strncmp(a_name, "/vicep", 6)) {
487 strncpy(ascii, a_name + 6, 2);
488 } else if (!strncmp(a_name, "vicep", 5)) {
489 strncpy(ascii, a_name + 5, 2);
494 * Now, partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
495 * .../vicepzz, and are numbered from 0. Do the appropriate conversion.
499 * Single-char name, 0..25
501 if (ascii[0] < 'a' || ascii[0] > 'z')
502 return (-1); /* wrongo */
503 return (ascii[0] - 'a');
506 * Two-char name, 26 .. <whatever>
508 if (ascii[0] < 'a' || ascii[0] > 'z')
510 if (ascii[1] < 'a' || ascii[1] > 'z')
512 return ((ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26);
514 } /*uss_vol_GetPartitionID */
517 /*-----------------------------------------------------------------------
518 * static CheckDoubleMount
521 * Make sure we're not trying to mount a volume in the same place
525 * a_mp : Mountpoint pathname to check.
526 * a_oldmp : Ptr to buffer into which the old value of the
527 * mountpoint is placed (if any).
530 * 0 if the volume was not previously mounted.
531 * uss_procs_ANCIENT if there was already a mountpoint AND the
532 * user was already recorded in the password
534 * uss_procs_YOUNG if there was a mountpoint for the user taken
535 * from the directory pool, yet the user was not
536 * yet in the password file.
539 * Nothing interesting.
542 * May fill in the a_oldmp buffer with the value of the old
544 *------------------------------------------------------------------------*/
547 CheckDoubleMount(a_mp, a_oldmp)
551 { /*CheckDoubleMount */
553 static char rn[] = "uss_vol:CheckDoubleMount";
554 int start, len, mlen, tlen;
559 pws = getpwuid(atoi(uss_Uid));
562 * User exists in the password file, so they've been fully
563 * created and integrated. Return the ``ancient'' mountpoint.
565 strcpy(a_oldmp, pws->pw_dir);
566 return (uss_procs_ANCIENT);
571 * $AUTO used. Search among the possible directories.
573 len = strlen(uss_Auto);
575 while (strncmp(&a_mp[i], uss_Auto, len)) {
576 a_oldmp[i] = a_mp[i];
577 if (++i > (mlen - len)) {
582 if ((start = i) != -1) {
584 * $AUTO used in mountpoint.
586 for (i = 0; i < uss_NumGroups; i++) {
588 * Copy in the base and tail components.
590 tlen = strlen(uss_DirPool[i]);
591 strncpy(&a_oldmp[start], uss_DirPool[i], tlen);
592 strcpy(&a_oldmp[start + tlen], &a_mp[start + len]);
594 printf("%s: Checking '%s' for mount point\n", rn, a_oldmp);
595 #endif /* USS_VOL_DB */
596 if (lstat(a_oldmp, &stbuf) == 0) /*mp exists */
597 if (strcmp(a_oldmp, a_mp))
598 /* and is different */
600 * The old mount point exists and is different
601 * from the current one, so return the fact
602 * that we have a ``young'' mountpoint.
604 return (uss_procs_YOUNG);
605 } /*Check each $AUTO directory */
609 /*$AUTO has been used */
611 * No luck finding the old mount point, so we just return that
612 * this is the first time we've seen this volume.
616 } /*CheckDoubleMount */
619 /*------------------------------------------------------------------------
620 * EXPORTED uss_vol_CreateVol
623 * Called from the code generated by the uss grammar.
627 *------------------------------------------------------------------------*/
630 uss_vol_CreateVol(a_volname, a_server, a_partition, a_quota, a_mpoint,
640 { /*uss_vol_CreateVol */
642 static char rn[] = "uss_vol_CreateVol"; /*Routine name */
643 afs_int32 pname; /*Partition name */
644 afs_int32 volid, code; /*Volume ID, return code */
645 afs_int32 saddr; /*Socket info for server */
646 int VolExistFlag = 0; /*Does the volume exist? */
647 int mpExistFlag = 0; /*Does the mountpoint exist? */
648 char *Oldmpoint = NULL; /*Old mountpoint name, if any */
649 char tmp_str[uss_MAX_SIZE]; /*Useful string buffer */
650 int o; /*Owner's user id */
651 char userinput[64]; /*User's input */
652 struct uss_subdir *new_dir; /*Used to remember original ACL */
655 * Don't do anything if there's already a problem.
661 fprintf(stderr, "%s:uss_vol_CreateVol params:\n", rn);
663 "%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, a_owner,
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
687 "%s: Overriding partition field: template value is '%s', overridden to '%s'\n",
688 rn, a_partition, uss_Partition);
689 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
690 a_partition = uss_Partition;
693 if (uss_MountPoint[0] != '\0') {
694 #ifdef USS_VOL_DB_SHOW_OVERRIDES
697 "%s: overriding mountpoint field: template value is '%s', overridden to '%s'\n",
698 rn, a_mpoint, uss_MountPoint);
699 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
700 a_mpoint = uss_MountPoint;
702 #ifdef USS_VOL_DB_SHOW_OVERRIDES
703 printf("%s: Params after overrides:\n", uss_whoami);
705 ("%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
706 uss_whoami, a_volname, a_server, a_partition, a_quota, a_mpoint,
708 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
712 "Creating volume '%s' on server '%s', partition '%s'\n",
713 a_volname, a_server, a_partition);
715 saddr = uss_vol_GetServer(a_server);
717 uss_procs_PrintErr(line,
718 "File server '%s' not found in config info\n",
722 pname = uss_vol_GetPartitionID(a_partition);
724 uss_procs_PrintErr(line, "Couldn't interpret partition name '%s'\n",
730 * Make sure our VLDB connection(s) is/are set up before actually
731 * trying to perform a volume creation creation.
734 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
736 afs_com_err(uss_whoami, code,
737 "while inititializing VLDB connection(s)\n");
741 /*Initialize VLDB connection(s) */
744 printf("%s: Creating volume on srv 0x%x, part %d, vol name '%s'\n",
745 rn, saddr, pname, a_volname);
746 #endif /* USS_VOL_DB */
747 code = UV_CreateVolume(saddr, pname, a_volname, &volid);
749 if (code == VL_NAMEEXIST) {
752 "%s: Warning; Volume '%s' exists, using existing one.\n",
753 uss_whoami, a_volname);
756 * We should get the volid here if we want to use it, but
757 * we don't need it right now. What we DO need, though, is
758 * to ask our caller if it's OK to overwrite the user's files
759 * if they're pre-existing.
761 if (!uss_OverwriteThisOne) {
763 ("Overwrite files in pre-existing '%s' volume? [y, n]: ",
765 scanf("%s", userinput);
766 if ((userinput[0] == 'y') || (userinput[0] == 'Y')) {
767 printf("\t[Overwriting allowed]\n");
768 uss_OverwriteThisOne = 1;
770 printf("\t[Overwriting not permitted]\n");
771 } /*Overwriting not previously allowed */
772 } /*Volume already existed */
774 uss_procs_PrintErr(line,
775 "Couldn't create volume '%s' [error %d]: %s\n",
776 a_volname, code, strerror(errno));
778 } /*Failure was NOT because it already existed */
779 } /*UV_CreateVolume failed */
783 "\t[Dry run: Creating volume '%s' on '%s', partition '%s']\n",
784 a_volname, a_server, a_partition);
787 /* OK, we want to make sure we don't double-mount the volume.
788 * If the volume existed, it can be the case that it is
789 * already mounted somewhere else (because of $AUTO or others).
790 * Let's check for that. Note: we never enter this portion of
791 * the code if we're doing a dry run.
794 if ((Oldmpoint = (char *)malloc(strlen(a_mpoint) + 50)) == NULL) {
795 fprintf(stderr, "%s: No more memory!\n", uss_whoami);
799 mpExistFlag = CheckDoubleMount(a_mpoint, Oldmpoint);
800 if (mpExistFlag == uss_procs_ANCIENT) {
802 "%s:\t*** WARNING ***; This user (%s) is already in passwd file (or equivalent). IGNORED.\n",
803 uss_whoami, uss_User);
805 uss_syntax_err = 1; /*I know, I know, it's not a SYNTAX error */
809 if (mpExistFlag == uss_procs_YOUNG) {
811 "%s: Warning; Volume '%s' is already mounted on %s. Using the existing one.\n",
812 uss_whoami, a_volname, Oldmpoint);
813 a_mpoint = Oldmpoint;
817 if (mpExistFlag == 0) {
818 extern int local_Cell;
823 sprintf(tmp_str, "#%s.", a_volname);
825 sprintf(tmp_str, "#%s:%s.", uss_Cell, a_volname);
827 if (symlink(tmp_str, a_mpoint)) {
828 if (errno == EEXIST) {
830 "%s: Warning: Mount point '%s' already exists.\n",
831 uss_whoami, a_mpoint);
834 "%s: Can't mount volume '%s' on '%s': %s\n",
835 uss_whoami, a_volname, a_mpoint, strerror(errno));
839 } /*There was already something mounted there */
843 fprintf(stderr, "\t[Dry run: Mounting '%s' at '%s']\n", tmp_str,
848 /*Mount point didn't already exist */
850 * Set the volume disk quota.
853 if (code = uss_acl_SetDiskQuota(a_mpoint, atoi(a_quota)))
858 "\t[Dry run: Setting disk quota for '%s' to %s blocks]\n",
862 /*Copy mpoint into $MTPT for others to use */
863 strcpy(uss_MountPoint, a_mpoint);
865 o = uss_procs_GetOwner(a_owner);
867 if (chown(a_mpoint, o, -1)) {
869 "%s: Can't chown() mountpoint '%s' to owner '%s' (uid %d): %s\n",
870 uss_whoami, a_mpoint, a_owner, o, strerror(errno));
878 "\t[Dry run: chown() mountpoint '%s' to be owned by user]\n",
883 * Set the ACL on the user's home directory so that, for the duration of
884 * the account creation, only the uss_AccountCreator has any rights on the
885 * files therein. Make sure to clear this ACL to remove anyone that might
886 * already be there due to volume creation defaults. We will set this ACL
887 * properly, as well as all ACLs of future subdirectories,as the very last
888 * thing we do to the new account.
890 new_dir = (struct uss_subdir *)malloc(sizeof(struct uss_subdir));
891 new_dir->previous = uss_currentDir;
892 new_dir->path = (char *)malloc(strlen(a_mpoint) + 1);
893 strcpy(new_dir->path, a_mpoint);
894 new_dir->finalACL = (char *)malloc(strlen(a_acl) + 1);
895 strcpy(new_dir->finalACL, a_acl);
896 uss_currentDir = new_dir;
897 sprintf(tmp_str, "%s %s all", a_mpoint, uss_AccountCreator);
904 fprintf(stderr, "Setting ACL: '%s'\n", tmp_str);
905 if (uss_acl_SetAccess(tmp_str, 1, 0))
909 fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s)]\n", tmp_str);
912 } /*uss_vol_CreateVol */
915 /*------------------------------------------------------------------------
916 * EXPORTED uss_vol_DeleteVol
919 * Nothing interesting.
923 *------------------------------------------------------------------------*/
926 uss_vol_DeleteVol(a_volName, a_volID, a_servName, a_servID, a_partName,
935 { /*uss_vol_DeleteVol */
937 static char rn[] = "uss_vol_DeleteVol"; /*Routine name */
938 register afs_int32 code; /*Return code */
941 * Make sure we've initialized our VLDB connection(s) before
945 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
952 * Go for the deletion.
956 ("%s: Deleting volume '%s' (ID %d) on FileServer '%s' (0x%x), partition '%s' (%d)\n",
957 rn, a_volName, a_volID, a_servName, a_servID, a_partName,
959 #endif /* USS_VOL_DB */
961 code = UV_DeleteVolume(a_servID, a_partID, a_volID);
963 printf("%s: Can't delete volume '%s'\n", uss_whoami, a_volName);
965 printf("\t[Dry run - volume '%s' NOT removed]\n", a_volName);
969 } /*uss_vol_DeleteVol */
972 /*------------------------------------------------------------------------
973 * static GetServerAndPart
976 * Given a VLDB entry, return the server and partition IDs for
977 * the read/write volume.
980 * a_vldbEntryP : Ptr to VLDB entry.
981 * a_servIDP : Ptr to server ID to set.
982 * a_partIDP : Ptr to partition ID to set.
985 * 0 if everything went well, or
989 * Nothing interesting.
993 *------------------------------------------------------------------------*/
996 GetServerAndPart(a_vldbEntryP, a_servIDP, a_partIDP)
997 struct vldbentry *a_vldbEntryP;
998 afs_int32 *a_servIDP;
999 afs_int32 *a_partIDP;
1001 { /*GetServerAndPart */
1004 * It really looks like all we need to do is pull off the
1005 * first entry's info.
1007 *a_servIDP = a_vldbEntryP->serverNumber[0];
1008 *a_partIDP = a_vldbEntryP->serverPartition[0];
1011 } /*GetServerAndPart */
1014 /*------------------------------------------------------------------------
1015 * EXPORTED uss_vol_GetVolInfoFromMountPoint
1018 * If the mountpoint path provided is not
1022 *------------------------------------------------------------------------*/
1025 uss_vol_GetVolInfoFromMountPoint(a_mountpoint)
1028 { /*uss_vol_GetVolInfoFromMountPoint */
1030 static char rn[] = "uss_vol_GetVolInfoFromMountPoint";
1031 register afs_int32 code; /*Return code */
1032 uss_VolumeStatus_t *statusP; /*Ptr to returned status */
1033 afs_int32 volID; /*Volume ID */
1034 struct vldbentry vldbEntry; /*VLDB entry for volume */
1035 afs_int32 serverID; /*Addr of host FileServer */
1036 afs_int32 partID; /*Volume's partition ID */
1039 * Set up to ask the CacheManager to give us all the info
1040 * it has about the given mountpoint.
1042 code = uss_fs_GetVolStat(a_mountpoint, uss_fs_OutBuff, USS_FS_MAX_SIZE);
1044 printf("[%s] Result of uss_fs_GetVolStat: code = %d, errno = %d\n", rn,
1046 #endif /* USS_VOL_DB */
1048 if (errno == EINVAL || errno == ENOENT || errno == ENODEV) {
1050 * We were given a mountpoint pathname that doesn't
1051 * point to a volume, or a mountpoint that has already
1052 * been deleted. This means that there is no info
1053 * to get from this pathname. Zero out the volume,
1054 * server & partition info and return successfully.
1056 uss_Volume[0] = '\0';
1057 uss_Server[0] = '\0';
1058 uss_Partition[0] = '\0';
1061 uss_PartitionID = 0;
1063 printf("%s: Warning: Mountpoint pathname '%s': ", uss_whoami,
1065 if (errno == EINVAL)
1066 printf("Volume not reachable\n");
1067 else if (errno == ENODEV)
1068 printf("No such device\n");
1070 printf("Not found\n");
1074 printf("%s: Can't get volume information from mountpoint '%s'\n",
1075 uss_whoami, a_mountpoint);
1080 /*Can't get volume status */
1082 * Pull out the volume name from the returned information and store
1083 * it in the common area. It resides right after the basic volume
1086 statusP = (uss_VolumeStatus_t *) uss_fs_OutBuff;
1087 strcpy(uss_Volume, (((char *)statusP) + sizeof(*statusP)));
1088 volID = statusP->Vid;
1089 uss_VolumeID = volID;
1091 printf("%s: Illegal volume ID: %d\n", uss_whoami, volID);
1096 * With the volume name in hand, find out where that volume
1097 * lives. Make sure our VLDB stuff has been initialized first.
1100 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
1104 code = ubik_Call(VL_GetEntryByID, uconn_vldbP, 0, volID, -1, &vldbEntry);
1106 printf("%s: Can't fetch VLDB entry for volume ID %d\n", uss_whoami,
1112 * Translate the given VLDB entry from network to host format, then
1113 * checking on the volume's validity. Specifically, it must be a
1114 * read/write volume and must only exist on one server.
1116 MapHostToNetwork(&vldbEntry);
1117 if (vldbEntry.volumeId[RWVOL] != volID) {
1118 printf("%s: Volume '%s' (ID %d) is not a read/write volume!!\n",
1119 uss_whoami, uss_Volume, volID);
1122 if (vldbEntry.nServers != 1) {
1123 printf("s: Volume '%s' (ID %d) exists on multiple servers!!\n",
1124 uss_whoami, uss_Volume, volID);
1129 * Pull out the int32words containing the server and partition info
1130 * for the read/write volume.
1132 code = GetServerAndPart(&vldbEntry, &serverID, &partID);
1135 ("%s: Can't get server/partition info from VLDB entry for volume '%s' (ID %d)\n",
1136 uss_whoami, uss_Volume, volID);
1141 * Store the raw data, then translate the FileServer address to a
1142 * host name, and the partition ID to a partition name.
1144 uss_ServerID = serverID;
1145 uss_PartitionID = partID;
1146 HostIDToHostName(serverID, uss_Server);
1148 printf("[%s] Server ID 0x%x translated to '%s'\n", rn, serverID,
1150 #endif /* USS_VOL_DB */
1151 code = PartIDToPartName(partID, uss_Partition);
1153 printf("%s: Error translating partition ID %d to partition name\n",
1154 uss_whoami, partID);
1159 * We got it, home boy.
1163 } /*uss_vol_GetVolInfoFromMountPoint */