/** * Decode buffer considering it's a floating point encoded value of an SMC key * * @param type SMC type name will be used to determine decoding rules * @param size Encoded value buffer size * @param data Pointer to a encoded value buffer * @param outValue Decoded float value will be returned * * @return True on success False otherwise */ bool fakeSMCPluginDecodeFloatValue(const char *type, const UInt8 size, const void *data, float *outValue) { if (type && data && outValue) { size_t typeLength = strnlen(type, 4); if (typeLength >= 3 && (type[0] == 'f' || type[0] == 's') && type[1] == 'p' && size == 2) { UInt16 encoded = 0; bcopy(data, &encoded, 2); UInt8 i = fakeSMCPluginGetIndexFromChar(type[2]); UInt8 f = fakeSMCPluginGetIndexFromChar(type[3]); if (i + f != (type[0] == 's' ? 15 : 16) ) return false; UInt16 swapped = OSSwapBigToHostInt16(encoded); bool signd = type[0] == 's'; bool minus = bit_get(swapped, BIT(15)); if (signd && minus) bit_clear(swapped, BIT(15)); *outValue = ((float)swapped / (float)BIT(f)) * (signd && minus ? -1 : 1); return true; } } return false; }
static uint16_t _dispatch_transform_swap_to_host(uint16_t x, int32_t byteOrder) { if (byteOrder == OSLittleEndian) { return OSSwapLittleToHostInt16(x); } return OSSwapBigToHostInt16(x); }
WebSocketFrameRef WebSocketFrameCreateWithPayloadData (CFAllocatorRef allocator, WebSocketFrameOpCode opCode, Boolean isMasked, UInt8 *maskingKey, CFDataRef payload) { WebSocketFrameRef self = WebSocketFrameCreate(allocator); if_self { UInt8 header[2 + 8]; memset(header, 0, sizeof(header)); Boolean isFin = TRUE; Boolean rsv1 = FALSE; Boolean rsv2 = FALSE; Boolean rsv3 = FALSE; header[0] |= ((isFin ? 1 : 0) << 7); header[0] |= ((rsv1 ? 1 : 0) << 6); header[0] |= ((rsv2 ? 1 : 0) << 5); header[0] |= ((rsv3 ? 1 : 0) << 4); header[0] |= (opCode & 0xf); header[1] |= ((isMasked ? 1 : 0) << 7); CFIndex length = payload != NULL ? CFDataGetLength(payload) : 0; if (length <= 125) { header[1] |= (UInt8) length; WebSocketFrameAppend(self, header, 2); } else { if (length < 65535) { header[1] |= 126; *((UInt16 *) &header[2]) = OSSwapBigToHostInt16(length); WebSocketFrameAppend(self, header, 2 + 2); } else { header[1] |= 127; *((UInt64 *) &header[2]) = OSSwapBigToHostInt64(length); WebSocketFrameAppend(self, header, 2 + 8); } } if (isMasked) { UInt8 autoMaskingKey[4] = { 0, 0, 0, 0 }; if (maskingKey == NULL) { * (u_int32_t *) autoMaskingKey = arc4random(); maskingKey = autoMaskingKey; } WebSocketFrameAppend(self, maskingKey, 4); } if (length > 0) { WebSocketFrameAppend(self, CFDataGetBytePtr(payload), length); } WebSocketFrameParse(self); } return self; }
static inline unsigned int NextNum(NewMappingData *nmd) { if (nmd->bp >= nmd->endPtr) return(0); if (nmd->shorts) { unsigned short tmp = *((unsigned short *)nmd->bp); nmd->bp += 2; return OSSwapBigToHostInt16(tmp); } else { unsigned char tmp = *(nmd->bp); nmd->bp++; return tmp; } }
void DisposeBufferFromIORegistry ( QTOCDataFormat10Ptr TOCDataPtr ) { DebugLog ( ( "DisposeBufferFromIORegistry: Entering...\n" ) ); DebugAssert ( ( TOCDataPtr != NULL ) ); // Free the correct number of bytes. The TOCData has a length word // for its first field, so we free the number of bytes specified by // the length word, plus the length word itself. IOFree ( TOCDataPtr, ( OSSwapBigToHostInt16 ( TOCDataPtr->TOCDataLength ) + sizeof ( TOCDataPtr->TOCDataLength ) ) ); DebugLog ( ( "DisposeBufferFromIORegistry: Exiting...\n" ) ); }
__private_extern__ int ___chattr( const char * path, ___attr_t attr, ___attr_t noattr ) { /* * Change file flags. */ struct __chattrbuf { uint32_t size; uint8_t reserved0032[8]; ___attr_t attr; uint8_t reserved0112[22]; }; typedef struct __chattrbuf __chattrbuf; struct attrlist attributes; __chattrbuf buffer; int status; attributes.bitmapcount = ATTR_BIT_MAP_COUNT; attributes.commonattr = ATTR_CMN_FNDRINFO; attributes.dirattr = 0; attributes.fileattr = 0; attributes.forkattr = 0; attributes.volattr = 0; status = getattrlist( path, &attributes, &buffer, sizeof( buffer ), 0 ); if ( status == 0 ) { buffer.attr = OSSwapHostToBigInt16( ( OSSwapBigToHostInt16( buffer.attr ) & ~noattr ) | attr ); status = setattrlist( path, &attributes, ( ( uint8_t * ) &buffer ) + sizeof( buffer.size ), sizeof( buffer ) - sizeof( buffer.size ), 0 ); } return status; }
static errno_t fuse_vfsop_getattr(mount_t mp, struct vfs_attr *attr, vfs_context_t context) { int err = 0; bool deading = false, faking = false; struct fuse_dispatcher fdi; struct fuse_statfs_out *fsfo; struct fuse_statfs_out faked; struct fuse_data *data; fuse_trace_printf_vfsop(); data = fuse_get_mpdata(mp); if (!data) { panic("fuse4x: no private data for mount point?"); } if (!(data->dataflags & FSESS_INITED)) { // coreservices process requests ATTR_VOL_CAPABILITIES on the mountpoint right before // returning from mount() syscall. We need to fake the output because daemon might // not be ready to response yet (and deadlock will happen). faking = true; goto dostatfs; } fdisp_init(&fdi, 0); fdisp_make(&fdi, FUSE_STATFS, mp, FUSE_ROOT_ID, context); if ((err = fdisp_wait_answ(&fdi))) { // If we cannot communicate with the daemon (most likely because // it's dead), we still want to portray that we are a bonafide // file system so that we can be gracefully unmounted. if (err == ENOTCONN) { deading = faking = true; goto dostatfs; } return err; } dostatfs: if (faking) { bzero(&faked, sizeof(faked)); fsfo = &faked; } else { fsfo = fdi.answ; } if (fsfo->st.bsize == 0) { fsfo->st.bsize = FUSE_DEFAULT_IOSIZE; } if (fsfo->st.frsize == 0) { fsfo->st.frsize = FUSE_DEFAULT_BLOCKSIZE; } /* optimal transfer block size; will go into f_iosize in the kernel */ fsfo->st.bsize = fuse_round_size(fsfo->st.bsize, FUSE_MIN_IOSIZE, FUSE_MAX_IOSIZE); /* file system fragment size; will go into f_bsize in the kernel */ fsfo->st.frsize = fuse_round_size(fsfo->st.frsize, FUSE_MIN_BLOCKSIZE, FUSE_MAX_BLOCKSIZE); /* We must have: f_iosize >= f_bsize (fsfo->st.bsize >= fsfo->st_frsize) */ if (fsfo->st.bsize < fsfo->st.frsize) { fsfo->st.bsize = fsfo->st.frsize; } /* * TBD: Possibility: * * For actual I/O to fuse4x's "virtual" storage device, we use * data->blocksize and data->iosize. These are really meant to be * constant across the lifetime of a single mount. If necessary, we * can experiment by updating the mount point's stat with the frsize * and bsize values we come across here. */ /* * FUSE user daemon will (might) give us this: * * __u64 blocks; // total data blocks in the file system * __u64 bfree; // free blocks in the file system * __u64 bavail; // free blocks available to non-superuser * __u64 files; // total file nodes in the file system * __u64 ffree; // free file nodes in the file system * __u32 bsize; // preferred/optimal file system block size * __u32 namelen; // maximum length of filenames * __u32 frsize; // fundamental file system block size * * On Mac OS X, we will map this data to struct vfs_attr as follows: * * Mac OS X FUSE * -------- ---- * uint64_t f_supported <- // handled here * uint64_t f_active <- // handled here * uint64_t f_objcount <- - * uint64_t f_filecount <- files * uint64_t f_dircount <- - * uint32_t f_bsize <- frsize * size_t f_iosize <- bsize * uint64_t f_blocks <- blocks * uint64_t f_bfree <- bfree * uint64_t f_bavail <- bavail * uint64_t f_bused <- blocks - bfree * uint64_t f_files <- files * uint64_t f_ffree <- ffree * fsid_t f_fsid <- // handled elsewhere * uid_t f_owner <- // handled elsewhere * ... capabilities <- // handled here * ... attributes <- // handled here * f_create_time <- - * f_modify_time <- - * f_access_time <- - * f_backup_time <- - * uint32_t f_fssubtype <- // daemon provides * char *f_vol_name <- // handled here * uint16_t f_signature <- // handled here * uint16_t f_carbon_fsid <- // handled here */ VFSATTR_RETURN(attr, f_filecount, fsfo->st.files); VFSATTR_RETURN(attr, f_bsize, fsfo->st.frsize); VFSATTR_RETURN(attr, f_iosize, fsfo->st.bsize); VFSATTR_RETURN(attr, f_blocks, fsfo->st.blocks); VFSATTR_RETURN(attr, f_bfree, fsfo->st.bfree); VFSATTR_RETURN(attr, f_bavail, fsfo->st.bavail); VFSATTR_RETURN(attr, f_bused, (fsfo->st.blocks - fsfo->st.bfree)); VFSATTR_RETURN(attr, f_files, fsfo->st.files); VFSATTR_RETURN(attr, f_ffree, fsfo->st.ffree); /* f_fsid and f_owner handled elsewhere. */ /* Handle capabilities and attributes. */ handle_capabilities_and_attributes(mp, attr); VFSATTR_RETURN(attr, f_create_time, kZeroTime); VFSATTR_RETURN(attr, f_modify_time, kZeroTime); VFSATTR_RETURN(attr, f_access_time, kZeroTime); VFSATTR_RETURN(attr, f_backup_time, kZeroTime); if (deading) { VFSATTR_RETURN(attr, f_fssubtype, (uint32_t)FUSE_FSSUBTYPE_INVALID); } else { VFSATTR_RETURN(attr, f_fssubtype, data->fssubtype); } /* Daemon needs to pass this. */ if (VFSATTR_IS_ACTIVE(attr, f_vol_name)) { if (data->volname[0] != 0) { strncpy(attr->f_vol_name, data->volname, MAXPATHLEN); attr->f_vol_name[MAXPATHLEN - 1] = 0; VFSATTR_SET_SUPPORTED(attr, f_vol_name); } } VFSATTR_RETURN(attr, f_signature, OSSwapBigToHostInt16(FUSEFS_SIGNATURE)); VFSATTR_RETURN(attr, f_carbon_fsid, 0); if (!faking) fuse_ticket_drop(fdi.tick); return 0; }
IOReturn AppleFileSystemDriver::readHFSUUID(IOMedia *media, void **uuidPtr) { bool mediaIsOpen = false; UInt64 mediaBlockSize = 0; IOBufferMemoryDescriptor * buffer = 0; uint8_t * bytes = 0; UInt64 bytesAt = 0; UInt64 bufferReadAt = 0; vm_size_t bufferSize = 0; IOReturn status = kIOReturnError; HFSMasterDirectoryBlock * mdbPtr = 0; HFSPlusVolumeHeader * volHdrPtr = 0; VolumeUUID * volumeUUIDPtr = (VolumeUUID *)uuidPtr; DEBUG_LOG("%s::%s\n", kClassName, __func__); do { mediaBlockSize = media->getPreferredBlockSize(); bufferSize = IORound(sizeof(HFSMasterDirectoryBlock), mediaBlockSize); buffer = IOBufferMemoryDescriptor::withCapacity(bufferSize, kIODirectionIn); if ( buffer == 0 ) break; bytes = (uint8_t *) buffer->getBytesNoCopy(); // Open the media with read access. mediaIsOpen = media->open(media, 0, kIOStorageAccessReader); if ( mediaIsOpen == false ) break; bytesAt = 2 * kHFSBlockSize; bufferReadAt = IOTrunc( bytesAt, mediaBlockSize ); bytesAt -= bufferReadAt; mdbPtr = (HFSMasterDirectoryBlock *)&bytes[bytesAt]; volHdrPtr = (HFSPlusVolumeHeader *)&bytes[bytesAt]; status = media->read(media, bufferReadAt, buffer); if ( status != kIOReturnSuccess ) break; /* * If this is a wrapped HFS Plus volume, read the Volume Header from * sector 2 of the embedded volume. */ if ( OSSwapBigToHostInt16(mdbPtr->drSigWord) == kHFSSigWord && OSSwapBigToHostInt16(mdbPtr->drEmbedSigWord) == kHFSPlusSigWord) { u_int32_t allocationBlockSize, firstAllocationBlock, startBlock, blockCount; if (OSSwapBigToHostInt16(mdbPtr->drSigWord) != kHFSSigWord) { break; } allocationBlockSize = OSSwapBigToHostInt32(mdbPtr->drAlBlkSiz); firstAllocationBlock = OSSwapBigToHostInt16(mdbPtr->drAlBlSt); if (OSSwapBigToHostInt16(mdbPtr->drEmbedSigWord) != kHFSPlusSigWord) { break; } startBlock = OSSwapBigToHostInt16(mdbPtr->drEmbedExtent.startBlock); blockCount = OSSwapBigToHostInt16(mdbPtr->drEmbedExtent.blockCount); bytesAt = ((u_int64_t)startBlock * (u_int64_t)allocationBlockSize) + ((u_int64_t)firstAllocationBlock * (u_int64_t)kHFSBlockSize) + (u_int64_t)(2 * kHFSBlockSize); bufferReadAt = IOTrunc( bytesAt, mediaBlockSize ); bytesAt -= bufferReadAt; mdbPtr = (HFSMasterDirectoryBlock *)&bytes[bytesAt]; volHdrPtr = (HFSPlusVolumeHeader *)&bytes[bytesAt]; status = media->read(media, bufferReadAt, buffer); if ( status != kIOReturnSuccess ) break; } /* * At this point, we have the MDB for plain HFS, or VHB for HFS Plus and HFSX * volumes (including wrapped HFS Plus). Verify the signature and grab the * UUID from the Finder Info. */ if (OSSwapBigToHostInt16(mdbPtr->drSigWord) == kHFSSigWord) { bcopy((void *)&mdbPtr->drFndrInfo[6], volumeUUIDPtr->bytes, kVolumeUUIDValueLength); status = kIOReturnSuccess; } else if (OSSwapBigToHostInt16(volHdrPtr->signature) == kHFSPlusSigWord || OSSwapBigToHostInt16(volHdrPtr->signature) == kHFSXSigWord) { bcopy((void *)&volHdrPtr->finderInfo[24], volumeUUIDPtr->bytes, kVolumeUUIDValueLength); status = kIOReturnSuccess; } else { // status = 0 from earlier successful media->read() status = kIOReturnBadMedia; } } while (false); if ( mediaIsOpen ) media->close(media); if ( buffer ) buffer->release(); DEBUG_LOG("%s::%s finishes with status %d\n", kClassName, __func__, status); return status; }
int main(int argc, char *argv[]) { FILE *fp = fopen(argv[1],"rb"); int pmt_pid = -1; int vid_pid = -1; int aud_pid = -1; int ecm_pid = -1; int ecm_found = 0; int trmp_pid = -1; while(1) { if(fgetc(fp) == 0x47) { unsigned char header[3]; fread(header,1,3,fp); int adaptation_field_control = (header[2]>>4)&0x3; int pid = ((unsigned int)(header[0]&0x1f)<<8)|header[1]; int payload_unit_start_indicator = (header[0]>>6)&0x1; /*if(pid != vid_pid && pid != aud_pid) { fprintf(stderr,"PID: 0x%x\n",pid); fprintf(stderr," transport_error_indicator: %d\n",header[0]>>7); fprintf(stderr," payload_unit_start_indicator: %d\n",payload_unit_start_indicator); fprintf(stderr," transport_priority: %d\n",(header[0]>>5)&0x1); fprintf(stderr," transport_scramble_control: 0x%x\n",(header[2]>>6)&0x3); fprintf(stderr," adaptation_field_control: 0x%x\n",adaptation_field_control); fprintf(stderr," counter: %d\n",header[2]&0xf); }*/ if(pid == 0) { fprintf(stderr,"PID: 0x%x (PAT)\n",pid); fprintf(stderr," adaptation_field_control: 0x%x\n",adaptation_field_control); fprintf(stderr," payload_unit_start_indicator: %d\n",payload_unit_start_indicator); off_t packet_beginning = ftello(fp); if(adaptation_field_control & 0x2) { fseeko(fp,fgetc(fp),SEEK_CUR); } if(payload_unit_start_indicator) { /* 1 byte pointer_field exists at the beginning of the payload */ fseeko(fp,1,SEEK_CUR); } unsigned short section_length; fseeko(fp,1,SEEK_CUR); fread(§ion_length,2,1,fp); section_length = OSSwapBigToHostInt16(section_length) & 0xfff; fseeko(fp,5,SEEK_CUR); int table_count = (section_length - 4 - 3 - 2) / 4; int i; for(i=0;i<table_count;i++) { unsigned short pno,pid; fread(&pno,2,1,fp); fread(&pid,2,1,fp); pno = OSSwapBigToHostInt16(pno); pid = OSSwapBigToHostInt16(pid) & 0x1fff; if(pno == 0) { fprintf(stderr," NIT PID : 0x%04x\n",pid); } else { fprintf(stderr," Program 0x%04x PMT PID : 0x%04x\n",pno,pid); pmt_pid = pid; } } fseeko(fp,packet_beginning,SEEK_SET); } else if(pid == 1) { fprintf(stderr,"PID: 0x%x (CAT)\n",pid); fprintf(stderr," adaptation_field_control: 0x%x\n",adaptation_field_control); fprintf(stderr," payload_unit_start_indicator: %d\n",payload_unit_start_indicator); off_t packet_beginning = ftello(fp); if(adaptation_field_control & 0x2) { fseeko(fp,fgetc(fp),SEEK_CUR); } if(payload_unit_start_indicator) { /* 1 byte pointer_field exists at the beginning of the payload */ fseeko(fp,1,SEEK_CUR); } unsigned short section_length; fseeko(fp,1,SEEK_CUR); fread(§ion_length,2,1,fp); section_length = OSSwapBigToHostInt16(section_length) & 0xfff; fseeko(fp,5,SEEK_CUR); section_length -= 5 + 4; int read = 0; while(read < section_length) { unsigned char tag; unsigned char length; unsigned short ca_system_id; unsigned short pid; fread(&tag,1,1,fp); fread(&length,1,1,fp); fread(&ca_system_id,2,1,fp); fread(&pid,2,1,fp); ca_system_id = OSSwapBigToHostInt16(ca_system_id); pid = OSSwapBigToHostInt16(pid) & 0x1fff; if(tag == 0x09) { fprintf(stderr," EMM PID : 0x%04x\n",pid); } else if(tag == 0xf6) { fprintf(stderr," TRMP system ID : 0x%04x\n",ca_system_id); fprintf(stderr," TRMP PID : 0x%04x\n",pid); } fseeko(fp,length-2,SEEK_CUR); read += 2 + length; } fseeko(fp,packet_beginning,SEEK_SET); } else if(pid == pmt_pid) { fprintf(stderr,"PID: 0x%x (PMT)\n",pid); fprintf(stderr," adaptation_field_control: 0x%x\n",adaptation_field_control); fprintf(stderr," payload_unit_start_indicator: %d\n",payload_unit_start_indicator); off_t packet_beginning = ftello(fp); if(adaptation_field_control & 0x2) { fseeko(fp,fgetc(fp),SEEK_CUR); } if(payload_unit_start_indicator) { /* 1 byte pointer_field exists at the beginning of the payload */ fseeko(fp,1,SEEK_CUR); } unsigned short section_length; fseeko(fp,1,SEEK_CUR); fread(§ion_length,2,1,fp); section_length = OSSwapBigToHostInt16(section_length) & 0xfff; fseeko(fp,7,SEEK_CUR); unsigned short program_info_length; fread(&program_info_length,2,1,fp); program_info_length = OSSwapBigToHostInt16(program_info_length) & 0xfff; int read = 0; while(read < program_info_length) { unsigned char tag; unsigned char length; fread(&tag,1,1,fp); fread(&length,1,1,fp); if(tag == 0x09) { unsigned short pid; fseeko(fp,2,SEEK_CUR); fread(&pid,2,1,fp); ecm_pid = OSSwapBigToHostInt16(pid) & 0x1fff; fseeko(fp,-4,SEEK_CUR); fprintf(stderr," ECM PID : 0x%04x\n",ecm_pid); } else if(tag == 0xf6) { unsigned short pid; fread(&pid,2,1,fp); fprintf(stderr," TRMP system ID : 0x%04x\n",OSSwapBigToHostInt16(pid)); fread(&pid,2,1,fp); trmp_pid = OSSwapBigToHostInt16(pid) & 0x1fff; fseeko(fp,-4,SEEK_CUR); fprintf(stderr," TRMP PID : 0x%04x\n",trmp_pid); } fseeko(fp,length,SEEK_CUR); read += 2 + length; } section_length -= 7 + 2 + program_info_length + 4; read = 0; while(read < section_length) { unsigned char stream_type; unsigned short pid; unsigned short length; fread(&stream_type,1,1,fp); fread(&pid,2,1,fp); fread(&length,2,1,fp); pid = OSSwapBigToHostInt16(pid) & 0x1fff; length = OSSwapBigToHostInt16(length) & 0xfff; if(stream_type == 0x02) { fprintf(stderr," MPEG-2 video PID : 0x%04x\n",pid); vid_pid = pid; } else if(stream_type == 0x0f) { fprintf(stderr," MPEG-2 AAC PID : 0x%04x\n",pid); aud_pid = pid; } unsigned char tag; fread(&tag,1,1,fp); if(tag == 0xf6) { fprintf(stderr," TRMP descriptor found\n"); } fseeko(fp,length-1,SEEK_CUR); read += 5 + length; } fseeko(fp,packet_beginning,SEEK_SET); } else if(pid == ecm_pid) { fprintf(stderr,"PID: 0x%x (ECM)\n",pid); fprintf(stderr," adaptation_field_control: 0x%x\n",adaptation_field_control); fprintf(stderr," payload_unit_start_indicator: %d\n",payload_unit_start_indicator); off_t packet_beginning = ftello(fp); if(adaptation_field_control & 0x2) { fseeko(fp,fgetc(fp),SEEK_CUR); } if(payload_unit_start_indicator) { /* 1 byte pointer_field exists at the beginning of the payload */ fseeko(fp,1,SEEK_CUR); } /*------------------------- bit 8 table descriptor (0x82 or 0x83) 1 section syntax indicator 1 '1' 2 '11' 12 section length 16 table descriptor extension 2 '11' 5 version number 1 current next indicator 8 section number 8 last section number n data 32 CRC32 ---------------------------*/ unsigned short section_length; fseeko(fp,1,SEEK_CUR); fread(§ion_length,2,1,fp); section_length = OSSwapBigToHostInt16(section_length) & 0xfff; fseeko(fp,5,SEEK_CUR); section_length -= 5 + 4; int i; for(i=0;i<section_length;i++) { fprintf(stderr,"0x%02x,",fgetc(fp)); } putchar('\n'); /*int i; for(i=0;i<184;i++) { fprintf(stderr,"%02x ",fgetc(fp)); if((i&0xf) == 0xf) putchar('\n'); } putchar('\n');*/ ecm_found++; //if(ecm_found == 1) break; fseeko(fp,packet_beginning,SEEK_SET); } else if(pid == vid_pid) { #if 0 if(ecm_found) { fprintf(stderr,"PID: 0x%x (video)\n",pid); fprintf(stderr," adaptation_field_control: 0x%x\n",adaptation_field_control); fprintf(stderr," transport_scramble_control: 0x%x\n",(header[2]>>6)&0x3); fprintf(stderr," payload_unit_start_indicator: %d\n",payload_unit_start_indicator); int i; for(i=0;i<184;i++) { fprintf(stderr,"0x%02x, ",fgetc(fp)); if((i&0xf) == 0xf) putchar('\n'); } putchar('\n'); break; } #endif } //if(((header[2]>>6)&0x3) != 0) break; fseeko(fp,184,SEEK_CUR); } else fseeko(fp,1,SEEK_CUR);
void commonattrpack(attrinfo_t *aip, zfsvfs_t *zfsvfs, znode_t *zp, const char *name, ino64_t objnum, enum vtype vtype, boolean_t user64) { attrgroup_t commonattr = aip->ai_attrlist->commonattr; void *attrbufptr = *aip->ai_attrbufpp; void *varbufptr = *aip->ai_varbufpp; struct mount *mp = zfsvfs->z_vfs; cred_t *cr = (cred_t *)vfs_context_ucred(aip->ai_context); finderinfo_t finderinfo; /* * We should probably combine all the sa_lookup into a bulk * lookup operand. */ finderinfo.fi_flags = 0; if (ATTR_CMN_NAME & commonattr) { nameattrpack(aip, name, strlen(name)); attrbufptr = *aip->ai_attrbufpp; varbufptr = *aip->ai_varbufpp; } if (ATTR_CMN_DEVID & commonattr) { *((dev_t *)attrbufptr) = vfs_statfs(mp)->f_fsid.val[0]; attrbufptr = ((dev_t *)attrbufptr) + 1; } if (ATTR_CMN_FSID & commonattr) { *((fsid_t *)attrbufptr) = vfs_statfs(mp)->f_fsid; attrbufptr = ((fsid_t *)attrbufptr) + 1; } if (ATTR_CMN_OBJTYPE & commonattr) { *((fsobj_type_t *)attrbufptr) = vtype; attrbufptr = ((fsobj_type_t *)attrbufptr) + 1; } if (ATTR_CMN_OBJTAG & commonattr) { *((fsobj_tag_t *)attrbufptr) = VT_ZFS; attrbufptr = ((fsobj_tag_t *)attrbufptr) + 1; } /* * Note: ATTR_CMN_OBJID is lossy (only 32 bits). */ if ((ATTR_CMN_OBJID | ATTR_CMN_OBJPERMANENTID) & commonattr) { u_int32_t fileid; /* * On Mac OS X we always export the root directory id as 2 */ fileid = (objnum == zfsvfs->z_root) ? 2 : objnum; if (ATTR_CMN_OBJID & commonattr) { ((fsobj_id_t *)attrbufptr)->fid_objno = fileid; ((fsobj_id_t *)attrbufptr)->fid_generation = 0; attrbufptr = ((fsobj_id_t *)attrbufptr) + 1; } if (ATTR_CMN_OBJPERMANENTID & commonattr) { ((fsobj_id_t *)attrbufptr)->fid_objno = fileid; ((fsobj_id_t *)attrbufptr)->fid_generation = 0; attrbufptr = ((fsobj_id_t *)attrbufptr) + 1; } } /* * Note: ATTR_CMN_PAROBJID is lossy (only 32 bits). */ if (ATTR_CMN_PAROBJID & commonattr) { uint64_t parentid; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs), &parentid, sizeof (parentid)) == 0); /* * On Mac OS X we always export the root * directory id as 2 and its parent as 1 */ if (zp && zp->z_id == zfsvfs->z_root) parentid = 1; else if (parentid == zfsvfs->z_root) parentid = 2; ASSERT(parentid != 0); ((fsobj_id_t *)attrbufptr)->fid_objno = (uint32_t)parentid; ((fsobj_id_t *)attrbufptr)->fid_generation = 0; attrbufptr = ((fsobj_id_t *)attrbufptr) + 1; } if (ATTR_CMN_SCRIPT & commonattr) { *((text_encoding_t *)attrbufptr) = kTextEncodingMacUnicode; attrbufptr = ((text_encoding_t *)attrbufptr) + 1; } if (ATTR_CMN_CRTIME & commonattr) { uint64_t times[2]; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs), times, sizeof(times)) == 0); if (user64) { ZFS_TIME_DECODE((timespec_user64_t *)attrbufptr, times); attrbufptr = ((timespec_user64_t *)attrbufptr) + 1; } else { ZFS_TIME_DECODE((timespec_user32_t *)attrbufptr, times); attrbufptr = ((timespec_user32_t *)attrbufptr) + 1; } } if (ATTR_CMN_MODTIME & commonattr) { uint64_t times[2]; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_MTIME(zfsvfs), times, sizeof(times)) == 0); if (user64) { ZFS_TIME_DECODE((timespec_user64_t *)attrbufptr, times); attrbufptr = ((timespec_user64_t *)attrbufptr) + 1; } else { ZFS_TIME_DECODE((timespec_user32_t *)attrbufptr, times); attrbufptr = ((timespec_user32_t *)attrbufptr) + 1; } } if (ATTR_CMN_CHGTIME & commonattr) { uint64_t times[2]; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_CTIME(zfsvfs), times, sizeof(times)) == 0); if (user64) { ZFS_TIME_DECODE((timespec_user64_t *)attrbufptr, times); attrbufptr = ((timespec_user64_t *)attrbufptr) + 1; } else { ZFS_TIME_DECODE((timespec_user32_t *)attrbufptr, times); attrbufptr = ((timespec_user32_t *)attrbufptr) + 1; } } if (ATTR_CMN_ACCTIME & commonattr) { uint64_t times[2]; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs), times, sizeof(times)) == 0); if (user64) { ZFS_TIME_DECODE((timespec_user64_t *)attrbufptr, times); attrbufptr = ((timespec_user64_t *)attrbufptr) + 1; } else { ZFS_TIME_DECODE((timespec_user32_t *)attrbufptr, times); attrbufptr = ((timespec_user32_t *)attrbufptr) + 1; } } if (ATTR_CMN_BKUPTIME & commonattr) { /* legacy attribute -- just pass zero */ if (user64) { ((timespec_user64_t *)attrbufptr)->tv_sec = 0; ((timespec_user64_t *)attrbufptr)->tv_nsec = 0; attrbufptr = ((timespec_user64_t *)attrbufptr) + 1; } else { ((timespec_user32_t *)attrbufptr)->tv_sec = 0; ((timespec_user32_t *)attrbufptr)->tv_nsec = 0; attrbufptr = ((timespec_user32_t *)attrbufptr) + 1; } } if (ATTR_CMN_FNDRINFO & commonattr) { uint64_t val; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs), &val, sizeof(val)) == 0); getfinderinfo(zp, cr, &finderinfo); /* Shadow ZFS_HIDDEN to Finder Info's invisible bit */ if (val & ZFS_HIDDEN) { finderinfo.fi_flags |= OSSwapHostToBigConstInt16(kIsInvisible); } bcopy(&finderinfo, attrbufptr, sizeof (finderinfo)); attrbufptr = (char *)attrbufptr + 32; } if (ATTR_CMN_OWNERID & commonattr) { uint64_t val; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_UID(zfsvfs), &val, sizeof(val)) == 0); *((uid_t *)attrbufptr) = val; attrbufptr = ((uid_t *)attrbufptr) + 1; } if (ATTR_CMN_GRPID & commonattr) { uint64_t val; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_GID(zfsvfs), &val, sizeof(val)) == 0); *((gid_t *)attrbufptr) = val; attrbufptr = ((gid_t *)attrbufptr) + 1; } if (ATTR_CMN_ACCESSMASK & commonattr) { uint64_t val; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs), &val, sizeof(val)) == 0); *((u_int32_t *)attrbufptr) = val; attrbufptr = ((u_int32_t *)attrbufptr) + 1; } if (ATTR_CMN_FLAGS & commonattr) { u_int32_t flags = zfs_getbsdflags(zp); /* Shadow Finder Info's invisible bit to UF_HIDDEN */ if ((ATTR_CMN_FNDRINFO & commonattr) && (OSSwapBigToHostInt16(finderinfo.fi_flags) & kIsInvisible)) flags |= UF_HIDDEN; *((u_int32_t *)attrbufptr) = flags; attrbufptr = ((u_int32_t *)attrbufptr) + 1; } if (ATTR_CMN_USERACCESS & commonattr) { u_int32_t user_access = 0; uint64_t val; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs), &val, sizeof(val)) == 0); user_access = getuseraccess(zp, aip->ai_context); /* Also consider READ-ONLY file system. */ if (vfs_flags(mp) & MNT_RDONLY) { user_access &= ~W_OK; } /* Locked objects are not writable either */ if ((val & ZFS_IMMUTABLE) && (vfs_context_suser(aip->ai_context) != 0)) { user_access &= ~W_OK; } *((u_int32_t *)attrbufptr) = user_access; attrbufptr = ((u_int32_t *)attrbufptr) + 1; } if (ATTR_CMN_FILEID & commonattr) { /* * On Mac OS X we always export the root directory id as 2 */ if (objnum == zfsvfs->z_root) objnum = 2; *((u_int64_t *)attrbufptr) = objnum; attrbufptr = ((u_int64_t *)attrbufptr) + 1; } if (ATTR_CMN_PARENTID & commonattr) { uint64_t parentid; VERIFY(sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs), &parentid, sizeof (parentid)) == 0); /* * On Mac OS X we always export the root * directory id as 2 and its parent as 1 */ if (zp && zp->z_id == zfsvfs->z_root) parentid = 1; else if (parentid == zfsvfs->z_root) parentid = 2; ASSERT(parentid != 0); *((u_int64_t *)attrbufptr) = parentid; attrbufptr = ((u_int64_t *)attrbufptr) + 1; } *aip->ai_attrbufpp = attrbufptr; *aip->ai_varbufpp = varbufptr; }
uint16_t fmbe16(uint16_t x) { return OSSwapBigToHostInt16(x); }
static BVRef diskScanAPMBootVolumes( int biosdev, int * countPtr ) { struct DiskBVMap * map; struct Block0 *block0_p; unsigned int blksize; unsigned int factor; void *buffer = malloc(BPS); /* Check for alternate block size */ if (readBytes( biosdev, 0, BPS, buffer ) != 0) { return NULL; } block0_p = buffer; if (OSSwapBigToHostInt16(block0_p->sbSig) == BLOCK0_SIGNATURE) { blksize = OSSwapBigToHostInt16(block0_p->sbBlkSize); if (blksize != BPS) { free(buffer); buffer = malloc(blksize); } factor = blksize / BPS; } else { blksize = BPS; factor = 1; } do { // Create a new mapping. map = (struct DiskBVMap *) malloc( sizeof(*map) ); if ( map ) { int error; DPME *dpme_p = (DPME *)buffer; UInt32 i, npart = UINT_MAX; BVRef bvr; map->biosdev = biosdev; map->bvr = NULL; map->bvrcnt = 0; map->next = gDiskBVMap; gDiskBVMap = map; for (i=0; i<npart; i++) { error = readBytes( biosdev, (kAPMSector + i) * factor, blksize, buffer ); if (error || OSSwapBigToHostInt16(dpme_p->dpme_signature) != DPME_SIGNATURE) { break; } if (i==0) { npart = OSSwapBigToHostInt32(dpme_p->dpme_map_entries); } /* printf("name = %s, %s%s %d -> %d [%d -> %d] {%d}\n", dpme.dpme_name, dpme.dpme_type, (dpme.dpme_flags & DPME_FLAGS_BOOTABLE) ? "(bootable)" : "", dpme.dpme_pblock_start, dpme.dpme_pblocks, dpme.dpme_lblock_start, dpme.dpme_lblocks, dpme.dpme_boot_block); */ if (strcmp(dpme_p->dpme_type, "Apple_HFS") == 0) { bvr = newAPMBVRef(biosdev, i, OSSwapBigToHostInt32(dpme_p->dpme_pblock_start) * factor, dpme_p, HFSInitPartition, HFSLoadFile, HFSReadFile, HFSGetDirEntry, HFSGetFileBlock, HFSGetDescription, 0, kBIOSDevTypeHardDrive); bvr->next = map->bvr; map->bvr = bvr; map->bvrcnt++; } } } } while (0); free(buffer); if (countPtr) *countPtr = map ? map->bvrcnt : 0; return map ? map->bvr : NULL; }
IOReturn IOCDBlockStorageDriver::cacheTocInfo(void) { IOBufferMemoryDescriptor *buffer; IOReturn result; CDTOC *toc; UInt16 tocSize; assert(sizeof(CDTOC) == 4); /* (compiler/platform check) */ assert(sizeof(CDTOCDescriptor) == 11); /* (compiler/platform check) */ assert(_toc == NULL); /* Read the TOC header: */ buffer = IOBufferMemoryDescriptor::withCapacity(sizeof(CDTOC),kIODirectionIn); if (buffer == NULL) { return(kIOReturnNoMemory); } result = getProvider()->readTOC(buffer); if (result != kIOReturnSuccess) { buffer->release(); return(result); } toc = (CDTOC *) buffer->getBytesNoCopy(); tocSize = OSSwapBigToHostInt16(toc->length) + sizeof(toc->length); buffer->release(); /* Reject the TOC if its size is too small: */ if (tocSize <= sizeof(CDTOC)) { return(kIOReturnNotFound); } /* Read the TOC in full: */ buffer = IOBufferMemoryDescriptor::withCapacity(tocSize,kIODirectionIn); if (buffer == NULL) { return(kIOReturnNoMemory); } result = getProvider()->readTOC(buffer); if (result != kIOReturnSuccess) { buffer->release(); return(result); } toc = (CDTOC *) IOMalloc(tocSize); if (toc == NULL) { buffer->release(); return(kIOReturnNoMemory); } if (buffer->readBytes(0,toc,tocSize) != tocSize) { buffer->release(); IOFree(toc,tocSize); return(kIOReturnNoMemory); } _toc = toc; _tocSize = tocSize; buffer->release(); return(result); }
/** * Decode buffer considering it's an integer encoded value of an SMC key * * @param type SMC type name will be used to determine decoding rules * @param size Size of encoded value buffer * @param data Pointer to encoded value buffer * @param outValue Decoded integer value will be returned * * @return True on success False otherwise */ bool fakeSMCPluginDecodeIntValue(const char *type, const UInt8 size, const void *data, int *outValue) { if (type && data && outValue) { size_t typeLength = strnlen(type, 4); if (typeLength >= 3 && (type[0] == 'u' || type[0] == 's') && type[1] == 'i') { bool signd = type[0] == 's'; switch (type[2]) { case '8': if (size == 1) { UInt8 encoded = 0; bcopy(data, &encoded, 1); if (signd && bit_get(encoded, BIT(7))) { bit_clear(encoded, BIT(7)); *outValue = -encoded; } *outValue = encoded; return true; } break; case '1': if (type[3] == '6' && size == 2) { UInt16 encoded = 0; bcopy(data, &encoded, 2); encoded = OSSwapBigToHostInt16(encoded); if (signd && bit_get(encoded, BIT(15))) { bit_clear(encoded, BIT(15)); *outValue = -encoded; } *outValue = encoded; return true; } break; case '3': if (type[3] == '2' && size == 4) { UInt32 encoded = 0; bcopy(data, &encoded, 4); encoded = OSSwapBigToHostInt32(encoded); if (signd && bit_get(encoded, BIT(31))) { bit_clear(encoded, BIT(31)); *outValue = -encoded; } *outValue = encoded; return true; } break; } } } return false; }