findlanabyname-20040228
[openafs.git] / src / WINNT / afssvrcfg / partition_utils.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * INCLUDES ___________________________________________________________________
12  *
13  */
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include "afscfg.h"
20 #include "partition_utils.h"
21 #include <afs\afs_cfgAdmin.h>
22
23
24 /*
25  * DEFINITIONS _________________________________________________________________
26  *
27  */
28 static cfg_partitionEntry_t *pTable = 0;        // Partition table
29 static int cPartitions = 0;                                     // Count of partitions
30
31
32 /*
33  * EXPORTED FUNCTIONS _________________________________________________________
34  *
35  */
36 cfg_partitionEntry_t *GetPartitionTable(int &nNumPartitions)
37 {
38         nNumPartitions = cPartitions;
39
40         return pTable;
41 }
42
43 int GetNumPartitions()
44 {
45         return cPartitions;
46 }
47
48 int ReadPartitionTable(afs_status_t *pStatus)
49 {
50         ASSERT(g_hServer);
51
52         FreePartitionTable();
53
54         cPartitions = 0;
55         pTable = 0;
56         
57         int nResult = cfg_HostPartitionTableEnumerate(g_hServer, &pTable, &cPartitions, pStatus);
58
59         return nResult;
60 }
61
62 BOOL IsAnAfsPartition(LPCTSTR pszRootDir)
63 {
64         for (int ii = 0; ii < cPartitions; ii++) {
65
66                 TCHAR ch1 = pTable[ii].deviceName[0];
67                 if (_istupper(ch1))
68                         ch1 = _totlower(ch1);
69
70                 TCHAR ch2 = pszRootDir[0];
71                 if (_istupper(ch2))
72                         ch2 = _totlower(ch2);
73
74                 if (ch1 == ch2)
75                         return TRUE;
76         }
77
78         return FALSE;
79 }
80
81 BOOL DoesPartitionExist(LPCTSTR pszName)
82 {
83         for (int ii = 0; ii < cPartitions; ii++) {
84                 if (lstrcmp(A2S(pTable[ii].partitionName), pszName) == 0)
85                         return TRUE;
86         }
87         
88         return FALSE;
89 }
90         
91 void FreePartitionTable()
92 {
93         if (pTable) {
94                 afs_status_t nStatus;
95                 cfg_PartitionListDeallocate(pTable, &nStatus);
96         }
97         
98         pTable = 0;
99         cPartitions = 0;
100 }
101