?? grub-0.97-patch3-ntfs
字號:
diff -Naur grub-0.97_findroot/ChangeLog grub-0.97_ntfs/ChangeLog--- grub-0.97_findroot/ChangeLog 2006-10-24 12:28:50.000000000 +0800+++ grub-0.97_ntfs/ChangeLog 2006-10-24 12:28:51.000000000 +0800@@ -1,5 +1,8 @@ 2005-05-11 + From Gandalf <f22_storm@163.com>:+ NTFS support+ From Chris Semler <csemler@mail.com>: * stage2/builtins.c (find_func): added an option --set-rootdiff -Naur grub-0.97_findroot/configure.ac grub-0.97_ntfs/configure.ac--- grub-0.97_findroot/configure.ac 2005-05-08 10:36:03.000000000 +0800+++ grub-0.97_ntfs/configure.ac 2006-10-24 12:28:51.000000000 +0800@@ -235,6 +235,13 @@ FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_FAT=1" fi +AC_ARG_ENABLE(ntfs,+ [ --disable-ntfs disable NTFS support in Stage 2])++if test x"$enable_ntfs" != xno; then+ FSYS_CFLAGS="$FSYS_CFLAGS -DFSYS_NTFS=1"+fi+ AC_ARG_ENABLE(ffs, [ --disable-ffs disable FFS support in Stage 2]) diff -Naur grub-0.97_findroot/grub/Makefile.am grub-0.97_ntfs/grub/Makefile.am--- grub-0.97_findroot/grub/Makefile.am 2005-02-03 04:38:19.000000000 +0800+++ grub-0.97_ntfs/grub/Makefile.am 2006-10-24 12:28:51.000000000 +0800@@ -6,7 +6,7 @@ SERIAL_FLAGS = -DSUPPORT_SERIAL=1 endif -AM_CPPFLAGS = -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_FFS=1 \+AM_CPPFLAGS = -DGRUB_UTIL=1 -DFSYS_EXT2FS=1 -DFSYS_FAT=1 -DFSYS_NTFS=1 -DFSYS_FFS=1 \ -DFSYS_ISO9660=1 -DFSYS_JFS=1 -DFSYS_MINIX=1 -DFSYS_REISERFS=1 \ -DFSYS_UFS2=1 -DFSYS_VSTAFS=1 -DFSYS_XFS=1 \ -DUSE_MD5_PASSWORDS=1 -DSUPPORT_HERCULES=1 \diff -Naur grub-0.97_findroot/INSTALL grub-0.97_ntfs/INSTALL--- grub-0.97_findroot/INSTALL 2005-05-08 10:43:15.000000000 +0800+++ grub-0.97_ntfs/INSTALL 2006-10-24 12:28:51.000000000 +0800@@ -198,6 +198,9 @@ `--disable-fat' Omit the FAT support in Stage 2. +`--disable-ntfs'+ Omit the NTFS support in Stage 2.+ `--disable-ffs' Omit the FFS support in Stage 2. diff -Naur grub-0.97_findroot/stage2/builtins.c grub-0.97_ntfs/stage2/builtins.c--- grub-0.97_findroot/stage2/builtins.c 2006-10-24 12:28:50.000000000 +0800+++ grub-0.97_ntfs/stage2/builtins.c 2006-10-24 12:28:51.000000000 +0800@@ -3987,6 +3987,7 @@ { {"ext2fs", "/e2fs_stage1_5"}, {"fat", "/fat_stage1_5"},+ {"ntfs", "/ntfs_stage1_5"}, {"ufs2", "/ufs2_stage1_5"}, {"ffs", "/ffs_stage1_5"}, {"iso9660", "/iso9660_stage1_5"},diff -Naur grub-0.97_findroot/stage2/char_io.c grub-0.97_ntfs/stage2/char_io.c--- grub-0.97_findroot/stage2/char_io.c 2006-10-24 12:28:50.000000000 +0800+++ grub-0.97_ntfs/stage2/char_io.c 2006-10-24 12:28:51.000000000 +0800@@ -898,7 +898,7 @@ } #endif /* STAGE1_5 */ -#if !defined(STAGE1_5) || defined(FSYS_FAT)+#if !defined(STAGE1_5) || defined(FSYS_FAT) || defined(FSYS_NTFS) int grub_tolower (int c) {@@ -907,7 +907,7 @@ return c; }-#endif /* ! STAGE1_5 || FSYS_FAT */+#endif /* ! STAGE1_5 || FSYS_FAT || FSYS_NTFS */ int grub_isspace (int c)@@ -1161,7 +1161,9 @@ return 0; }+#endif /* ! STAGE1_5 */ +#if !defined(STAGE1_5) || defined(FSYS_NTFS) int grub_strlen (const char *str) {@@ -1172,7 +1174,7 @@ return len; }-#endif /* ! STAGE1_5 */+#endif /* ! STAGE1_5 || FSYS_NTFS */ int memcheck (int addr, int len)diff -Naur grub-0.97_findroot/stage2/disk_io.c grub-0.97_ntfs/stage2/disk_io.c--- grub-0.97_findroot/stage2/disk_io.c 2006-10-24 12:28:50.000000000 +0800+++ grub-0.97_ntfs/stage2/disk_io.c 2006-10-24 12:28:51.000000000 +0800@@ -54,6 +54,9 @@ # ifdef FSYS_FAT {"fat", fat_mount, fat_read, fat_dir, 0, 0}, # endif+# ifdef FSYS_NTFS+ {"ntfs", ntfs_mount, ntfs_read, ntfs_dir, 0, 0},+# endif # ifdef FSYS_EXT2FS {"ext2fs", ext2fs_mount, ext2fs_read, ext2fs_dir, 0, 0}, # endifdiff -Naur grub-0.97_findroot/stage2/filesys.h grub-0.97_ntfs/stage2/filesys.h--- grub-0.97_findroot/stage2/filesys.h 2004-05-15 03:36:43.000000000 +0800+++ grub-0.97_ntfs/stage2/filesys.h 2006-10-24 12:28:51.000000000 +0800@@ -49,6 +49,15 @@ #define FSYS_FAT_NUM 0 #endif +#ifdef FSYS_NTFS+#define FSYS_NTFS_NUM 1+int ntfs_mount (void);+int ntfs_read (char *buf, int len);+int ntfs_dir (char *dirname);+#else+#define FSYS_NTFS_NUM 0+#endif+ #ifdef FSYS_EXT2FS #define FSYS_EXT2FS_NUM 1 int ext2fs_mount (void);@@ -126,7 +135,7 @@ #ifndef NUM_FSYS #define NUM_FSYS \- (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM \+ (FSYS_FFS_NUM + FSYS_FAT_NUM + FSYS_NTFS_NUM + FSYS_EXT2FS_NUM + FSYS_MINIX_NUM \ + FSYS_REISERFS_NUM + FSYS_VSTAFS_NUM + FSYS_JFS_NUM + FSYS_XFS_NUM \ + FSYS_TFTP_NUM + FSYS_ISO9660_NUM + FSYS_UFS2_NUM) #endifdiff -Naur grub-0.97_findroot/stage2/fsys_ntfs.c grub-0.97_ntfs/stage2/fsys_ntfs.c--- grub-0.97_findroot/stage2/fsys_ntfs.c 1970-01-01 08:00:00.000000000 +0800+++ grub-0.97_ntfs/stage2/fsys_ntfs.c 2006-10-24 12:28:51.000000000 +0800@@ -0,0 +1,1263 @@+/* vim: set sw=4 :*/+/*+ * GRUB -- GRand Unified Bootloader+ * Copyright (C) 1999 Free Software Foundation, Inc.+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.+ */++/*+ * Samuel Leo <samuel@_.remove.me._szonline.net>+ * Limitations:+ * 1. Only 32 bit size support+ * 2. don't support >1k MFT record size, >16k INDEX record size+ * 3. don't support recursive at_attribute_list+ * 4. don't support compressed attribute other than Datastream+ * 5. all MFT's at_attribute_list must resident at first run list+ * 6. don't support journaling+ * 7. don't support EFS encryption+ * 8. don't support mount point and junction+ */+#ifdef FSYS_NTFS++//#define DEBUG_NTFS 1++/*+#define NO_ATTRIBUTE_LIST 1+ totally disable at_attribute_list support,+ if no compressed/fragment file and MFT,+ not recommended+#define NO_NON_RESIDENT_ATTRIBUTE_LIST 1+ disable non-resident at_attribute_list support,+ if no huge compressed/fragment file and MFT+#define NO_NTFS_DECOMPRESSION 1+ disable ntfs compressed file support+#define NO_ALTERNATE_DATASTREAM 1+ disable ntfs alternate datastream support+*/+/*#ifdef STAGE1_5*/++#include <shared.h>+#include <filesys.h>+#include "ntfs.h"++/* safe turn off non-resident attribute list if MFT fragments < 4000 */+//#define NO_NON_RESIDENT_ATTRIBUTE_LIST 1+#define NO_NTFS_DECOMPRESSION 1+#endif+++#define MAX_MFT_RECORD_SIZE 1024+#define MAX_INDEX_RECORD_SIZE 16384+#define MAX_INDEX_BITMAP_SIZE 4096+#define DECOMP_DEST_BUFFER_SIZE 16384+#define DECOMP_SOURCE_BUFFER_SIZE (8192+2)+#define MAX_DIR_DEPTH 64++/* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */+#define DEV_BSIZE 512++/* include/linux/fs.h */+#define BLOCK_SIZE 512++#define WHICH_SUPER 1+#define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE) /* = 2 */++/* include/asm-i386/type.h */+typedef __signed__ char __s8;+typedef unsigned char __u8;+typedef __signed__ short __s16;+typedef unsigned short __u16;+typedef __signed__ int __s32;+typedef unsigned int __u32;+typedef __signed__ long long __s64;+typedef unsigned long long __u64;++#define FILE_MFT 0+#define FILE_MFTMIRR 1+#define FILE_LOGFILE 2+#define FILE_VOLUME 3+#define FILE_ATTRDEF 4+#define FILE_ROOT 5+#define FILE_BITMAP 6+#define FILE_BOOT 7+#define FILE_BADCLUS 8+#define FILE_QUOTA 9+#define FILE_UPCASE 10++#define at_standard_information 0x10+#define at_attribute_list 0x20+#define at_filename 0x30+#define at_security_descriptor 0x50+#define at_data 0x80+#define at_index_root 0x90+#define at_index_allocation 0xa0+#define at_bitmap 0xb0+#define at_symlink 0xc0++#define NONAME ""+#define ATTR_NORMAL 0+#define ATTR_COMPRESSED 1+#define ATTR_RESIDENT 2+#define ATTR_ENCRYPTED 16384+#define ATTR_SPARSE 32768++++#define index_data ((char *)FSYS_BUF)+#define bitmap_data ((__u8 *)(FSYS_BUF+MAX_INDEX_RECORD_SIZE))+#define dcdbuf ((__u8 *)index_data)+#define dcsbuf (bitmap_data)+#define dcend (dcsbuf+DECOMP_SOURCE_BUFFER_SIZE)+#define fnbuf ((char *)(bitmap_data+MAX_INDEX_BITMAP_SIZE))+#define mmft ((MFTR *)dcend)+#define cmft ((MFTR *)(dcend+sizeof(MFTR)))+#define mft_run ((RUNL *)(dcend+2*sizeof(MFTR)))+#define path_ino ((int *)(dcend+2*sizeof(MFTR)+sizeof(RUNL)))+#define cluster16 (path_ino+MAX_DIR_DEPTH)+#define index16 cluster16[16]+#define blocksize cluster16[17]+#define clustersize cluster16[18]+#define mft_record_size cluster16[19]+#define index_record_size cluster16[20]+#define dcvcn cluster16[21]+#define dcoff cluster16[22]+#define dclen cluster16[23]+#define dcrem cluster16[24]+#define dcslen cluster16[25]+#define dcsptr ((__u8 *)cluster16[26])+#define is_ads_completion cluster16[27]++typedef struct run_list {+ char *start;+ char *ptr;+ int svcn;+ int evcn;+ int vcn;+ int cnum0;+ int cnum;+ int clen;+} RUNL;++typedef struct ntfs_mft_record {+ char mft[MAX_MFT_RECORD_SIZE];+ char mft2[MAX_MFT_RECORD_SIZE];+ int attr_type;+ char *attr_name;+ int attr_flag;+ int attr_size;+ char *attr;+ int attr_len;+ RUNL runl;+ char *attr_list;+ int attr_list_len;+ int attr_list_size;+ int attr_list_off;+ int attr_inited;+ char attr_list_buf[2*BLOCK_SIZE];+ RUNL attr_list_runl;+} MFTR;++static int read_mft_record(int mftno, char *mft, int self);+static int read_attribute(MFTR *mftr, int offset, char *buf, int len, RUNL *from_rl);+static int get_next_run(RUNL *runl);+++++static inline int+nsubstring (char *s1, char *s2)+{+ while (tolower(*s1) == tolower(*s2))+ {+ /* The strings match exactly. */+ if (! *(s1++))+ return 0;+ s2 ++;+ }++ /* S1 is a substring of S2. */+ if (*s1 == 0)+ return -1;++ /* S1 isn't a substring. */+ return 1;+}++static int fixup_record(char *record, char *magic, int size)+{+ int start, count, offset;+ __u16 fixup;++ if(*(int *)record != *(int *)magic)+ return 0;+ start=*(__u16 *)(record+4);+ count=*(__u16 *)(record+6);+ count--;+ if(size && blocksize*count != size)+ return 0;+ fixup = *(__u16 *)(record+start);+ start+=2;+ offset=blocksize-2;+ while(count--){+ if(*(__u16 *)(record+offset)!=fixup)+ return 0;+ *(__u16 *)(record+offset) = *(__u16 *)(record+start);+ start+=2;+ offset+=blocksize;+ }+ return 1;+}++static void rewind_run_list( RUNL *runl) {+ runl->vcn = runl->svcn;+ runl->ptr = runl->start;+ runl->cnum0 = 0;+ runl->cnum = 0;+ runl->clen = 0;+}++static int get_next_run(RUNL *runl){+ int t, n, v;++#ifdef DEBUG_NTFS+ printf("get_next_run: s=%d e=%d c=%d start=%x ptr=%x\n",+ runl->svcn, runl->evcn, runl->vcn, runl->start, runl->ptr);+#endif++ runl->vcn += runl->clen;+ if(runl->vcn > runl->evcn) {+ return 0;+ }++ t = *(runl->ptr)++;+ n = t&0xf;+ runl->clen = 0; v = 1;+ while(n--) {+ runl->clen += v * (*(__u8 *)((runl->ptr)++));+ v <<= 8;+ }+ n = (t>>4)&0xf;+ if(n==0)+ runl->cnum = 0;+ else {+ int c = 0;+ v = 1;+ while(n--) {+ c += v * (*(__u8 *)((runl->ptr)++));+ v <<= 8;+ }+ if(c & (v>>1)) c -= v;+ runl->cnum0 += c;+ runl->cnum = runl->cnum0;+ }+#ifdef DEBUG_NTFS+ printf("got_next_run: t=%x cluster %x len %x vcn=%x ecn=%x\n",+ t, runl->cnum, runl->clen, runl->vcn, runl->evcn);+#endif+ return 1;+}++#ifndef NO_ATTRIBUTE_LIST+static void init_run_list(char *attr, int len, RUNL *runl, __u32 *initp) {+ int allocated;+ /* int inited; */++ runl->svcn = *(__u32 *)(attr+0x10); /* only support 32 bit */+ runl->evcn = *(__u32 *)(attr+0x18); /* only support 32 bit */+ runl->start = attr + *(__u16 *)(attr+0x20);+ allocated = *(__u32 *)(attr+0x28);+ if(initp) *initp = *(__u32 *)(attr+0x38);+ if(!runl->evcn) runl->evcn = (allocated - 1) / clustersize;+#ifdef DEBUG_NTFS+ printf("size %d allocated=%d inited=%d cegin=%x csize=%d vcn=%d-%d\n",+ /*attr_size*/ *(__u32 *)(attr+0x30),+ /*allocated*/ *(__u32 *)(attr+0x28),+ /*attr_inited*/ *(__u32 *)(attr+0x38),+ /*cengin*/ *(__u16 *)(attr+0x22),+ /*csize*/ *(__u16 *)(attr+0x40),+ runl->svcn, runl->evcn);+#endif+ rewind_run_list(runl);+}+#endif+++static int find_attribute(char *mft, int type, char *name, char **attr, int *size, int *len, int *flag) {+ int t, l, r, n, i, namelen;+ unsigned short *attr_name;++ n = strlen(name);+ r = mft_record_size - *(__u16 *)(mft+0x14);+ mft += *(__u16 *)(mft+0x14);+ while( (t = *(__s32 *)mft) != -1 ) {+ l = *(__u32 *)(mft+4);+ if(l>r) break;+#ifdef DEBUG_NTFS+ printf("type = %x len = %d namelen=%d resident=%d compresed=%d attrno=%d\n",+ t, l,+ /*namelen*/ *(mft+9),+ //name = (__u16 *)(mft + *(__u16 *)(mft+10)),+ /*resident */ (*(mft+8) == 0),+ /*compressed*/ *(__u16 *)(mft+12),+ /*attrno*/ *(__u16 *)(mft+14));+#endif+ namelen = *(mft+9);+ if(t == type) {+#ifndef STAGE1_5+#ifndef NO_ALTERNATE_DATASTREAM+ if(is_ads_completion && type == at_data) {+ if(namelen && namelen >= n &&+ (!*(mft+8)/*resident*/ || !*(__u32 *)(attr+0x10)/*svcn==0*/))+ {+ for(i=0, attr_name=(__u16 *)(mft + *(__u16 *)(mft+10)); i < n; i++)+ if(tolower(name[i]) != tolower(attr_name[i]))+ break;+ if(i >= n) {+ for(; i < namelen; i++)+ name[i] = attr_name[i];+ name[i] = '\0';+ if(print_possibilities > 0)+ print_possibilities = -print_possibilities;+ print_a_completion(fnbuf);+ name[n] = '\0';+ }+ }+ } else+#endif+#endif+ if(namelen == n) {++ for(i=0, attr_name=(__u16 *)(mft + *(__u16 *)(mft+10)); i<n; i++)+ if(tolower(name[i]) != tolower(attr_name[i]))+ break;+ if(i>=n) {+ if(flag) *flag = *(__u16 *)(mft+12);+ if(*(mft+8) == 0) {+ if(flag) *flag |= ATTR_RESIDENT;+#ifdef DEBUG_NTFS+ printf("resident data at %x size %x indexed=%d\n",+ /*data*/ *(__u16 *)(mft+0x14),+ /*attr_size*/ *(__u16 *)(mft+0x10),+ /*indexed*/ *(__u16 *)(mft+0x16));+#endif+ if(attr) *attr = mft + *(__u16 *)(mft+0x14);+ if(size) *size = *(__u16 *)(mft+0x10);+ if(len) *len = *(__u16 *)(mft+0x10);+ } else {+ if(attr) *attr = mft;+ if(size) *size = *(__u32 *)(mft+0x30);+ if(len) *len = l;+ }+ return 1;+ }+ }+ }+ mft += l;+ r -= l;+ }+ return 0;+}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -