2
using TeeJee.FileSystem;
4
using TeeJee.JsonHelper;
5
using TeeJee.ProcessHelper;
6
using TeeJee.GtkHelper;
10
public class FsTabEntry : GLib.Object{
11
public bool is_comment = false;
12
public bool is_empty_line = false;
13
public string device = "";
14
public string mount_point = "";
15
public string type = "";
16
public string options = "defaults";
17
public string dump = "0";
18
public string pass = "0";
19
public string line = "";
21
public static Gee.ArrayList<FsTabEntry> read_fstab_file(string fstab_file_path){
22
Gee.ArrayList<FsTabEntry> list = new Gee.ArrayList<FsTabEntry>();
24
if (!file_exists(fstab_file_path)){ return list; }
26
string text = file_read(fstab_file_path);
27
string[] lines = text.split("\n");
28
foreach(string line in lines){
29
FsTabEntry entry = new FsTabEntry();
32
entry.is_comment = line.strip().has_prefix("#");
33
entry.is_empty_line = (line.strip().length == 0);
35
if (entry.is_comment){
38
else if (entry.is_empty_line){
44
string[] parts = line.replace("\t"," ").split(" ");
46
foreach(string part in parts){
47
if (part.strip().length == 0) { continue; }
50
entry.device = part.strip();
53
entry.mount_point = part.strip();
56
entry.type = part.strip();
59
entry.options = part.strip();
62
entry.dump = part.strip();
65
entry.pass = part.strip();
75
public static string create_fstab_file(FsTabEntry[] fstab_entries, bool keep_comments_and_empty_lines = true){
77
foreach(FsTabEntry entry in fstab_entries){
78
if (entry.is_comment || entry.is_empty_line){
79
if (keep_comments_and_empty_lines){
80
text += "%s\n".printf(entry.line);
84
text += "%s\t%s\t%s\t%s\t%s\t%s\n".printf(entry.device, entry.mount_point, entry.type, entry.options, entry.dump, entry.pass);