作者 主題: [分享] 壓縮檔案系統 (三)  (閱讀 27643 次)

0 會員 與 1 訪客 正在閱讀本文。

thyme

  • 老人組
  • 俺是博士!
  • *****
  • 文章數: 1281
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 於: 2005-03-11 11:28 »
「cramfs」

這篇是重點,也是最後一篇,這系列只能談到這兒了。
有沒有想過,為什麼一定要解開之後才能讀呢?不解直接讀,可行否?
是的,可以的,但檔案系統不同,有個檔案系統很符合--cramfs ,
代碼: [選擇]

# mkdir /tmp/tmp_root
# copy你所要的檔案到 /tmp/tmp_root
# mkcramfs /tmp/tmp_root.img /tmp/tmp_root
# mount -t cramfs -o loop /tmp/tmp_root.img /mnt/tmp

你會發覺,/mnt/tmp 和 /tmp/tmp_root 的內容是相同的,用 du 去查,
大小也差不多,但是,/tmp/tmp_root.img 的大小卻小很多,而且
也不用另外解開才能讀,不會另外再佔一個非壓縮的空間唷!
說明一下,mkcramfs 主要目的就是做一個壓縮的檔案系統,它做法是
直接把一個目錄轉成一個檔案系統,你可以直接做用 mount 的方式來
掛載,就如同前面的 iso9660 、 ext2 的使用方式。放入嵌入式系統
時,也不用另外再把有限的記憶體割一塊來放檔案系統了。另外,
你或許要重編 kernel 才可支援 cramfs。

這有什麼限制?當然有,最大限制就是,它是一個唯讀的,你對它寫
入是無效的,由於要即時解壓縮,效能上也會差一點點,但不會影響
很大。

那有沒有像 Windows 一樣的,可以對某些檔案、目錄壓縮,也可以
即時寫入的?有的,要 patch C library 及 Kernel。那怎麼用?很抱
歉,你問錯人了,我不會。


OK,結束,下課!

longlife

  • 活潑的大學生
  • ***
  • 文章數: 476
    • 檢視個人資料
    • Arch
[分享] 壓縮檔案系統 (三)
« 回覆 #1 於: 2005-03-11 13:03 »
敢問 thyme 兄這系列文章能否收集於敝人的部落格上?
個人空間 - 部落格、相冊、書籤
論壇 - 商品、懸賞、活動、辯論

duan

  • 榮譽博士
  • 活潑的大學生
  • ***
  • 文章數: 253
    • 檢視個人資料
Re: [分享] 壓縮檔案系統 (三)
« 回覆 #2 於: 2005-03-11 14:42 »
引述: "thyme"

是的,可以的,但檔案系統不同,有個檔案系統很符合--cramfs


如果沒記錯, 印像中 cramfs 是有容量限制的. 而且不只是總容量
有限制, 裡面包含的單一檔案大小也有限制, 否則壓出來的會有
問題.

所以 cramfs 多半應用在 embedded system 裡面.

不知道有沒有記錯, 有錯請指正, 謝謝   :)

thyme

  • 老人組
  • 俺是博士!
  • *****
  • 文章數: 1281
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 回覆 #3 於: 2005-03-11 15:16 »
引述: "longlife"
敢問 thyme 兄這系列文章能否收集於敝人的部落格上?


沒問題,自由轉載,註明出處即可。

thyme

  • 老人組
  • 俺是博士!
  • *****
  • 文章數: 1281
    • 檢視個人資料
Re: [分享] 壓縮檔案系統 (三)
« 回覆 #4 於: 2005-03-11 15:27 »
引述: "duan"
引述: "thyme"

是的,可以的,但檔案系統不同,有個檔案系統很符合--cramfs


如果沒記錯, 印像中 cramfs 是有容量限制的. 而且不只是總容量
有限制, 裡面包含的單一檔案大小也有限制, 否則壓出來的會有
問題.

所以 cramfs 多半應用在 embedded system 裡面.

不知道有沒有記錯, 有錯請指正, 謝謝   :)


沒錯,單一檔案大小有限制,忘記是多少,也許是 8MB,要看看文件了,
當初包 JVM 時,有個檔是 24MB ,害我 debug 了好幾天,
至於總容量,目前壓出來都是少於 128MB,也都沒問題。

hata

  • 懷疑的國中生
  • **
  • 文章數: 32
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 回覆 #5 於: 2005-03-13 11:59 »
用 squashfs 比較沒有限制,而且壓縮比較好。
\bye

duan

  • 榮譽博士
  • 活潑的大學生
  • ***
  • 文章數: 253
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 回覆 #6 於: 2005-03-14 14:43 »
引述: "hata"
用 squashfs 比較沒有限制,而且壓縮比較好。


hata?  看這篇留言, 應該就是我認識的那位 hata  吧?   :P
問一下, 後來有真的使用 squashfs 這個 filesystem 嗎?   :)

thyme

  • 老人組
  • 俺是博士!
  • *****
  • 文章數: 1281
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 回覆 #7 於: 2005-03-14 15:33 »
引述: "hata"
用 squashfs 比較沒有限制,而且壓縮比較好。


cramfs 不用另外 patch kernel ,比較省事一點 ,
咦,好像做 embedded 的人是不能怕麻煩的 ;p

引述: "duan"

hata?  看這篇留言, 應該就是我認識的那位 hata  吧?   :P
問一下, 後來有真的使用 squashfs 這個 filesystem 嗎?   :)


我也想知道這個好不好用,也許將來用來改進 24MB 的 java 問題,
奇怪,沒事弄一個這麼大的檔會好用嗎??

SaPow

  • 榮譽博士
  • 鑽研的研究生
  • *****
  • 文章數: 509
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 回覆 #8 於: 2005-03-24 23:16 »
路過補充一下, cramfs-1.1.tar.gz 裡的 readme 有說


代碼: [選擇]
Cramfs - cram a filesystem onto a small ROM

cramfs is designed to be simple and small, and to compress things well.

It uses the zlib routines to compress a file one page at a time, and
allows random page access.  The meta-data is not compressed, but is
expressed in a very terse representation to make it use much less
diskspace than traditional filesystems.

You can't write to a cramfs filesystem (making it compressible and
compact also makes it _very_ hard to update on-the-fly), so you have to
create the disk image with the "mkcramfs" utility.


Usage Notes
-----------

File sizes are limited to less than 16MB.

Maximum filesystem size is a little over 256MB.  (The last file on the
filesystem is allowed to extend past 256MB.)

Only the low 8 bits of gid are stored.  The current version of
mkcramfs simply truncates to 8 bits, which is a potential security
issue.

Hard links are supported, but hard linked files
will still have a link count of 1 in the cramfs image.

Cramfs directories have no `.' or `..' entries.  Directories (like
every other file on cramfs) always have a link count of 1.  (There's
no need to use -noleaf in `find', btw.)

No timestamps are stored in a cramfs, so these default to the epoch
(1970 GMT).  Recently-accessed files may have updated timestamps, but
the update lasts only as long as the inode is cached in memory, after
which the timestamp reverts to 1970, i.e. moves backwards in time.

Currently, cramfs must be written and read with architectures of the
same endianness, and can be read only by kernels with PAGE_CACHE_SIZE
== 4096.  At least the latter of these is a bug, but it hasn't been
decided what the best fix is.  For the moment if you have larger pages
you can just change the #define in mkcramfs.c, so long as you don't
mind the filesystem becoming unreadable to future kernels.


For /usr/share/magic
--------------------

0 ulelong 0x28cd3d45 Linux cramfs offset 0
>4 ulelong x size %d
>8 ulelong x flags 0x%x
>12 ulelong x future 0x%x
>16 string >\0 signature "%.16s"
>32 ulelong x fsid.crc 0x%x
>36 ulelong x fsid.edition %d
>40 ulelong x fsid.blocks %d
>44 ulelong x fsid.files %d
>48 string >\0 name "%.16s"
512 ulelong 0x28cd3d45 Linux cramfs offset 512
>516 ulelong x size %d
>520 ulelong x flags 0x%x
>524 ulelong x future 0x%x
>528 string >\0 signature "%.16s"
>544 ulelong x fsid.crc 0x%x
>548 ulelong x fsid.edition %d
>552 ulelong x fsid.blocks %d
>556 ulelong x fsid.files %d
>560 string >\0 name "%.16s"


Hacker Notes
------------

See fs/cramfs/README for filesystem layout and implementation notes.

siyou

  • 可愛的小學生
  • *
  • 文章數: 4
    • 檢視個人資料
[分享] 壓縮檔案系統 (三)
« 回覆 #9 於: 2005-12-15 20:40 »
現在要算squashfs + lzma 最棒了.
squashfs default use gzip, but you can try to patch it to use lzma,
of course you have to change mksquashfs to use lzma too.

siyou.