3 * NTFS driver for Linux 2.3.x
5 * Copyright (C) 1995-1997, 1999 Martin von Löwis
6 * Copyright (C) 1996 Richard Russon
7 * Copyright (C) 1996-1997 Régis Duchesne
8 * Copyright (C) 2000, Anton Altaparmakov
14 #ifdef NTFS_IN_LINUX_KERNEL
15 #include <linux/config.h>
18 #include "ntfstypes.h"
27 #include <linux/module.h>
28 #include <asm/uaccess.h>
29 #include <linux/nls.h>
30 #include <linux/locks.h>
31 #include <linux/init.h>
33 /* Forward declarations */
34 static struct inode_operations ntfs_dir_inode_operations
;
35 static struct file_operations ntfs_dir_operations
;
37 #define ITEM_SIZE 2040
39 /* io functions to user space */
40 static void ntfs_putuser(ntfs_io
* dest
,void *src
,ntfs_size_t len
)
42 copy_to_user(dest
->param
,src
,len
);
47 struct ntfs_getuser_update_vm_s
{
53 static void ntfs_getuser_update_vm (void *dest
, ntfs_io
*src
, ntfs_size_t len
)
55 struct ntfs_getuser_update_vm_s
*p
= src
->param
;
56 copy_from_user (dest
, p
->user
, len
);
63 ntfs_read(struct file
* filp
, char *buf
, size_t count
, loff_t
*off
)
67 ntfs_inode
*ino
=NTFS_LINO2NINO(filp
->f_dentry
->d_inode
);
69 /* inode is not properly initialized */
70 if(!ino
)return -EINVAL
;
71 ntfs_debug(DEBUG_OTHER
, "ntfs_read %x,%x,%x ->",
72 (unsigned)ino
->i_number
,(unsigned)*off
,(unsigned)count
);
73 /* inode has no unnamed data attribute */
74 if(!ntfs_find_attr(ino
,ino
->vol
->at_data
,NULL
))
78 io
.fn_put
=ntfs_putuser
;
82 error
=ntfs_read_attr(ino
,ino
->vol
->at_data
,NULL
,*off
,&io
);
83 if(error
)return -error
;
91 ntfs_write(struct file
*filp
,const char* buf
,size_t count
,loff_t
*pos
)
95 struct inode
*inode
= filp
->f_dentry
->d_inode
;
96 ntfs_inode
*ino
= NTFS_LINO2NINO(inode
);
97 struct ntfs_getuser_update_vm_s param
;
101 ntfs_debug (DEBUG_LINUX
, "ntfs_write %x,%x,%x ->\n",
102 (unsigned)ino
->i_number
, (unsigned)*pos
, (unsigned)count
);
103 /* Allows to lock fs ro at any time */
104 if (inode
->i_sb
->s_flags
& MS_RDONLY
)
106 if (!ntfs_find_attr(ino
,ino
->vol
->at_data
,NULL
))
109 /* Evaluating O_APPEND is the file system's job... */
110 if (filp
->f_flags
& O_APPEND
)
111 *pos
= inode
->i_size
;
116 io
.fn_get
= ntfs_getuser_update_vm
;
119 ret
= ntfs_write_attr (ino
, ino
->vol
->at_data
, NULL
, *pos
, &io
);
120 ntfs_debug (DEBUG_LINUX
, "write -> %x\n", ret
);
125 if (*pos
> inode
->i_size
)
126 inode
->i_size
= *pos
;
127 mark_inode_dirty (filp
->f_dentry
->d_inode
);
142 static int ntfs_printcb(ntfs_u8
*entry
,void *param
)
144 struct ntfs_filldir
* nf
=param
;
145 int flags
=NTFS_GETU8(entry
+0x51);
147 int length
=NTFS_GETU8(entry
+0x50);
148 int inum
=NTFS_GETU32(entry
);
150 #ifdef NTFS_NGT_NT_DOES_LOWER
155 /* Don't display long names */
160 /* Don't display short-only names */
163 #ifdef NTFS_NGT_NT_DOES_LOWER
174 if(!show_hidden
&& ((NTFS_GETU8(entry
+0x48) & 2)==2)){
175 ntfs_debug(DEBUG_OTHER
,"Skipping hidden file\n");
179 if(ntfs_encodeuni(NTFS_INO2VOL(nf
->dir
),(ntfs_u16
*)(entry
+0x52),
180 length
,&nf
->name
,&nf
->namelen
)){
181 ntfs_debug(DEBUG_OTHER
,"Skipping unrepresentable file\n");
182 if(nf
->name
)ntfs_free(nf
->name
);
185 /* Do not return ".", as this is faked */
186 if(length
==1 && *nf
->name
=='.')
188 #ifdef NTFS_NGT_NT_DOES_LOWER
190 for(i
=0;i
<nf
->namelen
;i
++)
191 /* This supports ASCII only. Since only DOS-only
192 names get converted, and since those are restricted
193 to ASCII, this should be correct */
194 if(nf
->name
[i
]>='A' && nf
->name
[i
]<='Z')
195 nf
->name
[i
]+='a'-'A';
197 nf
->name
[nf
->namelen
]=0;
198 ntfs_debug(DEBUG_OTHER
, "readdir got %s,len %d\n",nf
->name
,nf
->namelen
);
199 /* filldir expects an off_t rather than an loff_t.
200 Hope we don't have more than 65535 index records */
201 error
=nf
->filldir(nf
->dirent
,nf
->name
,nf
->namelen
,
202 (nf
->ph
<<16)|nf
->pl
,inum
);
204 /* Linux filldir errors are negative, other errors positive */
208 /* readdir returns '..', then '.', then the directory entries in sequence
209 As the root directory contains a entry for itself, '.' is not emulated
210 for the root directory */
211 static int ntfs_readdir(struct file
* filp
, void *dirent
, filldir_t filldir
)
213 struct ntfs_filldir cb
;
215 struct inode
*dir
=filp
->f_dentry
->d_inode
;
217 ntfs_debug(DEBUG_OTHER
, "ntfs_readdir ino %x mode %x\n",
218 (unsigned)dir
->i_ino
,(unsigned int)dir
->i_mode
);
220 ntfs_debug(DEBUG_OTHER
, "readdir: Looking for file %x dircount %d\n",
221 (unsigned)filp
->f_pos
,atomic_read(&dir
->i_count
));
222 cb
.pl
=filp
->f_pos
& 0xFFFF;
223 cb
.ph
=filp
->f_pos
>> 16;
224 /* end of directory */
226 /* FIXME: Maybe we can return those with the previous call */
228 case 0: filldir(dirent
,".",1,filp
->f_pos
,dir
->i_ino
);
229 filp
->f_pos
=0xFFFF0001;
231 /* FIXME: parent directory */
232 case 1: filldir(dirent
,"..",2,filp
->f_pos
,0);
233 filp
->f_pos
=0xFFFF0002;
236 ntfs_debug(DEBUG_OTHER
, "readdir: EOD\n");
242 cb
.type
=NTFS_INO2VOL(dir
)->ngt
;
244 ntfs_debug(DEBUG_OTHER
,"looking for next file\n");
245 error
=ntfs_getdir_unsorted(NTFS_LINO2NINO(dir
),&cb
.ph
,&cb
.pl
,
247 }while(!error
&& cb
.ph
!=0xFFFFFFFF);
248 filp
->f_pos
=(cb
.ph
<<16)|cb
.pl
;
249 ntfs_debug(DEBUG_OTHER
, "new position %x\n",(unsigned)filp
->f_pos
);
250 /* -EINVAL is on user buffer full. This is not considered
251 as an error by sys_getdents */
254 /* Otherwise (device error, inconsistent data), switch the sign */
258 /* Copied from vfat driver */
259 static int simple_getbool(char *s
, int *setval
)
262 if (!strcmp(s
,"1") || !strcmp(s
,"yes") || !strcmp(s
,"true")) {
264 } else if (!strcmp(s
,"0") || !strcmp(s
,"no") || !strcmp(s
,"false")) {
275 /* Parse the (re)mount options */
276 static int parse_options(ntfs_volume
* vol
,char *opt
)
287 for(opt
= strtok(opt
,",");opt
;opt
=strtok(NULL
,","))
289 if ((value
= strchr(opt
, '=')) != NULL
)
291 if(strcmp(opt
,"uid")==0)
293 if(!value
|| !*value
)goto needs_arg
;
294 vol
->uid
=simple_strtoul(value
,&value
,0);
296 printk(KERN_ERR
"NTFS: uid invalid argument\n");
299 }else if(strcmp(opt
, "gid") == 0)
301 if(!value
|| !*value
)goto needs_arg
;
302 vol
->gid
=simple_strtoul(value
,&value
,0);
304 printk(KERN_ERR
"gid invalid argument\n");
307 }else if(strcmp(opt
, "umask") == 0)
309 if(!value
|| !*value
)goto needs_arg
;
310 vol
->umask
=simple_strtoul(value
,&value
,0);
312 printk(KERN_ERR
"umask invalid argument\n");
315 }else if(strcmp(opt
, "iocharset") == 0){
316 if(!value
|| !*value
)goto needs_arg
;
317 vol
->nls_map
=load_nls(value
);
320 printk(KERN_ERR
"NTFS: charset not found");
323 }else if(strcmp(opt
, "posix") == 0){
325 if(!value
|| !*value
)goto needs_arg
;
326 if(!simple_getbool(value
,&val
))
328 vol
->ngt
=val
?ngt_posix
:ngt_nt
;
329 }else if(strcmp(opt
,"utf8") == 0){
331 if(!value
|| !*value
)
333 else if(!simple_getbool(value
,&val
))
337 }else if(strcmp(opt
,"uni_xlate") == 0){
339 /* no argument: uni_vfat.
340 boolean argument: uni_vfat.
343 if(!value
|| !*value
)
345 else if(strcmp(value
,"2")==0)
346 vol
->nct
|= nct_uni_xlate
;
347 else if(!simple_getbool(value
,&val
))
350 vol
->nct
|= nct_uni_xlate_vfat
| nct_uni_xlate
;
352 printk(KERN_ERR
"NTFS: unkown option '%s'\n", opt
);
356 if(vol
->nct
& nct_utf8
& (nct_map
| nct_uni_xlate
)){
357 printk(KERN_ERR
"utf8 cannot be combined with iocharset or uni_xlate\n");
361 if((vol
->nct
& (nct_uni_xlate
| nct_map
| nct_utf8
))==0)
362 /* default to UTF-8 */
365 vol
->nls_map
=load_nls_default();
369 printk(KERN_ERR
"NTFS: %s needs an argument",opt
);
372 printk(KERN_ERR
"NTFS: %s needs boolean argument",opt
);
376 static struct dentry
*ntfs_lookup(struct inode
*dir
, struct dentry
*d
)
382 ntfs_debug(DEBUG_NAME1
, "Looking up %s in %x\n",d
->d_name
.name
,
383 (unsigned)dir
->i_ino
);
384 /* convert to wide string */
385 error
=ntfs_decodeuni(NTFS_INO2VOL(dir
),(char*)d
->d_name
.name
,
386 d
->d_name
.len
,&walk
.name
,&walk
.namelen
);
388 return ERR_PTR(-error
);
389 item
=ntfs_malloc(ITEM_SIZE
);
391 return ERR_PTR(-ENOMEM
);
392 /* ntfs_getdir will place the directory entry into item,
393 and the first long long is the MFT record number */
395 walk
.dir
=NTFS_LINO2NINO(dir
);
397 if(ntfs_getdir_byname(&walk
))
399 res
=iget(dir
->i_sb
,NTFS_GETU32(item
));
403 ntfs_free(walk
.name
);
404 /* Always return success, the dcache will handle negative entries. */
408 static struct file_operations ntfs_file_operations_nommap
= {
410 #ifdef CONFIG_NTFS_RW
415 static struct inode_operations ntfs_inode_operations_nobmap
= {
418 #ifdef CONFIG_NTFS_RW
420 ntfs_create(struct inode
* dir
,struct dentry
*d
,int mode
)
434 ntfs_debug(DEBUG_OTHER
, "ntfs_create %s\n",d
->d_name
.name
);
435 vol
=NTFS_INO2VOL(dir
);
436 #ifdef NTFS_IN_LINUX_KERNEL
437 ino
=NTFS_LINO2NINO(r
);
439 ino
=ntfs_malloc(sizeof(ntfs_inode
));
446 error
=ntfs_alloc_file(NTFS_LINO2NINO(dir
),ino
,(char*)d
->d_name
.name
,
449 error
=ntfs_update_inode(ino
);
451 error
=ntfs_update_inode(NTFS_LINO2NINO(dir
));
458 /* FIXME: dirty? dev? */
459 /* get the file modification times from the standard information */
460 si
=ntfs_find_attr(ino
,vol
->at_standard_information
,NULL
);
462 char *attr
=si
->d
.data
;
463 r
->i_atime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+0x18));
464 r
->i_ctime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
));
465 r
->i_mtime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+8));
467 /* It's not a directory */
468 r
->i_op
=&ntfs_inode_operations_nobmap
;
469 r
->i_fop
=&ntfs_file_operations_nommap
,
470 r
->i_mode
=S_IFREG
|S_IRUGO
;
471 #ifdef CONFIG_NTFS_RW
474 r
->i_mode
&= ~vol
->umask
;
476 insert_inode_hash(r
);
480 #ifndef NTFS_IN_LINUX_KERNEL
481 if(ino
)ntfs_free(ino
);
488 _linux_ntfs_mkdir(struct inode
*dir
, struct dentry
* d
, int mode
)
496 ntfs_debug (DEBUG_DIR1
, "mkdir %s in %x\n",d
->d_name
.name
, dir
->i_ino
);
497 error
= ENAMETOOLONG
;
498 if (d
->d_name
.len
> /* FIXME */255)
502 r
= get_empty_inode();
506 vol
= NTFS_INO2VOL(dir
);
507 #ifdef NTFS_IN_LINUX_KERNEL
508 ino
= NTFS_LINO2NINO(r
);
510 ino
= ntfs_malloc(sizeof(ntfs_inode
));
514 r
->u
.generic_ip
= ino
;
516 error
= ntfs_mkdir(NTFS_LINO2NINO(dir
),
517 d
->d_name
.name
, d
->d_name
.len
, ino
);
524 si
= ntfs_find_attr(ino
,vol
->at_standard_information
,NULL
);
526 char *attr
= si
->d
.data
;
527 r
->i_atime
= ntfs_ntutc2unixutc(NTFS_GETU64(attr
+0x18));
528 r
->i_ctime
= ntfs_ntutc2unixutc(NTFS_GETU64(attr
));
529 r
->i_mtime
= ntfs_ntutc2unixutc(NTFS_GETU64(attr
+8));
531 /* It's a directory */
532 r
->i_op
= &ntfs_dir_inode_operations
;
533 r
->i_fop
= &ntfs_dir_operations
;
534 r
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
535 #ifdef CONFIG_NTFS_RW
538 r
->i_mode
&= ~vol
->umask
;
540 insert_inode_hash(r
);
544 ntfs_debug (DEBUG_DIR1
, "mkdir returns %d\n", -error
);
550 ntfs_bmap(struct inode
*ino
,int block
)
552 int ret
=ntfs_vcn_to_lcn(NTFS_LINO2NINO(ino
),block
);
553 ntfs_debug(DEBUG_OTHER
, "bmap of %lx,block %x is %x\n",
554 ino
->i_ino
,block
,ret
);
555 return (ret
==-1) ? 0:ret
;
558 /* It's fscking broken. */
560 static int ntfs_get_block(struct inode
*inode
, long block
, struct buffer_head
*bh
, int create
)
566 static struct file_operations ntfs_file_operations
= {
568 mmap
: generic_file_mmap
,
569 #ifdef CONFIG_NTFS_RW
574 static struct inode_operations ntfs_inode_operations
= {
577 static struct file_operations ntfs_dir_operations
= {
578 read
: generic_read_dir
,
579 readdir
: ntfs_readdir
,
582 static struct inode_operations ntfs_dir_inode_operations
= {
584 #ifdef CONFIG_NTFS_RW
586 mkdir
: _linux_ntfs_mkdir
,
590 static int ntfs_writepage(struct file
*file
, struct page
*page
)
592 return block_write_full_page(page
,ntfs_get_block
);
594 static int ntfs_readpage(struct file
*file
, struct page
*page
)
596 return block_read_full_page(page
,ntfs_get_block
);
598 static int ntfs_prepare_write(struct file
*file
, struct page
*page
, unsigned from
, unsigned to
)
600 return cont_prepare_write(page
,from
,to
,ntfs_get_block
,
601 &((struct inode
*)page
->mapping
->host
)->u
.ntfs_i
.mmu_private
);
603 static int _ntfs_bmap(struct address_space
*mapping
, long block
)
605 return generic_block_bmap(mapping
,block
,ntfs_get_block
);
607 struct address_space_operations ntfs_aops
= {
608 readpage
: ntfs_readpage
,
609 writepage
: ntfs_writepage
,
610 sync_page
: block_sync_page
,
611 prepare_write
: ntfs_prepare_write
,
612 commit_write
: generic_commit_write
,
615 /* ntfs_read_inode is called by the Virtual File System (the kernel layer that
616 * deals with filesystems) when iget is called requesting an inode not already
617 * present in the inode table. Typically filesystems have separate
618 * inode_operations for directories, files and symlinks.
620 static void ntfs_read_inode(struct inode
* inode
)
625 ntfs_attribute
*data
;
628 vol
=NTFS_INO2VOL(inode
);
630 ntfs_debug(DEBUG_OTHER
, "ntfs_read_inode %x\n",(unsigned)inode
->i_ino
);
634 /* those are loaded special files */
636 ntfs_error("Trying to open MFT\n");return;
638 #ifdef NTFS_IN_LINUX_KERNEL
639 ino
=&inode
->u
.ntfs_i
;
641 /* FIXME: check for ntfs_malloc failure */
642 ino
=(ntfs_inode
*)ntfs_malloc(sizeof(ntfs_inode
));
643 inode
->u
.generic_ip
=ino
;
645 if(!ino
|| ntfs_init_inode(ino
,
646 NTFS_INO2VOL(inode
),inode
->i_ino
))
648 ntfs_debug(DEBUG_OTHER
, "NTFS:Error loading inode %x\n",
649 (unsigned int)inode
->i_ino
);
653 /* Set uid/gid from mount options */
654 inode
->i_uid
=vol
->uid
;
655 inode
->i_gid
=vol
->gid
;
657 /* Use the size of the data attribute as file size */
658 data
= ntfs_find_attr(ino
,vol
->at_data
,NULL
);
666 inode
->i_size
=data
->size
;
667 can_mmap
=!data
->resident
&& !data
->compressed
;
669 /* get the file modification times from the standard information */
670 si
=ntfs_find_attr(ino
,vol
->at_standard_information
,NULL
);
672 char *attr
=si
->d
.data
;
673 inode
->i_atime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+0x18));
674 inode
->i_ctime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
));
675 inode
->i_mtime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+8));
677 /* if it has an index root, it's a directory */
678 if(ntfs_find_attr(ino
,vol
->at_index_root
,"$I30"))
681 at
= ntfs_find_attr (ino
, vol
->at_index_allocation
, "$I30");
682 inode
->i_size
= at
? at
->size
: 0;
684 inode
->i_op
=&ntfs_dir_inode_operations
;
685 inode
->i_fop
=&ntfs_dir_operations
;
686 inode
->i_mode
=S_IFDIR
|S_IRUGO
|S_IXUGO
;
691 inode
->i_op
= &ntfs_inode_operations
;
692 inode
->i_fop
= &ntfs_file_operations
;
693 inode
->i_mapping
->a_ops
= &ntfs_aops
;
694 inode
->u
.ntfs_i
.mmu_private
= inode
->i_size
;
696 inode
->i_op
=&ntfs_inode_operations_nobmap
;
697 inode
->i_fop
=&ntfs_file_operations_nommap
;
699 inode
->i_mode
=S_IFREG
|S_IRUGO
;
701 #ifdef CONFIG_NTFS_RW
702 if(!data
|| !data
->compressed
)
703 inode
->i_mode
|=S_IWUGO
;
705 inode
->i_mode
&= ~vol
->umask
;
708 #ifdef CONFIG_NTFS_RW
710 ntfs_write_inode (struct inode
*ino
)
712 ntfs_debug (DEBUG_LINUX
, "ntfs:write inode %x\n", ino
->i_ino
);
713 ntfs_update_inode (NTFS_LINO2NINO (ino
));
717 static void _ntfs_clear_inode(struct inode
*ino
)
719 ntfs_debug(DEBUG_OTHER
, "ntfs_clear_inode %lx\n",ino
->i_ino
);
720 #ifdef NTFS_IN_LINUX_KERNEL
721 if(ino
->i_ino
!=FILE_MFT
)
722 ntfs_clear_inode(&ino
->u
.ntfs_i
);
724 if(ino
->i_ino
!=FILE_MFT
&& ino
->u
.generic_ip
)
726 ntfs_clear_inode(ino
->u
.generic_ip
);
727 ntfs_free(ino
->u
.generic_ip
);
734 /* Called when umounting a filesystem by do_umount() in fs/super.c */
735 static void ntfs_put_super(struct super_block
*sb
)
739 ntfs_debug(DEBUG_OTHER
, "ntfs_put_super\n");
743 ntfs_release_volume(vol
);
745 unload_nls(vol
->nls_map
);
746 #ifndef NTFS_IN_LINUX_KERNEL
749 ntfs_debug(DEBUG_OTHER
, "ntfs_put_super: done\n");
752 /* Called by the kernel when asking for stats */
753 static int ntfs_statfs(struct super_block
*sb
, struct statfs
*sf
)
760 ntfs_debug(DEBUG_OTHER
, "ntfs_statfs\n");
762 sf
->f_type
=NTFS_SUPER_MAGIC
;
763 sf
->f_bsize
=vol
->clustersize
;
765 error
= ntfs_get_volumesize( NTFS_SB2VOL( sb
), &size
);
768 sf
->f_blocks
= size
; /* volumesize is in clusters */
769 sf
->f_bfree
=ntfs_get_free_cluster_count(vol
->bitmap
);
770 sf
->f_bavail
=sf
->f_bfree
;
772 mft
=iget(sb
,FILE_MFT
);
775 /* So ... we lie... thus this following cast of loff_t value
777 sf
->f_files
= (unsigned long)mft
->i_size
/ vol
->mft_recordsize
;
780 /* should be read from volume */
785 /* Called when remounting a filesystem by do_remount_sb() in fs/super.c */
786 static int ntfs_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
788 if(!parse_options(NTFS_SB2VOL(sb
), options
))
793 /* Define the super block operation that are implemented */
794 static struct super_operations ntfs_super_operations
= {
795 read_inode
: ntfs_read_inode
,
796 #ifdef CONFIG_NTFS_RW
797 write_inode
: ntfs_write_inode
,
799 put_super
: ntfs_put_super
,
801 remount_fs
: ntfs_remount_fs
,
802 clear_inode
: _ntfs_clear_inode
,
805 /* Called to mount a filesystem by read_super() in fs/super.c
806 * Return a super block, the main structure of a filesystem
808 * NOTE : Don't store a pointer to an option, as the page containing the
809 * options is freed after ntfs_read_super() returns.
811 * NOTE : A context switch can happen in kernel code only if the code blocks
812 * (= calls schedule() in kernel/sched.c).
814 struct super_block
* ntfs_read_super(struct super_block
*sb
,
815 void *options
, int silent
)
818 struct buffer_head
*bh
;
821 ntfs_debug(DEBUG_OTHER
, "ntfs_read_super\n");
823 #ifdef NTFS_IN_LINUX_KERNEL
824 vol
= NTFS_SB2VOL(sb
);
826 if(!(vol
= ntfs_malloc(sizeof(ntfs_volume
))))
827 goto ntfs_read_super_dec
;
831 if(!parse_options(vol
,(char*)options
))
832 goto ntfs_read_super_vol
;
835 /* Set to read only, user option might reset it */
836 sb
->s_flags
|= MS_RDONLY
;
839 /* Assume a 512 bytes block device for now */
840 set_blocksize(sb
->s_dev
, 512);
841 /* Read the super block (boot block) */
842 if(!(bh
=bread(sb
->s_dev
,0,512))) {
843 ntfs_error("Reading super block failed\n");
844 goto ntfs_read_super_unl
;
846 ntfs_debug(DEBUG_OTHER
, "Done reading boot block\n");
848 /* Check for 'NTFS' magic number */
849 if(!IS_NTFS_VOLUME(bh
->b_data
)){
850 ntfs_debug(DEBUG_OTHER
, "Not a NTFS volume\n");
852 goto ntfs_read_super_unl
;
855 ntfs_debug(DEBUG_OTHER
, "Going to init volume\n");
856 ntfs_init_volume(vol
,bh
->b_data
);
857 ntfs_debug(DEBUG_OTHER
, "MFT record at cluster 0x%X\n",vol
->mft_cluster
);
860 ntfs_debug(DEBUG_OTHER
, "Done to init volume\n");
862 /* Inform the kernel that a device block is a NTFS cluster */
863 sb
->s_blocksize
=vol
->clustersize
;
864 for(i
=sb
->s_blocksize
,sb
->s_blocksize_bits
=0;i
!= 1;i
>>=1)
865 sb
->s_blocksize_bits
++;
866 set_blocksize(sb
->s_dev
,sb
->s_blocksize
);
867 ntfs_debug(DEBUG_OTHER
, "set_blocksize\n");
869 /* Allocate a MFT record (MFT record can be smaller than a cluster) */
870 if(!(vol
->mft
=ntfs_malloc(max(vol
->mft_recordsize
,vol
->clustersize
))))
871 goto ntfs_read_super_unl
;
873 /* Read at least the MFT record for $MFT */
874 for(i
=0;i
<max(vol
->mft_clusters_per_record
,1);i
++){
875 if(!(bh
=bread(sb
->s_dev
,vol
->mft_cluster
+i
,vol
->clustersize
))) {
876 ntfs_error("Could not read MFT record 0\n");
877 goto ntfs_read_super_mft
;
879 ntfs_memcpy(vol
->mft
+i
*vol
->clustersize
,bh
->b_data
,vol
->clustersize
);
881 ntfs_debug(DEBUG_OTHER
, "Read cluster %x\n",vol
->mft_cluster
+i
);
884 /* Check and fixup this MFT record */
885 if(!ntfs_check_mft_record(vol
,vol
->mft
)){
886 ntfs_error("Invalid MFT record 0\n");
887 goto ntfs_read_super_mft
;
890 /* Inform the kernel about which super operations are available */
891 sb
->s_op
= &ntfs_super_operations
;
892 sb
->s_magic
= NTFS_SUPER_MAGIC
;
894 ntfs_debug(DEBUG_OTHER
, "Reading special files\n");
895 if(ntfs_load_special_files(vol
)){
896 ntfs_error("Error loading special files\n");
897 goto ntfs_read_super_mft
;
900 ntfs_debug(DEBUG_OTHER
, "Getting RootDir\n");
901 /* Get the root directory */
902 if(!(sb
->s_root
=d_alloc_root(iget(sb
,FILE_ROOT
)))){
903 ntfs_error("Could not get root dir inode\n");
904 goto ntfs_read_super_mft
;
906 ntfs_debug(DEBUG_OTHER
, "read_super: done\n");
913 #ifndef NTFS_IN_LINUX_KERNEL
917 ntfs_debug(DEBUG_OTHER
, "read_super: done\n");
921 /* Define the filesystem
923 static DECLARE_FSTYPE_DEV(ntfs_fs_type
, "ntfs", ntfs_read_super
);
925 static int __init
init_ntfs_fs(void)
927 /* Comment this if you trust klogd. There are reasons not to trust it
929 #if defined(DEBUG) && !defined(MODULE)
930 extern int console_loglevel
;
933 printk(KERN_NOTICE
"NTFS version " NTFS_VERSION
"\n");
935 ntfs_debug(DEBUG_OTHER
, "registering %s\n",ntfs_fs_type
.name
);
936 /* add this filesystem to the kernel table of filesystems */
937 return register_filesystem(&ntfs_fs_type
);
940 static void __exit
exit_ntfs_fs(void)
943 ntfs_debug(DEBUG_OTHER
, "unregistering %s\n",ntfs_fs_type
.name
);
944 unregister_filesystem(&ntfs_fs_type
);
948 MODULE_AUTHOR("Martin von Löwis");
949 MODULE_DESCRIPTION("NTFS driver");
950 MODULE_PARM(ntdebug
, "i");
951 MODULE_PARM_DESC(ntdebug
, "Debug level");
953 module_init(init_ntfs_fs
)
954 module_exit(exit_ntfs_fs
)
957 * c-file-style: "linux"