⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.c

📁 fdisk 实现源码,可以查询Linux下系统的分区信息
💻 C
📖 第 1 页 / 共 5 页
字号:
			}			else if (part->geom.length > constraint->max_size) {				ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,				_("The partition is too big to create %s filesystem on it"), type->name);				ped_constraint_destroy(constraint);				return 0;			}			/* FIXME: WHAT THE?.. */			//else {			//	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,			//        _("You can't create %s filesystem on this partition."), type->name);			//}			//ped_constraint_destroy(constraint);			//return 0;		}	ped_constraint_destroy(constraint);        fs = ped_file_system_create (&part->geom, type, uiquery->timer);        if (!fs)                return 0;        ped_file_system_close (fs);        if (!ped_partition_set_system (part, type))                return 0;        if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))                ped_partition_set_flag (part, PED_PARTITION_LBA, 1);        if (!ped_disk_commit (disk)) {		//if (uiquery->need_commit) uiquery->need_commit = -1;               return 0;	}	uiquery->need_commit = 0;        return 1;}/* The parameter custom is 1, then the user is asked about the start and end sector * * If the parameter newpart is not NULL, it is set to the newly created partition *//* NOTE: On some occassions it changes the *newpart to NULL! */intperform_mkpart (PedDisk* disk, PartPos *pos, PedPartitionType part_type,	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts){        PedPartition*            part;        PedConstraint*           user_constraint;        PedConstraint*           dev_constraint;        PedConstraint*           final_constraint;	PedConstraint*		 fs_constraint;       /* char*                    peek_word;*/        char*                    part_name = NULL;        char                     *start_usr = NULL, *end_usr = NULL;        char                     *start_sol = NULL, *end_sol = NULL;                if (!disk)                goto error;        if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED)) {		if (part_type && part_type != PED_PARTITION_NORMAL)			goto error;                part_type = PED_PARTITION_NORMAL;        } else if (opts & UI_SPECIFY_PART_TYPE) {                if (!get_part_type (_("Partition type"), disk, &part_type))                        goto error;        }                    if (part_type == PED_PARTITION_EXTENDED) {		if (opts & UI_MAKEPARTFS) {                	ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,                        	_("An extended partition cannot hold a file system."));                	return 0;        	}		else                	fs_type = NULL;        } else if (!fs_type) {                if (!get_fs_type (_("File system type"), &fs_type, 0))                        goto error;        }        if (ped_disk_type_check_feature (disk->type,                                         PED_DISK_TYPE_PARTITION_NAME))                 uiquery->getstring(_("Partition name"), &part_name, NULL, NULL, 1); 	if ((opts & UI_CUSTOM_VALUES) &&			pos->start.sector == 0LL && pos->end.sector == 0LL) {		place_part_start(disk,pos,part_type);		if (!get_position(pos, disk, GET_SECT | PLACE_END_NEWPART))			goto error;	}	else {		if (!get_position(pos, disk, opts & UI_CUSTOM_VALUES))			goto error;	}        /* processing starts here */        part = ped_partition_new (disk, part_type, fs_type,	                          pos->start.sector, pos->end.sector);        if (!part)                goto error;	/* Check if the partition occupying the space before the place we 	   are trying to put this one, requires a metadata sectors after it,	   and if so, increase the range of the constraint */	fuzzify(pos->start.range, disk->dev, NULL, 0,		metadata_tail_sectors(			disk_get_prev_nmd_partition(				disk,				ped_disk_get_partition_by_sector(					disk, 					pos->start.sector				)			)		)	);        snap_to_boundaries (&part->geom, NULL, disk,	                    pos->start.range, pos->end.range);        /* create constraints */        user_constraint = constraint_from_start_end (disk->dev,                        pos->start.range, pos->end.range);        PED_ASSERT (user_constraint != NULL, return 0);        dev_constraint = ped_device_get_constraint (disk->dev);        PED_ASSERT (dev_constraint != NULL, return 0);        final_constraint = ped_constraint_intersect (user_constraint,                        dev_constraint);        if (!final_constraint)                goto error_destroy_simple_constraints;        /* subject to partition constraint */        ped_exception_fetch_all();        if (!ped_disk_add_partition (disk, part, final_constraint)) {		ped_exception_catch();                ped_exception_leave_all();                               if (ped_disk_add_partition (disk, part,                                        ped_constraint_any (disk->dev))) {                        start_usr = ped_unit_format (disk->dev, pos->start.sector);                        end_usr   = ped_unit_format (disk->dev, pos->end.sector);                        start_sol = ped_unit_format (disk->dev, part->geom.start);                        end_sol   = ped_unit_format (disk->dev, part->geom.end);			/* TODO: With the changes from 06/08/06, we might remove 			   the "if" and warn the user always if this is out of 			   range */			if (opts & UI_CUSTOM_VALUES)				switch (ped_exception_throw (					PED_EXCEPTION_WARNING,					PED_EXCEPTION_YES_NO,					_("You requested a partition from %s to %s.\n"					"The closest location we can manage is "					"%s to %s.  "					"Is this still acceptable to you?"),					start_usr, end_usr, start_sol, end_sol))				{					case PED_EXCEPTION_YES:						/* all is well in this state */						break;					case PED_EXCEPTION_NO:					case PED_EXCEPTION_UNHANDLED:					default:						/* undo partition addition */						goto error_remove_part;				}                } else {                        goto error_remove_part;                }        } else {		ped_exception_leave_all();	}	/* We check whether we can create this filesystem here */	if (fs_type)		fs_constraint = ped_file_system_get_create_constraint(fs_type,disk->dev);	else		fs_constraint = NULL;	if (fs_constraint) {		if (!ped_constraint_is_solution(fs_constraint,&(part->geom))) {			const char *error = NULL;			if (part->geom.length < fs_constraint->min_size) {				error = _("The size of the partition is too small for %s filesystem");			}			else if (part->geom.length > fs_constraint->max_size) {				error = _("The size of the partition is too big for %s filesystem");			}			/* FIXME: WHAT THE?.. */			/* OK, I got it, but I will leave it here for a while */			//else {			//	error = _("You can't use this partition for %s filesystem");			//}			if (error)				switch (ped_exception_throw (					PED_EXCEPTION_WARNING,					PED_EXCEPTION_IGNORE_CANCEL,					error, fs_type->name)) {					case PED_EXCEPTION_IGNORE:						/* User doesn't care */						break;					case PED_EXCEPTION_CANCEL:					case PED_EXCEPTION_UNHANDLED:					default:						ped_constraint_destroy(fs_constraint);						goto error_remove_part;				}		}		ped_constraint_destroy(fs_constraint);	}        /* set minor attributes */        if (part_name)                PED_ASSERT (ped_partition_set_name (part, part_name), return 0);        if (!ped_partition_set_system (part, fs_type))                goto error;        if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))                ped_partition_set_flag (part, PED_PARTITION_LBA, 1);                /*if (!ped_disk_commit (disk))                goto error;*/	uiquery->need_commit = 1;                /* clean up */        ped_constraint_destroy (final_constraint);        ped_constraint_destroy (user_constraint);        ped_constraint_destroy (dev_constraint);                if (pos->start.range != NULL)                ped_geometry_destroy (pos->start.range);        if (pos->end.range != NULL)                ped_geometry_destroy (pos->end.range);                if (start_usr != NULL)                ped_free (start_usr);        if (end_usr != NULL)                ped_free (end_usr);        if (start_sol != NULL)                ped_free (start_sol);        if (end_sol != NULL)                ped_free (end_sol);	if (newpart) *newpart = part;        return 1;error_remove_part:	/* We need to make this NULL here, for cfdisk's usage */	if (newpart) *newpart = NULL;        ped_disk_remove_partition (disk, part);error_destroy_all_constraints:        ped_constraint_destroy (final_constraint);error_destroy_simple_constraints:        ped_constraint_destroy (user_constraint);        ped_constraint_destroy (dev_constraint);error_destroy_part:        ped_partition_destroy (part);error:        if (pos->start.range != NULL)                ped_geometry_destroy (pos->start.range);        if (pos->end.range != NULL)                ped_geometry_destroy (pos->end.range);        if (start_usr != NULL)                ped_free (start_usr);        if (end_usr != NULL)                ped_free (end_usr);        if (start_sol != NULL)                ped_free (start_sol);        if (end_sol != NULL)                ped_free (end_sol);        return 0;}intperform_mkpartfs (PedDisk* disk, PartPos *pos, PedPartitionType part_type,	const PedFileSystemType* fs_type, PedPartition **newpart, UIOpts opts){        PedPartition*            part = NULL;                if (!disk)                return 0;	if (opts & UI_WARN_COMMIT) {		if (!ask_boolean_question 		(_("WARNING: This writes all data to disk automatically, continue?"))) 			return 0;	}        if (!fs_type) {                if (!get_fs_type (_("File system type"), &fs_type, 1))                        return 0;        }	if (!perform_mkpart(disk,pos,part_type,fs_type,&part,opts | UI_MAKEPARTFS))		return 0;	if (!perform_mkfs(disk,part,fs_type,opts & ~UI_WARN_COMMIT))		return 0;	if (newpart) *newpart = part;	return 1;}/* FIXME: This function seems to be problematic, deal with it appropriately in the ui */intperform_move (PedDisk *disk,  PedPartition* part, PartPos *pos, UIOpts opts){               PedFileSystem*  fs;        PedFileSystem*  fs_copy;        PedConstraint*  constraint;        PedGeometry     old_geom, new_geom;        if (!disk)                goto error;		if (opts & UI_WARN_COMMIT) {		if (!ask_boolean_question 		(_("WARNING: This writes all data to disk automatically, continue?"))) 			return 0;	}	/* So the best we can do here is to commit */	if (uiquery->need_commit)		if (!perform_commit(disk,UI_DEFAULT))			goto error;	if (!part)        	if (!get_partition (_("Partition"), disk, &part))                	goto error;        if (!_partition_warn_busy (part))                goto error;        if (part->type == PED_PARTITION_EXTENDED) {                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,                        _("Can't move an extended partition."));                goto error;        }        old_geom = part->geom;        fs = ped_file_system_open (&old_geom);        if (!fs)                goto error;        /* get new target */	if ((opts & UI_CUSTOM_VALUES) &&			pos->start.sector == 0LL && pos->end.sector == 0LL) {		place_part_start(disk,pos,part->type);		if (!get_position(pos, disk, GET_SECT | PLACE_END_NEWPART))			goto error_close_fs;	}	else {		if (!get_position(pos, disk, opts & UI_CUSTOM_VALUES))			goto error_close_fs;	}        /* set / test on "disk" */        if (!ped_geometry_init (&new_geom, disk->dev, pos->start.sector,                                pos->end.sector - pos->start.sector + 1LL))                goto error_close_fs;        snap_to_boundaries (&new_geom, NULL, disk,                            pos->start.range, pos->end.range);        constraint = constraint_intersect_and_destroy (                        ped_file_system_get_copy_constraint (fs, disk->dev),                        constraint_from_start_end (disk->dev, pos->start.range,                                                   pos->end.range));	/* So here we do something worth commiting and dangerous. UI *must* 	   do something if we fail and need_commit is true... */	uiquery->need_commit = 1;        if (!ped_disk_set_partition_geom (disk, part, constraint,                                          new_geom.start, new_geom.end))                goto error_destroy_constraint;        ped_constraint_destroy (constraint);        if (ped_geometry_test_overlap (&old_geom, &part->geom)) {                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,                        _("Can't move a partition onto itself.  Try using resize, perhaps?"));                goto error_close_fs;        }        /* do the move */        fs_copy = ped_file_system_copy (fs, &part->geom, uiquery->timer);        if (!fs_copy) {		#if 0		ped_constraint_destroy (constraint);		constraint = ped_constraint_any(disk->dev);		ped_disk_set_partition_geom(disk,part,constraint,		                            old_geom.start,old_geom.end);		#endif		ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,			_("Couldn't run the partition copy"));                goto error_close_fs;	}        ped_file_system_close (fs_copy);        ped_file_system_close (fs);        if (!ped_disk_commit (disk)) {		//if (uiquery->need_commit) uiquery->need_commit = -1;                goto error;	}	uiquery->need_commit = 0;        if (pos->start.range != NULL)                ped_geometry_destroy (pos->start.range);        if (pos->end.range != NULL)                ped_geometry_destroy (pos->end.range);        return 1;error_destroy_constraint:        ped_constraint_destroy (constraint);error_close_fs:        ped_file_system_close (fs);error:        if (pos->start.range != NULL)                ped_geometry_destroy (pos->start.range);        if (pos->end.range != NULL)                ped_geometry_destroy (pos->end.range);        return 0;}intperform_name (PedDisk* disk, PedPartition* part, char *name){	const char *temp;	int n;        if (!disk)                goto error;	if (!part)         	if (!get_partition (_("Partition"), disk, &part))                	goto error;	if (!name) {		temp = ped_partition_get_name(part);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -