Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 207565
b: refs/heads/master
c: f8ad850
h: refs/heads/master
i:
  207563: 38d189f
v: v3
  • Loading branch information
Al Viro committed Aug 9, 2010
1 parent 1b8d9a9 commit a25f2e6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f8d7e1877e5121841bc9a4d284a04dbc13f45bea
refs/heads/master: f8ad850f11e11d10e7de1a16ca53cb193afc9313
1 change: 1 addition & 0 deletions trunk/fs/hostfs/hostfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern void *open_dir(char *path, int *err_out);
extern char *read_dir(void *stream, unsigned long long *pos,
unsigned long long *ino_out, int *len_out);
extern void close_file(void *stream);
extern int replace_file(int oldfd, int fd);
extern void close_dir(void *stream);
extern int read_file(int fd, unsigned long long *offset, char *buf, int len);
extern int write_file(int fd, unsigned long long *offset, const char *buf,
Expand Down
43 changes: 31 additions & 12 deletions trunk/fs/hostfs/hostfs_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,27 +302,22 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)

int hostfs_file_open(struct inode *ino, struct file *file)
{
static DEFINE_MUTEX(open_mutex);
char *name;
fmode_t mode = 0;
int err;
int r = 0, w = 0, fd;

mode = file->f_mode & (FMODE_READ | FMODE_WRITE);
if ((mode & HOSTFS_I(ino)->mode) == mode)
return 0;

/*
* The file may already have been opened, but with the wrong access,
* so this resets things and reopens the file with the new access.
*/
if (HOSTFS_I(ino)->fd != -1) {
close_file(&HOSTFS_I(ino)->fd);
HOSTFS_I(ino)->fd = -1;
}
mode |= HOSTFS_I(ino)->mode;

HOSTFS_I(ino)->mode |= mode;
if (HOSTFS_I(ino)->mode & FMODE_READ)
retry:
if (mode & FMODE_READ)
r = 1;
if (HOSTFS_I(ino)->mode & FMODE_WRITE)
if (mode & FMODE_WRITE)
w = 1;
if (w)
r = 1;
Expand All @@ -335,7 +330,31 @@ int hostfs_file_open(struct inode *ino, struct file *file)
__putname(name);
if (fd < 0)
return fd;
FILE_HOSTFS_I(file)->fd = fd;

mutex_lock(&open_mutex);
/* somebody else had handled it first? */
if ((mode & HOSTFS_I(ino)->mode) == mode) {
mutex_unlock(&open_mutex);
return 0;
}
if ((mode | HOSTFS_I(ino)->mode) != mode) {
mode |= HOSTFS_I(ino)->mode;
mutex_unlock(&open_mutex);
close_file(&fd);
goto retry;
}
if (HOSTFS_I(ino)->fd == -1) {
HOSTFS_I(ino)->fd = fd;
} else {
err = replace_file(fd, HOSTFS_I(ino)->fd);
close_file(&fd);
if (err < 0) {
mutex_unlock(&open_mutex);
return err;
}
}
HOSTFS_I(ino)->mode = mode;
mutex_unlock(&open_mutex);

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions trunk/fs/hostfs/hostfs_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ int fsync_file(int fd, int datasync)
return 0;
}

int replace_file(int oldfd, int fd)
{
return dup2(oldfd, fd);
}

void close_file(void *stream)
{
close(*((int *) stream));
Expand Down

0 comments on commit a25f2e6

Please sign in to comment.