@@ -1900,46 +1900,6 @@ enum REPARSE_SIGN ni_parse_reparse(struct ntfs_inode *ni, struct ATTRIB *attr,
1900
1900
return REPARSE_LINK ;
1901
1901
}
1902
1902
1903
- /*
1904
- * fiemap_fill_next_extent_k - a copy of fiemap_fill_next_extent
1905
- * but it uses 'fe_k' instead of fieinfo->fi_extents_start
1906
- */
1907
- static int fiemap_fill_next_extent_k (struct fiemap_extent_info * fieinfo ,
1908
- struct fiemap_extent * fe_k , u64 logical ,
1909
- u64 phys , u64 len , u32 flags )
1910
- {
1911
- struct fiemap_extent extent ;
1912
-
1913
- /* only count the extents */
1914
- if (fieinfo -> fi_extents_max == 0 ) {
1915
- fieinfo -> fi_extents_mapped ++ ;
1916
- return (flags & FIEMAP_EXTENT_LAST ) ? 1 : 0 ;
1917
- }
1918
-
1919
- if (fieinfo -> fi_extents_mapped >= fieinfo -> fi_extents_max )
1920
- return 1 ;
1921
-
1922
- if (flags & FIEMAP_EXTENT_DELALLOC )
1923
- flags |= FIEMAP_EXTENT_UNKNOWN ;
1924
- if (flags & FIEMAP_EXTENT_DATA_ENCRYPTED )
1925
- flags |= FIEMAP_EXTENT_ENCODED ;
1926
- if (flags & (FIEMAP_EXTENT_DATA_TAIL | FIEMAP_EXTENT_DATA_INLINE ))
1927
- flags |= FIEMAP_EXTENT_NOT_ALIGNED ;
1928
-
1929
- memset (& extent , 0 , sizeof (extent ));
1930
- extent .fe_logical = logical ;
1931
- extent .fe_physical = phys ;
1932
- extent .fe_length = len ;
1933
- extent .fe_flags = flags ;
1934
-
1935
- memcpy (fe_k + fieinfo -> fi_extents_mapped , & extent , sizeof (extent ));
1936
-
1937
- fieinfo -> fi_extents_mapped ++ ;
1938
- if (fieinfo -> fi_extents_mapped == fieinfo -> fi_extents_max )
1939
- return 1 ;
1940
- return (flags & FIEMAP_EXTENT_LAST ) ? 1 : 0 ;
1941
- }
1942
-
1943
1903
/*
1944
1904
* ni_fiemap - Helper for file_fiemap().
1945
1905
*
@@ -1950,11 +1910,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
1950
1910
__u64 vbo , __u64 len )
1951
1911
{
1952
1912
int err = 0 ;
1953
- struct fiemap_extent * fe_k = NULL ;
1954
1913
struct ntfs_sb_info * sbi = ni -> mi .sbi ;
1955
1914
u8 cluster_bits = sbi -> cluster_bits ;
1956
- struct runs_tree * run ;
1957
- struct rw_semaphore * run_lock ;
1915
+ struct runs_tree run ;
1958
1916
struct ATTRIB * attr ;
1959
1917
CLST vcn = vbo >> cluster_bits ;
1960
1918
CLST lcn , clen ;
@@ -1965,13 +1923,11 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
1965
1923
u32 flags ;
1966
1924
bool ok ;
1967
1925
1926
+ run_init (& run );
1968
1927
if (S_ISDIR (ni -> vfs_inode .i_mode )) {
1969
- run = & ni -> dir .alloc_run ;
1970
1928
attr = ni_find_attr (ni , NULL , NULL , ATTR_ALLOC , I30_NAME ,
1971
1929
ARRAY_SIZE (I30_NAME ), NULL , NULL );
1972
- run_lock = & ni -> dir .run_lock ;
1973
1930
} else {
1974
- run = & ni -> file .run ;
1975
1931
attr = ni_find_attr (ni , NULL , NULL , ATTR_DATA , NULL , 0 , NULL ,
1976
1932
NULL );
1977
1933
if (!attr ) {
@@ -1986,7 +1942,6 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
1986
1942
"fiemap is not supported for compressed file (cp -r)" );
1987
1943
goto out ;
1988
1944
}
1989
- run_lock = & ni -> file .run_lock ;
1990
1945
}
1991
1946
1992
1947
if (!attr || !attr -> non_res ) {
@@ -1998,51 +1953,33 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
1998
1953
goto out ;
1999
1954
}
2000
1955
2001
- /*
2002
- * To avoid lock problems replace pointer to user memory by pointer to kernel memory.
2003
- */
2004
- fe_k = kmalloc_array (fieinfo -> fi_extents_max ,
2005
- sizeof (struct fiemap_extent ),
2006
- GFP_NOFS | __GFP_ZERO );
2007
- if (!fe_k ) {
2008
- err = - ENOMEM ;
2009
- goto out ;
2010
- }
2011
-
2012
1956
end = vbo + len ;
2013
1957
alloc_size = le64_to_cpu (attr -> nres .alloc_size );
2014
1958
if (end > alloc_size )
2015
1959
end = alloc_size ;
2016
1960
2017
- down_read (run_lock );
2018
1961
2019
1962
while (vbo < end ) {
2020
1963
if (idx == -1 ) {
2021
- ok = run_lookup_entry (run , vcn , & lcn , & clen , & idx );
1964
+ ok = run_lookup_entry (& run , vcn , & lcn , & clen , & idx );
2022
1965
} else {
2023
1966
CLST vcn_next = vcn ;
2024
1967
2025
- ok = run_get_entry (run , ++ idx , & vcn , & lcn , & clen ) &&
1968
+ ok = run_get_entry (& run , ++ idx , & vcn , & lcn , & clen ) &&
2026
1969
vcn == vcn_next ;
2027
1970
if (!ok )
2028
1971
vcn = vcn_next ;
2029
1972
}
2030
1973
2031
1974
if (!ok ) {
2032
- up_read (run_lock );
2033
- down_write (run_lock );
2034
-
2035
1975
err = attr_load_runs_vcn (ni , attr -> type ,
2036
1976
attr_name (attr ),
2037
- attr -> name_len , run , vcn );
2038
-
2039
- up_write (run_lock );
2040
- down_read (run_lock );
1977
+ attr -> name_len , & run , vcn );
2041
1978
2042
1979
if (err )
2043
1980
break ;
2044
1981
2045
- ok = run_lookup_entry (run , vcn , & lcn , & clen , & idx );
1982
+ ok = run_lookup_entry (& run , vcn , & lcn , & clen , & idx );
2046
1983
2047
1984
if (!ok ) {
2048
1985
err = - EINVAL ;
@@ -2067,8 +2004,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
2067
2004
} else if (is_attr_compressed (attr )) {
2068
2005
CLST clst_data ;
2069
2006
2070
- err = attr_is_frame_compressed (
2071
- ni , attr , vcn >> attr -> nres .c_unit , & clst_data );
2007
+ err = attr_is_frame_compressed (ni , attr ,
2008
+ vcn >> attr -> nres .c_unit ,
2009
+ & clst_data , & run );
2072
2010
if (err )
2073
2011
break ;
2074
2012
if (clst_data < NTFS_LZNT_CLUSTERS )
@@ -2097,8 +2035,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
2097
2035
if (vbo + dlen >= end )
2098
2036
flags |= FIEMAP_EXTENT_LAST ;
2099
2037
2100
- err = fiemap_fill_next_extent_k (fieinfo , fe_k , vbo , lbo ,
2101
- dlen , flags );
2038
+ err = fiemap_fill_next_extent (fieinfo , vbo , lbo , dlen ,
2039
+ flags );
2102
2040
2103
2041
if (err < 0 )
2104
2042
break ;
@@ -2119,8 +2057,7 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
2119
2057
if (vbo + bytes >= end )
2120
2058
flags |= FIEMAP_EXTENT_LAST ;
2121
2059
2122
- err = fiemap_fill_next_extent_k (fieinfo , fe_k , vbo , lbo , bytes ,
2123
- flags );
2060
+ err = fiemap_fill_next_extent (fieinfo , vbo , lbo , bytes , flags );
2124
2061
if (err < 0 )
2125
2062
break ;
2126
2063
if (err == 1 ) {
@@ -2131,19 +2068,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
2131
2068
vbo += bytes ;
2132
2069
}
2133
2070
2134
- up_read (run_lock );
2135
-
2136
- /*
2137
- * Copy to user memory out of lock
2138
- */
2139
- if (copy_to_user (fieinfo -> fi_extents_start , fe_k ,
2140
- fieinfo -> fi_extents_max *
2141
- sizeof (struct fiemap_extent ))) {
2142
- err = - EFAULT ;
2143
- }
2144
-
2145
2071
out :
2146
- kfree ( fe_k );
2072
+ run_close ( & run );
2147
2073
return err ;
2148
2074
}
2149
2075
@@ -2672,7 +2598,8 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
2672
2598
down_write (& ni -> file .run_lock );
2673
2599
run_truncate_around (run , le64_to_cpu (attr -> nres .svcn ));
2674
2600
frame = frame_vbo >> (cluster_bits + NTFS_LZNT_CUNIT );
2675
- err = attr_is_frame_compressed (ni , attr , frame , & clst_data );
2601
+ err = attr_is_frame_compressed (ni , attr , frame , & clst_data ,
2602
+ run );
2676
2603
up_write (& ni -> file .run_lock );
2677
2604
if (err )
2678
2605
goto out1 ;
0 commit comments