2013-03-16 14:56:02 -06:00
|
|
|
/* Copyright (C) 2013 Patrick Verner <exodusrobot@yahoo.com>
|
|
|
|
*
|
|
|
|
* 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
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2013-03-16 14:56:02 -06:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2013-03-16 14:56:02 -06:00
|
|
|
*/
|
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "f2fs.h"
|
2018-01-18 09:26:20 -07:00
|
|
|
#include "FileSystem.h"
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "Partition.h"
|
2013-03-16 14:56:02 -06:00
|
|
|
|
2018-12-04 09:46:27 -07:00
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
#include <glibmm/shell.h>
|
|
|
|
|
|
|
|
|
2013-03-16 14:56:02 -06:00
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
FS f2fs::get_filesystem_support()
|
|
|
|
{
|
2015-11-13 14:46:57 -07:00
|
|
|
FS fs( FS_F2FS );
|
2013-03-16 14:56:02 -06:00
|
|
|
|
2014-02-14 18:26:32 -07:00
|
|
|
fs .busy = FS::GPARTED ;
|
|
|
|
|
2019-03-15 12:22:00 -06:00
|
|
|
if (! Glib::find_program_in_path("dump.f2fs").empty())
|
|
|
|
fs.read = FS::EXTERNAL;
|
|
|
|
|
2013-03-16 14:56:02 -06:00
|
|
|
if ( ! Glib::find_program_in_path( "mkfs.f2fs" ) .empty() )
|
2013-06-05 15:15:47 -06:00
|
|
|
{
|
2018-10-13 05:59:31 -06:00
|
|
|
fs.create = FS::EXTERNAL;
|
|
|
|
fs.create_with_label = FS::EXTERNAL;
|
2013-06-05 15:15:47 -06:00
|
|
|
}
|
2013-03-16 14:56:02 -06:00
|
|
|
|
2019-03-15 12:22:00 -06:00
|
|
|
if (! Glib::find_program_in_path("fsck.f2fs").empty())
|
|
|
|
fs.check = FS::EXTERNAL;
|
|
|
|
|
|
|
|
if (! Glib::find_program_in_path("resize.f2fs").empty())
|
|
|
|
fs.grow = FS::EXTERNAL;
|
|
|
|
|
2013-03-16 14:56:02 -06:00
|
|
|
fs .copy = FS::GPARTED ;
|
|
|
|
fs .move = FS::GPARTED ;
|
|
|
|
fs .online_read = FS::GPARTED ;
|
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
2019-03-15 12:22:00 -06:00
|
|
|
|
|
|
|
void f2fs::set_used_sectors(Partition & partition)
|
|
|
|
{
|
2019-03-19 03:45:28 -06:00
|
|
|
exit_status = Utils::execute_command("dump.f2fs -d 1 " + Glib::shell_quote(partition.get_path()),
|
|
|
|
output, error, true);
|
|
|
|
if (exit_status != 0)
|
2019-03-15 12:22:00 -06:00
|
|
|
{
|
|
|
|
if (! output.empty())
|
|
|
|
partition.push_back_message(output);
|
|
|
|
if (! error.empty())
|
|
|
|
partition.push_back_message(error);
|
2019-03-19 03:45:28 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// used FS blocks
|
|
|
|
long long user_block_count = -1;
|
|
|
|
Glib::ustring::size_type index = output.find("user_block_count");
|
|
|
|
if (index < output.length())
|
|
|
|
sscanf(output.substr(index).c_str(), "user_block_count [0x %*x : %lld]", &user_block_count);
|
|
|
|
|
|
|
|
// total FS blocks
|
|
|
|
long long valid_block_count = -1;
|
|
|
|
index = output.find("valid_block_count");
|
|
|
|
if (index < output.length())
|
|
|
|
sscanf(output.substr(index).c_str(), "valid_block_count [0x %*x : %lld]", &valid_block_count);
|
|
|
|
|
|
|
|
// log2 of FS block size
|
|
|
|
long long log_blocksize = -1;
|
|
|
|
index = output.find("log_blocksize");
|
|
|
|
if (index < output.length())
|
|
|
|
sscanf(output.substr(index).c_str(), "log_blocksize [0x %*x : %lld]", &log_blocksize);
|
|
|
|
|
|
|
|
// FS "sector" size
|
|
|
|
long long fs_sector_size = -1;
|
|
|
|
index = output.find("Info: sector size =");
|
|
|
|
if (index < output.length())
|
|
|
|
sscanf(output.substr(index).c_str(), "Info: sector size = %lld", &fs_sector_size);
|
|
|
|
|
|
|
|
// FS size in "sectors"
|
|
|
|
long long total_fs_sectors = -1;
|
|
|
|
index = output.find("Info: total FS sectors =");
|
|
|
|
if (index < output.length())
|
|
|
|
sscanf(output.substr(index).c_str(), "Info: total FS sectors = %lld", &total_fs_sectors);
|
|
|
|
|
2019-03-19 13:27:39 -06:00
|
|
|
if (user_block_count > -1 && valid_block_count > -1 && log_blocksize > -1)
|
2019-03-19 03:45:28 -06:00
|
|
|
{
|
|
|
|
long long blocksize = 1 << log_blocksize;
|
|
|
|
long long fs_free_bytes = (user_block_count - valid_block_count) * blocksize;
|
|
|
|
Sector fs_free_sectors = fs_free_bytes / partition.sector_size;
|
2019-03-19 13:27:39 -06:00
|
|
|
|
|
|
|
// dump.f2fs < 1.5.0 doesn't report "total FS sectors" so leave
|
|
|
|
// fs_size_sectors = -1 for unknown.
|
|
|
|
Sector fs_size_sectors = -1;
|
|
|
|
if (fs_sector_size > -1 && total_fs_sectors > -1)
|
|
|
|
{
|
|
|
|
long long fs_size_bytes = total_fs_sectors * fs_sector_size;
|
|
|
|
fs_size_sectors = fs_size_bytes / partition.sector_size;
|
|
|
|
}
|
2019-03-19 03:45:28 -06:00
|
|
|
|
|
|
|
partition.set_sector_usage(fs_size_sectors, fs_free_sectors);
|
|
|
|
partition.fs_block_size = blocksize;
|
2019-03-15 12:22:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-16 14:56:02 -06:00
|
|
|
bool f2fs::create( const Partition & new_partition, OperationDetail & operationdetail )
|
|
|
|
{
|
2017-09-03 01:52:54 -06:00
|
|
|
return ! execute_command( "mkfs.f2fs -l " + Glib::shell_quote( new_partition.get_filesystem_label() ) +
|
|
|
|
" " + Glib::shell_quote( new_partition.get_path() ),
|
Time and check nearly all file system action commands (#754684)
There has been an undocumented rule that external commands displayed in
the operation details, as part of file system manipulations, only get a
time and check mark displayed when multiple commands are needed, and not
otherwise. (GParted checks whether all commands are successful or not
regardless of whether a check mark is displayed in the operation details
or not).
EXCEPTION 1: btrfs resize
Since the following commit [1] from 2013-02-22, GParted stopped
displaying the timing for the btrfs resize command in the operation
details. It being part of a multi-command sequence to perform the step.
This is because FileSystem::execute_command() since the commit can only
check the exit status for zero / non-zero while timing and checking the
command status but btrfs resize needs to consider some non-zero statuses
as successful.
[1] 52a2a9b00a32996921ace055e71d0e09fb33c5fe
Reduce threading (#685740)
EXCEPTION 2: ext2/3/4 move and copy using e2image
When use of e2image was added [2] the single command steps were timed
and check.
[2] 86111fe12a26d23d9fc2a9e2d19281290ecaf985
Use e2image to move/copy ext[234] file systems (#721516)
EXCEPTION 3: fat16/32 write label and UUID
Uses Utils::execute_command() rather than FileSystem::execute_command()
so can be separately changed. See the following commit for resolution
of the final commands not yet timed and check mark displayed.
CHANGE:
Lets make a simpler rule of always displaying the time and a check mark
for all external commands displayed in the operation details. However
this makes several of the other single command actions need special exit
status handling because zero success, non-zero failure is not correct
for every case. Specifically affects resizing of reiserfs and check
repair of ext2/3/4, fat16/32, jfs and reiserfs.
After this change all external commands run as file system actions must
follow one of these two patterns of using the EXEC_CHECK_STATUS flag or
separately calling FileSystem::set_status() to register success or
failure of the command:
exit_status = execute_command(cmd, od, EXEC_CHECK_STATUS...);
or:
exit_status = execute_command(cmd, od, ...);
bool success = (exit_status == 0 || exit_status == OTHER_SUCCESS_VALUE...);
set_status(od, success );
Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
functions
2015-09-05 02:31:16 -06:00
|
|
|
operationdetail, EXEC_CHECK_STATUS );
|
2013-03-16 14:56:02 -06:00
|
|
|
}
|
|
|
|
|
2019-03-15 12:22:00 -06:00
|
|
|
|
|
|
|
bool f2fs::resize(const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition)
|
|
|
|
{
|
|
|
|
Glib::ustring size = "";
|
|
|
|
if (! fill_partition)
|
|
|
|
// resize.f2fs works in sector size units of whatever device the file
|
|
|
|
// system is currently stored on.
|
|
|
|
size = "-t " + Utils::num_to_str(partition_new.get_sector_length()) + " ";
|
|
|
|
|
|
|
|
return ! execute_command("resize.f2fs " + size + Glib::shell_quote(partition_new.get_path()),
|
|
|
|
operationdetail, EXEC_CHECK_STATUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool f2fs::check_repair(const Partition & partition, OperationDetail & operationdetail)
|
|
|
|
{
|
2019-03-19 14:02:15 -06:00
|
|
|
return ! execute_command("fsck.f2fs -f -a " + Glib::shell_quote(partition.get_path()),
|
2019-03-15 12:22:00 -06:00
|
|
|
operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-16 14:56:02 -06:00
|
|
|
} //GParted
|