344
339
public string uuid = "";
345
340
public string available = "";
346
341
public string used_percent = "";
347
public string mount_point = "";
348
342
public string dist_info = "";
343
public Gee.ArrayList<string> mount_point_list;
345
public PartitionInfo(){
346
mount_point_list = new Gee.ArrayList<string>();
350
349
public string description(){
353
352
s += (type.length > 0) ? " ~ " + type : "";
354
s += (used.length > 0) ? " ~ " + used + " / " + size + " used (" + used_percent + ")" : "";
353
s += (used.length > 0) ? " ~ " + used + " / " + size + " GB used (" + used_percent + ")" : "";
358
public string description_device(){
357
public string description_full(){
361
s += (uuid.length == 0) ? "" : ", UUID=" + uuid;
360
s += (uuid.length > 0) ? " ~ " + uuid : "";
361
s += (type.length > 0) ? " ~ " + type : "";
362
s += (used.length > 0) ? " ~ " + used + " / " + size + " GB used (" + used_percent + ")" : "";
365
foreach(string mp in mount_point_list){
368
s += (mps.length > 0) ? " ~ " + mps.strip() : "";
449
public PartitionInfo get_partition_info(string path){
451
/* Returns partition info for specified path or device name */
453
PartitionInfo info = new PartitionInfo();
457
int exit_code = execute_command_script_sync("df -T -BM \"" + path + "\"| uniq -w 12", out std_out, out std_err);
458
if (exit_code != 0){ return info; }
460
string[] lines = std_out.split("\n");
463
if (lines.length == 3){
464
foreach(string part in lines[1].split(" ")){
466
if (part.strip().length == 0){ continue; }
470
info.device = part.strip();
473
info.type = part.strip();
476
info.size_mb = long.parse(part.strip().replace("M",""));
479
info.used_mb = long.parse(part.strip().replace("M",""));
482
info.available = part.strip();
485
info.used_percent = part.strip();
488
info.mount_point = part.strip();
494
foreach(PartitionInfo pi in get_all_partitions()){
495
if (pi.device == info.device){
496
info.label = pi.label;
505
public Gee.ArrayList<PartitionInfo?> get_mounted_partitions(){
507
/* Returns list of mounted partitions */
458
public Gee.ArrayList<PartitionInfo?> get_mounted_partitions_using_df(bool exclude_unknown = true){
460
/* Returns list of mounted partitions using 'df' command
461
Populates device, type, size, used and mount_point_list */
509
463
var list = new Gee.ArrayList<PartitionInfo?>();
522
493
if (++line_num == 1) { continue; }
523
494
if (line.strip().length == 0) { continue; }
525
PartitionInfo info = new PartitionInfo();
496
PartitionInfo pi = new PartitionInfo();
498
//parse & populate fields ------------------
528
foreach(string part in line.split(" ")){
501
foreach(string val in line.split(" ")){
530
if (part.strip().length == 0){ continue; }
503
if (val.strip().length == 0){ continue; }
534
info.device = part.strip();
507
pi.device = val.strip();
537
info.type = part.strip();
510
pi.type = val.strip();
540
info.size_mb = long.parse(part.strip().replace("M",""));
513
pi.size_mb = long.parse(val.strip().replace("M",""));
543
info.used_mb = long.parse(part.strip().replace("M",""));
516
pi.used_mb = long.parse(val.strip().replace("M",""));
546
info.available = part.strip();
519
pi.available = val.strip();
549
info.used_percent = part.strip();
522
pi.used_percent = val.strip();
552
info.mount_point = part.strip();
525
string mount_point = val.strip();
526
if (!pi.mount_point_list.contains(mount_point)){
527
pi.mount_point_list.add(mount_point);
533
//exclude unknown devices
534
if (exclude_unknown){
535
if (!(pi.device.has_prefix("/dev/sd") || pi.device.has_prefix("/dev/hd") || pi.device.has_prefix("/dev/mapper/"))) {
540
//check for duplicates
542
foreach(PartitionInfo pm in list){
543
if (pm.device == pi.device){
544
//add mount points and continue
545
foreach(string mount_point in pi.mount_point_list){
546
if (!pm.mount_point_list.contains(mount_point)){
547
pm.mount_point_list.add(mount_point);
564
public Gee.ArrayList<PartitionInfo?> get_mounted_partitions_using_mount(bool exclude_unknown = true){
566
/* Returns list of mounted partitions using 'mount' command
567
Populates device, type and mount_point_list */
569
var list = new Gee.ArrayList<PartitionInfo?>();
574
int exit_code = execute_command_script_sync("mount", out std_out, out std_err);
577
log_error ("Failed to get list of partitions");
578
return list; //return empty list
584
/dev/sda3 on / type ext4 (rw,errors=remount-ro)
585
proc on /proc type proc (rw,noexec,nosuid,nodev)
586
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
587
none on /sys/fs/cgroup type tmpfs (rw)
588
none on /sys/fs/fuse/connections type fusectl (rw)
591
foreach(string line in std_out.split("\n")){
593
if (line.strip().length == 0) { continue; }
595
PartitionInfo pi = new PartitionInfo();
597
//parse & populate fields ------------------
600
foreach(string val in line.split(" ")){
601
if (val.strip().length == 0){ continue; }
604
pi.device = val.strip();
610
string mount_point = val.strip();
611
if (!pi.mount_point_list.contains(mount_point)){
612
pi.mount_point_list.add(mount_point);
619
pi.type = val.strip();
627
//exclude unknown devices
628
if (exclude_unknown){
629
if (!(pi.device.has_prefix("/dev/sd") || pi.device.has_prefix("/dev/hd") || pi.device.has_prefix("/dev/mapper/"))) {
634
//check for duplicates
636
foreach(PartitionInfo pm in list){
637
if (pm.device == pi.device){
638
//add mount points and continue
639
foreach(string mount_point in pi.mount_point_list){
640
if (!pm.mount_point_list.contains(mount_point)){
641
pm.mount_point_list.add(mount_point);
563
public Gee.ArrayList<PartitionInfo?> get_all_partitions(){
658
public Gee.ArrayList<PartitionInfo?> get_partitions_using_blkid(bool exclude_unknown = true){
565
/* Returns list of mounted/unmounted, physical/LVM partitions */
660
/* Returns list of mounted/unmounted, physical/LVM partitions
661
* Populates device, uuid, type and label */
567
663
var list = new Gee.ArrayList<PartitionInfo?>();
568
var list_mounted = get_mounted_partitions();
671
ret_val = execute_command_script_sync("/sbin/blkid", out std_out, out std_err);
674
log_error ("Failed to get list of partitions");
675
return list; //return empty list
681
/dev/sda1: LABEL="System Reserved" UUID="F476B08076B04560" TYPE="ntfs"
682
/dev/sda2: LABEL="windows" UUID="BE00B6DB00B69A3B" TYPE="ntfs"
683
/dev/sda3: UUID="03f3f35d-71fa-4dff-b740-9cca19e7555f" TYPE="ext4"
580
ret_val = execute_command_script_sync(cmd, out std_out, out std_err);
583
log_error ("Failed to get list of partitions");
585
return list_mounted; //return list of mounted devices
588
687
foreach(string line in std_out.split("\n")){
589
688
if (line.strip().length == 0) { continue; }
618
717
pi.type = match.fetch(1).strip();
622
foreach(PartitionInfo pm in list_mounted){
720
//check for duplicates
722
foreach(PartitionInfo pm in list){
723
if (pm.device == pi.device){
724
//add mount points and continue
725
foreach(string mount_point in pi.mount_point_list){
726
if (!pm.mount_point_list.contains(mount_point)){
727
pm.mount_point_list.add(mount_point);
742
log_error (e.message);
748
public Gee.ArrayList<PartitionInfo?> get_all_partitions(bool exclude_unknown = true, bool get_usage = true){
750
/* Returns list of mounted/unmounted, physical/logical partitions */
752
var list = new Gee.ArrayList<PartitionInfo?>();
754
// get initial list --------
756
var list_blkid = get_partitions_using_blkid(exclude_unknown);
758
foreach (PartitionInfo pi in list_blkid){
762
// add more devices ----------
764
var list_mount = get_mounted_partitions_using_mount(exclude_unknown);
766
foreach (PartitionInfo pm in list_mount){
769
foreach (PartitionInfo pi in list){
770
if (pi.device == pm.device){
771
//add more mount points
772
foreach(string mount_point in pm.mount_point_list){
773
if (!pi.mount_point_list.contains(mount_point)){
774
pi.mount_point_list.add(mount_point);
787
// get usage info -------------
791
var list_df = get_mounted_partitions_using_df(exclude_unknown);
793
for(int k = 0; k < list.size; k++){
794
PartitionInfo pi = list[k];
795
foreach(PartitionInfo pm in list_df){
623
796
if (pm.device == pi.device){
624
797
pi.size_mb = pm.size_mb;
625
798
pi.used_mb = pm.used_mb;
626
799
pi.used_percent = pm.used_percent;
627
pi.mount_point = pm.mount_point;
801
foreach(string mount_point in pm.mount_point_list){
802
if (!pi.mount_point_list.contains(mount_point)){
803
pi.mount_point_list.add(mount_point);
635
log_error (e.message);
814
public PartitionInfo refresh_partition_usage_info(PartitionInfo pi){
816
/* Updates and returns the given PartitionInfo object */
821
int exit_code = execute_command_script_sync("df -T -BM \"" + pi.device + "\"| uniq -w 12", out std_out, out std_err);
827
string[] lines = std_out.split("\n");
830
if (lines.length == 3){
831
foreach(string part in lines[1].split(" ")){
833
if (part.strip().length == 0){ continue; }
837
pi.size_mb = long.parse(part.strip().replace("M",""));
840
pi.used_mb = long.parse(part.strip().replace("M",""));
843
pi.available = part.strip();
846
pi.used_percent = part.strip();
641
859
public bool mount(string device, string mount_point, string mount_options = ""){
643
861
/* Mounts specified device at specified mount point.
659
877
//check if mounted
660
878
bool mounted = false;
661
foreach(PartitionInfo info in get_mounted_partitions()){
879
foreach(PartitionInfo info in get_mounted_partitions_using_df()){
663
if (info.mount_point == mount_point && info.device == device){
881
if (info.mount_point_list.contains(mount_point) && info.device == device){
664
882
//device is already mounted at mount point
668
else if (info.mount_point == mount_point && info.device != device){
886
else if (info.mount_point_list.contains(mount_point) && info.device != device){
669
887
//another device is mounted at mount point - unmount it -------
670
888
cmd = "sudo umount \"%s\"".printf(mount_point);
671
889
Process.spawn_command_line_sync(cmd, out std_out, out std_err, out ret_val);
672
890
if (ret_val != 0){
673
log_error ("Failed to unmount device '%s' from mount point '%s'".printf(info.device, info.mount_point));
891
log_error ("Failed to unmount device '%s' from mount point '%s'".printf(info.device, mount_point));
674
892
log_error (std_err);
678
log_msg ("Unmounted device '%s' from mount point '%s'".printf(info.device, info.mount_point));
896
log_msg ("Unmounted device '%s' from mount point '%s'".printf(info.device, mount_point));
1562
1781
path = get_cmd_path ("exo-open");
1563
1782
if ((path != null)&&(path != "")){
1564
return execute_command_async ("exo-open \"" + dir_path + "\"");
1783
return execute_command_script_async ("exo-open \"" + dir_path + "\"");
1567
1786
path = get_cmd_path ("nemo");
1568
1787
if ((path != null)&&(path != "")){
1569
return execute_command_async ("nemo \"" + dir_path + "\"");
1788
return execute_command_script_async ("nemo \"" + dir_path + "\"");
1572
1791
path = get_cmd_path ("nautilus");
1573
1792
if ((path != null)&&(path != "")){
1574
return execute_command_async ("nautilus \"" + dir_path + "\"");
1793
return execute_command_script_async ("nautilus \"" + dir_path + "\"");
1577
1796
path = get_cmd_path ("thunar");
1578
1797
if ((path != null)&&(path != "")){
1579
return execute_command_async ("thunar \"" + dir_path + "\"");
1798
return execute_command_script_async ("thunar \"" + dir_path + "\"");
1585
public int exo_open_textfile (string txt){
1804
public bool exo_open_textfile (string txt){
1587
1806
/* Tries to open the given text file in a text editor */