void MParted::MParted_Core::closeDeviceAndDisk() { closeDisk() ; if (pedDevice) ped_device_destroy(pedDevice); pedDevice = NULL; }
/* This functions opens a regular UNIX file and designates the first nBytes of it as space for the emulated disk. nBytes should be an integral number of the block size. If nBytes > 0 and there is already a file by the given filename, that file’s contents may be overwritten. If nBytes is 0, an existing disk is opened, and should not be overwritten. There is no requirement to maintain integrity of any file content beyond nBytes. The return value is -1 on failure or a disk number on success. */ int openDisk(char *filename, int nBytes) { if (nBytes < 0 || nBytes % BLOCKSIZE) return EINVALIDSIZE; if (!diskTable) initDiskTable(); int i = 0; FILE *disk; for (i = 0; i < MAX_DISKS; i++) { if (diskTable[i].name && !strcmp(diskTable[i].name, filename)) closeDisk(i); } for (i = 0; (i < MAX_DISKS) && diskTable[i].size != 0; i++); if (i == MAX_DISKS) return EMAXDISKS; if (nBytes) { disk = fopen(filename, "w+"); fseek(disk, nBytes, SEEK_SET); fputc(EOF, disk); diskTable[i].size = nBytes; diskTable[i].name = filename; diskTable[i].fp = disk; } else { disk = fopen(filename, "r+"); if (!disk) return EFILENOTFOUND; diskTable[i].fp = disk; diskTable[i].name = filename; fseek(disk, 0, SEEK_END); diskTable[i].size = ftell(disk) - 1; } //printDiskTable(); return i; }