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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/* Copyright (C) 2004 Bart
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GPARTED_FILESYSTEM_H
#define GPARTED_FILESYSTEM_H
#include "Operation.h"
#include "Partition.h"
#include "PipeCapture.h"
#include "Utils.h"
#include <fstream>
#include <sys/stat.h>
#include <sigc++/slot.h>
namespace GParted
{
enum CUSTOM_TEXT
{
CTEXT_NONE,
CTEXT_ACTIVATE_FILESYSTEM, // Activate text ('Mount', 'Swapon', VG 'Activate', ...)
CTEXT_DEACTIVATE_FILESYSTEM, // Deactivate text ('Unmount', 'Swapoff', VG 'Deactivate', ...)
CTEXT_CHANGE_UUID_WARNING, // Warning to print when changing UUIDs
CTEXT_RESIZE_DISALLOWED_WARNING // File system resizing currently disallowed reason
};
// Minimum and maximum file system size limits
struct FS_Limits
{
Byte_Value min_size; // 0 => no limit, +ve => limit defined. (As implemented by)
Byte_Value max_size; // -----------------"----------------- (code using these.)
FS_Limits() : min_size( 0 ) , max_size( 0 ) {};
FS_Limits( Byte_Value min, Byte_Value max ) : min_size( min ), max_size( max ) {};
};
// Struct to store file system support information
struct FS
{
enum Support
{
NONE = 0,
GPARTED = 1,
LIBPARTED = 2,
EXTERNAL = 3
};
FSType fstype;
Support busy; // How to determine if partition/file system is busy
Support read; // Can and how to read sector usage while inactive
Support read_label;
Support write_label;
Support read_uuid;
Support write_uuid;
Support create;
Support create_with_label; // Can and how to format file system with label
Support grow;
Support shrink;
Support move; // start point and endpoint
Support check; // Some check tool available?
Support copy;
Support remove;
Support online_read; // Can and how to read sector usage while active
Support online_grow;
Support online_shrink;
Support online_write_label;
FS(FSType fstype_ = FS_UNSUPPORTED) : fstype(fstype_)
{
busy = read = read_label = write_label = read_uuid = write_uuid = create =
create_with_label = grow = shrink = move = check = copy = remove = online_read =
online_grow = online_shrink = online_write_label = NONE;
}
};
enum ExecFlags
{
EXEC_NONE = 1 << 0,
EXEC_CHECK_STATUS = 1 << 1, // Set the status of the command in the operation
// details based on the exit status being zero or
// non-zero. Must either use this flag when calling
// ::execute_command() or call ::set_status()
// afterwards.
EXEC_CANCEL_SAFE = 1 << 2,
EXEC_PROGRESS_STDOUT = 1 << 3, // Run progress tracking callback after reading new
// data on stdout from command.
EXEC_PROGRESS_STDERR = 1 << 4, // Same but for stderr.
EXEC_PROGRESS_TIMED = 1 << 5 // Run progress tracking callback periodically.
};
inline ExecFlags operator|( ExecFlags lhs, ExecFlags rhs )
{ return static_cast<ExecFlags>( static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs) ); }
inline ExecFlags operator&( ExecFlags lhs, ExecFlags rhs )
{ return static_cast<ExecFlags>( static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs) ); }
class FileSystem
{
public:
FileSystem() ;
virtual ~FileSystem() {}
virtual const Glib::ustring & get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) const;
static const Glib::ustring & get_generic_text( CUSTOM_TEXT ttype, int index = 0 );
virtual FS get_filesystem_support() = 0 ;
virtual FS_Limits get_filesystem_limits( const Partition & partition ) const { return fs_limits; };
virtual bool is_busy( const Glib::ustring & path ) { return false ; } ;
virtual void set_used_sectors( Partition & partition ) {};
virtual void read_label( Partition & partition ) {};
virtual bool write_label( const Partition & partition, OperationDetail & operationdetail ) { return false; };
virtual void read_uuid( Partition & partition ) {};
virtual bool write_uuid( const Partition & partition, OperationDetail & operationdetail ) { return false; };
virtual bool create( const Partition & new_partition, OperationDetail & operationdetail ) { return false; };
virtual bool resize( const Partition & partition_new,
OperationDetail & operationdetail,
bool fill_partition ) { return false; };
virtual bool move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
) { return false; };
virtual bool copy( const Partition & src_part,
Partition & dest_part,
OperationDetail & operationdetail ) { return false; };
virtual bool check_repair( const Partition & partition, OperationDetail & operationdetail ) { return false; };
virtual bool remove( const Partition & partition, OperationDetail & operationdetail ) { return true; };
protected:
typedef sigc::slot<void, OperationDetail *> StreamSlot;
typedef sigc::slot<bool, OperationDetail *> TimedSlot;
int execute_command( const Glib::ustring & command, OperationDetail & operationdetail,
ExecFlags flags = EXEC_NONE );
int execute_command(const Glib::ustring& command, const char *input, OperationDetail& operationdetail,
ExecFlags flags = EXEC_NONE);
int execute_command( const Glib::ustring & command, OperationDetail & operationdetail,
ExecFlags flags,
StreamSlot stream_progress_slot );
int execute_command( const Glib::ustring & command, OperationDetail & operationdetail,
ExecFlags flags,
TimedSlot timed_progress_slot );
void set_status( OperationDetail & operationdetail, bool success );
void execute_command_eof();
Glib::ustring mk_temp_dir( const Glib::ustring & infix, OperationDetail & operationdetail ) ;
void rm_temp_dir( const Glib::ustring dir_name, OperationDetail & operationdetail ) ;
FS_Limits fs_limits; // File system minimum and maximum size limits. In derived
// classes either assign fixed values in get_filesystem_support()
// or implement get_filesystem_limits() for dynamic values.
//those are used in several places..
Glib::ustring output, error ;
int exit_status ;
private:
int execute_command_internal(const Glib::ustring& command, const char *input,
OperationDetail& operationdetail,
ExecFlags flags,
StreamSlot stream_progress_slot,
TimedSlot timed_progress_slot);
void store_exit_status( GPid pid, int status );
bool running;
int pipecount;
};
} //GParted
#endif /* GPARTED_FILESYSTEM_H */
|