2009-10-01 16:00:27 +02:00
|
|
|
#include "inc.h"
|
2011-07-01 21:35:54 +02:00
|
|
|
#include <assert.h>
|
2009-10-01 16:00:27 +02:00
|
|
|
#include <sys/stat.h>
|
2010-06-24 01:57:26 +02:00
|
|
|
#include <sys/statvfs.h>
|
2009-10-01 16:00:27 +02:00
|
|
|
#include <minix/com.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* stat_dir_record *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int stat_dir_record(
|
2010-03-30 16:07:15 +02:00
|
|
|
register struct dir_record *dir, /* pointer to dir record to stat */
|
|
|
|
int pipe_pos, /* position in a pipe, supplied by fstat() */
|
|
|
|
endpoint_t who_e, /* Caller endpoint */
|
|
|
|
cp_grant_id_t gid /* grant for the stat buf */
|
|
|
|
)
|
2009-10-01 16:00:27 +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
|
|
|
/* This function returns all the info about a particular inode. It's missing
|
|
|
|
* the recording date because of a bug in the standard functions stdtime.
|
|
|
|
* Once the bug is fixed the function can be called inside this function to
|
|
|
|
* return the date. */
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
/* Common code for stat and fstat system calls. */
|
|
|
|
struct stat statbuf;
|
2010-04-01 15:25:05 +02:00
|
|
|
int r;
|
2009-10-01 16:00:27 +02:00
|
|
|
struct tm ltime;
|
|
|
|
time_t time1;
|
2011-07-01 21:35:54 +02:00
|
|
|
u32_t blocks;
|
|
|
|
|
|
|
|
blocks = v_pri.volume_space_size_l;
|
|
|
|
/* The unit of blocks should be 512 */
|
|
|
|
assert(v_pri.logical_block_size_l >= 512);
|
|
|
|
blocks = blocks * (v_pri.logical_block_size_l >> 9);
|
|
|
|
|
|
|
|
memset(&statbuf, 0, sizeof(struct stat));
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
statbuf.st_dev = fs_dev; /* the device of the file */
|
|
|
|
statbuf.st_ino = ID_DIR_RECORD(dir); /* the id of the dir record */
|
|
|
|
statbuf.st_mode = dir->d_mode; /* flags of the file */
|
|
|
|
statbuf.st_nlink = dir->d_count; /* times this file is used */
|
|
|
|
statbuf.st_uid = 0; /* user root */
|
|
|
|
statbuf.st_gid = 0; /* group operator */
|
|
|
|
statbuf.st_rdev = NO_DEV;
|
|
|
|
statbuf.st_size = dir->d_file_size; /* size of the file */
|
2011-07-01 21:35:54 +02:00
|
|
|
statbuf.st_blksize = v_pri.logical_block_size_l;
|
|
|
|
statbuf.st_blocks = blocks;
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
ltime.tm_year = dir->rec_date[0];
|
|
|
|
ltime.tm_mon = dir->rec_date[1] - 1;
|
|
|
|
ltime.tm_mday = dir->rec_date[2];
|
|
|
|
ltime.tm_hour = dir->rec_date[3];
|
|
|
|
ltime.tm_min = dir->rec_date[4];
|
|
|
|
ltime.tm_sec = dir->rec_date[5];
|
|
|
|
ltime.tm_isdst = 0;
|
|
|
|
|
|
|
|
if (dir->rec_date[6] != 0)
|
- 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
|
|
|
ltime.tm_hour += dir->rec_date[6] / 4;
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
time1 = mktime(<ime);
|
|
|
|
|
|
|
|
statbuf.st_atime = time1;
|
|
|
|
statbuf.st_mtime = time1;
|
|
|
|
statbuf.st_ctime = time1;
|
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
|
|
|
r = sys_safecopyto(who_e, gid, 0, (vir_bytes) &statbuf,
|
2012-06-16 03:46:15 +02:00
|
|
|
(phys_bytes) sizeof(statbuf));
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2009-10-01 16:00:27 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* fs_stat *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_stat()
|
2009-10-01 16:00:27 +02:00
|
|
|
{
|
|
|
|
register int r; /* return value */
|
|
|
|
struct dir_record *dir;
|
|
|
|
r = EINVAL;
|
|
|
|
|
2014-05-01 10:05:07 +02:00
|
|
|
if ((dir = get_dir_record(fs_m_in.m_vfs_fs_stat.inode)) != NULL) {
|
|
|
|
r = stat_dir_record(dir, 0, fs_m_in.m_source, fs_m_in.m_vfs_fs_stat.grant);
|
- 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
|
|
|
release_dir_record(dir);
|
|
|
|
}
|
2009-10-01 16:00:27 +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
|
|
|
return(r);
|
2009-10-01 16:00:27 +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
|
|
|
|
2010-06-24 01:57:26 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* fs_statvfs *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_statvfs()
|
2010-06-24 01:57:26 +02:00
|
|
|
{
|
|
|
|
struct statvfs st;
|
|
|
|
int r;
|
|
|
|
|
2013-08-20 01:35:35 +02:00
|
|
|
memset(&st, 0, sizeof(st));
|
2010-06-24 01:57:26 +02:00
|
|
|
|
|
|
|
st.f_bsize = v_pri.logical_block_size_l;
|
|
|
|
st.f_frsize = st.f_bsize;
|
2013-08-20 01:35:35 +02:00
|
|
|
st.f_iosize = st.f_bsize;
|
2010-06-24 01:57:26 +02:00
|
|
|
st.f_blocks = v_pri.volume_space_size_l;
|
|
|
|
st.f_namemax = NAME_MAX;
|
|
|
|
|
|
|
|
/* Copy the struct to user space. */
|
2014-05-01 11:19:18 +02:00
|
|
|
r = sys_safecopyto(fs_m_in.m_source, fs_m_in.m_vfs_fs_statvfs.grant, 0,
|
|
|
|
(vir_bytes) &st, (phys_bytes) sizeof(st));
|
2010-06-24 01:57:26 +02:00
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
2012-10-16 17:40:39 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* blockstats *
|
|
|
|
*===========================================================================*/
|
2013-04-18 14:42:15 +02:00
|
|
|
void fs_blockstats(u64_t *blocks, u64_t *free, u64_t *used)
|
2012-10-16 17:40:39 +02:00
|
|
|
{
|
|
|
|
*used = *blocks = v_pri.volume_space_size_l;
|
|
|
|
*free = 0;
|
|
|
|
}
|
|
|
|
|