Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
bc93ea47
Commit
bc93ea47
authored
May 13, 2002
by
Richard Gooch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed race when devfs lookup()/readdir() triggers partition rescanning.
parent
d7760f3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
19 deletions
+52
-19
Documentation/filesystems/devfs/ChangeLog
Documentation/filesystems/devfs/ChangeLog
+5
-0
fs/devfs/base.c
fs/devfs/base.c
+47
-19
No files found.
Documentation/filesystems/devfs/ChangeLog
View file @
bc93ea47
...
...
@@ -1926,3 +1926,8 @@ Changes for patch v211
Changes for patch v212
- Added BKL to <devfs_open> because drivers still need it
===============================================================================
Changes for patch v213
- Protected <scan_dir_for_removable> and <get_removable_partition>
from changing directory contents
fs/devfs/base.c
View file @
bc93ea47
...
...
@@ -626,6 +626,10 @@
20020510 Richard Gooch <rgooch@atnf.csiro.au>
Added BKL to <devfs_open> because drivers still need it.
v1.15
20020512 Richard Gooch <rgooch@atnf.csiro.au>
Protected <scan_dir_for_removable> and <get_removable_partition>
from changing directory contents.
v1.16
*/
#include <linux/types.h>
#include <linux/errno.h>
...
...
@@ -658,7 +662,7 @@
#include <asm/bitops.h>
#include <asm/atomic.h>
#define DEVFS_VERSION "1.1
5 (20020510
)"
#define DEVFS_VERSION "1.1
6 (20020512
)"
#define DEVFS_NAME "devfs"
...
...
@@ -2415,6 +2419,9 @@ static int try_modload (struct devfs_entry *parent, struct fs_info *fs_info,
* @de: The device.
*
* Returns 1 if the media was changed, else 0.
*
* This function may block, and may indirectly cause the parent directory
* contents to be changed due to partition re-reading.
*/
static
int
check_disc_changed
(
struct
devfs_entry
*
de
)
...
...
@@ -2449,6 +2456,10 @@ static int check_disc_changed (struct devfs_entry *de)
/**
* scan_dir_for_removable - Scan a directory for removable media devices and check media.
* @dir: The directory.
*
* This function may block, and may indirectly cause the directory
* contents to be changed due to partition re-reading. The directory will
* be locked for reading.
*/
static
void
scan_dir_for_removable
(
struct
devfs_entry
*
dir
)
...
...
@@ -2456,12 +2467,15 @@ static void scan_dir_for_removable (struct devfs_entry *dir)
struct
devfs_entry
*
de
;
if
(
dir
->
u
.
dir
.
num_removable
<
1
)
return
;
read_lock
(
&
dir
->
u
.
dir
.
lock
);
for
(
de
=
dir
->
u
.
dir
.
first
;
de
!=
NULL
;
de
=
de
->
next
)
{
if
(
!
S_ISBLK
(
de
->
mode
)
)
continue
;
if
(
!
de
->
u
.
fcb
.
removable
)
continue
;
check_disc_changed
(
de
);
if
(
S_ISBLK
(
de
->
mode
)
&&
de
->
u
.
fcb
.
removable
)
break
;
}
devfs_get
(
de
);
read_unlock
(
&
dir
->
u
.
dir
.
lock
);
if
(
de
)
check_disc_changed
(
de
);
devfs_put
(
de
);
}
/* End Function scan_dir_for_removable */
/**
...
...
@@ -2471,25 +2485,37 @@ static void scan_dir_for_removable (struct devfs_entry *dir)
* @namelen: The number of characters in <<name>>.
*
* Returns 1 if the media was changed, else 0.
*
* This function may block, and may indirectly cause the directory
* contents to be changed due to partition re-reading. The directory must
* be locked for reading upon entry, and will be unlocked upon exit.
*/
static
int
get_removable_partition
(
struct
devfs_entry
*
dir
,
const
char
*
name
,
unsigned
int
namelen
)
{
int
retval
;
struct
devfs_entry
*
de
;
if
(
dir
->
u
.
dir
.
num_removable
<
1
)
{
read_unlock
(
&
dir
->
u
.
dir
.
lock
);
return
0
;
}
for
(
de
=
dir
->
u
.
dir
.
first
;
de
!=
NULL
;
de
=
de
->
next
)
{
if
(
!
S_ISBLK
(
de
->
mode
)
)
continue
;
if
(
!
de
->
u
.
fcb
.
removable
)
continue
;
if
(
strcmp
(
de
->
name
,
"disc"
)
==
0
)
return
check_disc_changed
(
de
);
if
(
!
S_ISBLK
(
de
->
mode
)
||
!
de
->
u
.
fcb
.
removable
)
continue
;
if
(
strcmp
(
de
->
name
,
"disc"
)
==
0
)
break
;
/* Support for names where the partition is appended to the disc name
*/
if
(
de
->
namelen
>=
namelen
)
continue
;
if
(
strncmp
(
de
->
name
,
name
,
de
->
namelen
)
!=
0
)
continue
;
return
check_disc_changed
(
de
);
if
(
strncmp
(
de
->
name
,
name
,
de
->
namelen
)
==
0
)
break
;
}
return
0
;
devfs_get
(
de
);
read_unlock
(
&
dir
->
u
.
dir
.
lock
);
retval
=
de
?
check_disc_changed
(
de
)
:
0
;
devfs_put
(
de
);
return
retval
;
}
/* End Function get_removable_partition */
...
...
@@ -2942,15 +2968,17 @@ static struct dentry *devfs_lookup (struct inode *dir, struct dentry *dentry)
if
(
parent
==
NULL
)
return
ERR_PTR
(
-
ENOENT
);
read_lock
(
&
parent
->
u
.
dir
.
lock
);
de
=
_devfs_search_dir
(
parent
,
dentry
->
d_name
.
name
,
dentry
->
d_name
.
len
);
read_unlock
(
&
parent
->
u
.
dir
.
lock
);
if
(
(
de
==
NULL
)
&&
(
parent
->
u
.
dir
.
num_removable
>
0
)
&&
get_removable_partition
(
parent
,
dentry
->
d_name
.
name
,
dentry
->
d_name
.
len
)
)
{
read_lock
(
&
parent
->
u
.
dir
.
lock
);
de
=
_devfs_search_dir
(
parent
,
dentry
->
d_name
.
name
,
dentry
->
d_name
.
len
);
read_unlock
(
&
parent
->
u
.
dir
.
lock
);
if
(
de
)
read_unlock
(
&
parent
->
u
.
dir
.
lock
);
else
{
/* Try re-reading the partition (media may have changed) */
if
(
get_removable_partition
(
parent
,
dentry
->
d_name
.
name
,
dentry
->
d_name
.
len
)
)
/* Unlocks */
{
/* Media did change */
read_lock
(
&
parent
->
u
.
dir
.
lock
);
de
=
_devfs_search_dir
(
parent
,
dentry
->
d_name
.
name
,
dentry
->
d_name
.
len
);
read_unlock
(
&
parent
->
u
.
dir
.
lock
);
}
}
lookup_info
.
de
=
de
;
init_waitqueue_head
(
&
lookup_info
.
wait_queue
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment