[轉載]Fusion Drive 简介


But original post can not access anymore.

Fusion Drive 简介

1 Fusion Drive 介绍

Apple 的官方介绍如下 :
在 Apple Store 在线商店作为可配置选件提供的 Fusion Drive 是一个突破性概念,它将传统硬盘存储容量大的特点与闪存高性能的特点融合在一起。iMac 配置 Fusion Drive 之后,在执行磁盘密集型任务时,例如启动系统、启动 app 以及导入照片时,将运行地更加快速、更加高效。这是因为频繁使用的项目存储在速度更快的闪存中,不常访问的项目则存储在硬盘中。文件传输在后台进行,你甚至丝毫察觉不到。随着系统逐渐了解你的工作方式,Fusion Drive 可以为你带来更出色的 Mac 使用体验,而你不必费心做任何事。目前,Apple 可提供 1TB 和 3TB 两种容量的 Fusion Drive 供用户选择。

2 Fusion Drive 背景

虽然 SSD 固态硬盘的价格已经变的越来越亲民,但是其容量上依然不能与传统 HDD 机械硬盘相媲美。因此,兼顾 SSD 性能和传统 HDD 容量的方案层出不穷。一直以来,很多 Mac 用户选择自行在机器中配置一块 SSD 和一块 HDD,并通过手工分配系统,应用程序和文档的方法来在性能和容量上获得一种平衡,但是此方法较为繁琐,且没有一个较为方便的工具来帮助用户实现。特别对于新手来说,无论是硬件的安装还是系统的配置都显得异常困难。另外,由于普通用户缺乏对系统的认识,导致其手工配置的方案从性能上来说无法达到最优,甚至还会出现严重的系统问题。后来,随着技术的进步出现了基于硬件的方案。比较有名的是来自希捷的混合硬盘(Momentus XT)。但是此技术依赖特定硬件且与 OS X 系统兼容性不佳而不被 Mac 用户所接受。Apple 洞悉用户的此种需求,则在 2012 年随着新 iMac 和 Mac mini 的发布,推出了 Fusion Drive 这一新技术。用户可以为 Mac 选配 Fusion Drive 而直接获得这一性能与容量完美平衡的存储方案,无需任何额外配置,也不会绑定特定硬件品牌型号。

3 Fusion Drive 类似技术

Fusion Drive 的类似技术有很多,除了上文提到过的希捷混合硬盘技术,还有 Intel 的 Smart Response Technology 智能响应 (SRT) 技术,以及企业存储中常见的 Automated Tiered Storage (自动分层存储) 技术。
  1. 混合硬盘技术
    优点
     - 无需用户配置 
     - 兼容多种操作系统
     - 花费较小
    
    不足
     - 需特定硬件
     - 与某些操作系统,如 OS X 兼容性不佳
     - 算法无法根据不同操作系统做特定优化
    
  2. SRT
    优点
     - 花费较小,性能提升明显
     - SSD 和 HDD 无需选择特定厂商产品 在 Enhanced 模式下,可以获得与单块硬盘相同的数据安全性并获得更高的读写性能
    
    不足
     - 需要用户有一定的计算机使用和配置经验 
     - 概念较多,用户不容易掌握。比如在 Maximize 模式下的数据安全危险 
     - 目前并不能在 OS X 系统下使用 
    
  3. Automated Tiered Storage
    优点
     - 性能强悍
     - 数据安全性高
    
    不足
     - 价格高昂
     - 需要特定的软硬件
     - OS X 下目前难以配置
    
  4. Fusion Drive
    优点
     - 无需用户配置
     - 花费较小
     - 性能提升较明显
     - SSD 和 HDD 无需选择特定厂商产品
    
    不足
     - 目前只能在 OS X 10.8.2 及以上系统中支持
     - 只能支持 BootCamp 方式安装的 Windows 系统
     - 如果非特定 Mac 机型用户需要 Fusion Drive 产品只能向 Apple 购买
    

Fusion Drive 背后的技术

CoreStorage 与 Logical Volume Manager (LVM)

HFS+ 是一个古老的文件系统。10.6 时,Apple 曾经有意愿将文件系统替换为最为先进的 ZFS。但天不随人愿,可能的风险,专利问题,以及 ZFS 专利持有人 Sun 被 Oracle 收购等众多原因最终导致了这一计划的流产。文件系统的落后阻碍了操作系统的前进,所以,Apple 开始转而自行在 HFS+ 基础上加入各项改进,以便让其能够支撑新的操作系统特性。随着有众多改进的 OS X Lion 10.7 发布,Apple 的工作成果也渐渐为人所知。比如 Auto Save ,本地 Time Machine Snapshot (快照),File Vault 2 全盘加密等。这些工作都是在“古老的” HFS+ 上完成,其背后的功臣,就是 CoreStorage。CoreStorage 其实是一套 API 和 Kext (Kernel Extension 或者说是驱动程序)的集合,存在与文件系统与物理存储媒介(比如硬盘等)之间,用于给文件系统提供最大限度的灵活性。其实它还有一个更为通俗的名字,那就是 Logical Volume Manager (LVM 逻辑卷管理器)。 长久以来,OS X 都缺乏一个现代操作系统所必须的组件,那就是逻辑卷管理器。逻辑卷管理器以一个虚拟层(或抽象层)存在与物理存储媒介与文件系统之间,为操作系统管理,分配存储空间带来最大的便利性。LVM 是现代操作系统中非常重要的一个组件。因为当前用户的存储媒介多样化,除了系统内置的存储器,还有比如 DAS (Direct Attached Storage) 外接大容量存储,或 NAS (Network Attached Storage) 网络存储,或 Cloud Storage 云存储等。所有这些都要求操作系统拥有能够统一管理这些存储设备(空间)的能力。这个能力就来自于逻辑卷管理器。以前的 OS X 操作系统,只能够提供软件 RAID 来实现一小部分的 LVM 功能,比如磁盘连接 (Concatenated Disk Set 即让多块磁盘在用户空间 Finder 中显示为一块磁盘) 等。这些操作对于普通用户来说过于复杂,而且由于其自身的缺陷,数据安全,灵活性,性能等无法得到很好的保证,所以在用户中使用率非常低。而通过 LVM,用户不仅能够方便的管理多个存储,而且能够方便的对其中的某个存储进行更换,而不影响数据的一致性。另外,CoreStorage 还能够判断其管理下存储设备的性能,也能够自动对访问频率高的文件进行存储位置优化。所有这些特性,促成了 Fusion Drive 的诞生。

DIY Fusion Drive

在了解了 Fusion Drive 和其背后的技术后,我们完全可以在 CoreStorage 的基础上自行组建一个 Fusion Drive,本节下面的内容就是带你一步步的在老 Mac 上创建一个 Fusion Drive。
  1. 软件与硬件要求
    -硬件
     - 一台装备有至少一块 SSD 和一块 HDD 的 Mac
     - 用于启动并安装 OS X Mountain Lion 10.8.2+ 系统的 USB 闪存盘或外置硬盘一块
     - 如何制作 OS X Mountain Lion 安装媒介
    
    -软件
     - Install OS X Mountain Lion.app 即 OS X Mountain Lion 安装程序 (版本 1.3.18)。它用于制作启动安装媒介。
    
  2. 注意事项
    备份你的所有数据,因为这个操作将会清空 SSD 和 HDD 上的所有内容
  3. 2011 iMac 27'' 实践
    1. 实验平台
      • iMac 27'' mid 2011
      • OS X Mountain Lion 10.8.2
      • 2.7 GHz Intel Core i5
      • 16 GB 1333 MHz DDR3 RAM
      • Samsung 470 Series SSD 128 GB
      • Seagate 7200 rpm HDD 1 TB
    2. 制作过程
      1. 首先使用制作好的 OS X Mountain Lion 安装媒介启动 Mac。(开机按住 Option,选择使用安装媒介启动)
      2. 到安装界面后,启动 Disk Utility 磁盘工具,如图:1。图中可见,我将要用于制作 Fusion Drive 的两块磁盘,1 TB ST 和 128.04 GB Samsung。
      3. 分别选中每个磁盘,然后点击磁盘工具右边栏中的 Partition 标签页,然后点击分区列表下方的 - 减号按钮删除这两块磁盘上所有的卷宗 (分区),如图: 23。删除完毕后,磁盘工具应该类似如图显示: 4
      4. 完毕后退出磁盘工具,点击工具栏上的 Utilities 菜单,启动 Terminal 终端 5
      5. 首先执行 diskutil list 命令,你可以在终端中获得一个完整的当前磁盘卷宗列表,如图 6。就本示例来说,/dev/disk0 (1TB HDD) 和 /dev/disk1 (128GB SSD) 是本次将要用来制作 Fusion Drive 的磁盘。(需要注意的是,你的系统显示可能与此不同,请根据你的实际情况来定)
      6. 因为 Fusion Drive 在用户层是显示为一个单独的卷宗(分区)而它又是基于 CoreStorage 的,所以我们只需要创建一个CoreStorage逻辑卷将两块磁盘管理起来即可,但是目前磁盘工具并不支持这一功能,所以我们还是要到终端下进行。执行此命令 diskutil coreStorage create FusionDrive disk0 disk1 7。其中,FusionDrive 是逻辑卷名称,你可以将其修改为任意你喜欢的名称 (需要注意的是,如果名称中有空格,则需要加上双引号,如 "ibuick FusionDrive")。disk0 disk1 则是需要用于制作 Fusion Drive 的磁盘设备命,你需要根据你在上一步骤中获得设备名称进行填写。执行此命令时,你可一看到终端的类似输出 8。当终端输出 "Finished CoreStorage operation" 并返回光标闪烁状态,则表明操作完成。我们可以打开磁盘工具,验证一下:9。图中我们可以看到,在磁盘工具中出现了我们刚才创建的 FusionDrive,且大小为 1.13 TB (1TB+128GB)。我们还可以使用 diskutil coreStorage list 命令,来对磁盘工具中显示的内容进行验证,10。从终端输出的结果,result1 我们可以看到其中的奥秘。首先是一个 UUID 为 56E62D7F-37C2-4257-BB09-9D10EE84E97E 的 CoreStorage logical volume group (CoreStorage 逻辑卷宗组)。它含有两块物理卷宗(或磁盘 Physical Volume),UUID 为 DE2086FB-9306-4C44-98B6-241B1F2D4DFB 的 disk0 和 UUID 为 50368349-C9BC-4BE6-9357-E845C2CCD3D1 的 disk1。
      7. 这里你可以将逻辑卷宗组简单理解为一块磁盘,它可以由多块磁盘组成。有了磁盘,我们可以在上面建立卷宗(即分区),同样使用命令来实现。执行此命令,diskutil coreStorage createVolume 56E62D7F-37C2-4257-BB09-9D10EE84E97E jhfs+ MacintoshFD 1110g 创建一个卷宗。其中,56E62D7F-37C2-4257-BB09-9D10EE84E97E 是刚刚我们创建的逻辑卷宗组的 UUID,你的实际情况可能与此不同。jhfs+ 则是磁盘格式 (Mac OS 扩展日志式) 1110g 则是指定卷宗的大小。11,执行完毕后,我们也能在磁盘工具中找到新创建的分区。12。这时,我们还可以通过 diskutil coreStorage list 命令来验证,result2 。其中的 Logical Volume MacintoshFD 及是我们刚刚创建的分区。
过程到此,我们就完成了 DIY Fusion Drive 的整个工作,你可以退出磁盘工具和终端,开始安装 OS X Mountain Lion。

参考文档

[轉載]BCB:Put DLL File into EXE File


ref


BCB:Put DLL File into EXE File

把 DLL File 存放於應用程式裡,在應用程式是很常用的技巧,這個方法可以讓程式設計者只需給使用者一個執行檔就可以,不需再給DLL File。就不需要擔心使用者忘了把應用程式 和 DLL File 放在同一個目錄之下。有些程式設計者會使用InstallShield 把應用程式和DLL整合在一起來解決這個問題,而我們是把DLL放到執行檔的資源裡。

在PE格式的執行檔包含了資源,CODE 和 DATA,其中資源可以是文字(EX:版權宣告),圖片,ICON,動畫及二進制檔,我們就是把 DLL FILE 或者 DRIVER 宣告成二進制檔放到執行檔的資源中。

1.下載免費軟體 ResEdit
1-1. 開啟 ResEdit 選擇 File-> New project -> Resource Script File Name (.RC)
1-2. 在 Resources 欄位中,選擇 Add Resources ... -> User Defined -> Name identifier -> 輸入 RCDATA -> 選擇你的 DLL File.
1-3. 選擇檔案儲存,一共會有二個檔案,一個為 Resource.h 及 .RC FILE。

2. 打開 BCB 並開啟你的專案,選擇 View/Project Manager 開啟Project Manager DIALOG,將 .RC File 加入到你的專案中

在 Unit1.cpp 中,加入以下的程式碼
#include "resource.h"

typedef int (*GETNAME)(void); // DLL Function Name

void __fastcall TForm1::Button2Click(TObject *Sender) 
{
  HINSTANCE hinstApp;
  hinstApp=LoadLibrary(ExtractFileName(Application->ExeName).c_str());
  if(hinstApp!=NULL) {
      TResourceStream *rcStream=new
      TResourceStream ((int)hinstApp,IDR_RCDATA1,  RT_RCDATA);
      rcStream->SaveToFile("Naming.dll");
      HINSTANCE hinstDll;
      hinstDll=LoadLibrary("Naming.dll");
      if(hinstDll!=NULL) {
          GETNAME getName;
          int NameId=0;
          getName=(GETNAME)GetProcAddress(hinstDll,"_getName");
          if(getName!=NULL) {
              NameId=getName();
              ShowMessage(IntToStr(NameId));
          }
          FreeLibrary(hinstDll);
     }
     delete rcStream;
     FreeLibrary(hinstApp);
 }
}

[轉]How to compile Android Device Driver as a Module(.ko)


How to compile Android Device Driver as a Module(.ko)

Here are the quick steps to be followed.

Prerequisite:
1. kernel sources from vendor say HTC wildfire(2.1 update-1)
2. Android source code for Éclair
3. Create a new folder called Kernel and copy the contents from the sources download via vendor

Step1: Copy config.gz from running hardware

adb pull /proc/config.gz
gunzip config.gz
mv config .config


Step 2: Copy/Overwrite the .config file to the kenel root directory

open .config file and search for
CONFIG_MODULE_NAME1=y
CONFIG_MODULE_NAME2=y


and replace 'y' with 'm', we use CONFIG_MODULE_NAME1 as module

CONFIG_MODULE_NAME1=m
CONFIG_MODULE_NAME2=y

Step 3: Check the active kernel version on the hardware using 'OR' if you are using own Boot.img then skip this and move on to step 4:

adb shell
# uname -a

or you may get the details of the kernel from the Settings->Aboutphone->SoftwareInformation: Kernel version

2.6.29-6fb59e13 HTC-kernel@xxxxxxxx

open Makefile in the kernel folder, search and replace "EXTRAVERSION =" with "EXTRAVERSION =-6fb59e13"

Step 4: Set the Env variables

export ARCH=arm
exprot CROSS_COMPILE=arm-eabi-
export PATH=$PATH:~/eclair/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/


now perform make modules for make from the kernel sources

kernel:$ make modules or make

after successful compilation, check out the .ko files next to the sources in the same directory

Complete example: How to get LG headset sources compile in to kernel module(.ko)
ref: http://android-jotting.blogspot.tw/2010/12/how-to-compile-android-device-driver-as.html

Mac 終端機顏色設定

对于从Unix/Linux平台转到Mac的同学来说,“终端”是经常要使用的一个工具。不过可能有很多人已经发现了,当我们使用ls命令来显示目录内容的时候,“终端”对于目录、可执行文件等特殊类型的文件并没有使用颜色来显示,只有使用“ls -G”时,才能显示颜色,这可真是不方便啊。有没有方法可以默认显示颜色呢?方法当然有。

方案一

第一个方案是让ls自动变成ls -G。我们要在用户目录下(~)创建一个名为.bash_profile的文件,如果这个文件已经存在,我们直接编辑这个文件就可以了。在~/.bash_profile中加入下面的内容:

alias ls=”ls -G”
保存文件后,重新启动“终端”。这时,运行ls命令,我们就可以看到文件已经可以用彩色来显示了。



方案二

上面这个方案虽然解决了彩色显示问题,但是还有一点不足,就是无法设置显示的颜色。比如说,我想用红色显示目录,那么这种方法是做不到的。下面我们来看看一个更好的解决方案。同样是修改~/.bash_profile文件,在文件中加入下面两行配置。

export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad
保存文件,重新运行“终端”,我们发现目录的颜色由蓝色变成了青色。

 

配置

那么应该怎样来配置成我喜欢的颜色呢?下面我们就来详细说一些这些配置。

~/.bash_profile是bash shell中当前登录用户的配置文件。bash是“终端”中默认的shell。

alias ls=”ls -G”是给”ls -G”起了一个别名,当执行ls时,就相当于执行了ls -G。

CLICOLOR是用来设置是否进行颜色的显示。CLI是Command Line Interface的缩写。

LSCOLORS是用来设置当CLICOLOR被启用后,各种文件类型的颜色。LSCOLORS的值中每两个字母为一组,分别设置某个文件类型的文字颜色和背景颜色。LSCOLORS中一共11组颜色设置,按照先后顺序,分别对以下的文件类型进行设置:

directory
symbolic link
socket
pipe
executable
block special
character special
executable with setuid bit set
executable with setgid bit set
directory writable to others, with sticky bit
directory writable to others, without sticky bit
LSCOLORS中,字母代表的颜色如下:

a 黑色
b 红色
c 绿色
d 棕色
e 蓝色
f 洋红色
g 青色
h 浅灰色
A 黑色粗体
B 红色粗体
C 绿色粗体
D 棕色粗体
E 蓝色粗体
F 洋红色粗体
G 青色粗体
H 浅灰色粗体
系统默认颜色
所以,如果我们想把目录显示成红色,就可以把LSCOLORS设置为bxfxaxdxcxegedabagacad就可以了 


所以对照这张表就可以得知:
bxfxaxdxcxegedabagacad
就是对于directory而言,它的前景色就是: b(red),而背景色就是:x(默认的背景色).

[轉載] Developing for Linux under MacOSX using Xcode

[ref]: http://ricardo-dias.com/2012/01/08/developing-for-linux-under-os-x-in-xcode/


In this mini-article I will show you how I develop applications for Linux in XCode 4. At the moment I’m using XCode 4.2.1, in OSX Lion, with Ubuntu 10.04 running on a virtual machine.
Although the article is related to XCode, after reading and trying out for yourself, you will notice that you can use whatever IDE you like. Here I’m just showing you how you can code in a OSX-only IDE and deploy in Linux.

Requirements

You will need some tools before we start:
  • VMWare or similar virtual machine application for Mac
    • Used to run our Linux system, and that’s where we will compile and run the target application.
      You can also use a physical computer instead. However, you will need network connectivity from mac to that computer because the communication between this linux System and our Mac is done by SSH.
  • OSXFuse
    • Requirement for the next point
  • SSHFS
    • It will be used to mount a remote directory in our Mac, and access it as if it was an external hard disk drive
Once you have all these, we are ready to go, but take some seconds to make sure you can compile the application in your slave Linux system. This will ensure that any problems you may encounter are not related to your slave machine or the code you are trying to compile.

Accessing slave machine using SSH

Now you will need the slave machine’s IP address, typing ifconfig in its Terminal.
As you can see in the image above, in my case I’ll be using 172.16.68.128 as the slave’s IP Address.
Then we make sure we can access it from your Mac typing the next command in Mac Terminal:
ssh username@ip
If we are asked for the password, then we got a valid SSH connection and we can move on…

Adding an alias for the Linux Slave IP

Because IPs can change sometimes, even inside Local Area Network, I added an alias for this IP, so that I could use it in scripts instead of the IP address itself. When it changes, I only have to modify one single file. You can do the same, by editing the hosts file, so grab the Mac Terminal and type as you see:
sudo vim /etc/hosts
Add a new line in the end, pressing I to enter insert mode:
172.16.68.128 vmcode
Now press ESC to exit “INSERT mode” and type :wq (yes, including the colon). If you have any problems using vim to edit this file, you can try nano instead – just replace “vim” with “nano” in the first command of this section. Now, you can use the virtual hostname “vmcode” instead of the real IP (which will be a lot easier to remember).

Setup script files

Now we need to setup two script files. I called them mountDir and sshbuild. The first one will mount the remote directory in our Mac and the latter is used to remotely compile the application.
Firstly pick a directory for these scripts, where you need to place the sshfs-static-leopard file, because it will be needed for the mountDir script.

Mounting Directory Script

Using your favorite text editor, create a new file called “mountDir” (no extension), and paste the following code:
#!/bin/bash
echo password | ./sshfs-static-leopard username@vmcode:codedir ~/path/to/mount/dir -o password_stdin
I’m explaining some of the variables in the command, that you should change to fit your needs:
  • username and password are the credentials for the user in the slave Linux machine
  • codedir is the directory in slave machine you want to mount in Mac
  • ~/path/to/mount/dir is the path to the Mac’s directory where you want to mount the slave’s directory
If you are using a real box instead of a VM, I recommend you configure ssh public keys instead of storing your password in plain text. You SHOULD NOT use the same password as of your Mac User
This was pointed by reader Daid, and I explained him I used it in plain text because I’m connecting to this VM, used only for compiling purposes and not accessible from outside, so I’m not that worried about it.

Building remotely

The SSH command accepts a second argument, that is the command you want to execute right after the remote login. Save and create another file called “sshbuild” with the following content:
#!/bin/bash
ssh username@vmcode 'cd codedir; make'
Note that username and codedir must match the ones you used before.

Setting up XCode

Before we move to XCode, you first need to mount the directory: open the Terminal, cd to your scripts dir, and run sh mountDir. Now you should see the contents of remote dir in your Mac’s ~/path/to/mount/dir.
Any change you make to these files will be reproduced in the remote slave system (our VM), because SSHFS will be syncing in real-time.
Start XCode, then click File > New > New Workspace… and chose a location for the workspace file (I used the same as the scripts). You should see a window with three different spaces, they should have texts in the middle, from left ro right, saying “No Files”“No Editor” and “No Selection”. Open a Finder window in the location ~/path/to/mount/ and then drag the subfolder that has a name starting with “OSXFUSE” to the “No Files” space in XCode.
A popup will show up. Firstly, XCode will prompt you about your build tool. You should type the complete path to the sshbuild script, starting on root, on the “Build Tool” field.
After clicking “Next”, you will be presented something like the image below, you should select the second option, which is “Create folder references for any added folders”.
Basically you are adding a reference to that directory, so instead of working in a local copy, you will edit the remote files directly. Now that you have all the directories in the slave’s codedir in the left panel of XCode, you can now open, edit and save any of your files using XCode. Now hit Command+B to run the build tool, and if everything goes well, you should see a message box saying Build Successful.

Running the Application

As you are developing for Linux, you should preferably debug under Linux. However, I often use an Application called X11, taht can be found in your Applications/Utilities folder. Type this command under X11 console window and the application should run in your Mac as if it was on Linux, even if it needs to open windows:
ssh -X username@vmcode
cd codedir./application

Conclusion

Here I shown you how I develop applications for Linux using the resourceful XCode and all it’s features, without quitting Mac OSX. I hope you found it useful and it helps you by increasing your productivity. Leave a reply, share your thoughts and suggestions and happy coding ;)

– edit 11/01/2012 –
After reading this article, Simon Elliston Ball posted a reply with a link to his blog suggesting a different solution – vagrant – that let’s you achieve the same results, but storing your files on Mac instead of the Linux system. I believe there are some advantages of doing this way, so you may choose the solution that best fits your needs. Thank you Simon.

Missing Library folder in Mac OS X Lion


Problem
In your home folder, you notice that there is no longer a Library folder.
Cause
This is the default setting by design in Mac OS X Lion.
SolutionTo get your Library folder back:
  1. Go to your Applications folder.
  2. Go to the Utilities folder.
  3. Double click on Terminal.
  4. Select all the text in the box below and press cmd + C to Copy.
    chflags nohidden ~/Library
  5. In the Terminal window press cmd + V or click Edit > Paste (on the top menu).
  6. Press Enter.
To revert back to the default setting change “nohidden” to “hidden” in Step 4.

虹光大成就-密教灌頂(一)