Esempio n. 1
0
static void
sync_volume(const char *path) {
        int full_sync = FSCTL_SYNC_FULLSYNC | FSCTL_SYNC_WAIT;

        (void)fsctl(path, FSCTL_SYNC_VOLUME, &full_sync, 0);
        return;
}
Esempio n. 2
0
int
sync_volume_np(const char *path, int flags) {
	int full_sync = 0;
	int terrno;
	int rv;

	if (flags & SYNC_VOLUME_FULLSYNC)
		full_sync |= FSCTL_SYNC_FULLSYNC;

	if (flags & SYNC_VOLUME_WAIT)
		full_sync |= FSCTL_SYNC_WAIT;

	terrno = errno;
	rv = (fsctl(path, FSCTL_SYNC_VOLUME, &full_sync, 0) == -1) ? errno : 0;
	errno = terrno;
	return rv;
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
	
	if ( argc != 3 ) {
		printf("Usage: %s <path to filesystem> <size in bytes>\n", argv[0]);
		exit(-1);
	};
	
	char *device = "/dev/rdisk0s1";	
	int fd = open(device, O_RDWR | O_SHLOCK);

	if ( fd < 0 ) {
		printf("[-] Couldn't open disk %s.\n", device);
		exit(-1);
	};

	uint32_t blocksize = 0;
	if ( ioctl(fd, DKIOCGETBLOCKSIZE, &blocksize) != 0 ) {
		printf("[-] ioctl DKIOCGETBLOCKSIZE failed.\n");
		close(fd);
		exit(-1);
	};
	
	close(fd);

	uint64_t required_size = atoll(argv[2]);

	uint64_t mod;
	if ( (mod = required_size % blocksize) != 0 ) {
		printf("[-] Required size has to be multiple of blocksize (%u).\n", blocksize);
		required_size = required_size - mod + (uint64_t) blocksize;
		printf("[i] Adjusting size to %llu to match next block.\n", required_size);
	}

	
	printf("Resizing %s to %llu bytes.\n", argv[1], required_size);
	
	int err;
	if ( ( err = fsctl(argv[1], RESIZE_PARTITION, &required_size, 0)) != 0) {
		printf("[-] HFS resize failed. errno=%i\n", err);
	};

	return 0;
}
Esempio n. 4
0
T_DECL(fsctl_get_uninitialized,
	"Initial fsctl.get should return zeros",
	T_META_ASROOT(false))
{
	int err;
	char *mount_path;
	disk_conditioner_info info = {0};
	disk_conditioner_info expected_info = {0};

	T_SETUPBEGIN;
	mount_path = mktempmount();
	T_SETUPEND;

	info.enabled = true;
	info.is_ssd = true;
	err = fsctl(mount_path, DISK_CONDITIONER_IOC_GET, &info, 0);
	T_WITH_ERRNO;
	T_ASSERT_EQ_INT(0, err, "fsctl(DISK_CONDITIONER_IOC_GET)");

	err = memcmp(&info, &expected_info, sizeof(info));
	T_ASSERT_EQ_INT(0, err, "initial DMC info is zeroed");
}

T_DECL(fsctl_set,
	"fsctl.set should succeed and fsctl.get should verify")
{
	int err;
	char *mount_path;
	disk_conditioner_info info = {0};
	disk_conditioner_info expected_info = {0};