summarylogtreecommitdiffstats
path: root/f2fs-verify-resize.patch
blob: fca05bb595be997f7d846e2b8ef1881cc65c549c (plain)
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
diff -u b/include/f2fs.h b/include/f2fs.h
--- b/include/f2fs.h
+++ b/include/f2fs.h
@@ -29,6 +29,9 @@
 public:
 	FS get_filesystem_support() ;
 	bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
+	bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition );
+	bool check_repair( const Partition & partition, OperationDetail & operationdetail );
+	void set_used_sectors( Partition & partition ) ;
 };
 
 } //GParted
diff -u b/src/f2fs.cc b/src/f2fs.cc
--- b/src/f2fs.cc
+++ b/src/f2fs.cc
@@ -37,6 +37,20 @@
 		fs.create_with_label = FS::EXTERNAL;
 	}
 
+	if ( ! Glib::find_program_in_path( "resize.f2fs" ).empty() )
+	{
+		fs.grow = FS::EXTERNAL;
+
+	}
+
+	if ( ! Glib::find_program_in_path( "fsck.f2fs" ).empty() )
+		fs.check = FS::EXTERNAL;
+
+	if ( ! Glib::find_program_in_path( "dump.f2fs").empty() )
+	{
+		fs.read = FS::EXTERNAL;
+	}
+
 	fs .copy = FS::GPARTED ;
 	fs .move = FS::GPARTED ;
 	fs .online_read = FS::GPARTED ;
@@ -44,6 +58,60 @@
 	return fs ;
 }
 
+void f2fs::set_used_sectors( Partition & partition )
+{
+	if ( ! Utils::execute_command( "dump.f2fs -d 1 " + Glib::shell_quote( partition.get_path() ), output, error, true ))
+	{
+		long long int user_block_count;
+		long long int valid_block_count;
+		long long int log_blocksize;
+		long long int blocksize;
+		long long int total_fs_sectors;
+
+		Glib::ustring temp;
+		temp = Utils::regexp_label( output, "user_block_count\\s+\\[0x\\s+[0-9a-f]+ : ([0-9]+)\\]" ) ;
+		sscanf( temp.c_str(), "%lld", &user_block_count );
+
+
+		temp = Utils::regexp_label( output, "valid_block_count\\s+\\[0x\\s+[0-9a-f]+ : ([0-9]+)\\]" ) ;
+		sscanf( temp.c_str(), "%lld", &valid_block_count );
+
+
+		temp = Utils::regexp_label( output, "log_blocksize\\s+\\[0x\\s+[0-9a-f]+ : ([0-9]+)\\]" ) ;
+		sscanf( temp.c_str(), "%lld", &log_blocksize );
+
+
+		temp = Utils::regexp_label( output, "sector size = ([0-9]+)" ) ;
+		sscanf( temp.c_str(), "%lld", &S );
+
+
+		temp = Utils::regexp_label( output, "total FS sectors = ([0-9]+)" ) ;
+		sscanf( temp.c_str(), "%lld", &total_fs_sectors );
+
+
+		blocksize = (1 << log_blocksize);
+		N = (user_block_count - valid_block_count)*blocksize;
+		T = (total_fs_sectors * S);
+
+
+
+		T = Utils::round( T / double(partition.sector_size) );
+		N = Utils::round( N / double(partition.sector_size) );
+
+
+		partition.set_sector_usage( T, N );
+		partition.fs_block_size = S;
+	}
+	else
+	{
+		if ( ! output .empty() )
+			partition.push_back_message( output );
+
+		if ( ! error .empty() )
+			partition.push_back_message( error );
+	}
+}
+
 bool f2fs::create( const Partition & new_partition, OperationDetail & operationdetail )
 {
 	return ! execute_command( "mkfs.f2fs -l " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
@@ -53,2 +121,21 @@
 
+bool f2fs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
+{
+	Glib::ustring args = "";
+
+	if ( ! fill_partition )
+		args += " -t " + Utils::num_to_str( floor( Utils::sector_to_unit(
+			 partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + " ";
+
+	Glib::ustring str_temp = "resize.f2fs " + args + Glib::shell_quote( partition_new.get_path() );
+
+	return ! execute_command( str_temp, operationdetail, EXEC_CHECK_STATUS );
+}
+
+bool f2fs::check_repair( const Partition & partition, OperationDetail & operationdetail )
+{
+	return ! execute_command( "fsck.f2fs -f -y -a " + Glib::shell_quote( partition.get_path() ),
+	                               operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE );
+}
+
 } //GParted