2006-10-25 15:40:36 +02:00
|
|
|
/* This file contains the code for performing four system calls relating to
|
|
|
|
* status and directories.
|
|
|
|
*
|
|
|
|
* The entry points into this file are
|
|
|
|
* do_chdir: perform the CHDIR system call
|
|
|
|
* do_chroot: perform the CHROOT system call
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
* do_lstat: perform the LSTAT system call
|
2006-10-25 15:40:36 +02:00
|
|
|
* do_stat: perform the STAT system call
|
|
|
|
* do_fstat: perform the FSTAT system call
|
2013-08-20 01:28:23 +02:00
|
|
|
* do_statvfs: perform the STATVFS1 system call
|
|
|
|
* do_fstatvfs: perform the FSTATVFS1 system call
|
2013-08-20 01:39:47 +02:00
|
|
|
* do_getvfsstat: perform the GETVFSSTAT system call
|
2006-10-25 15:40:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <minix/com.h>
|
2006-11-27 15:21:43 +01:00
|
|
|
#include <minix/u64.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include "file.h"
|
2012-02-13 16:28:04 +01:00
|
|
|
#include "path.h"
|
2006-10-25 15:40:36 +02:00
|
|
|
#include <minix/vfsif.h>
|
2011-07-01 21:35:54 +02:00
|
|
|
#include <minix/callnr.h>
|
2006-10-25 15:40:36 +02:00
|
|
|
#include "vnode.h"
|
|
|
|
#include "vmnt.h"
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int change_into(struct vnode **iip, struct vnode *vp);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_fchdir *
|
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_fchdir(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
/* Change directory on already-opened fd. */
|
|
|
|
struct filp *rfilp;
|
2012-04-13 14:50:38 +02:00
|
|
|
int r, rfd;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
rfd = job_m_in.VFS_FCHDIR_FD;
|
2009-04-29 18:59:18 +02:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/* Is the file descriptor valid? */
|
2012-04-13 14:50:38 +02:00
|
|
|
if ((rfilp = get_filp(rfd, VNODE_READ)) == NULL) return(err_code);
|
2012-02-13 16:28:04 +01:00
|
|
|
r = change_into(&fp->fp_wd, rfilp->filp_vno);
|
|
|
|
unlock_filp(rfilp);
|
|
|
|
return(r);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_chdir *
|
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_chdir(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
2012-04-13 14:50:38 +02:00
|
|
|
/* Perform the chdir(name) system call.
|
|
|
|
* syscall might provide 'name' embedded in the message.
|
|
|
|
*/
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
int r;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vmnt *vmp;
|
|
|
|
char fullpath[PATH_MAX];
|
|
|
|
struct lookup resolve;
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
if (copy_path(fullpath, sizeof(fullpath)) != OK)
|
|
|
|
return(err_code);
|
2012-04-13 14:50:38 +02:00
|
|
|
|
|
|
|
/* Try to open the directory */
|
|
|
|
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
|
|
|
|
resolve.l_vmnt_lock = VMNT_READ;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
|
|
|
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
|
|
|
|
|
|
|
|
r = change_into(&fp->fp_wd, vp);
|
|
|
|
|
|
|
|
unlock_vnode(vp);
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
put_vnode(vp);
|
|
|
|
|
|
|
|
return(r);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2012-04-13 14:50:38 +02:00
|
|
|
* do_chroot *
|
2006-10-25 15:40:36 +02:00
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_chroot(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
2012-04-13 14:50:38 +02:00
|
|
|
/* Perform the chroot(name) system call.
|
|
|
|
* syscall might provide 'name' embedded in the message.
|
|
|
|
*/
|
|
|
|
int r;
|
2007-01-05 17:36:55 +01:00
|
|
|
struct vnode *vp;
|
2012-02-13 16:28:04 +01:00
|
|
|
struct vmnt *vmp;
|
|
|
|
char fullpath[PATH_MAX];
|
|
|
|
struct lookup resolve;
|
2012-04-13 14:50:38 +02:00
|
|
|
|
|
|
|
if (!super_user) return(EPERM); /* only su may chroot() */
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
if (copy_path(fullpath, sizeof(fullpath)) != OK)
|
|
|
|
return(err_code);
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
/* Try to open the directory */
|
2012-02-13 16:28:04 +01:00
|
|
|
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
|
|
|
|
resolve.l_vmnt_lock = VMNT_READ;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
|
|
|
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
|
2012-04-13 14:50:38 +02:00
|
|
|
|
|
|
|
r = change_into(&fp->fp_rd, vp);
|
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
unlock_vnode(vp);
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
put_vnode(vp);
|
2012-04-13 14:50:38 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
return(r);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* change_into *
|
|
|
|
*===========================================================================*/
|
2012-04-13 14:50:38 +02:00
|
|
|
static int change_into(struct vnode **result, struct vnode *vp)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
int r;
|
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
if (*result == vp) return(OK); /* Nothing to do */
|
2012-02-13 16:28:04 +01:00
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
/* It must be a directory and also be searchable */
|
2012-04-25 14:44:42 +02:00
|
|
|
if (!S_ISDIR(vp->v_mode))
|
2012-02-13 16:28:04 +01:00
|
|
|
r = ENOTDIR;
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
else
|
2012-01-27 17:06:43 +01:00
|
|
|
r = forbidden(fp, vp, X_BIT); /* Check if dir is searchable*/
|
2012-02-13 16:28:04 +01:00
|
|
|
if (r != OK) return(r);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/* Everything is OK. Make the change. */
|
2012-04-13 14:50:38 +02:00
|
|
|
put_vnode(*result); /* release the old directory */
|
2012-02-13 16:28:04 +01:00
|
|
|
dup_vnode(vp);
|
2012-04-13 14:50:38 +02:00
|
|
|
*result = vp; /* acquire the new one */
|
2006-10-25 15:40:36 +02:00
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_stat *
|
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_stat(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
/* Perform the stat(name, buf) system call. */
|
|
|
|
int r;
|
2007-08-07 14:52:47 +02:00
|
|
|
struct vnode *vp;
|
2012-02-13 16:28:04 +01:00
|
|
|
struct vmnt *vmp;
|
|
|
|
char fullpath[PATH_MAX];
|
|
|
|
struct lookup resolve;
|
2012-04-13 14:50:38 +02:00
|
|
|
vir_bytes vname1, statbuf;
|
|
|
|
size_t vname1_length;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
vname1 = (vir_bytes) job_m_in.VFS_STAT_NAME;
|
|
|
|
vname1_length = (size_t) job_m_in.VFS_STAT_LEN;
|
|
|
|
statbuf = (vir_bytes) job_m_in.VFS_STAT_BUF;
|
2011-07-01 21:35:54 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
|
|
|
|
resolve.l_vmnt_lock = VMNT_READ;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
if (fetch_name(vname1, vname1_length, fullpath) != OK) return(err_code);
|
2012-02-13 16:28:04 +01:00
|
|
|
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
|
2013-02-28 15:44:23 +01:00
|
|
|
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, statbuf);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
unlock_vnode(vp);
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
|
2007-08-07 14:52:47 +02:00
|
|
|
put_vnode(vp);
|
|
|
|
return r;
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_fstat *
|
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_fstat(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
/* Perform the fstat(fd, buf) system call. */
|
|
|
|
register struct filp *rfilp;
|
2013-02-28 15:44:23 +01:00
|
|
|
int r, rfd;
|
2012-04-13 14:50:38 +02:00
|
|
|
vir_bytes statbuf;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
statbuf = (vir_bytes) job_m_in.VFS_FSTAT_BUF;
|
|
|
|
rfd = job_m_in.VFS_FSTAT_FD;
|
2011-07-01 21:35:54 +02:00
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/* Is the file descriptor valid? */
|
2012-04-13 14:50:38 +02:00
|
|
|
if ((rfilp = get_filp(rfd, VNODE_READ)) == NULL) return(err_code);
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
r = req_stat(rfilp->filp_vno->v_fs_e, rfilp->filp_vno->v_inode_nr,
|
2013-02-28 15:44:23 +01:00
|
|
|
who_e, statbuf);
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
unlock_filp(rfilp);
|
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2013-08-20 01:39:47 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* update_statvfs *
|
|
|
|
*===========================================================================*/
|
|
|
|
int update_statvfs(struct vmnt *vmp, struct statvfs *buf)
|
|
|
|
{
|
|
|
|
/* Get statistics from a file system, and cache part of the results. */
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if ((r = req_statvfs(vmp->m_fs_e, buf)) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
vmp->m_stats.f_flag = buf->f_flag;
|
|
|
|
vmp->m_stats.f_bsize = buf->f_bsize;
|
|
|
|
vmp->m_stats.f_frsize = buf->f_frsize;
|
|
|
|
vmp->m_stats.f_iosize = buf->f_iosize;
|
|
|
|
|
|
|
|
vmp->m_stats.f_blocks = buf->f_blocks;
|
|
|
|
vmp->m_stats.f_bfree = buf->f_bfree;
|
|
|
|
vmp->m_stats.f_bavail = buf->f_bavail;
|
|
|
|
vmp->m_stats.f_bresvd = buf->f_bresvd;
|
|
|
|
|
|
|
|
vmp->m_stats.f_files = buf->f_files;
|
|
|
|
vmp->m_stats.f_ffree = buf->f_ffree;
|
|
|
|
vmp->m_stats.f_favail = buf->f_favail;
|
|
|
|
vmp->m_stats.f_fresvd = buf->f_fresvd;
|
|
|
|
|
|
|
|
vmp->m_stats.f_syncreads = buf->f_syncreads;
|
|
|
|
vmp->m_stats.f_syncwrites = buf->f_syncwrites;
|
|
|
|
|
|
|
|
vmp->m_stats.f_asyncreads = buf->f_asyncreads;
|
|
|
|
vmp->m_stats.f_asyncwrites = buf->f_asyncwrites;
|
|
|
|
|
|
|
|
vmp->m_stats.f_namemax = buf->f_namemax;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-08-20 01:35:35 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* fill_statvfs *
|
|
|
|
*===========================================================================*/
|
2013-08-20 01:39:47 +02:00
|
|
|
static int fill_statvfs(struct vmnt *vmp, endpoint_t endpt, vir_bytes buf_addr,
|
|
|
|
int flags)
|
2013-08-20 01:35:35 +02:00
|
|
|
{
|
|
|
|
/* Fill a statvfs structure in a userspace process. First let the target file
|
2013-08-20 01:39:47 +02:00
|
|
|
* server fill in most fields, or use the cached copy if ST_NOWAIT is given.
|
|
|
|
* Then fill in some remaining fields with local information. Finally, copy
|
|
|
|
* the result to user space.
|
2013-08-20 01:35:35 +02:00
|
|
|
*/
|
|
|
|
struct statvfs buf;
|
|
|
|
|
2013-08-20 01:39:47 +02:00
|
|
|
if (!(flags & ST_NOWAIT)) {
|
|
|
|
/* Get fresh statistics from the file system. */
|
|
|
|
if (update_statvfs(vmp, &buf) != OK)
|
|
|
|
return EIO;
|
|
|
|
} else {
|
|
|
|
/* Use the cached statistics. */
|
|
|
|
memset(&buf, 0, sizeof(buf));
|
2013-08-20 01:35:35 +02:00
|
|
|
|
2013-08-20 01:39:47 +02:00
|
|
|
buf.f_flag = vmp->m_stats.f_flag;
|
|
|
|
buf.f_bsize = vmp->m_stats.f_bsize;
|
|
|
|
buf.f_frsize = vmp->m_stats.f_frsize;
|
|
|
|
buf.f_iosize = vmp->m_stats.f_iosize;
|
|
|
|
|
|
|
|
buf.f_blocks = vmp->m_stats.f_blocks;
|
|
|
|
buf.f_bfree = vmp->m_stats.f_bfree;
|
|
|
|
buf.f_bavail = vmp->m_stats.f_bavail;
|
|
|
|
buf.f_bresvd = vmp->m_stats.f_bresvd;
|
|
|
|
|
|
|
|
buf.f_files = vmp->m_stats.f_files;
|
|
|
|
buf.f_ffree = vmp->m_stats.f_ffree;
|
|
|
|
buf.f_favail = vmp->m_stats.f_favail;
|
|
|
|
buf.f_fresvd = vmp->m_stats.f_fresvd;
|
|
|
|
|
|
|
|
buf.f_syncreads = vmp->m_stats.f_syncreads;
|
|
|
|
buf.f_syncwrites = vmp->m_stats.f_syncwrites;
|
|
|
|
|
|
|
|
buf.f_asyncreads = vmp->m_stats.f_asyncreads;
|
|
|
|
buf.f_asyncwrites = vmp->m_stats.f_asyncwrites;
|
|
|
|
|
|
|
|
buf.f_namemax = vmp->m_stats.f_namemax;
|
|
|
|
}
|
2013-08-20 01:35:35 +02:00
|
|
|
|
|
|
|
if (vmp->m_flags & VMNT_READONLY)
|
|
|
|
buf.f_flag |= ST_RDONLY;
|
|
|
|
|
|
|
|
buf.f_fsid = vmp->m_dev;
|
2013-08-20 01:37:18 +02:00
|
|
|
buf.f_fsidx.__fsid_val[0] = 0;
|
|
|
|
buf.f_fsidx.__fsid_val[1] = vmp->m_dev;
|
2013-08-20 01:35:35 +02:00
|
|
|
|
2013-08-20 01:37:18 +02:00
|
|
|
strlcpy(buf.f_fstypename, vmp->m_fstype, sizeof(buf.f_fstypename));
|
2013-08-20 01:35:35 +02:00
|
|
|
strlcpy(buf.f_mntonname, vmp->m_mount_path, sizeof(buf.f_mntonname));
|
|
|
|
strlcpy(buf.f_mntfromname, vmp->m_mount_dev, sizeof(buf.f_mntfromname));
|
|
|
|
|
|
|
|
return sys_datacopy(SELF, (vir_bytes) &buf, endpt, buf_addr, sizeof(buf));
|
|
|
|
}
|
|
|
|
|
2010-06-24 01:53:50 +02:00
|
|
|
/*===========================================================================*
|
2012-04-13 14:50:38 +02:00
|
|
|
* do_statvfs *
|
2010-06-24 01:53:50 +02:00
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_statvfs(void)
|
2010-06-24 01:53:50 +02:00
|
|
|
{
|
2013-08-20 01:28:23 +02:00
|
|
|
/* Perform the statvfs1(name, buf, flags) system call. */
|
|
|
|
int r, flags;
|
2010-06-24 01:53:50 +02:00
|
|
|
struct vnode *vp;
|
2012-02-13 16:28:04 +01:00
|
|
|
struct vmnt *vmp;
|
|
|
|
char fullpath[PATH_MAX];
|
|
|
|
struct lookup resolve;
|
2012-04-13 14:50:38 +02:00
|
|
|
vir_bytes vname1, statbuf;
|
|
|
|
size_t vname1_length;
|
|
|
|
|
2013-08-20 01:28:23 +02:00
|
|
|
vname1 = (vir_bytes) job_m_in.VFS_STATVFS1_NAME;
|
|
|
|
vname1_length = (size_t) job_m_in.VFS_STATVFS1_LEN;
|
|
|
|
statbuf = (vir_bytes) job_m_in.VFS_STATVFS1_BUF;
|
|
|
|
flags = job_m_in.VFS_STATVFS1_FLAGS;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
|
|
|
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
|
|
|
|
resolve.l_vmnt_lock = VMNT_READ;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
2010-06-24 01:53:50 +02:00
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
if (fetch_name(vname1, vname1_length, fullpath) != OK) return(err_code);
|
2012-02-13 16:28:04 +01:00
|
|
|
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
|
2013-08-20 01:28:23 +02:00
|
|
|
r = fill_statvfs(vp->v_vmnt, who_e, statbuf, flags);
|
2010-06-24 01:53:50 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
unlock_vnode(vp);
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
|
2010-06-24 01:53:50 +02:00
|
|
|
put_vnode(vp);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_fstatvfs *
|
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_fstatvfs(void)
|
2010-06-24 01:53:50 +02:00
|
|
|
{
|
2013-08-20 01:28:23 +02:00
|
|
|
/* Perform the fstatvfs1(fd, buf, flags) system call. */
|
2010-06-24 01:53:50 +02:00
|
|
|
register struct filp *rfilp;
|
2013-08-20 01:28:23 +02:00
|
|
|
int r, rfd, flags;
|
2012-04-13 14:50:38 +02:00
|
|
|
vir_bytes statbuf;
|
2010-06-24 01:53:50 +02:00
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
rfd = job_m_in.VFS_STATVFS1_FD;
|
|
|
|
statbuf = (vir_bytes) job_m_in.VFS_STATVFS1_BUF;
|
|
|
|
flags = job_m_in.VFS_STATVFS1_FLAGS;
|
2012-02-13 16:28:04 +01:00
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
/* Is the file descriptor valid? */
|
|
|
|
if ((rfilp = get_filp(rfd, VNODE_READ)) == NULL) return(err_code);
|
2013-08-20 01:28:23 +02:00
|
|
|
r = fill_statvfs(rfilp->filp_vno->v_vmnt, who_e, statbuf, flags);
|
2010-06-24 01:53:50 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
unlock_filp(rfilp);
|
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
2006-10-25 15:40:36 +02:00
|
|
|
|
2013-08-20 01:39:47 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_getvfsstat *
|
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_getvfsstat(void)
|
2013-08-20 01:39:47 +02:00
|
|
|
{
|
|
|
|
/* Perform the getvfsstat(buf, bufsize, flags) system call. */
|
|
|
|
struct vmnt *vmp;
|
|
|
|
vir_bytes buf;
|
|
|
|
size_t bufsize;
|
|
|
|
int r, flags, count, do_lock;
|
|
|
|
|
|
|
|
buf = (vir_bytes) job_m_in.VFS_GETVFSSTAT_BUF;
|
2013-11-04 22:48:08 +01:00
|
|
|
bufsize = job_m_in.VFS_GETVFSSTAT_LEN;
|
2013-08-20 01:39:47 +02:00
|
|
|
flags = job_m_in.VFS_GETVFSSTAT_FLAGS;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
if (buf != 0) {
|
|
|
|
/* We only need to lock target file systems if we are going to query
|
|
|
|
* them. This will only happen if ST_NOWAIT is not given. If we do
|
|
|
|
* not lock, we rely on the VMNT_CANSTAT flag to protect us from
|
|
|
|
* concurrent (un)mount operations. Note that procfs relies on
|
|
|
|
* ST_NOWAIT calls being lock free, as it is a file system itself.
|
|
|
|
*/
|
|
|
|
do_lock = !(flags & ST_NOWAIT);
|
|
|
|
|
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) {
|
|
|
|
/* If there is no more space, return the count so far. */
|
|
|
|
if (bufsize < sizeof(struct statvfs))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Lock the file system before checking any fields. */
|
|
|
|
if (do_lock && (r = lock_vmnt(vmp, VMNT_READ)) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* Obtain information for this file system, if it is in use and
|
|
|
|
* can be reported. File systems that are being (un)mounted
|
|
|
|
* are skipped, as is PFS. The fill call will block only if
|
|
|
|
* ST_NOWAIT was not given.
|
|
|
|
*/
|
|
|
|
if (vmp->m_dev != NO_DEV && (vmp->m_flags & VMNT_CANSTAT)) {
|
|
|
|
if ((r = fill_statvfs(vmp, who_e, buf, flags)) != OK) {
|
|
|
|
if (do_lock)
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
buf += sizeof(struct statvfs);
|
|
|
|
bufsize -= sizeof(struct statvfs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_lock)
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Just report a file system count. No need to lock, as above. */
|
|
|
|
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) {
|
|
|
|
if (vmp->m_dev != NO_DEV && (vmp->m_flags & VMNT_CANSTAT))
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-10-25 15:40:36 +02:00
|
|
|
/*===========================================================================*
|
2007-08-07 14:52:47 +02:00
|
|
|
* do_lstat *
|
2006-10-25 15:40:36 +02:00
|
|
|
*===========================================================================*/
|
2013-10-29 23:15:15 +01:00
|
|
|
int do_lstat(void)
|
2006-10-25 15:40:36 +02:00
|
|
|
{
|
|
|
|
/* Perform the lstat(name, buf) system call. */
|
2007-08-07 14:52:47 +02:00
|
|
|
struct vnode *vp;
|
2012-02-13 16:28:04 +01:00
|
|
|
struct vmnt *vmp;
|
2006-10-25 15:40:36 +02:00
|
|
|
int r;
|
2012-02-13 16:28:04 +01:00
|
|
|
char fullpath[PATH_MAX];
|
|
|
|
struct lookup resolve;
|
2012-04-13 14:50:38 +02:00
|
|
|
vir_bytes vname1, statbuf;
|
|
|
|
size_t vname1_length;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
vname1 = (vir_bytes) job_m_in.VFS_STAT_NAME;
|
|
|
|
vname1_length = (size_t) job_m_in.VFS_STAT_LEN;
|
|
|
|
statbuf = (vir_bytes) job_m_in.VFS_STAT_BUF;
|
2011-07-01 21:35:54 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
lookup_init(&resolve, fullpath, PATH_RET_SYMLINK, &vmp, &vp);
|
|
|
|
resolve.l_vmnt_lock = VMNT_READ;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
|
|
|
|
2012-04-13 14:50:38 +02:00
|
|
|
if (fetch_name(vname1, vname1_length, fullpath) != OK) return(err_code);
|
2012-02-13 16:28:04 +01:00
|
|
|
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
|
2013-02-28 15:44:23 +01:00
|
|
|
r = req_stat(vp->v_fs_e, vp->v_inode_nr, who_e, statbuf);
|
2007-08-07 14:52:47 +02:00
|
|
|
|
2012-02-13 16:28:04 +01:00
|
|
|
unlock_vnode(vp);
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
|
2007-08-07 14:52:47 +02:00
|
|
|
put_vnode(vp);
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
return(r);
|
2006-10-25 15:40:36 +02:00
|
|
|
}
|