Code

Added some comments to the new FAIpartition handling
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiDiskEntry.inc
1 <?php
3 class faiDiskEntry extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes   = array("DISKcn","DISKdescription");
8   var $UsedAttrs            = array("cn","description","FAIpartitionType",
9       "FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize",
10       "FAIfsTuneOptions", "FAIfsCreateOptions", "FAImountOptions",
11       "FAIfsOptions","FAIpartitionFlags","FAIdiskOption");
13   var $objectclasses= array();
15   var $DISKcn              = "";
16   var $DISKdescription     = "";
17   var $DISKFAIdiskOptions  = "";
18   
19   var $partitions          = array();
20   var $is_edit             = false;
21   var $old_cn              = "";
22   var $status              = "new";
23   var $deletePartitions    = array();
24   var $fstabkey            = "device";
25   var $disklabel           = "msdos";
26   var $FAIstate            = "";
27   var $FAIdiskType         = "disk";
28   
29   var $lvmDevices          = array();
31   function faiDiskEntry (&$config, $dn= NULL,$parent,$disk,$type)
32   {
33     plugin::plugin ($config, $dn);
34   
35     // Set default attributes 
36     $this->parent = $parent;
37     $this->FAIdiskType = $type;
38     $this->status = "new";    
40     // If disk is not empty, then we are going to edit 
41     //  an existing disk, load disk info now. 
42     if($disk){
44       // Get devices used in volume base disks.
45       if(isset($disk['FAIlvmDevice'])){
46         $this->lvmDevices = $disk['FAIlvmDevice'];
47       }
49       // Get disk status
50       $this->status = $disk['status'];
52       // Load default attributes 
53       $this->DISKcn          = $disk['cn'];
54       $this->DISKdescription = $disk['description'];
55       $this->is_edit         = true;
56       $this->old_cn          = $disk['cn'];
58       // Load partition info 
59       foreach($disk['partitions'] as $name => $values){
61         // Do not load removed partitions 
62         if($values['status'] == "delete"){
63           unset($disk['partitions'][$name]);
64           $this->deletePartitions[]=$values;
65         }else{
67           /* If the partition status is not 'new', then set it to 'edit'. 
68            * New means that this partition wasn't saved to ldap, yet.
69            */
70           if($disk['partitions'][$name]['status']!="new"){
71             $disk['partitions'][$name]['status']="edited";
72           }
73     
74           // Load partition attributes  
75           $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
76           $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
77           foreach($this->UsedAttrs as $attr){
78             if(!isset($values[$attr])){
79               $disk['partitions'][$name][$attr]="";  
80             }
81           }
82       
83           if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
84             $disk['partitions'][$name]['FAIfsType']= 
85               preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
86           }
87         }
88       }
90       $this->partitions      = $disk['partitions'];
92       /* Load FAIdiskOptions.
93        * Some options are disk related and others are used for partitions.
94        *  - fstabkey    -> disk
95        *  - disklabel   -> disk
96        *  - bootable    -> partition
97        *  - preserve    -> partition
98        *  - resize      -> partition
99        */
100       if (isset($disk['FAIdiskOption'])){
101         foreach($disk['FAIdiskOption'] as $option) {
103           // Get fstab key  
104           if (preg_match("/fstabkey:(device|label|uuid)/", $option)){
105             $this->fstabkey= preg_replace("/^.*fstabkey:(device|label|uuid).*$/", "$1", $option);
106             continue;
107           }
109           // Get disk label
110           if (preg_match("/disklabel:(msdos|gpt)/", $option)){
111             $this->disklabel= preg_replace("/^.*disklabel:(msdos|gpt).*$/", "$1", $option);
112             continue;
113           }
115           // Load bootable flag for partitions 
116           if (preg_match("/^bootable:/", $option)){
117             $bootable = split(",", trim(preg_replace("/^bootable:/","",$option),","));
118             foreach($bootable as $bootflag){
119               if(isset($this->partitions[$bootflag])){
120                 $this->partitions[$bootflag]['bootable'] = TRUE;  
121               }
122             }
123             continue;
124           }
126           // Load resize flag for partitions 
127           if (preg_match("/^resize:/", $option)){
128             $resize = split(",", trim(preg_replace("/^resize:/","",$option),","));
129             foreach($resize as $id){
130               if(isset($this->partitions[$id])){
131                 $this->partitions[$id]['resize'] = TRUE;  
132               }
133             }
134             continue;
135           }
137           // Load preserve_always flag for partitions 
138           if (preg_match("/^preserve_always:/", $option)){
139             $preserve = split(",", trim(preg_replace("/^preserve_always:/","",$option),","));
140             foreach($preserve as $presflag){
141               if(isset($this->partitions[$presflag])){
142                 $this->partitions[$presflag]['preserve'] = TRUE;  
143                 $this->partitions[$presflag]['preserveType'] = 'always';  
144               }
145             }
146             continue;
147           }
149           // Load preserve_reinstall flag for partitions 
150           if (preg_match("/^preserve_reinstall:/", $option)){
151             $preserve = split(",", trim(preg_replace("/^preserve_reinstall:/","",$option),","));
152             foreach($preserve as $presflag){
153               if(isset($this->partitions[$bootflag])){
154                 $this->partitions[$presflag]['preserve'] = TRUE;  
155                 $this->partitions[$presflag]['preserveType'] = 'reinstall'; 
156               } 
157             }
158             continue;
159           }
160         }
161       } else {
162         $this->fstabkey= "device";
163       }
164     }
165   }
168   function execute()
169   {
170     /* Call parent execute */
171     plugin::execute();
173     // Fill templating stuff
174     $smarty     = get_smarty();
175     $s_action   = "";
176     $s_entry    = "";
177     $display    = "";
179     // Add partition to lvm compilation.
180     if(isset($_POST['addLvmPartition']) && isset($_POST['lvmPartitionAdd'])){
181       $name = get_post('lvmPartitionAdd');
182       $this->lvmDevices[$name] = $name;
183     }
185     // Remove partition from lvm compilation.
186     if(isset($_POST['delLvmPartition']) && isset($_POST['physicalPartition'])){
187       $names = $_POST['physicalPartition'];
188       foreach($names as $name){
189         if(isset($this->lvmDevices[$name])){
190           unset($this->lvmDevices[$name]);
191         }
192       }
193     }
195     /* Check all Posts if there is something usefull for us,
196      * For example : Delete is posted as Delete_1 
197      * The number specifies the index we want to delete
198      */
199     foreach($_POST as $name => $value){
200       if((preg_match("/RemovePartition_/",$name)) && 
201           $this->acl_is_removeable() && 
202           !preg_match("/freeze/i",$this->FAIstate)){
203         $tmp = split("_",$name);
204         $this->removePartition($tmp[1]);
205         break;
206       }
207       if(preg_match("/^EditPartition_/",$name)){
208         $id = preg_replace("/^EditPartition_/","",$name);
209         $id = preg_replace("/_.*$/","",$id);
210         if(isset($this->partitions[$id])){
211           $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
212           break;
213         }
214       } 
215     }
217     /* Act on _GET edit request
218      */
219     if(isset($_GET['act']) && $_GET['act'] == "editPart" && isset($_GET['id'])){
220       $id = $_GET['id'];
221       if(isset($this->partitions[$id])){
222         $this->dialog = new faiPartition($this->config,$this->partitions[$id], $this,$this->FAIdiskType);
223       }
224     }
226     /* Create a new partition for this disk.
227      */
228     if(isset($_POST['AddPartition']) && !preg_match("/freeze/i",$this->FAIstate)){
229       $this->dialog = new faiPartition($this->config, array(), $this,$this->FAIdiskType);
230     }
232     /* Handle partition dialogs.
233      */
234     if($this->dialog instanceOf plugin && isset($_POST['PartitionCancel'])){
235       $this->dialog = null;
236     }
237     if($this->dialog instanceOf plugin && isset($_POST['PartitionSave'])){
238       $this->dialog->save_object();
240       // Validate new partition
241       $new_partition = $this->dialog->save(); 
242       $msgs = $this->dialog->check();
243       $msgs = array_merge($msgs,$this->check_disks($new_partition));
245       if(!count($msgs)){
246         $this->updatePartition($new_partition);
247         $this->dialog = null;
248       }else{
249         msg_dialog::displayChecks($msgs);
250       }
251     }
252     if($this->dialog instanceOf plugin){
253       $this->dialog->save_object();
254       return($this->dialog->execute());
255     }
257     // Assign checkbox related values.
258     foreach($this->attributes as $attrs){
259       $smarty->assign($attrs,$this->$attrs);
260       if($this->$attrs){
261         $smarty->assign($attrs."CHK"," ");
262       }else{
263         $smarty->assign($attrs."CHK"," disabled ");
264       }
265     }
267     // Assign disk info to smarty.
268     $smarty->assign("setup", $this->generateParts());
269     $smarty->assign("sub_object_is_createable",$this->acl_is_createable());
270     $smarty->assign("freeze",preg_match("/freeze/i",$this->FAIstate));
271     $smarty->assign("fstabkeys", array("device" => _("Device"), "label" => _("Label"), "uuid" => _("UUID")));
272     $smarty->assign("disklabels", array("msdos" => "MSDOS", "gpt" => "GPT"));
273     $smarty->assign("fstabkey", $this->fstabkey);
274     $smarty->assign("disklabel", $this->disklabel);
275     $smarty->assign("FAIdiskType", $this->FAIdiskType);
276     $smarty->assign("plist", $this->getPartitionList());
277     $smarty->assign("physicalPartitionList", $this->getAvailablePartitions());
279     foreach($this->attributes as $attr){
280       $smarty->assign($attr,$this->$attr);
281     }
283     // Assign partitions
284     $tmp = $this->plInfo();
285     $sacl = "";
286     foreach($tmp['plProvidedAcls'] as $name => $translated){
287       $acl = $this->getacl($name, preg_match("/freeze/i",$this->FAIstate));
288       $smarty->assign($name."ACL",$acl);
289     }
290    
291     $display.= $smarty->fetch(get_template_path('faiDiskEntry.tpl', TRUE));
292     return($display);
293   }
296   /* Creates a human readable list, that contains all physical 
297    *  devices that are used by a volume group.
298    * This list will then be displayed in a html select box.
299    * (lvm)
300    */
301   function getPartitionList()
302   {
303     $divlist = new divSelectBox("RaidList");
305     /* Create a list of all available disks and partitions. 
306      * This list will then be used to display detailed info.
307      */
308     $disks = $this->parent->disks;
309     foreach($disks as $dname => $disk){
311       // Skip currently edited disk 
312       if($disk['cn'] == $this->old_cn) continue;
313    
314       // Add disk 
315       $objs[$dname] = $disk;
317       // Add disk partitions
318       foreach($disk['partitions'] as $id => $part){
319         $part['parentDisk'] = $disk;
320         $objs[$part['cn']] = $part;
321       }
322     }
324     // Attach current disk setup to the details list.
325     $data = $this->save();
326     $objs[$data['cn']] = $data;
327     foreach($data['partitions'] as $part){
328       $part['parentDisk'] = $data;
329       $objs[$part['cn']] = $part;
330     }
332     // Walk through physical partition combinations and build up 
333     //  user friendly list with partition details.
334     $list = array();
335     foreach($this->lvmDevices as $device){
337       // We've a html select box here, add spaces for better readability
338       $str = $device;
339       $str = preg_replace("/ /","&nbsp;",str_pad($str,20," "));
341       // Add disk/partition details.
342       if(isset($objs[$device])){
343         if(isset($objs[$device]['FAIpartitionSize'])){
344           if($objs[$device]['parentDisk']['FAIdiskType'] == "raid"){
345             $str .= _("Disks").":&nbsp;";
346             $str .= preg_replace("/(:spare|:missing)/i","",$objs[$device]['FAIpartitionSize']);
347           }else{
348             $str .= _("Size").":&nbsp;";
349             $str .= $objs[$device]['FAIpartitionSize'];
350           } 
351         }
352       }
353       $list[$device] = $str;
354     }
355     return($list);
356   }
358  
359   /* Returns a list of available partitions that are useable in 
360    *  lvm disk setups.
361    */ 
362   function getAvailablePartitions()
363   {
364     $array = array();
365     foreach($this->parent->disks as $disk){
367       // We can't add ourselves to the available partitions
368       if($disk['cn'] == $this->old_cn) continue;
370       // Add partitions to the list.
371       foreach($disk['partitions'] as $key => $part){
372         $name = $part['cn'];
373         if(!isset($this->lvmDevices[$name])){
374           $array[$name] = $name;
375         }
376       }
377     }
378     return($array);
380   }
383   /* Remove the selected partition and shift the following partitions 
384    *  to fill the gap.
385    * Additionally update the partition numbers correspondingly.
386    *  (Checks if the partition is in use, too)
387    */
388   function removePartition($id)
389   {
390     $start = false;
392     /* Create a list of all partitions that are used in
393      *  lvm or raid compilations.
394      */
395     $list = array();
396     foreach($this->parent->disks as $dname => $disk){
397       if($disk['FAIdiskType'] != "disk"){
398         if($disk['status'] == "delete") continue;
399         if($disk['FAIdiskType'] == "lvm"){
400           foreach($disk['FAIlvmDevice'] as $partname){
401             $list[preg_replace("/:.*$/","",$partname)][] = $disk;
402           }
403         }
404         foreach($disk['partitions'] as $partkey => $part){
405           if($part['status'] == "delete") continue;
406           if($disk['FAIdiskType'] == "raid"){
407             foreach(split(",",$part['FAIpartitionSize']) as $partname){
408               $list[preg_replace("/:.*$/","",$partname)][] = $disk;
409             }
410           }
411         }
412       }
413     }
415     /* Now that we've a list of all partition references, lets check if
416      *  one of the partitions we are going to remove is still in use.
417      */
418     if(isset($list[$this->partitions[$id]['cn']])){
419       $used = array();
420       foreach($list[$this->partitions[$id]['cn']] as $disk){
421         $used[$disk['cn']] = $disk['cn'];
422       }
423       $used = implode(",",$used);
424       msg_dialog::display(_("Error"),
425           sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"),
426             $used), ERROR_DIALOG);
428     }else{
429       foreach($this->partitions as $key => $part){
430         if($id == $key){
431           $start = true;
432         }
433         if($start){
434           if($this->partitions[$key]['status'] == "edited"){
435             $this->deletePartitions[$key]= $this->partitions[$key];
436             $this->deletePartitions[$key]['FAIpartitionNr']=$key;
437             unset($this->partitions[$key]);
438           }else{
439             unset($this->partitions[$key]);
440           }
441           if(isset($this->partitions[($key+1)])){
442             if(isset($this->deletePartitions[$key])){
443               unset($this->deletePartitions[$key]);
444             }
445             $this->partitions[$key] = $this->partitions[($key+1)];
446             $this->partitions[$key]['FAIpartitionNr'] = $key;
447             $this->partitions[$key]['status'] = "new";
448           }
449         }
450       }
451       $tmp= array();
452       foreach($this->partitions as $part){
453         $tmp[count($tmp)+1]=$part;
454       }
455       $this->partitions = $tmp;
456     }
457   }
460   /* Add or update a partition 
461    */
462   function updatePartition($part)
463   {
464     if(!isset($part['FAIpartitionNr']) || $part['FAIpartitionNr'] == "undefined"){
465       $part['FAIpartitionNr'] = count($this->partitions) + 1;
466     }
468     /* Update the disk cn -       
469      * Do NOT touch the partition 'cn' in case of lvm or raid devices. 
470      */
471     if($this->FAIdiskType == "disk"){
472       $part['cn'] = $this->DISKcn.$part['FAIpartitionNr'];
473     }
475     /* Check if we've to update partition names of lvm compilations.
476      */ 
477     if($this->FAIdiskType == "lvm"){
478       if(isset($this->partitions[$part['FAIpartitionNr']])){
479         $old_cn = $this->partitions[$part['FAIpartitionNr']]['cn'];
480         $new_cn = $part['cn'];
481         if(isset($this->lvmDevices[$old_cn])){
482           unset($this->lvmDevices[$old_cn]);
483           $this->lvmDevices[$new_cn] = $new_cn;
484         }
485       }
486     }
488     /* Set raid names to md#
489      */ 
490     if($this->FAIdiskType == "raid"){
491       $part['cn'] = 'md'.$part['FAIpartitionNr'];
492     }
494     $this->partitions[$part['FAIpartitionNr']] = $part;
495   }
498   /* This method generates the partition listing with all necessary info,
499    *  depending on the disk type.
500    * The list is of type divSelectBox.
501    */
502   function generateParts()
503   {
504     $divlist = new divSelectBox("DiskEntries"); 
505     foreach($this->partitions as $key => $part){
507       // Create default table cols 
508       $cn =array(
509           "string" => "<a href='?plug=".$_GET['plug']."&amp;act=editPart&amp;id={$key}'>".$part['cn']."</a>",
510           "attach" => "style='width:160px;'");
511       $desc =array(
512           "string" => "<a href='?plug=".$_GET['plug']."&amp;act=editPart&amp;id={$key}'>".
513               $part['description']."</a>",
514           "attach" => "style='width:200px;'");
515       $number =array(
516           "string" => $part['FAIpartitionNr'],
517           "attach" => "style='width:20px;'");
518       $size   =array(
519           "string" => $part['FAIpartitionSize'],
520           "attach" => "style='width:100px;'");
521       $type   =array(
522           "string" => $part['FAIpartitionType'],
523           "attach" => "style='width:80px;'");
525       // Remove encryption info from the mount point.
526       $mnt = $part['FAImountPoint'];
527       if(preg_match("/:encrypt/", $mnt)){
528         $mnt = preg_replace("/:encrypt/","",$mnt);
529       }
530       $mntp   =array("string" => $mnt);
532       // create human readable strings out of the flags.
533       $opt = "";
534       if(isset($part['encrypted']) && $part['encrypted']){
535         $opt.= "&nbsp;"._("encrypted").", ";
536       }      
537       if(isset($part['bootable']) && $part['bootable']){
538         $opt.= "&nbsp;"._("bootable").", ";
539       }      
540       if(isset($part['preserve']) && $part['preserve']){
541         $opt.= "&nbsp;"._("preserve").":&nbsp;".$part['preserveType'].", ";
542       }     
544       // Combine options to a single table col. 
545       $opt    =array(
546           "string" => "<i>".preg_replace('/, $/',"",$opt)."</i>");
548       // Depending on the FAIstatus (freeze?) we will display different options. 
549       // We can't remove freezed branches -> Hide remove button.
550       if(!preg_match("/freeze/", $this->FAIstate)){
551         $action =array(
552             "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>".
553             "<input type='image' src='images/lists/trash.png' name='RemovePartition_".$key."'>",
554             "attach" => "style='width:40px; border-right: 0px;'");
555       }else{
556         $action =array(
557             "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>",
558             "attach" => "style='width:40px; border-right: 0px;'");
559       }
561       // Build up info table, depending on the disk type. 
562       if($this->FAIdiskType == "lvm"){ 
563         $fields = array($cn,$desc,$mntp,$opt,$size, $action);
564       }elseif($this->FAIdiskType == "raid"){
565         $raid_str = $part['FAIpartitionType']." (".$part['FAIpartitionSize'].")";
566         $raid = array("string" => $raid_str);
567         $fields = array($cn,$desc,$raid,$mntp,$opt,$action);
568       }else{
569         $fields = array($number,$desc,$type,$mntp,$opt,$size,$action);
570       }
571       $divlist->AddEntry($fields);
572     }
573     return($divlist->DrawList());    
574   }
577   function save()
578   {
579     $tmp = array();
580     $tmp['cn']          = $this->DISKcn;
582     /* Attach partitions. 
583      * And prepare names and numbers.
584      */
585     foreach($this->partitions as $key=>$val) {
586       $this->partitions[$key]['FAIpartitionNr']=$key;
587       if($this->FAIdiskType == "disk"){
588         $this->partitions[$key]['cn'] = $this->DISKcn.$key;
589       }elseif($this->FAIdiskType == "lvm"){
590         $this->partitions[$key]['FAIpartitionType'] = 'lvm';
591       }
592     }
594     /* Attach deleted.
595      */
596     foreach($this->deletePartitions as $key=>$val) {
597       $this->partitions[$key."-delete"]=$val;
598       $this->partitions[$key."-delete"]['status']="delete";
599     }
601     $tmp['description'] = $this->DISKdescription;
602     $tmp['partitions']  = $this->partitions;
603     $tmp['status']      = $this->status;
604     $tmp['FAIdiskType'] = $this->FAIdiskType;
606     // Add lvm devices if available.
607     $tmp['FAIlvmDevice'] = array();
608     foreach($this->lvmDevices as $dev){
609       $tmp['FAIlvmDevice'][] = $dev;
610     } 
612     /* Assemble flags */
613     $tmp['FAIdiskOption'] = array("fstabkey:".$this->fstabkey, "disklabel:".$this->disklabel);
615     /* If hdd name has changed, tell partitionTable to rename it */
616     if(($this->is_edit)&&($this->old_cn != $this->DISKcn)){
617       $tmp['rename']['from']  = $this->old_cn;
618       $tmp['rename']['to']    = $this->DISKcn;
619     }
621     // Build up disk options 
622     $bootable = "";
623     $resize = "";
624     $preserve_always = "";
625     $preserve_reinstall = "";
627     /* Assemble boot, resize and preserve flags 
628      */
629     foreach($tmp['partitions'] as $id => $part){
630       if(isset($part['bootable']) && $part['bootable']){
631         $bootable .= $id.",";
632       }
633       if(isset($part['resize']) && $part['resize']){
634         $resize .= $id.",";
635       }
636       if(isset($part['preserve']) && $part['preserve']){
637         if($part['preserveType'] == "always"){
638           $preserve_always .= $id.",";
639         }else{
640           $preserve_reinstall .= $id.",";
641         }
642       }
643       $tmp['partitions'][$id]['status'] = $part['status'];
645       // Unset non valid attributes 
646       foreach(array("bootable","encrypted","preserve","preserveType","resize","FAIdiskType") as $attr){
647         if(isset($tmp['partitions'][$id][$attr])){
648           unset($tmp['partitions'][$id][$attr]);
649         }
650       }
651     }    
653     /* Assembe disk flags
654      */
655     if(!empty($bootable)){
656       $tmp['FAIdiskOption'][] = "bootable:".trim($bootable,",");
657     }
658     if(!empty($resize)){
659       $tmp['FAIdiskOption'][] = "resize:".trim($resize,",");
660     }
661     if(!empty($preserve_always)){
662       $tmp['FAIdiskOption'][] = "preserve_always:".trim($preserve_always,",");
663     }
664     if(!empty($preserve_reinstall)){
665       $tmp['FAIdiskOption'][] = "preserve_reinstall:".trim($preserve_reinstall,",");
666     }
668     $tmp['status'] = $this->status;
669     return($tmp);
670   }
673   /* Save data to object */
674   function save_object()
675   {
676     if((isset($_POST['TableEntryFrameSubmitted'])) && !preg_match("/freeze/", $this->FAIstate) ){
677       plugin::save_object();
679       // Save posted disk label and fstab key
680       if (isset($_POST['disklabel']) && preg_match("/^(msdos|gpt)$/", $_POST['disklabel'])){
681         $this->disklabel= $_POST['disklabel'];
682       }
683       if (isset($_POST['fstabkey']) && preg_match("/^(device|label|uuid)$/", $_POST['fstabkey'])){
684         $this->fstabkey= $_POST['fstabkey'];
685       }
686     }
687   }
690   /* Check supplied data */
691   function check()
692   {
693     /* Call common method to give check the hook */
694     $message= plugin::check();
695   
696     /* Check for an empty disk name */
697     $d = trim($this->DISKcn);
698     if($d == "" ){
699       $message[] = msgPool::required(_("Name"));
700     }
701     if(preg_match("/[^a-z0-9_\-]/i",$d)){
702       $message[] = msgPool::invalid(_("Name"),$d,"/[a-z0-9_\-]/i");
703     }
704     return ($message);
705   }
708   /* Checks the disk combinations.
709    * 
710    */  
711   function check_disks($disk_to_add = array())
712   {
713     $msgs = array();
715     /* Check 'disk' combinations. 
716      *  - There can be four primary partitions.
717      *  - If there is at least one 'logical' partition, then there can be only 
718      *     three 'primary' partitions.
719      */    
720     if($this->FAIdiskType == "disk"){
721      
722       $types = array('logical' => array(), 'primary' => array());
723       $types[$disk_to_add['FAIpartitionType']][$disk_to_add['FAIpartitionNr']] = 1;
724       foreach($this->partitions as $key => $part){
725         $types[$part['FAIpartitionType']][$part['FAIpartitionNr']] = 1;
726       }
728       // There can only be four primary partitions per disk - without any logical partition.
729       if(count($types['logical']) == 0){
730         if(count($types['primary']) > 4){
731           $msgs[] = _("You have more than four primary partition table entries in your configuration, please check your configuration twice.");
732         }
733       }else{
734         if(count($types['primary']) > 3){
735           $msgs[] = _("You cannot have more than three primary partition while using logical partitions, please check your configuration twice.");
736         }
737       }
738     }
740     return($msgs);
741   }  
744   /* Return plugin informations for acl handling */
745   static function plInfo()
746   {
747     return (array(
748           "plShortName" => _("Partition table entry"),
749           "plDescription" => _("FAI partition table entry"),
750           "plSelfModify"  => FALSE,
751           "plDepends"     => array(),
752           "plPriority"    => 27,
753           "plSection"     => array("administration"),
754           "plCategory"    => array("fai"),
755           "plProvidedAcls" => array(
756             "DISKcn"           => _("Name"),
757             "DISKdescription"  => _("Description"),
758             "DISKFAIdiskOption"  => _("Disk options"),
759             "FAIpartitionType"  => _("Partition type"),
760             "FAIpartitionNr"    => _("Partition no."),
761             "FAIfsType"         => _("File system type"),
762             "FAImountPoint"     => _("Mount point"),
763             "FAIpartitionSize"  => _("Partition size"),
764             "FAImountOptions"   => _("Mount options"),
765             "FAIfsOptions"      => _("File system options"),
766             "FAIpartitionFlags" => _("Partition flags"))
767           ));
768   }
769  
772 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
773 ?>