3 * NTFS driver for Linux 2.1
5 * Copyright (C) 1995-1997, 1999 Martin von Löwis
6 * Copyright (C) 1996 Richard Russon
7 * Copyright (C) 1996-1997 Régis Duchesne
13 #ifdef NTFS_IN_LINUX_KERNEL
14 #include <linux/config.h>
17 #include "ntfstypes.h"
26 #include <linux/module.h>
27 #include <asm/uaccess.h>
28 #include <linux/nls.h>
29 #include <linux/locks.h>
30 #include <linux/init.h>
32 /* Forward declarations */
33 static struct inode_operations ntfs_dir_inode_operations
;
35 #define ITEM_SIZE 2040
37 /* io functions to user space */
38 static void ntfs_putuser(ntfs_io
* dest
,void *src
,ntfs_size_t len
)
40 copy_to_user(dest
->param
,src
,len
);
45 struct ntfs_getuser_update_vm_s
{
51 static void ntfs_getuser_update_vm (void *dest
, ntfs_io
*src
, ntfs_size_t len
)
53 struct ntfs_getuser_update_vm_s
*p
= src
->param
;
54 copy_from_user (dest
, p
->user
, len
);
55 update_vm_cache (p
->ino
, p
->off
, dest
, len
);
62 ntfs_read(struct file
* filp
, char *buf
, size_t count
, loff_t
*off
)
66 ntfs_inode
*ino
=NTFS_LINO2NINO(filp
->f_dentry
->d_inode
);
68 /* inode is not properly initialized */
69 if(!ino
)return -EINVAL
;
70 ntfs_debug(DEBUG_OTHER
, "ntfs_read %x,%x,%x ->",
71 (unsigned)ino
->i_number
,(unsigned)*off
,(unsigned)count
);
72 /* inode has no unnamed data attribute */
73 if(!ntfs_find_attr(ino
,ino
->vol
->at_data
,NULL
))
77 io
.fn_put
=ntfs_putuser
;
81 error
=ntfs_read_attr(ino
,ino
->vol
->at_data
,NULL
,*off
,&io
);
82 if(error
)return -error
;
90 ntfs_write(struct file
*filp
,const char* buf
,size_t count
,loff_t
*pos
)
94 struct inode
*inode
= filp
->f_dentry
->d_inode
;
95 ntfs_inode
*ino
= NTFS_LINO2NINO(inode
);
96 struct ntfs_getuser_update_vm_s param
;
100 ntfs_debug (DEBUG_LINUX
, "ntfs_write %x,%x,%x ->\n",
101 (unsigned)ino
->i_number
, (unsigned)*pos
, (unsigned)count
);
102 /* Allows to lock fs ro at any time */
103 if (inode
->i_sb
->s_flags
& MS_RDONLY
)
105 if (!ntfs_find_attr(ino
,ino
->vol
->at_data
,NULL
))
108 /* Evaluating O_APPEND is the file system's job... */
109 if (filp
->f_flags
& O_APPEND
)
110 *pos
= inode
->i_size
;
115 io
.fn_get
= ntfs_getuser_update_vm
;
118 ret
= ntfs_write_attr (ino
, ino
->vol
->at_data
, NULL
, *pos
, &io
);
119 ntfs_debug (DEBUG_LINUX
, "write -> %x\n", ret
);
124 if (*pos
> inode
->i_size
)
125 inode
->i_size
= *pos
;
126 mark_inode_dirty (filp
->f_dentry
->d_inode
);
141 static int ntfs_printcb(ntfs_u8
*entry
,void *param
)
143 struct ntfs_filldir
* nf
=param
;
144 int flags
=NTFS_GETU8(entry
+0x51);
146 int length
=NTFS_GETU8(entry
+0x50);
147 int inum
=NTFS_GETU32(entry
);
149 #ifdef NTFS_NGT_NT_DOES_LOWER
154 /* Don't display long names */
159 /* Don't display short-only names */
162 #ifdef NTFS_NGT_NT_DOES_LOWER
173 if(!show_hidden
&& ((NTFS_GETU8(entry
+0x48) & 2)==2)){
174 ntfs_debug(DEBUG_OTHER
,"Skipping hidden file\n");
178 if(ntfs_encodeuni(NTFS_INO2VOL(nf
->dir
),(ntfs_u16
*)(entry
+0x52),
179 length
,&nf
->name
,&nf
->namelen
)){
180 ntfs_debug(DEBUG_OTHER
,"Skipping unrepresentable file\n");
181 if(nf
->name
)ntfs_free(nf
->name
);
184 /* Do not return ".", as this is faked */
185 if(length
==1 && *nf
->name
=='.')
187 #ifdef NTFS_NGT_NT_DOES_LOWER
189 for(i
=0;i
<nf
->namelen
;i
++)
190 /* This supports ASCII only. Since only DOS-only
191 names get converted, and since those are restricted
192 to ASCII, this should be correct */
193 if(nf
->name
[i
]>='A' && nf
->name
[i
]<='Z')
194 nf
->name
[i
]+='a'-'A';
196 nf
->name
[nf
->namelen
]=0;
197 ntfs_debug(DEBUG_OTHER
, "readdir got %s,len %d\n",nf
->name
,nf
->namelen
);
198 /* filldir expects an off_t rather than an loff_t.
199 Hope we don't have more than 65535 index records */
200 error
=nf
->filldir(nf
->dirent
,nf
->name
,nf
->namelen
,
201 (nf
->ph
<<16)|nf
->pl
,inum
);
203 /* Linux filldir errors are negative, other errors positive */
207 /* readdir returns '..', then '.', then the directory entries in sequence
208 As the root directory contains a entry for itself, '.' is not emulated
209 for the root directory */
210 static int ntfs_readdir(struct file
* filp
, void *dirent
, filldir_t filldir
)
212 struct ntfs_filldir cb
;
214 struct inode
*dir
=filp
->f_dentry
->d_inode
;
216 ntfs_debug(DEBUG_OTHER
, "ntfs_readdir ino %x mode %x\n",
217 (unsigned)dir
->i_ino
,(unsigned int)dir
->i_mode
);
219 ntfs_debug(DEBUG_OTHER
, "readdir: Looking for file %x dircount %d\n",
220 (unsigned)filp
->f_pos
,dir
->i_count
);
221 cb
.pl
=filp
->f_pos
& 0xFFFF;
222 cb
.ph
=filp
->f_pos
>> 16;
223 /* end of directory */
225 /* FIXME: Maybe we can return those with the previous call */
227 case 0: filldir(dirent
,".",1,filp
->f_pos
,dir
->i_ino
);
228 filp
->f_pos
=0xFFFF0001;
230 /* FIXME: parent directory */
231 case 1: filldir(dirent
,"..",2,filp
->f_pos
,0);
232 filp
->f_pos
=0xFFFF0002;
235 ntfs_debug(DEBUG_OTHER
, "readdir: EOD\n");
241 cb
.type
=NTFS_INO2VOL(dir
)->ngt
;
243 ntfs_debug(DEBUG_OTHER
,"looking for next file\n");
244 error
=ntfs_getdir_unsorted(NTFS_LINO2NINO(dir
),&cb
.ph
,&cb
.pl
,
246 }while(!error
&& cb
.ph
!=0xFFFFFFFF);
247 filp
->f_pos
=(cb
.ph
<<16)|cb
.pl
;
248 ntfs_debug(DEBUG_OTHER
, "new position %x\n",(unsigned)filp
->f_pos
);
249 /* -EINVAL is on user buffer full. This is not considered
250 as an error by sys_getdents */
253 /* Otherwise (device error, inconsistent data), switch the sign */
257 /* Copied from vfat driver */
258 static int simple_getbool(char *s
, int *setval
)
261 if (!strcmp(s
,"1") || !strcmp(s
,"yes") || !strcmp(s
,"true")) {
263 } else if (!strcmp(s
,"0") || !strcmp(s
,"no") || !strcmp(s
,"false")) {
274 /* Parse the (re)mount options */
275 static int parse_options(ntfs_volume
* vol
,char *opt
)
286 for(opt
= strtok(opt
,",");opt
;opt
=strtok(NULL
,","))
288 if ((value
= strchr(opt
, '=')) != NULL
)
290 if(strcmp(opt
,"uid")==0)
292 if(!value
|| !*value
)goto needs_arg
;
293 vol
->uid
=simple_strtoul(value
,&value
,0);
295 printk(KERN_ERR
"NTFS: uid invalid argument\n");
298 }else if(strcmp(opt
, "gid") == 0)
300 if(!value
|| !*value
)goto needs_arg
;
301 vol
->gid
=simple_strtoul(value
,&value
,0);
303 printk(KERN_ERR
"gid invalid argument\n");
306 }else if(strcmp(opt
, "umask") == 0)
308 if(!value
|| !*value
)goto needs_arg
;
309 vol
->umask
=simple_strtoul(value
,&value
,0);
311 printk(KERN_ERR
"umask invalid argument\n");
314 }else if(strcmp(opt
, "iocharset") == 0){
315 if(!value
|| !*value
)goto needs_arg
;
316 vol
->nls_map
=load_nls(value
);
319 printk(KERN_ERR
"NTFS: charset not found");
322 }else if(strcmp(opt
, "posix") == 0){
324 if(!value
|| !*value
)goto needs_arg
;
325 if(!simple_getbool(value
,&val
))
327 vol
->ngt
=val
?ngt_posix
:ngt_nt
;
328 }else if(strcmp(opt
,"utf8") == 0){
330 if(!value
|| !*value
)
332 else if(!simple_getbool(value
,&val
))
336 }else if(strcmp(opt
,"uni_xlate") == 0){
338 /* no argument: uni_vfat.
339 boolean argument: uni_vfat.
342 if(!value
|| !*value
)
344 else if(strcmp(value
,"2")==0)
345 vol
->nct
|= nct_uni_xlate
;
346 else if(!simple_getbool(value
,&val
))
349 vol
->nct
|= nct_uni_xlate_vfat
| nct_uni_xlate
;
351 printk(KERN_ERR
"NTFS: unkown option '%s'\n", opt
);
355 if(vol
->nct
& nct_utf8
& (nct_map
| nct_uni_xlate
)){
356 printk(KERN_ERR
"utf8 cannot be combined with iocharset or uni_xlate\n");
360 if((vol
->nct
& (nct_uni_xlate
| nct_map
| nct_utf8
))==0)
361 /* default to UTF-8 */
364 vol
->nls_map
=load_nls_default();
368 printk(KERN_ERR
"NTFS: %s needs an argument",opt
);
371 printk(KERN_ERR
"NTFS: %s needs boolean argument",opt
);
375 static struct dentry
*ntfs_lookup(struct inode
*dir
, struct dentry
*d
)
381 ntfs_debug(DEBUG_NAME1
, "Looking up %s in %x\n",d
->d_name
.name
,
382 (unsigned)dir
->i_ino
);
383 /* convert to wide string */
384 error
=ntfs_decodeuni(NTFS_INO2VOL(dir
),(char*)d
->d_name
.name
,
385 d
->d_name
.len
,&walk
.name
,&walk
.namelen
);
387 return ERR_PTR(-error
);
388 item
=ntfs_malloc(ITEM_SIZE
);
390 return ERR_PTR(-ENOMEM
);
391 /* ntfs_getdir will place the directory entry into item,
392 and the first long long is the MFT record number */
394 walk
.dir
=NTFS_LINO2NINO(dir
);
396 if(ntfs_getdir_byname(&walk
))
398 res
=iget(dir
->i_sb
,NTFS_GETU32(item
));
402 ntfs_free(walk
.name
);
403 /* Always return success, the dcache will handle negative entries. */
407 static struct file_operations ntfs_file_operations_nommap
= {
410 #ifdef CONFIG_NTFS_RW
424 NULL
, /* check_media_change */
425 NULL
, /* revalidate */
429 static struct inode_operations ntfs_inode_operations_nobmap
= {
430 &ntfs_file_operations_nommap
,
441 NULL
, /* follow_link */
442 NULL
, /* get_block */
444 NULL
, /* writepage */
445 NULL
, /* flushpage */
447 NULL
, /* permission */
449 NULL
, /* revalidate */
452 #ifdef CONFIG_NTFS_RW
454 ntfs_create(struct inode
* dir
,struct dentry
*d
,int mode
)
468 ntfs_debug(DEBUG_OTHER
, "ntfs_create %s\n",d
->d_name
.name
);
469 vol
=NTFS_INO2VOL(dir
);
470 #ifdef NTFS_IN_LINUX_KERNEL
471 ino
=NTFS_LINO2NINO(r
);
473 ino
=ntfs_malloc(sizeof(ntfs_inode
));
480 error
=ntfs_alloc_file(NTFS_LINO2NINO(dir
),ino
,(char*)d
->d_name
.name
,
483 error
=ntfs_update_inode(ino
);
485 error
=ntfs_update_inode(NTFS_LINO2NINO(dir
));
492 /* FIXME: dirty? dev? */
493 /* get the file modification times from the standard information */
494 si
=ntfs_find_attr(ino
,vol
->at_standard_information
,NULL
);
496 char *attr
=si
->d
.data
;
497 r
->i_atime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+0x18));
498 r
->i_ctime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
));
499 r
->i_mtime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+8));
501 /* It's not a directory */
502 r
->i_op
=&ntfs_inode_operations_nobmap
;
503 r
->i_mode
=S_IFREG
|S_IRUGO
;
504 #ifdef CONFIG_NTFS_RW
507 r
->i_mode
&= ~vol
->umask
;
509 insert_inode_hash(r
);
513 #ifndef NTFS_IN_LINUX_KERNEL
514 if(ino
)ntfs_free(ino
);
521 _linux_ntfs_mkdir(struct inode
*dir
, struct dentry
* d
, int mode
)
529 ntfs_debug (DEBUG_DIR1
, "mkdir %s in %x\n",d
->d_name
.name
, dir
->i_ino
);
530 error
= ENAMETOOLONG
;
531 if (d
->d_name
.len
> /* FIXME */255)
535 r
= get_empty_inode();
539 vol
= NTFS_INO2VOL(dir
);
540 #ifdef NTFS_IN_LINUX_KERNEL
541 ino
= NTFS_LINO2NINO(r
);
543 ino
= ntfs_malloc(sizeof(ntfs_inode
));
547 r
->u
.generic_ip
= ino
;
549 error
= ntfs_mkdir(NTFS_LINO2NINO(dir
),
550 d
->d_name
.name
, d
->d_name
.len
, ino
);
557 si
= ntfs_find_attr(ino
,vol
->at_standard_information
,NULL
);
559 char *attr
= si
->d
.data
;
560 r
->i_atime
= ntfs_ntutc2unixutc(NTFS_GETU64(attr
+0x18));
561 r
->i_ctime
= ntfs_ntutc2unixutc(NTFS_GETU64(attr
));
562 r
->i_mtime
= ntfs_ntutc2unixutc(NTFS_GETU64(attr
+8));
564 /* It's a directory */
565 r
->i_op
= &ntfs_dir_inode_operations
;
566 r
->i_mode
= S_IFDIR
|S_IRUGO
|S_IXUGO
;
567 #ifdef CONFIG_NTFS_RW
570 r
->i_mode
&= ~vol
->umask
;
572 insert_inode_hash(r
);
576 ntfs_debug (DEBUG_DIR1
, "mkdir returns %d\n", -error
);
582 ntfs_bmap(struct inode
*ino
,int block
)
584 int ret
=ntfs_vcn_to_lcn(NTFS_LINO2NINO(ino
),block
);
585 ntfs_debug(DEBUG_OTHER
, "bmap of %lx,block %x is %x\n",
586 ino
->i_ino
,block
,ret
);
587 return (ret
==-1) ? 0:ret
;
590 static struct file_operations ntfs_file_operations
= {
593 #ifdef CONFIG_NTFS_RW
607 NULL
, /* check_media_change */
608 NULL
, /* revalidate */
612 static struct inode_operations ntfs_inode_operations
= {
613 &ntfs_file_operations
,
624 NULL
, /* follow_link */
625 ntfs_bmap
, /* get_block */
626 block_read_full_page
, /* readpage */
627 NULL
, /* writepage */
628 NULL
, /* flushpage */
630 NULL
, /* permission */
632 NULL
, /* revalidate */
635 static struct file_operations ntfs_dir_operations
= {
639 ntfs_readdir
, /* readdir */
648 NULL
, /* check_media_change */
649 NULL
, /* revalidate */
653 static struct inode_operations ntfs_dir_inode_operations
= {
654 &ntfs_dir_operations
,
655 #ifdef CONFIG_NTFS_RW
656 ntfs_create
, /* create */
660 ntfs_lookup
, /* lookup */
664 #ifdef CONFIG_NTFS_RW
665 _linux_ntfs_mkdir
, /* mkdir */
673 NULL
, /* follow_link */
674 NULL
, /* get_block */
676 NULL
, /* writepage */
677 NULL
, /* flushpage */
679 NULL
, /* permission */
681 NULL
, /* revalidate */
684 /* ntfs_read_inode is called by the Virtual File System (the kernel layer that
685 * deals with filesystems) when iget is called requesting an inode not already
686 * present in the inode table. Typically filesystems have separate
687 * inode_operations for directories, files and symlinks.
689 static void ntfs_read_inode(struct inode
* inode
)
694 ntfs_attribute
*data
;
697 vol
=NTFS_INO2VOL(inode
);
700 ntfs_debug(DEBUG_OTHER
, "ntfs_read_inode %x\n",(unsigned)inode
->i_ino
);
704 /* those are loaded special files */
706 ntfs_error("Trying to open MFT\n");return;
708 #ifdef NTFS_IN_LINUX_KERNEL
709 ino
=&inode
->u
.ntfs_i
;
711 /* FIXME: check for ntfs_malloc failure */
712 ino
=(ntfs_inode
*)ntfs_malloc(sizeof(ntfs_inode
));
713 inode
->u
.generic_ip
=ino
;
715 if(!ino
|| ntfs_init_inode(ino
,
716 NTFS_INO2VOL(inode
),inode
->i_ino
))
718 ntfs_debug(DEBUG_OTHER
, "NTFS:Error loading inode %x\n",
719 (unsigned int)inode
->i_ino
);
723 /* Set uid/gid from mount options */
724 inode
->i_uid
=vol
->uid
;
725 inode
->i_gid
=vol
->gid
;
727 /* Use the size of the data attribute as file size */
728 data
= ntfs_find_attr(ino
,vol
->at_data
,NULL
);
736 inode
->i_size
=data
->size
;
737 can_mmap
=!data
->resident
&& !data
->compressed
;
739 /* get the file modification times from the standard information */
740 si
=ntfs_find_attr(ino
,vol
->at_standard_information
,NULL
);
742 char *attr
=si
->d
.data
;
743 inode
->i_atime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+0x18));
744 inode
->i_ctime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
));
745 inode
->i_mtime
=ntfs_ntutc2unixutc(NTFS_GETU64(attr
+8));
747 /* if it has an index root, it's a directory */
748 if(ntfs_find_attr(ino
,vol
->at_index_root
,"$I30"))
751 at
= ntfs_find_attr (ino
, vol
->at_index_allocation
, "$I30");
752 inode
->i_size
= at
? at
->size
: 0;
754 inode
->i_op
=&ntfs_dir_inode_operations
;
755 inode
->i_mode
=S_IFDIR
|S_IRUGO
|S_IXUGO
;
759 inode
->i_op
=can_mmap
? &ntfs_inode_operations
:
760 &ntfs_inode_operations_nobmap
;
761 inode
->i_mode
=S_IFREG
|S_IRUGO
;
763 #ifdef CONFIG_NTFS_RW
764 if(!data
|| !data
->compressed
)
765 inode
->i_mode
|=S_IWUGO
;
767 inode
->i_mode
&= ~vol
->umask
;
770 #ifdef CONFIG_NTFS_RW
772 ntfs_write_inode (struct inode
*ino
)
774 ntfs_debug (DEBUG_LINUX
, "ntfs:write inode %x\n", ino
->i_ino
);
775 ntfs_update_inode (NTFS_LINO2NINO (ino
));
779 static void _ntfs_clear_inode(struct inode
*ino
)
781 ntfs_debug(DEBUG_OTHER
, "ntfs_clear_inode %lx\n",ino
->i_ino
);
782 #ifdef NTFS_IN_LINUX_KERNEL
783 if(ino
->i_ino
!=FILE_MFT
)
784 ntfs_clear_inode(&ino
->u
.ntfs_i
);
786 if(ino
->i_ino
!=FILE_MFT
&& ino
->u
.generic_ip
)
788 ntfs_clear_inode(ino
->u
.generic_ip
);
789 ntfs_free(ino
->u
.generic_ip
);
796 /* Called when umounting a filesystem by do_umount() in fs/super.c */
797 static void ntfs_put_super(struct super_block
*sb
)
801 ntfs_debug(DEBUG_OTHER
, "ntfs_put_super\n");
805 ntfs_release_volume(vol
);
807 unload_nls(vol
->nls_map
);
808 #ifndef NTFS_IN_LINUX_KERNEL
811 ntfs_debug(DEBUG_OTHER
, "ntfs_put_super: done\n");
815 /* Called by the kernel when asking for stats */
816 static int ntfs_statfs(struct super_block
*sb
, struct statfs
*sf
, int bufsize
)
823 ntfs_debug(DEBUG_OTHER
, "ntfs_statfs\n");
825 memset(&fs
,0,sizeof(fs
));
826 fs
.f_type
=NTFS_SUPER_MAGIC
;
827 fs
.f_bsize
=vol
->clustersize
;
829 error
= ntfs_get_volumesize( NTFS_SB2VOL( sb
), &fs
.f_blocks
);
832 fs
.f_bfree
=ntfs_get_free_cluster_count(vol
->bitmap
);
833 fs
.f_bavail
=fs
.f_bfree
;
835 /* Number of files is limited by free space only, so we lie here */
837 mft
=iget(sb
,FILE_MFT
);
838 fs
.f_files
=mft
->i_size
/vol
->mft_recordsize
;
841 /* should be read from volume */
843 copy_to_user(sf
,&fs
,bufsize
);
847 /* Called when remounting a filesystem by do_remount_sb() in fs/super.c */
848 static int ntfs_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
850 if(!parse_options(NTFS_SB2VOL(sb
), options
))
855 /* Define the super block operation that are implemented */
856 static struct super_operations ntfs_super_operations
= {
858 #ifdef CONFIG_NTFS_RW
863 NULL
, /* put_inode */
864 NULL
, /* delete_inode */
865 NULL
, /* notify_change */
867 NULL
, /* write_super */
869 ntfs_remount_fs
, /* remount */
870 _ntfs_clear_inode
, /* clear_inode */
873 /* Called to mount a filesystem by read_super() in fs/super.c
874 * Return a super block, the main structure of a filesystem
876 * NOTE : Don't store a pointer to an option, as the page containing the
877 * options is freed after ntfs_read_super() returns.
879 * NOTE : A context switch can happen in kernel code only if the code blocks
880 * (= calls schedule() in kernel/sched.c).
882 struct super_block
* ntfs_read_super(struct super_block
*sb
,
883 void *options
, int silent
)
886 struct buffer_head
*bh
;
889 /* When the driver is compiled as a module, kmod must know when it
890 * can safely remove it from memory. To do this, each module owns a
894 /* Don't put ntfs_debug() before MOD_INC_USE_COUNT, printk() can block
895 * so this could lead to a race condition with kmod.
897 ntfs_debug(DEBUG_OTHER
, "ntfs_read_super\n");
899 #ifdef NTFS_IN_LINUX_KERNEL
900 vol
= NTFS_SB2VOL(sb
);
902 if(!(vol
= ntfs_malloc(sizeof(ntfs_volume
))))
903 goto ntfs_read_super_dec
;
907 if(!parse_options(vol
,(char*)options
))
908 goto ntfs_read_super_vol
;
910 /* Ensure that the super block won't be used until it is completed */
912 ntfs_debug(DEBUG_OTHER
, "lock_super\n");
914 /* Set to read only, user option might reset it */
915 sb
->s_flags
|= MS_RDONLY
;
918 /* Assume a 512 bytes block device for now */
919 set_blocksize(sb
->s_dev
, 512);
920 /* Read the super block (boot block) */
921 if(!(bh
=bread(sb
->s_dev
,0,512))) {
922 ntfs_error("Reading super block failed\n");
923 goto ntfs_read_super_unl
;
925 ntfs_debug(DEBUG_OTHER
, "Done reading boot block\n");
927 /* Check for 'NTFS' magic number */
928 if(!IS_NTFS_VOLUME(bh
->b_data
)){
929 ntfs_debug(DEBUG_OTHER
, "Not a NTFS volume\n");
931 goto ntfs_read_super_unl
;
934 ntfs_debug(DEBUG_OTHER
, "Going to init volume\n");
935 ntfs_init_volume(vol
,bh
->b_data
);
936 ntfs_debug(DEBUG_OTHER
, "MFT record at cluster 0x%X\n",vol
->mft_cluster
);
939 ntfs_debug(DEBUG_OTHER
, "Done to init volume\n");
941 /* Inform the kernel that a device block is a NTFS cluster */
942 sb
->s_blocksize
=vol
->clustersize
;
943 for(i
=sb
->s_blocksize
,sb
->s_blocksize_bits
=0;i
!= 1;i
>>=1)
944 sb
->s_blocksize_bits
++;
945 set_blocksize(sb
->s_dev
,sb
->s_blocksize
);
946 ntfs_debug(DEBUG_OTHER
, "set_blocksize\n");
948 /* Allocate a MFT record (MFT record can be smaller than a cluster) */
949 if(!(vol
->mft
=ntfs_malloc(max(vol
->mft_recordsize
,vol
->clustersize
))))
950 goto ntfs_read_super_unl
;
952 /* Read at least the MFT record for $MFT */
953 for(i
=0;i
<max(vol
->mft_clusters_per_record
,1);i
++){
954 if(!(bh
=bread(sb
->s_dev
,vol
->mft_cluster
+i
,vol
->clustersize
))) {
955 ntfs_error("Could not read MFT record 0\n");
956 goto ntfs_read_super_mft
;
958 ntfs_memcpy(vol
->mft
+i
*vol
->clustersize
,bh
->b_data
,vol
->clustersize
);
960 ntfs_debug(DEBUG_OTHER
, "Read cluster %x\n",vol
->mft_cluster
+i
);
963 /* Check and fixup this MFT record */
964 if(!ntfs_check_mft_record(vol
,vol
->mft
)){
965 ntfs_error("Invalid MFT record 0\n");
966 goto ntfs_read_super_mft
;
969 /* Inform the kernel about which super operations are available */
970 sb
->s_op
= &ntfs_super_operations
;
971 sb
->s_magic
= NTFS_SUPER_MAGIC
;
973 ntfs_debug(DEBUG_OTHER
, "Reading special files\n");
974 if(ntfs_load_special_files(vol
)){
975 ntfs_error("Error loading special files\n");
976 goto ntfs_read_super_mft
;
979 ntfs_debug(DEBUG_OTHER
, "Getting RootDir\n");
980 /* Get the root directory */
981 if(!(sb
->s_root
=d_alloc_root(iget(sb
,FILE_ROOT
)))){
982 ntfs_error("Could not get root dir inode\n");
983 goto ntfs_read_super_mft
;
986 ntfs_debug(DEBUG_OTHER
, "unlock_super\n");
987 ntfs_debug(DEBUG_OTHER
, "read_super: done\n");
995 ntfs_debug(DEBUG_OTHER
, "unlock_super\n");
997 #ifndef NTFS_IN_LINUX_KERNEL
1001 ntfs_debug(DEBUG_OTHER
, "read_super: done\n");
1006 /* Define the filesystem
1008 * Define SECOND if you cannot unload ntfs, and want to avoid rebooting
1009 * for just one more test
1011 static struct file_system_type ntfs_fs_type
= {
1012 /* Filesystem name, as used after mount -t */
1018 /* This filesystem requires a device (a hard disk)
1019 * May want to add FS_IBASKET when it works
1022 /* Entry point of the filesystem */
1024 /* Will point to the next filesystem in the kernel table */
1028 /* When this code is not compiled as a module, this is the main entry point,
1029 * called by do_sys_setup() in fs/filesystems.c
1031 * NOTE : __initfunc() is a macro used to remove this function from memory
1032 * once initialization is done
1034 __initfunc(int init_ntfs_fs(void))
1036 /* Comment this if you trust klogd. There are reasons not to trust it
1038 #if defined(DEBUG) && !defined(MODULE)
1039 extern int console_loglevel
;
1040 console_loglevel
=15;
1042 printk(KERN_NOTICE
"NTFS version " NTFS_VERSION
"\n");
1044 ntfs_debug(DEBUG_OTHER
, "registering %s\n",ntfs_fs_type
.name
);
1045 /* add this filesystem to the kernel table of filesystems */
1046 return register_filesystem(&ntfs_fs_type
);
1050 /* A module is a piece of code which can be inserted in and removed
1051 * from the running kernel whenever you want using lsmod, or on demand using
1055 /* No function of this module is needed by another module */
1057 /* Only used for documentation purposes at the moment,
1058 * see include/linux/module.h
1060 MODULE_AUTHOR("Martin von Löwis");
1061 MODULE_DESCRIPTION("NTFS driver");
1062 /* no MODULE_SUPPORTED_DEVICE() */
1063 /* Load-time parameter */
1064 MODULE_PARM(ntdebug
, "i");
1065 MODULE_PARM_DESC(ntdebug
, "Debug level");
1067 /* When this code is compiled as a module, if you use mount -t ntfs when no
1068 * ntfs filesystem is registered (see /proc/filesystems), get_fs_type() in
1069 * fs/super.c asks kmod to load the module named ntfs in memory.
1071 * Therefore, this function is the main entry point in this case
1073 int init_module(void)
1075 return init_ntfs_fs();
1078 /* Called by kmod just before the kernel removes the module from memory */
1079 void cleanup_module(void)
1082 ntfs_debug(DEBUG_OTHER
, "unregistering %s\n",ntfs_fs_type
.name
);
1083 unregister_filesystem(&ntfs_fs_type
);
1089 * c-file-style: "linux"