Пример #1
0
void displayFileLSLine(Volume* volume, HFSPlusCatalogFile* file, const char* name) {
	time_t fileTime;
	struct tm *date;
	HFSPlusDecmpfs* compressData;
	
	printf("%06o ", file->permissions.fileMode);
	printf("%3d ", file->permissions.ownerID);
	printf("%3d ", file->permissions.groupID);

	if(file->permissions.ownerFlags & UF_COMPRESSED) {
		getAttribute(volume, file->fileID, "com.apple.decmpfs", (uint8_t**)(&compressData));
		flipHFSPlusDecmpfs(compressData);
		printf("%12" PRId64 " ", compressData->size);
		free(compressData);
	} else {
		printf("%12" PRId64 " ", file->dataFork.logicalSize);
	}

	fileTime = APPLE_TO_UNIX_TIME(file->contentModDate);
	date = localtime(&fileTime);
	if(date != NULL) {
		printf("%2d/%2d/%4d %2d:%02d ", date->tm_mon, date->tm_mday, date->tm_year + 1900, date->tm_hour, date->tm_min);
	} else {
		printf("                 ");
	}
	printf("%s\n", name);

	XAttrList* next;
	XAttrList* attrs = getAllExtendedAttributes(file->fileID, volume);
	if(attrs != NULL) {
		printf("Extended attributes\n");
		while(attrs != NULL) {
			next = attrs->next;
			printf("\t%s\n", attrs->name);
			free(attrs->name);
			free(attrs);
			attrs = next;
		}	
	}	
}
Пример #2
0
int removeFile(const char* fileName, Volume* volume) {
	HFSPlusCatalogRecord* record;
	HFSPlusCatalogKey key;
	io_func* io;
	HFSPlusCatalogFolder* parentFolder = NULL;

	record = getRecordFromPath3(fileName, volume, NULL, &key, TRUE, FALSE, kHFSRootFolderID);
	if(record != NULL) {
		parentFolder = (HFSPlusCatalogFolder*) getRecordByCNID(key.parentID, volume);
		if(parentFolder != NULL) {
			if(parentFolder->recordType != kHFSPlusFolderRecord) {
				ASSERT(FALSE, "parent not folder");
				free(parentFolder);
				return FALSE;
			}
		} else {
			ASSERT(FALSE, "can't find parent");
			return FALSE;
		}

		if(record->recordType == kHFSPlusFileRecord) {
			XAttrList* next, *attrs;
			io = openRawFile(((HFSPlusCatalogFile*)record)->fileID, &((HFSPlusCatalogFile*)record)->dataFork, record, volume);
			allocate((RawFile*)io->data, 0);
			CLOSE(io);

			removeFromBTree(volume->catalogTree, (BTKey*)(&key));
			
			attrs = getAllExtendedAttributes(((HFSPlusCatalogFile*)record)->fileID, volume);
			if(attrs != NULL) {
				while(attrs != NULL) {
					next = attrs->next;
					unsetAttribute(volume, ((HFSPlusCatalogFile*)record)->fileID, attrs->name);
					free(attrs->name);
					free(attrs);
					attrs = next;
				}	
			}	


			key.nodeName.length = 0;
			key.parentID = ((HFSPlusCatalogFile*)record)->fileID;
			key.keyLength = sizeof(key.parentID) + sizeof(key.nodeName.length);
			removeFromBTree(volume->catalogTree, (BTKey*)(&key));

			volume->volumeHeader->fileCount--;
		} else {
			if(((HFSPlusCatalogFolder*)record)->valence > 0) {
				free(record);
				free(parentFolder);
				ASSERT(FALSE, "folder not empty");
				return FALSE;
			} else {
				XAttrList *next, *attrs;
				removeFromBTree(volume->catalogTree, (BTKey*)(&key));
				attrs = getAllExtendedAttributes(((HFSPlusCatalogFolder*)record)->folderID, volume);
				if(attrs != NULL) {
					while(attrs != NULL) {
						next = attrs->next;
						unsetAttribute(volume, ((HFSPlusCatalogFolder*)record)->folderID, attrs->name);
						free(attrs->name);
						free(attrs);
						attrs = next;
					}	
				}	

				key.nodeName.length = 0;
				key.parentID = ((HFSPlusCatalogFolder*)record)->folderID;
				key.keyLength = sizeof(key.parentID) + sizeof(key.nodeName.length);
				removeFromBTree(volume->catalogTree, (BTKey*)(&key));
			}

			parentFolder->folderCount--;
			volume->volumeHeader->folderCount--;
		}
		parentFolder->valence--;
		updateCatalog(volume, (HFSPlusCatalogRecord*) parentFolder);
		updateVolume(volume);

		free(record);
		free(parentFolder);

		return TRUE;
	} else {
		if(parentFolder)
			free(parentFolder);
		ASSERT(FALSE, "cannot find record");
		return FALSE;
	}
}