📄 vfs-volume.c
字号:
vfs_volume_free( vols[ i ] ); g_array_free( volumes, TRUE ); } if ( hal_context ) { libhal_ctx_shutdown( hal_context, NULL ); libhal_ctx_free ( hal_context ); } if ( dbus_connection ) dbus_connection_unref( dbus_connection );}void vfs_volume_add_callback( VFSVolumeCallback cb, gpointer user_data ){ VFSVolumeCallbackData e; if ( !cb ) return ; if ( !callbacks ) callbacks = g_array_sized_new( FALSE, FALSE, sizeof( VFSVolumeCallbackData ), 8 ); e.cb = cb; e.user_data = user_data; callbacks = g_array_append_val( callbacks, e );}void vfs_volume_remove_callback( VFSVolumeCallback cb, gpointer user_data ){ int i; VFSVolumeCallbackData* e; if ( !callbacks ) return ; e = ( VFSVolumeCallbackData* ) callbacks->data; for ( i = 0; i < callbacks->len; ++i ) { if ( e[ i ].cb == cb && e[ i ].user_data == user_data ) { callbacks = g_array_remove_index_fast( callbacks, i ); if ( callbacks->len > 8 ) g_array_set_size( callbacks, 8 ); break; } }}gboolean vfs_volume_mount( VFSVolume* vol ){ char cmd[ 1024 ]; int ret; char* mount; mount = g_find_program_in_path( "pmount-hal" ); if ( mount ) { g_snprintf( cmd, 1024, "%s %s", mount, vol->udi ); g_free( mount ); } else { char* device; device = libhal_device_get_property_string ( hal_context, vol->udi, "block.device", NULL ); mount = g_find_program_in_path( "pmount" ); if ( mount ) { g_snprintf( cmd, 1024, "%s %s", mount, device ); g_free( mount ); } else g_snprintf( cmd, 1024, "mount %s", device ); libhal_free_string( device ); } /* g_debug( "cmd: %s", cmd ); */ if ( !g_spawn_command_line_sync( cmd, NULL, NULL, &ret, NULL ) ) return FALSE; /* dirty hack :-( */ if ( ! vol->mount_point ) { vol->mount_point = libhal_device_get_property_string ( hal_context, vol->udi, "volume.mount_point", NULL ); if ( vol->mount_point && !*vol->mount_point ) { libhal_free_string( vol->mount_point ); vol->mount_point = NULL; } } return !ret;}gboolean vfs_volume_umount( VFSVolume *vol ){ char cmd[ 1024 ]; int ret; if ( !vol->mount_point ) return FALSE; g_snprintf( cmd, 1024, "pumount \"%s\"", vol->mount_point ); /* g_debug( "cmd: %s", cmd ); */ if ( !g_spawn_command_line_sync( cmd, NULL, NULL, &ret, NULL ) ) return FALSE; return !ret;}gboolean vfs_volume_eject( VFSVolume *vol ){ char cmd[ 1024 ]; int ret; char* device; device = libhal_device_get_property_string ( hal_context, vol->udi, "block.device", NULL ); if ( !device ) return FALSE; g_snprintf( cmd, 1024, "eject \"%s\"", device ); libhal_free_string( device ); /* g_debug( "cmd: %s", cmd ); */ if ( !g_spawn_command_line_sync( cmd, NULL, NULL, &ret, NULL ) ) { return FALSE; } return !ret;}const char* vfs_volume_get_disp_name( VFSVolume *vol ){ char * disp_name; if ( vol->disp_name ) return vol->disp_name; vfs_volume_update_disp_name( vol ); /* policy = libhal_storage_policy_new(); disp_name = libhal_volume_policy_compute_display_name( vol->drive, vol->vol, policy ); if ( vol->disp_name ) g_free( vol->disp_name ); vol->disp_name = disp_name; libhal_storage_policy_free( policy ); */ return vol->disp_name;}const char* vfs_volume_get_mount_point( VFSVolume *vol ){ return vol->mount_point;}const char* vfs_volume_get_device( VFSVolume *vol ){ return NULL; /* FIXME: vfs_volume_get_device is not implemented */}const char* vfs_volume_get_fstype( VFSVolume *vol ){ const char * fs = NULL; return fs; /* FIXME: vfs_volume_get_fstype is not implemented */}const char* vfs_volume_get_icon( VFSVolume *vol ){ char * icon; char* type; if ( vol->icon ) return vol->icon; icon = NULL; type = libhal_device_get_property_string ( hal_context, vol->storage_udi, "storage.drive_type", NULL ); if ( type ) { /* FIXME: Show different icons for different types of discs */ if ( 0 == strcmp( type, "cdrom" ) ) { gboolean is_dvd = libhal_device_get_property_bool ( hal_context, vol->storage_udi, "storage.cdrom.dvd", NULL ); icon = is_dvd ? "gnome-dev-dvd" : "gnome-dev-cdrom"; } else if ( 0 == strcmp( type, "floppy" ) ) icon = "gnome-dev-floppy"; libhal_free_string( type ); } if ( !icon ) { if ( vol->is_removable ) { char * bus; bus = libhal_device_get_property_string ( hal_context, vol->storage_udi, "storage.bus", NULL ); if ( bus ) { if ( 0 == strcmp( bus, "usb" ) ) icon = "gnome-dev-removable-usb"; libhal_free_string( bus ); } if ( ! icon ) icon = "gnome-dev-removable"; } if ( ! icon ) icon = "gnome-dev-harddisk"; } /* policy = libhal_storage_policy_new(); icon = libhal_volume_policy_compute_icon_name( vol->drive, vol->vol, policy ); if ( !icon ) { switch ( libhal_drive_get_type( vol->drive ) ) { case LIBHAL_DRIVE_TYPE_CDROM: icon = "gnome-dev-cdrom"; break; case LIBHAL_DRIVE_TYPE_REMOVABLE_DISK: if ( LIBHAL_DRIVE_BUS_USB == libhal_drive_get_bus( vol->drive ) ) icon = "gnome-dev-removable-usb"; else icon = "gnome-dev-removable"; break; default: if ( LIBHAL_DRIVE_BUS_USB == libhal_drive_get_bus( vol->drive ) ) icon = "gnome-dev-harddisk-usb"; else icon = "gnome-dev-harddisk"; } } vol->icon = icon; libhal_storage_policy_free( policy ); */ vol->icon = icon; return icon;}gboolean vfs_volume_is_removable( VFSVolume *vol ){ return vol->is_removable;}gboolean vfs_volume_is_mounted( VFSVolume *vol ){ return vol->is_mounted;}gboolean vfs_volume_requires_eject( VFSVolume *vol ){ return vol->requires_eject;}VFSVolume** vfs_volume_get_all_volumes( int* num ){ if( G_UNLIKELY( ! volumes ) ) { if( num ) *num = 0; return NULL; } if ( num ) * num = volumes->len; return ( VFSVolume** ) volumes->data;}#else /* Build without HAL */struct _VFSVolume{ char* disp_name;};gboolean vfs_volume_init(){ return TRUE;}gboolean vfs_volume_clean(){ return TRUE;}VFSVolume** vfs_volume_get_all_volumes( int* num ){ if ( num ) * num = 0; return NULL;}void vfs_volume_add_callback( VFSVolumeCallback cb, gpointer user_data ){}void vfs_volume_remove_callback( VFSVolumeCallback cb, gpointer user_data ){}gboolean vfs_volume_mount( VFSVolume* vol ){ return TRUE;}gboolean vfs_volume_umount( VFSVolume *vol ){ return TRUE;}gboolean vfs_volume_eject( VFSVolume *vol ){ return TRUE;}const char* vfs_volume_get_disp_name( VFSVolume *vol ){ return NULL;}const char* vfs_volume_get_mount_point( VFSVolume *vol ){ return NULL;}const char* vfs_volume_get_device( VFSVolume *vol ){ return NULL;}const char* vfs_volume_get_fstype( VFSVolume *vol ){ return NULL;}const char* vfs_volume_get_icon( VFSVolume *vol ){ return NULL;}gboolean vfs_volume_is_removable( VFSVolume *vol ){ return FALSE;}gboolean vfs_volume_is_mounted( VFSVolume *vol ){ return FALSE;}gboolean vfs_volume_requires_eject( VFSVolume *vol ){ return FALSE;}#endif /* #ifdef HAVE_HAL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -