2005-04-17 02:20:36 +04:00
/*
* linux / fs / hpfs / super . c
*
* Mikulas Patocka ( mikulas @ artax . karlin . mff . cuni . cz ) , 1998 - 1999
*
* mounting , unmounting , error handling
*/
# include "hpfs_fn.h"
# include <linux/module.h>
# include <linux/parser.h>
# include <linux/init.h>
# include <linux/statfs.h>
2006-09-24 19:13:19 +04:00
# include <linux/magic.h>
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-21 01:22:52 +04:00
# include <linux/sched.h>
2009-12-16 03:46:56 +03:00
# include <linux/bitmap.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2016-05-24 23:49:18 +03:00
# include <linux/seq_file.h>
2005-04-17 02:20:36 +04:00
/* Mark the filesystem dirty, so that chkdsk checks it when os/2 booted */
2011-05-08 22:44:08 +04:00
static void mark_dirty ( struct super_block * s , int remount )
2005-04-17 02:20:36 +04:00
{
2017-07-17 10:45:34 +03:00
if ( hpfs_sb ( s ) - > sb_chkdsk & & ( remount | | ! sb_rdonly ( s ) ) ) {
2005-04-17 02:20:36 +04:00
struct buffer_head * bh ;
struct hpfs_spare_block * sb ;
if ( ( sb = hpfs_map_sector ( s , 17 , & bh , 0 ) ) ) {
sb - > dirty = 1 ;
sb - > old_wrote = 0 ;
mark_buffer_dirty ( bh ) ;
2011-05-08 22:43:41 +04:00
sync_dirty_buffer ( bh ) ;
2005-04-17 02:20:36 +04:00
brelse ( bh ) ;
}
}
}
/* Mark the filesystem clean (mark it dirty for chkdsk if chkdsk==2 or if there
were errors ) */
static void unmark_dirty ( struct super_block * s )
{
struct buffer_head * bh ;
struct hpfs_spare_block * sb ;
2017-07-17 10:45:34 +03:00
if ( sb_rdonly ( s ) ) return ;
2011-05-08 22:43:41 +04:00
sync_blockdev ( s - > s_bdev ) ;
2005-04-17 02:20:36 +04:00
if ( ( sb = hpfs_map_sector ( s , 17 , & bh , 0 ) ) ) {
sb - > dirty = hpfs_sb ( s ) - > sb_chkdsk > 1 - hpfs_sb ( s ) - > sb_was_error ;
sb - > old_wrote = hpfs_sb ( s ) - > sb_chkdsk > = 2 & & ! hpfs_sb ( s ) - > sb_was_error ;
mark_buffer_dirty ( bh ) ;
2011-05-08 22:43:41 +04:00
sync_dirty_buffer ( bh ) ;
2005-04-17 02:20:36 +04:00
brelse ( bh ) ;
}
}
/* Filesystem error... */
2006-12-07 07:37:04 +03:00
void hpfs_error ( struct super_block * s , const char * fmt , . . . )
2005-04-17 02:20:36 +04:00
{
2015-03-27 06:47:10 +03:00
struct va_format vaf ;
2006-12-07 07:37:04 +03:00
va_list args ;
va_start ( args , fmt ) ;
2015-03-27 06:47:10 +03:00
vaf . fmt = fmt ;
vaf . va = & args ;
pr_err ( " filesystem error: %pV " , & vaf ) ;
2006-12-07 07:37:04 +03:00
va_end ( args ) ;
2005-04-17 02:20:36 +04:00
if ( ! hpfs_sb ( s ) - > sb_was_error ) {
if ( hpfs_sb ( s ) - > sb_err = = 2 ) {
2014-06-07 01:36:34 +04:00
pr_cont ( " ; crashing the system because you wanted it \n " ) ;
2011-05-08 22:44:08 +04:00
mark_dirty ( s , 0 ) ;
2005-04-17 02:20:36 +04:00
panic ( " HPFS panic " ) ;
} else if ( hpfs_sb ( s ) - > sb_err = = 1 ) {
2017-07-17 10:45:34 +03:00
if ( sb_rdonly ( s ) )
2014-06-07 01:36:34 +04:00
pr_cont ( " ; already mounted read-only \n " ) ;
2005-04-17 02:20:36 +04:00
else {
2014-06-07 01:36:34 +04:00
pr_cont ( " ; remounting read-only \n " ) ;
2011-05-08 22:44:08 +04:00
mark_dirty ( s , 0 ) ;
2017-11-28 00:05:09 +03:00
s - > s_flags | = SB_RDONLY ;
2005-04-17 02:20:36 +04:00
}
2017-07-17 10:45:34 +03:00
} else if ( sb_rdonly ( s ) )
2014-06-07 01:36:34 +04:00
pr_cont ( " ; going on - but anything won't be destroyed because it's read-only \n " ) ;
else
pr_cont ( " ; corrupted filesystem mounted read/write - your computer will explode within 20 seconds ... but you wanted it so! \n " ) ;
} else
pr_cont ( " \n " ) ;
2005-04-17 02:20:36 +04:00
hpfs_sb ( s ) - > sb_was_error = 1 ;
}
/*
* A little trick to detect cycles in many hpfs structures and don ' t let the
* kernel crash on corrupted filesystem . When first called , set c2 to 0.
*
* BTW . chkdsk doesn ' t detect cycles correctly . When I had 2 lost directories
* nested each in other , chkdsk locked up happilly .
*/
int hpfs_stop_cycles ( struct super_block * s , int key , int * c1 , int * c2 ,
char * msg )
{
if ( * c2 & & * c1 = = key ) {
hpfs_error ( s , " cycle detected on key %08x in %s " , key , msg ) ;
return 1 ;
}
( * c2 ) + + ;
if ( ! ( ( * c2 - 1 ) & * c2 ) ) * c1 = key ;
return 0 ;
}
2013-10-03 20:25:10 +04:00
static void free_sbi ( struct hpfs_sb_info * sbi )
2005-04-17 02:20:36 +04:00
{
2013-10-03 20:25:10 +04:00
kfree ( sbi - > sb_cp_table ) ;
kfree ( sbi - > sb_bmp_dir ) ;
kfree ( sbi ) ;
}
push BKL down into ->put_super
Move BKL into ->put_super from the only caller. A couple of
filesystems had trivial enough ->put_super (only kfree and NULLing of
s_fs_info + stuff in there) to not get any locking: coda, cramfs, efs,
hugetlbfs, omfs, qnx4, shmem, all others got the full treatment. Most
of them probably don't need it, but I'd rather sort that out individually.
Preferably after all the other BKL pushdowns in that area.
[AV: original used to move lock_super() down as well; these changes are
removed since we don't do lock_super() at all in generic_shutdown_super()
now]
[AV: fuse, btrfs and xfs are known to need no damn BKL, exempt]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2009-05-05 17:40:36 +04:00
2013-10-03 20:25:10 +04:00
static void lazy_free_sbi ( struct rcu_head * rcu )
{
free_sbi ( container_of ( rcu , struct hpfs_sb_info , rcu ) ) ;
}
static void hpfs_put_super ( struct super_block * s )
{
2011-05-08 22:42:54 +04:00
hpfs_lock ( s ) ;
unmark_dirty ( s ) ;
hpfs_unlock ( s ) ;
2013-10-03 20:25:10 +04:00
call_rcu ( & hpfs_sb ( s ) - > rcu , lazy_free_sbi ) ;
2005-04-17 02:20:36 +04:00
}
2014-01-29 03:10:44 +04:00
static unsigned hpfs_count_one_bitmap ( struct super_block * s , secno secno )
2005-04-17 02:20:36 +04:00
{
struct quad_buffer_head qbh ;
2009-12-16 03:46:56 +03:00
unsigned long * bits ;
unsigned count ;
2013-07-04 21:04:01 +04:00
bits = hpfs_map_4sectors ( s , secno , & qbh , 0 ) ;
2009-12-16 03:46:56 +03:00
if ( ! bits )
2014-01-29 03:10:44 +04:00
return ( unsigned ) - 1 ;
2009-12-16 03:46:56 +03:00
count = bitmap_weight ( bits , 2048 * BITS_PER_BYTE ) ;
2005-04-17 02:20:36 +04:00
hpfs_brelse4 ( & qbh ) ;
return count ;
}
static unsigned count_bitmaps ( struct super_block * s )
{
unsigned n , count , n_bands ;
n_bands = ( hpfs_sb ( s ) - > sb_fs_size + 0x3fff ) > > 14 ;
count = 0 ;
2013-07-04 21:04:01 +04:00
for ( n = 0 ; n < COUNT_RD_AHEAD ; n + + ) {
hpfs_prefetch_bitmap ( s , n ) ;
}
for ( n = 0 ; n < n_bands ; n + + ) {
2014-01-29 03:10:44 +04:00
unsigned c ;
2013-07-04 21:04:01 +04:00
hpfs_prefetch_bitmap ( s , n + COUNT_RD_AHEAD ) ;
2014-01-29 03:10:44 +04:00
c = hpfs_count_one_bitmap ( s , le32_to_cpu ( hpfs_sb ( s ) - > sb_bmp_dir [ n ] ) ) ;
if ( c ! = ( unsigned ) - 1 )
count + = c ;
2013-07-04 21:04:01 +04:00
}
2005-04-17 02:20:36 +04:00
return count ;
}
2014-01-29 03:10:44 +04:00
unsigned hpfs_get_free_dnodes ( struct super_block * s )
{
struct hpfs_sb_info * sbi = hpfs_sb ( s ) ;
if ( sbi - > sb_n_free_dnodes = = ( unsigned ) - 1 ) {
unsigned c = hpfs_count_one_bitmap ( s , sbi - > sb_dmap ) ;
if ( c = = ( unsigned ) - 1 )
return 0 ;
sbi - > sb_n_free_dnodes = c ;
}
return sbi - > sb_n_free_dnodes ;
}
2006-06-23 13:02:58 +04:00
static int hpfs_statfs ( struct dentry * dentry , struct kstatfs * buf )
2005-04-17 02:20:36 +04:00
{
2006-06-23 13:02:58 +04:00
struct super_block * s = dentry - > d_sb ;
2005-04-17 02:20:36 +04:00
struct hpfs_sb_info * sbi = hpfs_sb ( s ) ;
2009-04-03 03:59:37 +04:00
u64 id = huge_encode_dev ( s - > s_bdev - > bd_dev ) ;
2014-01-29 03:10:44 +04:00
2011-01-22 22:26:12 +03:00
hpfs_lock ( s ) ;
2005-04-17 02:20:36 +04:00
2014-01-29 03:10:44 +04:00
if ( sbi - > sb_n_free = = ( unsigned ) - 1 )
2005-04-17 02:20:36 +04:00
sbi - > sb_n_free = count_bitmaps ( s ) ;
2014-01-29 03:10:44 +04:00
2005-04-17 02:20:36 +04:00
buf - > f_type = s - > s_magic ;
buf - > f_bsize = 512 ;
buf - > f_blocks = sbi - > sb_fs_size ;
buf - > f_bfree = sbi - > sb_n_free ;
buf - > f_bavail = sbi - > sb_n_free ;
buf - > f_files = sbi - > sb_dirband_size / 4 ;
2014-01-29 03:10:44 +04:00
buf - > f_ffree = hpfs_get_free_dnodes ( s ) ;
2009-04-03 03:59:37 +04:00
buf - > f_fsid . val [ 0 ] = ( u32 ) id ;
buf - > f_fsid . val [ 1 ] = ( u32 ) ( id > > 32 ) ;
2005-04-17 02:20:36 +04:00
buf - > f_namelen = 254 ;
2011-01-22 22:26:12 +03:00
hpfs_unlock ( s ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2015-06-28 16:16:57 +03:00
long hpfs_ioctl ( struct file * file , unsigned cmd , unsigned long arg )
{
switch ( cmd ) {
case FITRIM : {
struct fstrim_range range ;
secno n_trimmed ;
int r ;
if ( ! capable ( CAP_SYS_ADMIN ) )
return - EPERM ;
if ( copy_from_user ( & range , ( struct fstrim_range __user * ) arg , sizeof ( range ) ) )
return - EFAULT ;
r = hpfs_trim_fs ( file_inode ( file ) - > i_sb , range . start > > 9 , ( range . start + range . len ) > > 9 , ( range . minlen + 511 ) > > 9 , & n_trimmed ) ;
if ( r )
return r ;
range . len = ( u64 ) n_trimmed < < 9 ;
if ( copy_to_user ( ( struct fstrim_range __user * ) arg , & range , sizeof ( range ) ) )
return - EFAULT ;
return 0 ;
}
default : {
return - ENOIOCTLCMD ;
}
}
}
2006-12-07 07:33:20 +03:00
static struct kmem_cache * hpfs_inode_cachep ;
2005-04-17 02:20:36 +04:00
static struct inode * hpfs_alloc_inode ( struct super_block * sb )
{
struct hpfs_inode_info * ei ;
2015-04-23 12:28:45 +03:00
ei = kmem_cache_alloc ( hpfs_inode_cachep , GFP_NOFS ) ;
2005-04-17 02:20:36 +04:00
if ( ! ei )
return NULL ;
return & ei - > vfs_inode ;
}
2019-04-16 03:12:58 +03:00
static void hpfs_free_inode ( struct inode * inode )
2005-04-17 02:20:36 +04:00
{
kmem_cache_free ( hpfs_inode_cachep , hpfs_i ( inode ) ) ;
}
2008-07-26 06:45:34 +04:00
static void init_once ( void * foo )
2005-04-17 02:20:36 +04:00
{
struct hpfs_inode_info * ei = ( struct hpfs_inode_info * ) foo ;
2007-05-17 09:10:57 +04:00
inode_init_once ( & ei - > vfs_inode ) ;
2005-04-17 02:20:36 +04:00
}
2007-07-20 05:11:58 +04:00
2005-04-17 02:20:36 +04:00
static int init_inodecache ( void )
{
hpfs_inode_cachep = kmem_cache_create ( " hpfs_inode_cache " ,
sizeof ( struct hpfs_inode_info ) ,
2006-03-24 14:16:06 +03:00
0 , ( SLAB_RECLAIM_ACCOUNT |
2016-01-15 02:18:21 +03:00
SLAB_MEM_SPREAD | SLAB_ACCOUNT ) ,
2007-07-20 05:11:58 +04:00
init_once ) ;
2005-04-17 02:20:36 +04:00
if ( hpfs_inode_cachep = = NULL )
return - ENOMEM ;
return 0 ;
}
static void destroy_inodecache ( void )
{
2012-09-26 05:33:07 +04:00
/*
* Make sure all delayed rcu free inodes are flushed before we
* destroy cache .
*/
rcu_barrier ( ) ;
2006-09-27 12:49:40 +04:00
kmem_cache_destroy ( hpfs_inode_cachep ) ;
2005-04-17 02:20:36 +04:00
}
/*
* A tiny parser for option strings , stolen from dosfs .
* Stolen again from read - only hpfs .
* And updated for table - driven option parsing .
*/
enum {
Opt_help , Opt_uid , Opt_gid , Opt_umask , Opt_case_lower , Opt_case_asis ,
Opt_check_none , Opt_check_normal , Opt_check_strict ,
Opt_err_cont , Opt_err_ro , Opt_err_panic ,
Opt_eas_no , Opt_eas_ro , Opt_eas_rw ,
Opt_chkdsk_no , Opt_chkdsk_errors , Opt_chkdsk_always ,
Opt_timeshift , Opt_err ,
} ;
2008-10-13 13:46:57 +04:00
static const match_table_t tokens = {
2005-04-17 02:20:36 +04:00
{ Opt_help , " help " } ,
{ Opt_uid , " uid=%u " } ,
{ Opt_gid , " gid=%u " } ,
{ Opt_umask , " umask=%o " } ,
{ Opt_case_lower , " case=lower " } ,
{ Opt_case_asis , " case=asis " } ,
{ Opt_check_none , " check=none " } ,
{ Opt_check_normal , " check=normal " } ,
{ Opt_check_strict , " check=strict " } ,
{ Opt_err_cont , " errors=continue " } ,
{ Opt_err_ro , " errors=remount-ro " } ,
{ Opt_err_panic , " errors=panic " } ,
{ Opt_eas_no , " eas=no " } ,
{ Opt_eas_ro , " eas=ro " } ,
{ Opt_eas_rw , " eas=rw " } ,
{ Opt_chkdsk_no , " chkdsk=no " } ,
{ Opt_chkdsk_errors , " chkdsk=errors " } ,
{ Opt_chkdsk_always , " chkdsk=always " } ,
{ Opt_timeshift , " timeshift=%d " } ,
{ Opt_err , NULL } ,
} ;
2012-02-08 04:27:53 +04:00
static int parse_opts ( char * opts , kuid_t * uid , kgid_t * gid , umode_t * umask ,
2011-05-08 22:43:19 +04:00
int * lowercase , int * eas , int * chk , int * errs ,
2005-04-17 02:20:36 +04:00
int * chkdsk , int * timeshift )
{
char * p ;
int option ;
if ( ! opts )
return 1 ;
2014-06-07 01:36:34 +04:00
/*pr_info("Parsing opts: '%s'\n",opts);*/
2005-04-17 02:20:36 +04:00
while ( ( p = strsep ( & opts , " , " ) ) ! = NULL ) {
substring_t args [ MAX_OPT_ARGS ] ;
int token ;
if ( ! * p )
continue ;
token = match_token ( p , tokens , args ) ;
switch ( token ) {
case Opt_help :
return 2 ;
case Opt_uid :
if ( match_int ( args , & option ) )
return 0 ;
2012-02-08 04:27:53 +04:00
* uid = make_kuid ( current_user_ns ( ) , option ) ;
if ( ! uid_valid ( * uid ) )
return 0 ;
2005-04-17 02:20:36 +04:00
break ;
case Opt_gid :
if ( match_int ( args , & option ) )
return 0 ;
2012-02-08 04:27:53 +04:00
* gid = make_kgid ( current_user_ns ( ) , option ) ;
if ( ! gid_valid ( * gid ) )
return 0 ;
2005-04-17 02:20:36 +04:00
break ;
case Opt_umask :
if ( match_octal ( args , & option ) )
return 0 ;
* umask = option ;
break ;
case Opt_case_lower :
* lowercase = 1 ;
break ;
case Opt_case_asis :
* lowercase = 0 ;
break ;
case Opt_check_none :
* chk = 0 ;
break ;
case Opt_check_normal :
* chk = 1 ;
break ;
case Opt_check_strict :
* chk = 2 ;
break ;
case Opt_err_cont :
* errs = 0 ;
break ;
case Opt_err_ro :
* errs = 1 ;
break ;
case Opt_err_panic :
* errs = 2 ;
break ;
case Opt_eas_no :
* eas = 0 ;
break ;
case Opt_eas_ro :
* eas = 1 ;
break ;
case Opt_eas_rw :
* eas = 2 ;
break ;
case Opt_chkdsk_no :
* chkdsk = 0 ;
break ;
case Opt_chkdsk_errors :
* chkdsk = 1 ;
break ;
case Opt_chkdsk_always :
* chkdsk = 2 ;
break ;
case Opt_timeshift :
{
int m = 1 ;
char * rhs = args [ 0 ] . from ;
if ( ! rhs | | ! * rhs )
return 0 ;
if ( * rhs = = ' - ' ) m = - 1 ;
if ( * rhs = = ' + ' | | * rhs = = ' - ' ) rhs + + ;
* timeshift = simple_strtoul ( rhs , & rhs , 0 ) * m ;
if ( * rhs )
return 0 ;
break ;
}
default :
return 0 ;
}
}
return 1 ;
}
static inline void hpfs_help ( void )
{
2014-06-07 01:36:34 +04:00
pr_info ( " \n \
2005-04-17 02:20:36 +04:00
HPFS filesystem options : \ n \
help do not mount and display this text \ n \
uid = xxx set uid of files that don ' t have uid specified in eas \ n \
gid = xxx set gid of files that don ' t have gid specified in eas \ n \
umask = xxx set mode of files that don ' t have mode specified in eas \ n \
case = lower lowercase all files \ n \
case = asis do not lowercase files ( default ) \ n \
check = none no fs checks - kernel may crash on corrupted filesystem \ n \
check = normal do some checks - it should not crash ( default ) \ n \
check = strict do extra time - consuming checks , used for debugging \ n \
errors = continue continue on errors \ n \
errors = remount - ro remount read - only if errors found ( default ) \ n \
errors = panic panic on errors \ n \
chkdsk = no do not mark fs for chkdsking even if there were errors \ n \
chkdsk = errors mark fs dirty if errors found ( default ) \ n \
chkdsk = always always mark fs dirty - used for debugging \ n \
eas = no ignore extended attributes \ n \
eas = ro read but do not write extended attributes \ n \
eas = rw r / w eas = > enables chmod , chown , mknod , ln - s ( default ) \ n \
timeshift = nnn add nnn seconds to file times \ n \
\ n " );
}
static int hpfs_remount_fs ( struct super_block * s , int * flags , char * data )
{
2012-02-08 04:27:53 +04:00
kuid_t uid ;
kgid_t gid ;
2005-04-17 02:20:36 +04:00
umode_t umask ;
2011-05-08 22:43:19 +04:00
int lowercase , eas , chk , errs , chkdsk , timeshift ;
2005-04-17 02:20:36 +04:00
int o ;
struct hpfs_sb_info * sbi = hpfs_sb ( s ) ;
2015-03-21 19:57:50 +03:00
2014-03-13 18:14:33 +04:00
sync_filesystem ( s ) ;
2017-11-28 00:05:09 +03:00
* flags | = SB_NOATIME ;
2015-03-21 19:57:50 +03:00
2011-01-22 22:26:12 +03:00
hpfs_lock ( s ) ;
2005-04-17 02:20:36 +04:00
uid = sbi - > sb_uid ; gid = sbi - > sb_gid ;
umask = 0777 & ~ sbi - > sb_mode ;
2011-05-08 22:43:19 +04:00
lowercase = sbi - > sb_lowercase ;
2005-04-17 02:20:36 +04:00
eas = sbi - > sb_eas ; chk = sbi - > sb_chk ; chkdsk = sbi - > sb_chkdsk ;
errs = sbi - > sb_err ; timeshift = sbi - > sb_timeshift ;
2011-05-08 22:43:19 +04:00
if ( ! ( o = parse_opts ( data , & uid , & gid , & umask , & lowercase ,
2005-04-17 02:20:36 +04:00
& eas , & chk , & errs , & chkdsk , & timeshift ) ) ) {
2014-06-07 01:36:36 +04:00
pr_err ( " bad mount options. \n " ) ;
2008-02-08 15:21:44 +03:00
goto out_err ;
2005-04-17 02:20:36 +04:00
}
if ( o = = 2 ) {
hpfs_help ( ) ;
2008-02-08 15:21:44 +03:00
goto out_err ;
2005-04-17 02:20:36 +04:00
}
if ( timeshift ! = sbi - > sb_timeshift ) {
2014-06-07 01:36:36 +04:00
pr_err ( " timeshift can't be changed using remount. \n " ) ;
2008-02-08 15:21:44 +03:00
goto out_err ;
2005-04-17 02:20:36 +04:00
}
unmark_dirty ( s ) ;
sbi - > sb_uid = uid ; sbi - > sb_gid = gid ;
sbi - > sb_mode = 0777 & ~ umask ;
2011-05-08 22:43:19 +04:00
sbi - > sb_lowercase = lowercase ;
2005-04-17 02:20:36 +04:00
sbi - > sb_eas = eas ; sbi - > sb_chk = chk ; sbi - > sb_chkdsk = chkdsk ;
sbi - > sb_err = errs ; sbi - > sb_timeshift = timeshift ;
2017-11-28 00:05:09 +03:00
if ( ! ( * flags & SB_RDONLY ) ) mark_dirty ( s , 1 ) ;
2005-04-17 02:20:36 +04:00
2011-01-22 22:26:12 +03:00
hpfs_unlock ( s ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
2008-02-08 15:21:44 +03:00
out_err :
2011-01-22 22:26:12 +03:00
hpfs_unlock ( s ) ;
2008-02-08 15:21:44 +03:00
return - EINVAL ;
2005-04-17 02:20:36 +04:00
}
2016-05-24 23:49:18 +03:00
static int hpfs_show_options ( struct seq_file * seq , struct dentry * root )
{
struct hpfs_sb_info * sbi = hpfs_sb ( root - > d_sb ) ;
seq_printf ( seq , " ,uid=%u " , from_kuid_munged ( & init_user_ns , sbi - > sb_uid ) ) ;
seq_printf ( seq , " ,gid=%u " , from_kgid_munged ( & init_user_ns , sbi - > sb_gid ) ) ;
seq_printf ( seq , " ,umask=%03o " , ( ~ sbi - > sb_mode & 0777 ) ) ;
if ( sbi - > sb_lowercase )
seq_printf ( seq , " ,case=lower " ) ;
if ( ! sbi - > sb_chk )
seq_printf ( seq , " ,check=none " ) ;
if ( sbi - > sb_chk = = 2 )
seq_printf ( seq , " ,check=strict " ) ;
if ( ! sbi - > sb_err )
seq_printf ( seq , " ,errors=continue " ) ;
if ( sbi - > sb_err = = 2 )
seq_printf ( seq , " ,errors=panic " ) ;
if ( ! sbi - > sb_chkdsk )
seq_printf ( seq , " ,chkdsk=no " ) ;
if ( sbi - > sb_chkdsk = = 2 )
seq_printf ( seq , " ,chkdsk=always " ) ;
if ( ! sbi - > sb_eas )
seq_printf ( seq , " ,eas=no " ) ;
if ( sbi - > sb_eas = = 1 )
seq_printf ( seq , " ,eas=ro " ) ;
if ( sbi - > sb_timeshift )
seq_printf ( seq , " ,timeshift=%d " , sbi - > sb_timeshift ) ;
return 0 ;
}
2005-04-17 02:20:36 +04:00
/* Super operations */
2007-02-12 11:55:41 +03:00
static const struct super_operations hpfs_sops =
2005-04-17 02:20:36 +04:00
{
. alloc_inode = hpfs_alloc_inode ,
2019-04-16 03:12:58 +03:00
. free_inode = hpfs_free_inode ,
2010-06-07 08:18:40 +04:00
. evict_inode = hpfs_evict_inode ,
2005-04-17 02:20:36 +04:00
. put_super = hpfs_put_super ,
. statfs = hpfs_statfs ,
. remount_fs = hpfs_remount_fs ,
2016-05-24 23:49:18 +03:00
. show_options = hpfs_show_options ,
2005-04-17 02:20:36 +04:00
} ;
static int hpfs_fill_super ( struct super_block * s , void * options , int silent )
{
struct buffer_head * bh0 , * bh1 , * bh2 ;
struct hpfs_boot_block * bootblock ;
struct hpfs_super_block * superblock ;
struct hpfs_spare_block * spareblock ;
struct hpfs_sb_info * sbi ;
struct inode * root ;
2012-02-08 04:27:53 +04:00
kuid_t uid ;
kgid_t gid ;
2005-04-17 02:20:36 +04:00
umode_t umask ;
2011-05-08 22:43:19 +04:00
int lowercase , eas , chk , errs , chkdsk , timeshift ;
2005-04-17 02:20:36 +04:00
dnode_secno root_dno ;
struct hpfs_dirent * de = NULL ;
struct quad_buffer_head qbh ;
int o ;
2006-09-27 12:49:37 +04:00
sbi = kzalloc ( sizeof ( * sbi ) , GFP_KERNEL ) ;
2010-08-16 00:51:10 +04:00
if ( ! sbi ) {
2005-04-17 02:20:36 +04:00
return - ENOMEM ;
2010-08-16 00:51:10 +04:00
}
2005-04-17 02:20:36 +04:00
s - > s_fs_info = sbi ;
2011-05-08 22:42:54 +04:00
mutex_init ( & sbi - > hpfs_mutex ) ;
hpfs_lock ( s ) ;
2008-11-14 02:38:55 +03:00
uid = current_uid ( ) ;
gid = current_gid ( ) ;
2009-03-30 03:08:22 +04:00
umask = current_umask ( ) ;
2005-04-17 02:20:36 +04:00
lowercase = 0 ;
eas = 2 ;
chk = 1 ;
errs = 1 ;
chkdsk = 1 ;
timeshift = 0 ;
2011-05-08 22:43:19 +04:00
if ( ! ( o = parse_opts ( options , & uid , & gid , & umask , & lowercase ,
2005-04-17 02:20:36 +04:00
& eas , & chk , & errs , & chkdsk , & timeshift ) ) ) {
2014-06-07 01:36:36 +04:00
pr_err ( " bad mount options. \n " ) ;
2005-04-17 02:20:36 +04:00
goto bail0 ;
}
if ( o = = 2 ) {
hpfs_help ( ) ;
goto bail0 ;
}
/*sbi->sb_mounting = 1;*/
sb_set_blocksize ( s , 512 ) ;
sbi - > sb_fs_size = - 1 ;
if ( ! ( bootblock = hpfs_map_sector ( s , 0 , & bh0 , 0 ) ) ) goto bail1 ;
if ( ! ( superblock = hpfs_map_sector ( s , 16 , & bh1 , 1 ) ) ) goto bail2 ;
if ( ! ( spareblock = hpfs_map_sector ( s , 17 , & bh2 , 0 ) ) ) goto bail3 ;
/* Check magics */
2011-05-08 22:44:26 +04:00
if ( /*le16_to_cpu(bootblock->magic) != BB_MAGIC
| | */ le32_to_cpu ( superblock - > magic ) ! = SB_MAGIC
| | le32_to_cpu ( spareblock - > magic ) ! = SP_MAGIC ) {
2014-06-07 01:36:34 +04:00
if ( ! silent )
2014-06-07 01:36:36 +04:00
pr_err ( " Bad magic ... probably not HPFS \n " ) ;
2005-04-17 02:20:36 +04:00
goto bail4 ;
}
/* Check version */
2017-07-17 10:45:34 +03:00
if ( ! sb_rdonly ( s ) & & superblock - > funcversion ! = 2 & & superblock - > funcversion ! = 3 ) {
2014-06-07 01:36:36 +04:00
pr_err ( " Bad version %d,%d. Mount readonly to go around \n " ,
2005-04-17 02:20:36 +04:00
( int ) superblock - > version , ( int ) superblock - > funcversion ) ;
2014-06-07 01:36:36 +04:00
pr_err ( " please try recent version of HPFS driver at http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi and if it still can't understand this format, contact author - mikulas@artax.karlin.mff.cuni.cz \n " ) ;
2005-04-17 02:20:36 +04:00
goto bail4 ;
}
2017-11-28 00:05:09 +03:00
s - > s_flags | = SB_NOATIME ;
2005-04-17 02:20:36 +04:00
/* Fill superblock stuff */
s - > s_magic = HPFS_SUPER_MAGIC ;
s - > s_op = & hpfs_sops ;
2011-01-13 00:12:05 +03:00
s - > s_d_op = & hpfs_dentry_operations ;
2005-04-17 02:20:36 +04:00
2011-05-08 22:44:26 +04:00
sbi - > sb_root = le32_to_cpu ( superblock - > root ) ;
sbi - > sb_fs_size = le32_to_cpu ( superblock - > n_sectors ) ;
sbi - > sb_bitmaps = le32_to_cpu ( superblock - > bitmaps ) ;
sbi - > sb_dirband_start = le32_to_cpu ( superblock - > dir_band_start ) ;
sbi - > sb_dirband_size = le32_to_cpu ( superblock - > n_dir_band ) ;
sbi - > sb_dmap = le32_to_cpu ( superblock - > dir_band_bitmap ) ;
2005-04-17 02:20:36 +04:00
sbi - > sb_uid = uid ;
sbi - > sb_gid = gid ;
sbi - > sb_mode = 0777 & ~ umask ;
sbi - > sb_n_free = - 1 ;
sbi - > sb_n_free_dnodes = - 1 ;
sbi - > sb_lowercase = lowercase ;
sbi - > sb_eas = eas ;
sbi - > sb_chk = chk ;
sbi - > sb_chkdsk = chkdsk ;
sbi - > sb_err = errs ;
sbi - > sb_timeshift = timeshift ;
sbi - > sb_was_error = 0 ;
sbi - > sb_cp_table = NULL ;
sbi - > sb_c_bitmap = - 1 ;
sbi - > sb_max_fwd_alloc = 0xffffff ;
2013-07-04 20:42:29 +04:00
if ( sbi - > sb_fs_size > = 0x80000000 ) {
hpfs_error ( s , " invalid size in superblock: %08x " ,
( unsigned ) sbi - > sb_fs_size ) ;
goto bail4 ;
}
2015-09-02 23:50:12 +03:00
if ( spareblock - > n_spares_used )
hpfs_load_hotfix_map ( s , spareblock ) ;
2005-04-17 02:20:36 +04:00
/* Load bitmap directory */
2011-05-08 22:44:26 +04:00
if ( ! ( sbi - > sb_bmp_dir = hpfs_load_bitmap_directory ( s , le32_to_cpu ( superblock - > bitmaps ) ) ) )
2005-04-17 02:20:36 +04:00
goto bail4 ;
/* Check for general fs errors*/
if ( spareblock - > dirty & & ! spareblock - > old_wrote ) {
if ( errs = = 2 ) {
2014-06-07 01:36:36 +04:00
pr_err ( " Improperly stopped, not mounted \n " ) ;
2005-04-17 02:20:36 +04:00
goto bail4 ;
}
hpfs_error ( s , " improperly stopped " ) ;
}
2017-07-17 10:45:34 +03:00
if ( ! sb_rdonly ( s ) ) {
2005-04-17 02:20:36 +04:00
spareblock - > dirty = 1 ;
spareblock - > old_wrote = 0 ;
mark_buffer_dirty ( bh2 ) ;
}
2011-05-08 22:44:26 +04:00
if ( le32_to_cpu ( spareblock - > n_dnode_spares ) ! = le32_to_cpu ( spareblock - > n_dnode_spares_free ) ) {
2005-04-17 02:20:36 +04:00
if ( errs > = 2 ) {
2014-06-07 01:36:36 +04:00
pr_err ( " Spare dnodes used, try chkdsk \n " ) ;
2011-05-08 22:44:08 +04:00
mark_dirty ( s , 0 ) ;
2005-04-17 02:20:36 +04:00
goto bail4 ;
}
hpfs_error ( s , " warning: spare dnodes used, try chkdsk " ) ;
2014-06-07 01:36:34 +04:00
if ( errs = = 0 )
2014-06-07 01:36:36 +04:00
pr_err ( " Proceeding, but your filesystem could be corrupted if you delete files or directories \n " ) ;
2005-04-17 02:20:36 +04:00
}
if ( chk ) {
unsigned a ;
2011-05-08 22:44:26 +04:00
if ( le32_to_cpu ( superblock - > dir_band_end ) - le32_to_cpu ( superblock - > dir_band_start ) + 1 ! = le32_to_cpu ( superblock - > n_dir_band ) | |
le32_to_cpu ( superblock - > dir_band_end ) < le32_to_cpu ( superblock - > dir_band_start ) | | le32_to_cpu ( superblock - > n_dir_band ) > 0x4000 ) {
2005-04-17 02:20:36 +04:00
hpfs_error ( s , " dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x " ,
2011-05-08 22:44:26 +04:00
le32_to_cpu ( superblock - > dir_band_start ) , le32_to_cpu ( superblock - > dir_band_end ) , le32_to_cpu ( superblock - > n_dir_band ) ) ;
2005-04-17 02:20:36 +04:00
goto bail4 ;
}
a = sbi - > sb_dirband_size ;
sbi - > sb_dirband_size = 0 ;
2011-05-08 22:44:26 +04:00
if ( hpfs_chk_sectors ( s , le32_to_cpu ( superblock - > dir_band_start ) , le32_to_cpu ( superblock - > n_dir_band ) , " dir_band " ) | |
hpfs_chk_sectors ( s , le32_to_cpu ( superblock - > dir_band_bitmap ) , 4 , " dir_band_bitmap " ) | |
hpfs_chk_sectors ( s , le32_to_cpu ( superblock - > bitmaps ) , 4 , " bitmaps " ) ) {
2011-05-08 22:44:08 +04:00
mark_dirty ( s , 0 ) ;
2005-04-17 02:20:36 +04:00
goto bail4 ;
}
sbi - > sb_dirband_size = a ;
2014-06-07 01:36:34 +04:00
} else
2014-06-07 01:36:36 +04:00
pr_err ( " You really don't want any checks? You are crazy... \n " ) ;
2005-04-17 02:20:36 +04:00
/* Load code page table */
2011-05-08 22:44:26 +04:00
if ( le32_to_cpu ( spareblock - > n_code_pages ) )
if ( ! ( sbi - > sb_cp_table = hpfs_load_code_page ( s , le32_to_cpu ( spareblock - > code_page_dir ) ) ) )
2014-06-07 01:36:36 +04:00
pr_err ( " code page support is disabled \n " ) ;
2005-04-17 02:20:36 +04:00
brelse ( bh2 ) ;
brelse ( bh1 ) ;
brelse ( bh0 ) ;
root = iget_locked ( s , sbi - > sb_root ) ;
if ( ! root )
goto bail0 ;
hpfs_init_inode ( root ) ;
hpfs_read_inode ( root ) ;
unlock_new_inode ( root ) ;
2012-01-09 07:15:13 +04:00
s - > s_root = d_make_root ( root ) ;
if ( ! s - > s_root )
2005-04-17 02:20:36 +04:00
goto bail0 ;
/*
* find the root directory ' s . pointer & finish filling in the inode
*/
root_dno = hpfs_fnode_dno ( s , sbi - > sb_root ) ;
if ( root_dno )
de = map_dirent ( root , root_dno , " \001 \001 " , 2 , NULL , & qbh ) ;
if ( ! de )
hpfs_error ( s , " unable to find root dir " ) ;
else {
2011-05-08 22:44:26 +04:00
root - > i_atime . tv_sec = local_to_gmt ( s , le32_to_cpu ( de - > read_date ) ) ;
2005-04-17 02:20:36 +04:00
root - > i_atime . tv_nsec = 0 ;
2011-05-08 22:44:26 +04:00
root - > i_mtime . tv_sec = local_to_gmt ( s , le32_to_cpu ( de - > write_date ) ) ;
2005-04-17 02:20:36 +04:00
root - > i_mtime . tv_nsec = 0 ;
2011-05-08 22:44:26 +04:00
root - > i_ctime . tv_sec = local_to_gmt ( s , le32_to_cpu ( de - > creation_date ) ) ;
2005-04-17 02:20:36 +04:00
root - > i_ctime . tv_nsec = 0 ;
2012-04-13 09:24:37 +04:00
hpfs_i ( root ) - > i_ea_size = le32_to_cpu ( de - > ea_size ) ;
2005-04-17 02:20:36 +04:00
hpfs_i ( root ) - > i_parent_dir = root - > i_ino ;
if ( root - > i_size = = - 1 )
root - > i_size = 2048 ;
if ( root - > i_blocks = = - 1 )
root - > i_blocks = 5 ;
hpfs_brelse4 ( & qbh ) ;
}
2011-05-08 22:42:54 +04:00
hpfs_unlock ( s ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
bail4 : brelse ( bh2 ) ;
bail3 : brelse ( bh1 ) ;
bail2 : brelse ( bh0 ) ;
bail1 :
bail0 :
2011-05-08 22:42:54 +04:00
hpfs_unlock ( s ) ;
2013-10-03 20:25:10 +04:00
free_sbi ( sbi ) ;
2005-04-17 02:20:36 +04:00
return - EINVAL ;
}
2010-07-25 00:46:55 +04:00
static struct dentry * hpfs_mount ( struct file_system_type * fs_type ,
int flags , const char * dev_name , void * data )
2005-04-17 02:20:36 +04:00
{
2010-07-25 00:46:55 +04:00
return mount_bdev ( fs_type , flags , dev_name , data , hpfs_fill_super ) ;
2005-04-17 02:20:36 +04:00
}
static struct file_system_type hpfs_fs_type = {
. owner = THIS_MODULE ,
. name = " hpfs " ,
2010-07-25 00:46:55 +04:00
. mount = hpfs_mount ,
2005-04-17 02:20:36 +04:00
. kill_sb = kill_block_super ,
. fs_flags = FS_REQUIRES_DEV ,
} ;
2013-03-11 18:05:42 +04:00
MODULE_ALIAS_FS ( " hpfs " ) ;
2005-04-17 02:20:36 +04:00
static int __init init_hpfs_fs ( void )
{
int err = init_inodecache ( ) ;
if ( err )
goto out1 ;
err = register_filesystem ( & hpfs_fs_type ) ;
if ( err )
goto out ;
return 0 ;
out :
destroy_inodecache ( ) ;
out1 :
return err ;
}
static void __exit exit_hpfs_fs ( void )
{
unregister_filesystem ( & hpfs_fs_type ) ;
destroy_inodecache ( ) ;
}
module_init ( init_hpfs_fs )
module_exit ( exit_hpfs_fs )
MODULE_LICENSE ( " GPL " ) ;