/
Drive_Linking.c
7590 lines (5111 loc) · 250 KB
/
Drive_Linking.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* Copyright (c) International Business Machines Corp., 2000
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: Drive_Linking.c
*/
/*
* Change History:
*
*/
/*
* Description: Since the LVM Engine Interface is very
* large, it became undesirable to put all of the code
* to implement it in a single file. Instead, the
* implementation of the LVM Engine Interface was divided
* among several C files which would have access to a
* core set of data. Engine.H and Engine.C define,
* allocate, and initialize that core set of data.
* Volume_Manager.H and Volume_Manager.C implement
* the volume management functions found in the
* LVM Engine Interface.
*
*
* Partition_Manager.C Volume_Manager.C
* \ /
* \ |-------------------------------------| /
* \| |/
* | Engine.H and Engine.C |
* /| |\
* / |-------------------------------------| \
* / | \
* BootManager.C Logging.C Handle_Manager.C
*
* Notes: LVM Drive Letter Assignment Tables (DLA_Tables) appear on the
* last sector of each track containing a valid MBR or EBR. Since
* partitions must be track aligned, any track containing an MBR or
* EBR will be almost all empty sectors. We will grab the last
* of these empty sectors for our DLT_Tables.
*
*/
#include <stdlib.h> /* malloc, free */
#include <stdio.h> /* sprintf */
#include <string.h> /* strlen */
#include "engine.h" /* Included for access to the global types and variables. */
#include "diskio.h" /* */
#define NEED_BYTE_DEFINED
#include "gbltypes.h" /* CARDINAL32, BYTE, BOOLEAN, ADDRESS */
#include "lvm_data.h"
#include "LVM_Interface.h"
#include "LVM_Constants.h" /* PARTITION_NAME_SIZE, VOLUME_NAME_SIZE, DISK_NAME_SIZE, BYTES_PER_SECTOR */
#include "lvm_plug.h"
#include "Drive_Linking_Feature.h"
#include "Drive_Linking.h"
#include "constant.h"
#include "panels.h"
#include "display.h"
#include "getkey.h"
#ifdef DEBUG
#ifdef PARANOID
#include <assert.h> /* assert */
#endif
#endif
typedef unsigned int bool, *pbool;
/*--------------------------------------------------
* Private Constants
--------------------------------------------------*/
#define UNEXPECTED_END_OF_INPUT "Unexpected end of input! Expecting 'ALL' or the name of an aggregate."
#define UNEXPECTED_END_OF_INPUT2 "Unexpected end of input! Expecting ')'."
#define AGGREGATE_NAME_EXPECTED "Error! An aggregate name or the word 'All' is expected here."
#define AGGREGATE_NAME_NOT_UNIQUE "Error! Duplicate aggregate name specified. Aggregate names must be unique!"
#define EQUAL_SIGN_EXPECTED "Error! An equal sign is expected after an aggregate name."
#define BRACE_EXPECTED " Error! A '{' character is expected!"
#define DRIVE_ID_EXPECTED "Error! A drive name or number is expected here!"
#define NEW_COMMAND_EXPECTED "Error! A ']' or an aggregate name is expected here!"
#define NEW_PARTITION_EXPECTED "Error! A comma or a '}' is expected here!"
#define INVALID_DRIVE_NUMBER_SPECIFIED "Error! The drive number specified is invalid!"
#define COMMA_EXPECTED "Error! A comma followed by a partition name is expected here!"
#define PARTITION_NAME_EXPECTED "Error! A partition name is expected here!"
#define PARTITION_NAME_TOO_LONG "Error! The partition name specified is too long!"
#define MISSING_AGGREGATE_NAME "Error! An aggregate name is expected after this comma!"
#define OLD_DRIVE_LINKING_MAJOR_VERSION 1
#define OLD_DRIVE_LINKING_MINOR_VERSION 0
#define OLD_CURRENT_LVM_MAJOR_VERSION_NUMBER 1 /* Define as appropriate. */
#define OLD_CURRENT_LVM_MINOR_VERSION_NUMBER 0 /* Define as appropriate. */
/*--------------------------------------------------
* Private Type definitions
--------------------------------------------------*/
typedef struct _Extended_Drive_Link {
Drive_Link Link_Data;
Partition_Data * PartitionRecord;
} Extended_Drive_Link;
typedef struct _Drive_Link_Array {
CARDINAL32 Links_In_Use;
Extended_Drive_Link LinkArray[MAXIMUM_LINKS];
CARDINAL32 Sequence_Number;
BOOLEAN ChangesMade;
CARDINAL32 Aggregate_Serial_Number;
LVM_Classes Actual_Class;
CARDINAL32 Feature_Sequence_Number;
BOOLEAN Top_Of_Class;
CARDINAL32 Fake_EBR_Size;
ADDRESS Fake_EBR_Buffer;
BOOLEAN Aggregate_Signature_Sector_Expected;
} Drive_Link_Array;
typedef struct _Aggregate_Search_Record {
Partition_Data * PartitionRecord;
CARDINAL32 Aggregate_Serial_Number;
Drive_Link_Array * LinkTable;
BOOLEAN Aggregate_Found;
} Aggregate_Search_Record;
typedef struct _Aggregate_Validation_Record {
DLIST Partition_List;
BOOLEAN Volume_Created;
CARDINAL32 * Error_Code;
} Aggregate_Validation_Record;
typedef struct _LSN_Translation_Record {
Partition_Data * Aggregate;
CARDINAL32 Sector_LSN;
Partition_Data * PartitionRecord; /* The PartitionRecord for the partition containing the specified sector. */
CARDINAL32 Sector_PSN; /* The sector's address relative to the partition containing it. */
} LSN_Translation_Record;
typedef struct _Partition_Deletion_Record {
CARDINAL32 LVM_Error;
BOOLEAN Kill_Partitions;
} Partition_Deletion_Record;
typedef struct _Commit_Changes_Record {
BOOLEAN Commit_Drive_Linking_Changes; /* If TRUE, then drive linking data was changed and needs to be written to disk. */
ADDRESS VData; /* The address of the volume data. This will be passed through to the next layer needing to do a commit. */
} Commit_Changes_Record;
typedef struct _PassThru_Data_Record {
CARDINAL32 Feature_ID;
ADDRESS Aggregate;
ADDRESS InputBuffer;
CARDINAL32 InputSize;
ADDRESS * OutputBuffer;
CARDINAL32 * OutputSize;
CARDINAL32 * Error_Code;
} PassThru_Data_Record;
typedef struct {
char * Aggregate_Name;
BOOLEAN Name_Found;
} Aggregate_Name_Search_Record;
/*--------------------------------------------------
* Private Global Variables.
--------------------------------------------------*/
static BYTE Feature_Data_Buffer1[BYTES_PER_SECTOR * DRIVE_LINKING_RESERVED_SECTOR_COUNT ];
static BYTE Feature_Data_Buffer2[BYTES_PER_SECTOR * DRIVE_LINKING_RESERVED_SECTOR_COUNT ];
static BYTE Fake_EBR_Buffer[BYTES_PER_SECTOR];
static DLIST Aggregate_List = NULL;
static Plugin_Function_Table_V1 Function_Table;
static LVM_Common_Services_V1 * LVM_Common_Services;
static Feature_ID_Data Feature_ID_Record;
static panel_t DL_help_panel = {0};
static char ** DL_help_panel_text;
static panel_t DL_group_panel = {0};
static char ** DL_group_panel_text;
static panel_t message_bar_panel = {0};
static char *message_bar_panel_text[2] = {NULL, NULL};
static unsigned int DL_group_panel_cursor = 0;
static unsigned int DL_group_partition_count;
static DLink_Comm_Struct *pDLink;
static int DL_cur_aggregate_number;
static unsigned int *DL_group_panel_state;
/*--------------------------------------------------
* Private functions.
--------------------------------------------------*/
static void _System Create_Aggregates( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static BOOLEAN _System Eliminate_Bad_Aggregates( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, BOOLEAN * FreeMemory, CARDINAL32 * Error_Code);
static void _System Remove_Features_From_Aggregate_Partitions( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static BOOLEAN _System Delete_Partitions( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, BOOLEAN * FreeMemory, CARDINAL32 * Error_Code);
static void _System Find_Existing_Aggregate(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static void _System Write_Feature_Data(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static BOOLEAN Feature_Data_Is_Valid( BOOLEAN Primary );
static BOOLEAN Link_Tables_Match(Drive_Link_Array * LinkTable, BOOLEAN Copy_Instead, BOOLEAN Use_Primary_Buffer);
static void _System Initialize_DL_Partitions(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static void _System Calculate_Aggregate_Size(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error);
static void _System Set_Spanned_Volume_Flag(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error);
static void _System Discover_Drive_Links( DLIST Partition_List, CARDINAL32 * Error_Code );
static void _System Create_DL_Volume( DLIST Partition_List,
ADDRESS VData,
ADDRESS Init_Data,
void (* _System Create_and_Configure) ( CARDINAL32 ID, ADDRESS InputBuffer, CARDINAL32 InputBufferSize, ADDRESS * OutputBuffer, CARDINAL32 * OutputBufferSize, CARDINAL32 * Error_Code),
LVM_Classes Actual_Class, /* Tells the feature what class it is being used in on this volume. Useful for features that can be in multiple classes. */
BOOLEAN Top_Of_Class, /* TRUE if this feature is the topmost feature in its class. The topmost aggregator must only turn out 1 aggregate! */
CARDINAL32 Sequence_Number,
CARDINAL32 * Error_Code );
static void _System Open_Feature( CARDINAL32 * Error_Code );
static void _System Close_Feature( void );
static BOOLEAN _System Can_Expand_DL_Volume( ADDRESS AData, CARDINAL32 * Feature_ID, CARDINAL32 * Error_Code );
static void _System Add_DL_Partition ( ADDRESS AData, ADDRESS PData, CARDINAL32 * Error_Code );
static void _System Delete_DL_Partition( ADDRESS AData, BOOLEAN Kill_Partitions, CARDINAL32 * Error_Code);
static void _System Commit_Drive_Linking_Changes( ADDRESS VData, ADDRESS PData, CARDINAL32 * Error_Code );
static void _System DL_Write( ADDRESS PData, LBA Starting_Sector, CARDINAL32 Sectors_To_Write, ADDRESS Buffer, CARDINAL32 * Error_Code);
static void _System DL_Read( ADDRESS PData, LBA Starting_Sector, CARDINAL32 Sectors_To_Read, ADDRESS Buffer, CARDINAL32 * Error_Code);
static void _System Remove_Features(ADDRESS Aggregate, CARDINAL32 * Error_Code);
static void _System ReturnCurrentClass( ADDRESS PartitionRecord, LVM_Classes * Actual_Class, BOOLEAN * Top_Of_Class, CARDINAL32 * Sequence_Number );
static void _System PassThru( CARDINAL32 Feature_ID, ADDRESS Aggregate, ADDRESS InputBuffer, CARDINAL32 InputSize, ADDRESS * OutputBuffer, CARDINAL32 * OutputSize, CARDINAL32 * Error_Code );
static BOOLEAN _System Load_Feature_Data(Partition_Data * PartitionRecord, Drive_Link_Array * LinkTable, CARDINAL32 * Error_Code);
static void _System Continue_PassThru(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static void _System Continue_Changes_Pending(ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static BOOLEAN _System Claim_Aggregate_Partitions( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, BOOLEAN * FreeMemory, CARDINAL32 * Error_Code);
static void _System Add_Partitions_To_Aggregate( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static void _System Fill_In_Comm_Buffer( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static BOOLEAN _System DL_ChangesPending(Partition_Data * PartitionRecord, CARDINAL32 * Error_Code);
static void _System DL_ParseCommandLineArguments(DLIST Token_List, LVM_Classes * Actual_Class, ADDRESS * Init_Data, char ** Error_Message, CARDINAL32 * Error_Code );
static void _System Find_Duplicate_Aggregate_Names( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static void Parse_Partition_List( DLIST Token_List, DLIST Potential_Aggregates, CARDINAL32 Current_Aggregate, LVM_Token * Aggregate_Name_Token, char ** Error_Message, CARDINAL32 * Error_Code);
static void _System Transfer_To_Comm_Buffer( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static LVM_Token * GetToken(DLIST Token_List, BOOLEAN CurrentToken, CARDINAL32 * Error_Code);
static LVM_Token * LookAhead(DLIST Token_List, CARDINAL32 Count, CARDINAL32 * Error_Code);
static void _System Find_Partition_By_Name( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
static void _System Find_Duplicate_ANames( ADDRESS Object, TAG ObjectTag, CARDINAL32 ObjectSize, ADDRESS ObjectHandle, ADDRESS Parameters, CARDINAL32 * Error_Code);
void _System VIO_Help_Panel (CARDINAL32 Help_Index, CARDINAL32 * Error_Code);
void _System VIO_Create_and_Configure ( CARDINAL32 ID, ADDRESS InputBuffer, CARDINAL32 InputBufferSize, ADDRESS * OutputBuffer, CARDINAL32 * OutputBufferSize, CARDINAL32 * Error_Code);
unsigned int _System Create_and_Configure_callback (panel_t *panel);
void Init_VIO_Help_Panel(void);
unsigned long VIO_ShowMessageBar(unsigned long message_number);
void VIO_ClearMessageBar(void);
void get_char_message ( char *memory, /* user supplied memory */
uint message_number,
char *array,
uint array_length );
char * get_line_message ( char *memory, /* user supplied memory */
uint message_number);
void * get_help_message ( uint message_number );
bool MoveMenuCursor( unsigned int cur_position,
unsigned int *new_position,
unsigned int *menu_state,
int count,
bool bForward);
/*--------------------------------------------------
* There are no additional public global variables
* beyond those declared in "engine.h".
--------------------------------------------------*/
/*--------------------------------------------------
* Public Functions Available
--------------------------------------------------*/
static void _System Discover_Drive_Links( DLIST Partition_List, CARDINAL32 * Error_Code )
{
CARDINAL32 Dlist_Error;
Aggregate_Validation_Record Validation_Record;
BOOLEAN Aggregates_Created = FALSE;
FEATURE_FUNCTION_ENTRY("Discover_Drive_Links")
/* Is logging active? */
if ( LVM_Common_Services->Logging_Enabled )
{
if ( ( Partition_List == NULL ) || ( Error_Code == NULL) )
{
sprintf(LVM_Common_Services->Log_Buffer,"Discover_Drive_Links has been invoked with one or more NULL pointers!\n Partition_List is %X (hex)\n Error_Code is %X (hex)", Partition_List, Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
}
/* Assume success. */
*Error_Code = LVM_ENGINE_NO_ERROR;
/* We must look at each item in the partitions list. This includes reading in and validating the feature data. */
LVM_Common_Services->ForEachItem( Partition_List, &Create_Aggregates, Error_Code, TRUE, &Dlist_Error);
/* Did we succeed? */
if ( *Error_Code != LVM_ENGINE_NO_ERROR )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"PruneList failed while creating aggregates.\n LVM error code %d (decimal)", *Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
if ( Dlist_Error != DLIST_SUCCESS )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"PruneList failed while creating aggregates.\n DLIST error code %d (decimal)", Dlist_Error);
LVM_Common_Services->Write_Log_Buffer();
}
if ( Dlist_Error != DLIST_OUT_OF_MEMORY )
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
else
*Error_Code = LVM_ENGINE_OUT_OF_MEMORY;
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
/* Now we must eliminate any incomplete Aggregates. */
Validation_Record.Partition_List = Partition_List;
Validation_Record.Volume_Created = FALSE;
Validation_Record.Error_Code = Error_Code;
/* Find and eliminate incomplete aggregates. */
LVM_Common_Services->PruneList( Aggregate_List, &Eliminate_Bad_Aggregates, &Validation_Record, &Dlist_Error);
/* Did we succeed? */
if ( ( *Error_Code != LVM_ENGINE_NO_ERROR ) && ( *Error_Code != LVM_ENGINE_PLUGIN_OPERATION_INCOMPLETE ) )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"PruneList failed while eliminating bad aggregates.\n LVM error code %d (decimal)", *Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
if ( Dlist_Error != DLIST_SUCCESS )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"PruneList failed while eliminating bad aggregates.\n DLIST error code %d (decimal)", Dlist_Error);
LVM_Common_Services->Write_Log_Buffer();
}
if ( Dlist_Error != DLIST_OUT_OF_MEMORY )
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
else
*Error_Code = LVM_ENGINE_OUT_OF_MEMORY;
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
/* Are there any complete aggregates in the Aggregate_List? */
if ( LVM_Common_Services->GetListSize(Aggregate_List, &Dlist_Error) == 0 )
{
if ( Dlist_Error != DLIST_SUCCESS )
{
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
}
else
Aggregates_Created = TRUE;
/* Now we must add the list of Aggregates to the List of Partitions. */
LVM_Common_Services->AppendList(Partition_List, Aggregate_List, &Dlist_Error);
/* Did we succeed? */
if ( Dlist_Error != DLIST_SUCCESS )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"AppendList failed with DLIST error code %d (decimal)", Dlist_Error);
LVM_Common_Services->Write_Log_Buffer();
}
if ( Dlist_Error != DLIST_OUT_OF_MEMORY )
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
else
*Error_Code = LVM_ENGINE_OUT_OF_MEMORY;
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
/* Indicate success and return. */
/* Were any aggregates created? */
if ( Aggregates_Created )
*Error_Code = LVM_ENGINE_NO_ERROR; /* At least 1 aggregate was created! */
else
*Error_Code = LVM_ENGINE_PLUGIN_OPERATION_INCOMPLETE; /* No aggregates could be created! */
FEATURE_FUNCTION_EXIT("Discover_Drive_Links")
return;
}
static void _System Open_Feature( CARDINAL32 * Error_Code )
{
FEATURE_FUNCTION_ENTRY("Open_Feature")
/* Is logging active? */
if ( LVM_Common_Services->Logging_Enabled )
{
if ( Aggregate_List != NULL )
{
sprintf(LVM_Common_Services->Log_Buffer,"Open_Feature has been invoked on drive linking, \n but drive linking is already open!");
LVM_Common_Services->Write_Log_Buffer();
}
if ( Error_Code == NULL )
{
sprintf(LVM_Common_Services->Log_Buffer,"Open_Feature for drive linking has been invoked with a NULL pointer!\n Error_Code is %X (hex)", Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
}
if ( Aggregate_List == NULL )
{
/* Initialize the Aggregate_List. */
Aggregate_List = LVM_Common_Services->CreateList();
if ( Aggregate_List == NULL )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Unable to create the Aggregate_List. Out of memory!");
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_OUT_OF_MEMORY;
}
else
*Error_Code = LVM_ENGINE_NO_ERROR;
}
else
*Error_Code = LVM_ENGINE_NO_ERROR;
FEATURE_FUNCTION_EXIT("Open_Feature")
return;
}
static void _System Close_Feature( void )
{
CARDINAL32 LocalError;
FEATURE_FUNCTION_ENTRY("Close_Feature")
/* Free up the memory associated with the global variable Aggregate_List. */
if ( Aggregate_List != NULL )
LVM_Common_Services->DestroyList(&Aggregate_List,TRUE, &LocalError);
FEATURE_FUNCTION_EXIT("Close_Feature")
return;
}
static BOOLEAN _System Can_Expand_DL_Volume( ADDRESS AData, CARDINAL32 * Feature_ID, CARDINAL32 * Error_Code )
{
Partition_Data * Aggregate = (Partition_Data *) AData;
Drive_Link_Array * LinkTable;
BOOLEAN ReturnValue = FALSE;
FEATURE_FUNCTION_ENTRY("Can_Expand_DL_Volume")
/* Is logging active? */
if ( LVM_Common_Services->Logging_Enabled )
{
if ( ( AData == NULL ) || ( Error_Code == NULL) )
{
sprintf(LVM_Common_Services->Log_Buffer,"Can_Expand_DL_Volume has been invoked with one or more NULL pointers!\n AData is %X (hex)\n Error_Code is %X (hex)", AData, Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
else
{
sprintf(LVM_Common_Services->Log_Buffer,
"Can_Expand_DL_Volume has been invoked with the following parameters.\n The partition specified has handle %X (hex)\n Error_Code is at address %X (hex)",
Aggregate->External_Handle,
Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
}
#ifdef DEBUG
#ifdef PARANOID
assert(Aggregate != NULL);
assert(Aggregate->Feature_Data != NULL);
assert(Aggregate->Feature_Data->Data != NULL);
#else
if ( ( Aggregate == NULL) ||
( Aggregate->Feature_Data == NULL) ||
( Aggregate->Feature_Data->Data == NULL)
)
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Invalid Aggregate specified!");
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Can_Expand_DL_Volume")
return FALSE;
}
#endif
#endif
/* Set the Feature_ID. */
*Feature_ID = DRIVE_LINKING_FEATURE_ID;
/* Get the drive linking table. */
LinkTable = (Drive_Link_Array *) Aggregate->Feature_Data->Data;
/* Check the Links_In_Use field of the link table. If it is less than MAXIMUM_LINKS - 1, then we can expand. */
if ( LinkTable->Links_In_Use < ( MAXIMUM_LINKS - 1 ) )
ReturnValue = TRUE;
else
ReturnValue = FALSE;
if ( LVM_Common_Services->Logging_Enabled )
{
if ( ReturnValue )
sprintf(LVM_Common_Services->Log_Buffer,"The volume can be expanded!");
else
sprintf(LVM_Common_Services->Log_Buffer,"The volume can NOT be expanded!");
LVM_Common_Services->Write_Log_Buffer();
}
/* Indicate success and return. */
*Error_Code = LVM_ENGINE_NO_ERROR;
FEATURE_FUNCTION_EXIT("Can_Expand_DL_Volume")
return ReturnValue;
}
static void _System Delete_DL_Partition( ADDRESS AData, BOOLEAN Kill_Partitions, CARDINAL32 * Error_Code)
{
Partition_Data * Aggregate = (Partition_Data *) AData;
CARDINAL32 Dlist_Error;
Partition_Deletion_Record Deletion_Data;
Drive_Link_Array * LinkTable;
FEATURE_FUNCTION_ENTRY("Delete_DL_Partition")
/* Is logging active? */
if ( LVM_Common_Services->Logging_Enabled )
{
if ( ( AData == NULL ) || ( Error_Code == NULL) )
{
sprintf(LVM_Common_Services->Log_Buffer,"Delete_DL_Partition has been invoked with one or more NULL pointers!\n AData is %X (hex)\n Error_Code is %X (hex)", AData, Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
else
{
sprintf(LVM_Common_Services->Log_Buffer,
"Delete_DL_Partition has been invoked with the following parameters.\n The Volume specified has handle %X (hex)\n Kill_Partitions is %X (hex)\n Error_Code is at address %X (hex)",
Aggregate->Volume_Handle,
Kill_Partitions,
Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
}
/* Does this partition have an LVM Signature Sector? */
if ( Aggregate->Signature_Sector != NULL )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Killing the LVM Signature Sector of the Aggregate.");
LVM_Common_Services->Write_Log_Buffer();
}
/* Now free the memory. */
memset(Aggregate->Signature_Sector,0, BYTES_PER_SECTOR);
LVM_Common_Services->Deallocate(Aggregate->Signature_Sector);
}
/* Remove the Aggregate from the list of Aggregates. */
LVM_Common_Services->DeleteItem(LVM_Common_Services->Aggregates, FALSE, Aggregate->Drive_Partition_Handle, &Dlist_Error);
if ( Dlist_Error != DLIST_SUCCESS )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"DeleteItem failed while removing an aggregate from the list of aggregates.\n The DLIST Error code is %d (decimal)", Dlist_Error);
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Delete_DL_Partition")
return;
}
/* Since this is an aggregate, we must walk the Partitions list and delete each of the Partitions which comprise this aggregate. */
Deletion_Data.LVM_Error = LVM_ENGINE_NO_ERROR;
Deletion_Data.Kill_Partitions = Kill_Partitions;
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Deleting the partitions which formed the Aggregate.");
LVM_Common_Services->Write_Log_Buffer();
}
LVM_Common_Services->PruneList(Aggregate->Feature_Data->Partitions, &Delete_Partitions, &Deletion_Data, &Dlist_Error);
if ( ( Dlist_Error != DLIST_SUCCESS ) && ( Deletion_Data.LVM_Error != LVM_ENGINE_NO_ERROR ) )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"PruneList failed while deleting partitions.\n The LVM Error code is %d (decimal)\n The DLIST Error code is %d (decimal)", *Error_Code, Dlist_Error);
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Delete_DL_Partition")
return;
}
/* Now free the memory. */
LVM_Common_Services->DestroyList(&(Aggregate->Feature_Data->Partitions), FALSE, &Dlist_Error);
if ( Dlist_Error != DLIST_SUCCESS )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"DestroyList failed with DLIST error %d (decimal)", Dlist_Error);
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Delete_DL_Partition")
return;
}
/* We must see if there is anything in the LinkTable to delete. */
/* Get the LinkTable. */
LinkTable = Aggregate->Feature_Data->Data;
/* Is there a Fake EBR associated with this aggregate? */
if ( LinkTable->Fake_EBR_Buffer != NULL )
{
/* Free the fake EBR. */
LVM_Common_Services->Deallocate(LinkTable->Fake_EBR_Buffer);
}
/* Now free the Link Table. */
LVM_Common_Services->Deallocate(Aggregate->Feature_Data->Data);
/* Now free the feature data. */
LVM_Common_Services->Deallocate(Aggregate->Feature_Data);
/* Free the aggregate's external handle. */
LVM_Common_Services->Destroy_Handle(Aggregate->External_Handle, Error_Code);
if ( *Error_Code != HANDLE_MANAGER_NO_ERROR )
{
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Delete_DL_Partition")
return;
}
/* Now we can free the aggregate. */
LVM_Common_Services->Deallocate(Aggregate);
*Error_Code = LVM_ENGINE_NO_ERROR;
FEATURE_FUNCTION_EXIT("Delete_DL_Partition")
return;
}
static void _System Create_DL_Volume( DLIST Partition_List,
ADDRESS VData,
ADDRESS Init_Data,
void (* _System Create_and_Configure) ( CARDINAL32 ID, ADDRESS InputBuffer, CARDINAL32 InputBufferSize, ADDRESS * OutputBuffer, CARDINAL32 * OutputBufferSize, CARDINAL32 * Error_Code),
LVM_Classes Actual_Class, /* Tells the feature what class it is being used in on this volume. Useful for features that can be in multiple classes. */
BOOLEAN Top_Of_Class, /* TRUE if this feature is the topmost feature in its class. The topmost aggregator must only turn out 1 aggregate! */
CARDINAL32 Sequence_Number,
CARDINAL32 * Error_Code )
{
Partition_Data * Aggregate;
Volume_Data * VolumeRecord = (Volume_Data*) VData;
LVM_Signature_Sector * Signature_Sector;
Drive_Link_Array * LinkTable;
CARDINAL32 Ignore_Error;
CARDINAL32 Comm_Buffer_Size;
DLink_Comm_Struct * Comm_Buffer = NULL; /* Used to communicate with the JAVA and VIO interface portions of this plug-in. */
DLIST Partitions_To_Use = (DLIST) NULL;
CARDINAL32 Aggregate_Count = 0;
CARDINAL32 Partition_Count;
CARDINAL32 Index;
Aggregate_Name_Search_Record Duplicate_Name_Data; /* Used to check for a duplicate aggregate name in the Partitions_List. */
char * Current_Aggregate_Name; /* Used to hold the name of the aggregate being created. */
BOOLEAN Process_Aggregate = TRUE;
BOOLEAN Make_One_Aggregate = FALSE; /* Set to TRUE if we are to put all partitions into one aggregate. */
FEATURE_FUNCTION_ENTRY("Create_DL_Volume")
/* Is logging active? */
if ( LVM_Common_Services->Logging_Enabled )
{
if ( ( Partition_List == NULL ) || ( VData == NULL ) || ( Error_Code == NULL) )
{
sprintf(LVM_Common_Services->Log_Buffer,"Create_DL_Volume has been invoked with one or more NULL pointers!\n Partition_List is %X (hex)\n VData is %X (hex)\n Error_Code is %X (hex)", Partition_List, VData, Error_Code);
LVM_Common_Services->Write_Log_Buffer();
}
if ( Actual_Class != Aggregate_Class )
{
sprintf(LVM_Common_Services->Log_Buffer,"Create_DL_Volume has been invoked with an invalid class!");
LVM_Common_Services->Write_Log_Buffer();
}
}
if ( Actual_Class != Aggregate_Class )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"The wrong LVM Class was specified for this feature!");
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_WRONG_CLASS_FOR_FEATURE;
FEATURE_FUNCTION_EXIT("Create_DL_Volume")
return;
}
/* How many partitions are in the Partition_List? */
Partition_Count = LVM_Common_Services->GetListSize(Partition_List, Error_Code);
if ( *Error_Code != LVM_ENGINE_NO_ERROR )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Unable to get the size of the Partition_List!");
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Create_DL_Volume")
return;
}
/* If we are not the topmost aggregator, then we must interface with the user to see what the user wants unless we have been given an initialization buffer. */
if ( ( ! Top_Of_Class ) &&
( Partition_Count > 1 )
)
{
/* Were we given an initialization buffer? */
if ( Init_Data != NULL )
{
/* We were given an initialization buffer. This initialization buffer is in the same format as the communication
buffer used with the Create_and_Configure function. We will set Comm_Buffer to the same address as Init_Data
and pretend we received the contents of Comm_Buffer from the Create_and_Configure function. */
Comm_Buffer = (DLink_Comm_Struct *) Init_Data;
}
else
{
/* We must build the Comm_Buffer and call the Create_and_Configure function. */
/* Allocate memory for the Comm_Buffer. */
Comm_Buffer_Size = sizeof(DLink_Comm_Struct) + ( ( Partition_Count - 1 ) * sizeof( DLink_Partition_Array_Entry ) );
Comm_Buffer = (DLink_Comm_Struct *) LVM_Common_Services->Allocate( Comm_Buffer_Size );
if ( Comm_Buffer == NULL )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Unable to allocate memory for the Comm_Buffer!");
LVM_Common_Services->Write_Log_Buffer();
}
*Error_Code = LVM_ENGINE_OUT_OF_MEMORY;
FEATURE_FUNCTION_EXIT("Create_DL_Volume")
return;
}
/* Now clear the Comm_Buffer. */
memset(Comm_Buffer,0,Comm_Buffer_Size);
/* Now fill in the Comm_Buffer. */
Comm_Buffer->Count = 0;
Comm_Buffer->Sequence_Number = VolumeRecord->Next_Aggregate_Number;
LVM_Common_Services->ForEachItem(Partition_List, &Fill_In_Comm_Buffer, Comm_Buffer, TRUE, Error_Code);
if ( *Error_Code != DLIST_SUCCESS )
{
if ( LVM_Common_Services->Logging_Enabled )
{
sprintf(LVM_Common_Services->Log_Buffer,"Error filling in the Comm_Buffer!");
LVM_Common_Services->Write_Log_Buffer();
}
LVM_Common_Services->Deallocate(Comm_Buffer);
*Error_Code = LVM_ENGINE_INTERNAL_ERROR;
FEATURE_FUNCTION_EXIT("Create_DL_Volume")
return;
}
/* Now call the create and configure function. */
Create_and_Configure( DRIVE_LINKING_FEATURE_ID, Comm_Buffer, Comm_Buffer_Size, NULL, NULL, Error_Code );
if ( *Error_Code != LVM_ENGINE_NO_ERROR )
{
if ( LVM_Common_Services->Logging_Enabled )
{