This patch will make mode_t 16-bits->32-bits, off_t 32-bits->64-bits,
ino_t 32-bits->64-bits, and nlink_t 16-bits->32-bits. As uid_t and
gid_t were already 32-bits we can drop the big_{mode,off,ino,uid,
gid,nlink}_t types from struct stat. This has huge consequences:
. lseek now has to accept a 64-bit argument and returns a 64-bit
result. Therefore we need a new lseek and return proper results
based on the used version (i.e., translate).
. some fcntl functions take and return a struct flock which holds 2
off_t fields. Like lseek, we need to distinguish between old and
new versions.
. getdents uses struct dirent which has among other fields an ino_t
and off_t field. Consequently we need a new getdents system call
and have to translate when we encounter an old call.
. truncate and ftruncate also take off_t arguments and therefore
require a new version.
To add insult to injury VFS itself uses getdents. This has as
consequence that we have 2^3 combinations of version for getdents; old
and new version of libc (new system calls), new and old version of VFS
(when booting an old image), old and new version of an FS. We can
distinguish between these cases as follows; libc will use new system
call numbers that have not yet been in use. When using a new number,
VFS knows libc is new, otherwise it's an old libc. Vice versa, libc
first tries the new number and if that fails due to ENOSYS (unknown
system call number) it knows it's dealing with an old VFS. Finally,
since we now have VFS-FS protocol versioning and by bumping the version
to 1, VFS knows an FS is old when it reports version 0 and an FS knows
VFS is old when VFS reports it's using version 0.
0 = old version, 1 = new version
libc | VFS | FS | approach
----------------------------
0 | 0 | 0 | Nothing to do
----------------------------
0 | 0 | 1 | VFS reports protocol version 0, FS falls back
| to using the old getdents function
----------------------------
0 | 1 | 0 | VFS reports protocol version 1, FS version 0.
| libc requires old getdents so there is nothing
| to do. VFS itself needs new getdents and will
| translate.
----------------------------
0 | 1 | 1 | VFS reports protocol version 1, FS version 1.
| VFS intercepts getdents results and translates
| them on the fly before returning results to libc
----------------------------
1 | 0 | 0 | libc first tries new system call number and
| then fall back to the old number. libc first
| translates the results to the new getdents before
| returning.
----------------------------
1 | 0 | 1 | VFS reports protocol version 0, so FS uses fall
| back. libc translates.
----------------------------
1 | 1 | 0 | VFS reports protocol version 1, FS version 0. VFS
| will intercept all results and translate on the
| fly.
----------------------------
1 | 1 | 1 | Nothing to do.
As VFS can distinguish between old and new system calls of (f)truncate,
lseek, and fcntl, it will translate the arguments and results if
necessary. Likewise libc falls back to using the old calls and
translating the results to the new version if necessary.
Change-Id: Id5bc819e6ef90f317dbddb21020e0a65028225ce
257 lines
7.5 KiB
C
257 lines
7.5 KiB
C
/* Created (MFS based):
|
|
* February 2010 (Evgeniy Ivanov)
|
|
*/
|
|
|
|
#include "fs.h"
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <minix/com.h>
|
|
#include <sys/stat.h>
|
|
#include "buf.h"
|
|
#include "inode.h"
|
|
#include "super.h"
|
|
#include <minix/vfsif.h>
|
|
#include <minix/bdev.h>
|
|
|
|
|
|
/*===========================================================================*
|
|
* fs_readsuper *
|
|
*===========================================================================*/
|
|
int fs_readsuper()
|
|
{
|
|
/* This function reads the superblock of the partition, gets the root inode
|
|
* and sends back the details of them. Note, that the FS process does not
|
|
* know the index of the vmnt object which refers to it, whenever the pathname
|
|
* lookup leaves a partition an ELEAVEMOUNT error is transferred back
|
|
* so that the VFS knows that it has to find the vnode on which this FS
|
|
* process' partition is mounted on.
|
|
*/
|
|
struct inode *root_ip;
|
|
cp_grant_id_t label_gid;
|
|
size_t label_len;
|
|
int r = OK;
|
|
int readonly, isroot;
|
|
u32_t mask;
|
|
|
|
fs_dev = fs_m_in.REQ_DEV;
|
|
label_gid = fs_m_in.REQ_GRANT;
|
|
label_len = fs_m_in.REQ_PATH_LEN;
|
|
readonly = (fs_m_in.REQ_FLAGS & REQ_RDONLY) ? 1 : 0;
|
|
isroot = (fs_m_in.REQ_FLAGS & REQ_ISROOT) ? 1 : 0;
|
|
|
|
if (!(fs_m_in.REQ_FLAGS & REQ_HASPROTO)) {
|
|
proto_version = 0;
|
|
} else {
|
|
proto_version = VFS_FS_PROTO_VERSION(fs_m_in.REQ_PROTO);
|
|
}
|
|
|
|
if (label_len > sizeof(fs_dev_label))
|
|
return(EINVAL);
|
|
|
|
r = sys_safecopyfrom(fs_m_in.m_source, label_gid, 0,
|
|
(vir_bytes)fs_dev_label, label_len);
|
|
if (r != OK) {
|
|
printf("%s:%d fs_readsuper: safecopyfrom failed: %d\n",
|
|
__FILE__, __LINE__, r);
|
|
return(EINVAL);
|
|
}
|
|
|
|
/* Map the driver label for this major. */
|
|
bdev_driver(fs_dev, fs_dev_label);
|
|
|
|
/* Open the device the file system lives on. */
|
|
if (bdev_open(fs_dev, readonly ? R_BIT : (R_BIT|W_BIT)) != OK) {
|
|
return(EINVAL);
|
|
}
|
|
|
|
/* Fill in the super block. */
|
|
STATICINIT(superblock, 1);
|
|
if (!superblock)
|
|
panic("Can't allocate memory for superblock.");
|
|
superblock->s_dev = fs_dev; /* read_super() needs to know which dev */
|
|
r = read_super(superblock);
|
|
|
|
/* Is it recognized as a Minix filesystem? */
|
|
if (r != OK) {
|
|
superblock->s_dev = NO_DEV;
|
|
bdev_close(fs_dev);
|
|
return(r);
|
|
}
|
|
|
|
if (superblock->s_rev_level != EXT2_GOOD_OLD_REV) {
|
|
struct super_block *sp = superblock; /* just shorter name */
|
|
mask = ~SUPPORTED_INCOMPAT_FEATURES;
|
|
if (HAS_INCOMPAT_FEATURE(sp, mask)) {
|
|
if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_COMPRESSION & mask))
|
|
printf("ext2: fs compression is not supported by server\n");
|
|
if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_FILETYPE & mask))
|
|
printf("ext2: fs in dir filetype is not supported by server\n");
|
|
if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_RECOVER & mask))
|
|
printf("ext2: fs recovery is not supported by server\n");
|
|
if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_JOURNAL_DEV & mask))
|
|
printf("ext2: fs journal dev is not supported by server\n");
|
|
if (HAS_INCOMPAT_FEATURE(sp, INCOMPAT_META_BG & mask))
|
|
printf("ext2: fs meta bg is not supported by server\n");
|
|
return(EINVAL);
|
|
}
|
|
mask = ~SUPPORTED_RO_COMPAT_FEATURES;
|
|
if (HAS_RO_COMPAT_FEATURE(sp, mask)) {
|
|
if (HAS_RO_COMPAT_FEATURE(sp, RO_COMPAT_SPARSE_SUPER & mask)) {
|
|
printf("ext2: sparse super is not supported by server, \
|
|
remount read-only\n");
|
|
}
|
|
if (HAS_RO_COMPAT_FEATURE(sp, RO_COMPAT_LARGE_FILE & mask)) {
|
|
printf("ext2: large files are not supported by server, \
|
|
remount read-only\n");
|
|
}
|
|
if (HAS_RO_COMPAT_FEATURE(sp, RO_COMPAT_BTREE_DIR & mask)) {
|
|
printf("ext2: dir's btree is not supported by server, \
|
|
remount read-only\n");
|
|
}
|
|
return(EINVAL);
|
|
}
|
|
}
|
|
|
|
if (superblock->s_state == EXT2_ERROR_FS) {
|
|
printf("ext2: filesystem wasn't cleanly unmounted last time\n");
|
|
superblock->s_dev = NO_DEV;
|
|
bdev_close(fs_dev);
|
|
return(EINVAL);
|
|
}
|
|
|
|
|
|
lmfs_set_blocksize(superblock->s_block_size, major(fs_dev));
|
|
|
|
/* Get the root inode of the mounted file system. */
|
|
if ( (root_ip = get_inode(fs_dev, ROOT_INODE)) == NULL) {
|
|
printf("ext2: couldn't get root inode\n");
|
|
superblock->s_dev = NO_DEV;
|
|
bdev_close(fs_dev);
|
|
return(EINVAL);
|
|
}
|
|
|
|
if (root_ip != NULL && root_ip->i_mode == 0) {
|
|
printf("%s:%d zero mode for root inode?\n", __FILE__, __LINE__);
|
|
put_inode(root_ip);
|
|
superblock->s_dev = NO_DEV;
|
|
bdev_close(fs_dev);
|
|
return(EINVAL);
|
|
}
|
|
|
|
if (root_ip != NULL && (root_ip->i_mode & I_TYPE) != I_DIRECTORY) {
|
|
printf("%s:%d root inode has wrong type, it's not a DIR\n",
|
|
__FILE__, __LINE__);
|
|
put_inode(root_ip);
|
|
superblock->s_dev = NO_DEV;
|
|
bdev_close(fs_dev);
|
|
return(EINVAL);
|
|
}
|
|
|
|
superblock->s_rd_only = readonly;
|
|
superblock->s_is_root = isroot;
|
|
|
|
if (!readonly) {
|
|
superblock->s_state = EXT2_ERROR_FS;
|
|
superblock->s_mnt_count++;
|
|
superblock->s_mtime = clock_time();
|
|
write_super(superblock); /* Commit info, we just set above */
|
|
}
|
|
|
|
/* Root inode properties */
|
|
fs_m_out.RES_INODE_NR = root_ip->i_num;
|
|
fs_m_out.RES_MODE = root_ip->i_mode;
|
|
fs_m_out.RES_FILE_SIZE_LO = root_ip->i_size;
|
|
fs_m_out.RES_UID = root_ip->i_uid;
|
|
fs_m_out.RES_GID = root_ip->i_gid;
|
|
fs_m_out.RES_PROTO = 0;
|
|
VFS_FS_PROTO_PUT_VERSION(fs_m_out.RES_PROTO, VFS_FS_CURRENT_VERSION);
|
|
VFS_FS_PROTO_PUT_CONREQS(fs_m_out.RES_PROTO, 1);
|
|
|
|
return(r);
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* fs_mountpoint *
|
|
*===========================================================================*/
|
|
int fs_mountpoint()
|
|
{
|
|
/* This function looks up the mount point, it checks the condition whether
|
|
* the partition can be mounted on the inode or not.
|
|
*/
|
|
register struct inode *rip;
|
|
int r = OK;
|
|
pmode_t bits;
|
|
|
|
/* Temporarily open the file. */
|
|
if( (rip = get_inode(fs_dev, fs_m_in.REQ_INODE_NR)) == NULL)
|
|
return(EINVAL);
|
|
|
|
|
|
if(rip->i_mountpoint) r = EBUSY;
|
|
|
|
/* It may not be special. */
|
|
bits = rip->i_mode & I_TYPE;
|
|
if (bits == I_BLOCK_SPECIAL || bits == I_CHAR_SPECIAL) r = ENOTDIR;
|
|
|
|
put_inode(rip);
|
|
|
|
if(r == OK) rip->i_mountpoint = TRUE;
|
|
|
|
return(r);
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* fs_unmount *
|
|
*===========================================================================*/
|
|
int fs_unmount()
|
|
{
|
|
/* Unmount a file system by device number. */
|
|
int count;
|
|
struct inode *rip, *root_ip;
|
|
|
|
if(superblock->s_dev != fs_dev) return(EINVAL);
|
|
|
|
/* See if the mounted device is busy. Only 1 inode using it should be
|
|
* open --the root inode-- and that inode only 1 time. */
|
|
count = 0;
|
|
for (rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
|
|
if (rip->i_count > 0 && rip->i_dev == fs_dev) count += rip->i_count;
|
|
|
|
if ((root_ip = find_inode(fs_dev, ROOT_INODE)) == NULL) {
|
|
printf("ext2: couldn't find root inode. Unmount failed.\n");
|
|
panic("ext2: couldn't find root inode");
|
|
return(EINVAL);
|
|
}
|
|
|
|
/* Sync fs data before checking count. In some cases VFS can force unmounting
|
|
* and it will damage unsynced FS. We don't sync before checking root_ip since
|
|
* if it is missing then something strange happened with FS, so it's better
|
|
* to not use possibly corrupted data for syncing.
|
|
*/
|
|
if (!superblock->s_rd_only) {
|
|
/* force any cached blocks out of memory */
|
|
(void) fs_sync();
|
|
}
|
|
|
|
if (count > 1) return(EBUSY); /* can't umount a busy file system */
|
|
|
|
put_inode(root_ip);
|
|
|
|
if (!superblock->s_rd_only) {
|
|
superblock->s_wtime = clock_time();
|
|
superblock->s_state = EXT2_VALID_FS;
|
|
write_super(superblock); /* Commit info, we just set above */
|
|
}
|
|
|
|
/* Close the device the file system lives on. */
|
|
bdev_close(fs_dev);
|
|
|
|
/* Finish off the unmount. */
|
|
superblock->s_dev = NO_DEV;
|
|
unmountdone = TRUE;
|
|
|
|
return(OK);
|
|
}
|