From d44aa2cf45c95c0f589670da3a4845dbd83a5cae Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Mon, 13 Dec 2004 21:24:12 +0000 Subject: [PATCH] ) * Added support for xfs. this means creating and growing xfs filesystems. Shrinking requires some hacking with dump_xfs etc.. i'll add that at a later point. :) --- ChangeLog | 5 ++ include/GParted_Core.h | 1 + include/Utils.h | 10 ++-- include/xfs.h | 43 ++++++++++++++ src/GParted_Core.cc | 5 ++ src/Makefile.am | 3 +- src/xfs.cc | 129 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 include/xfs.h create mode 100644 src/xfs.cc diff --git a/ChangeLog b/ChangeLog index e64ede5d..2c0c8bf9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-12-13 Bart Hakvoort + + * Added support for xfs. this means creating and growing xfs filesystems. Shrinking requires some hacking with dump_xfs etc.. + i'll add that at a later point. :) + 2004-12-13 Bart Hakvoort * Replaced boolean 'resize' with 'shrink' and 'grow'. It seems some filesystems only support growing (e.g. xfs) so i need diff --git a/include/GParted_Core.h b/include/GParted_Core.h index fc9214dc..a3f51404 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -26,6 +26,7 @@ #include "../include/linux_swap.h" #include "../include/reiserfs.h" #include "../include/ntfs.h" +#include "../include/xfs.h" #include diff --git a/include/Utils.h b/include/Utils.h index 246d209a..d355474f 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -117,6 +117,7 @@ inline FS Get_FS( const Glib::ustring & filesystem, const std::vector & FILE return FILESYSTEMS .back( ) ; } +//use http://developer.gnome.org/projects/gup/hig/2.0/design.html#Palette as a starting point.. inline Glib::ustring Get_Color( const Glib::ustring & filesystem ) { //blue teints @@ -133,18 +134,19 @@ inline Glib::ustring Get_Color( const Glib::ustring & filesystem ) //purple something.. else if ( filesystem == "reiserfs" ) return "#ADA7C8" ; - + + else if ( filesystem == "xfs" ) return "#EED680" ; + //libparted can only detect these, i decided to "yellow them" :^) else if ( filesystem == "HFS" ) return "yellow" ; else if ( filesystem == "JFS" ) return "yellow" ; else if ( filesystem == "UFS" ) return "yellow" ; - else if ( filesystem == "XFS" ) return "yellow" ; - + //darkgrey and ligthblue else if ( filesystem == "---" ) return "darkgrey"; else if ( filesystem == "extended" ) return "#7DFCFE" ; - //unknown filesystem ( damaged, unknown or simply no filesystem ) + //unknown filesystem ( damaged, unknown or simply no filesystem ) else return "black"; } diff --git a/include/xfs.h b/include/xfs.h new file mode 100644 index 00000000..a01028c6 --- /dev/null +++ b/include/xfs.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2004 Bart + * + * 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#ifndef XFS +#define XFS + +#include "../include/FileSystem.h" + +#include + +namespace GParted +{ + +class xfs : public FileSystem +{ +public: + FS get_filesystem_support( ) ; + void Set_Used_Sectors( Partition & partition ) ; + bool Create( const Glib::ustring device_path, const Partition & new_partition ) ; + bool Resize( const Partition & partition_new, bool fill_partition = false ) ; + bool Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) ; + bool Check_Repair( const Partition & partition ) ; + int get_estimated_time( long MB_to_Consider ) ; +}; + +} //GParted + +#endif //XFS diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index cbb5b976..b9722a77 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -42,6 +42,9 @@ void GParted_Core::find_supported_filesystems( ) ntfs fs_ntfs; FILESYSTEMS .push_back( fs_ntfs .get_filesystem_support( ) ) ; + xfs fs_xfs; + FILESYSTEMS .push_back( fs_xfs .get_filesystem_support( ) ) ; + //unknown filesystem (default when no match is found) FS fs ; fs .filesystem = "unknown" ; FILESYSTEMS .push_back( fs ) ; @@ -707,6 +710,8 @@ void GParted_Core::set_proper_filesystem( const Glib::ustring & filesystem ) p_filesystem = new reiserfs( ) ; else if ( filesystem == "ntfs" ) p_filesystem = new ntfs( ) ; + else if ( filesystem == "xfs" ) + p_filesystem = new xfs( ) ; else p_filesystem = NULL ; diff --git a/src/Makefile.am b/src/Makefile.am index f1a9662c..a28e2c8b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,7 +38,8 @@ gparted_SOURCES = \ linux_swap.cc\ main.cc\ ntfs.cc\ - reiserfs.cc + reiserfs.cc\ + xfs.cc gparted_LDFLAGS = -lparted -lgthread-2.0 diff --git a/src/xfs.cc b/src/xfs.cc new file mode 100644 index 00000000..6c0bc30c --- /dev/null +++ b/src/xfs.cc @@ -0,0 +1,129 @@ +/* Copyright (C) 2004 Bart + * + * 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#include "../include/xfs.h" + +namespace GParted +{ + +FS xfs::get_filesystem_support( ) +{ + FS fs ; + + fs .filesystem = "xfs" ; + if ( ! system( "which xfs_db 1>/dev/null 2>/dev/null" ) ) + fs .read = true ; + + if ( ! system( "which mkfs.xfs 1>/dev/null 2>/dev/null" ) ) + fs .create = true ; + + if ( ! system( "which xfs_repair 1>/dev/null 2>/dev/null" ) ) + fs .check = true ; + + //resizing of xfs requires xfs_db, xfs_growfs, xfs_repair, mount, umount and xfs support in the kernel + if ( ! system( "which xfs_growfs mount umount 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) + { + Glib::ustring line ; + std::ifstream input( "/proc/filesystems" ) ; + while ( input >> line ) + if ( line == "xfs" ) + { + fs .grow = true ; + break ; + } + + input .close( ) ; + } + + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) + fs .copy = true ; + + fs .MIN = 32 ;//official minsize = 16MB, but the smallest xfs_repair can handle is 32MB... + + return fs ; +} + +void xfs::Set_Used_Sectors( Partition & partition ) +{ + char c_buf[ 512 ] ; + FILE *f ; + + Glib::ustring output ; + Sector free_blocks = -1, blocksize = -1 ; + + //get free blocks.. + f = popen( ( "LANG=C xfs_db -c 'sb 0' -c print -r " + partition .partition ) .c_str( ), "r" ) ; + while ( fgets( c_buf, 512, f ) ) + { + output = Glib::locale_to_utf8( c_buf ) ; + + //free blocks + if ( output .find( "fdblocks" ) < output .length( ) ) + free_blocks = atoi( (output .substr( output .find( "=" ) +1, output .length( ) ) ) .c_str( ) ) ; + + //blocksize + if ( output .find( "blocksize" ) < output .length( ) ) + blocksize = atoi( (output .substr( output .find( "=" ) +1, output .length( ) ) ) .c_str( ) ) ; + + } + pclose( f ) ; + + if ( free_blocks > -1 && blocksize > -1 ) + partition .Set_Unused( free_blocks * blocksize / 512 ) ; +} + +bool xfs::Create( const Glib::ustring device_path, const Partition & new_partition ) +{ + return ! Execute_Command( "mkfs.xfs " + new_partition .partition ) ; +} + +bool xfs::Resize( const Partition & partition_new, bool fill_partition ) +{ + bool return_value = false ; + + //xfs kan only grow if the partition is mounted.. + system( "mkdir /tmp/gparted_tmp_xfs_mountpoint" ) ; + if ( ! Execute_Command( "mount " + partition_new .partition + " /tmp/gparted_tmp_xfs_mountpoint" ) ) + { + return_value = ! Execute_Command( "xfs_growfs /tmp/gparted_tmp_xfs_mountpoint" ) ; + Execute_Command( "umount " + partition_new .partition ) ; + } + system( "rmdir /tmp/gparted_tmp_xfs_mountpoint" ) ; + + return return_value ; +} + +bool xfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) +{ + return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; +} + +bool xfs::Check_Repair( const Partition & partition ) +{ + return ! Execute_Command( "xfs_repair " + partition .partition ) ; +} + +int xfs::get_estimated_time( long MB_to_Consider ) +{ + return -1 ; +} + + +} //GParted + +