2011-11-14 12:53:05 +01:00
|
|
|
/* Created (MFS based):
|
|
|
|
* June 2011 (Evgeniy Ivanov)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
|
|
|
|
#include "puffs.h"
|
|
|
|
#include "puffs_priv.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_create *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int fs_create(void)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct puffs_node *pn_dir;
|
|
|
|
struct puffs_node *pn;
|
2014-04-28 18:25:26 +02:00
|
|
|
mode_t omode;
|
2011-11-14 12:53:05 +01:00
|
|
|
struct puffs_newinfo pni;
|
|
|
|
struct puffs_kcn pkcnp;
|
|
|
|
PUFFS_MAKECRED(pcr, &global_kcred);
|
2012-02-01 12:44:26 +01:00
|
|
|
struct puffs_cn pcn = {&pkcnp, (struct puffs_cred *) __UNCONST(pcr), {0,0,0}};
|
2011-11-14 12:53:05 +01:00
|
|
|
struct vattr va;
|
2013-04-07 10:42:26 +02:00
|
|
|
struct timespec cur_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
int len;
|
|
|
|
|
|
|
|
if (global_pu->pu_ops.puffs_node_create == NULL) {
|
|
|
|
lpuffs_debug("No puffs_node_create");
|
|
|
|
return(ENFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read request message */
|
2014-04-28 18:25:26 +02:00
|
|
|
omode = fs_m_in.m_vfs_fs_create.mode;
|
|
|
|
caller_uid = fs_m_in.m_vfs_fs_create.uid;
|
|
|
|
caller_gid = fs_m_in.m_vfs_fs_create.gid;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* Copy the last component (i.e., file name) */
|
2014-04-28 18:25:26 +02:00
|
|
|
len = fs_m_in.m_vfs_fs_create.path_len;
|
2011-11-14 12:53:05 +01:00
|
|
|
pcn.pcn_namelen = len - 1;
|
|
|
|
if (pcn.pcn_namelen > NAME_MAX)
|
|
|
|
return(ENAMETOOLONG);
|
|
|
|
|
2014-04-28 18:25:26 +02:00
|
|
|
err_code = sys_safecopyfrom(VFS_PROC_NR, fs_m_in.m_vfs_fs_create.grant,
|
2011-11-14 12:53:05 +01:00
|
|
|
(vir_bytes) 0, (vir_bytes) pcn.pcn_name,
|
2012-06-16 03:46:15 +02:00
|
|
|
(size_t) len);
|
2011-11-14 12:53:05 +01:00
|
|
|
if (err_code != OK) return(err_code);
|
|
|
|
NUL(pcn.pcn_name, len, sizeof(pcn.pcn_name));
|
|
|
|
|
|
|
|
/* Get last directory pnode (i.e., directory that will hold the new pnode) */
|
2014-04-28 18:25:26 +02:00
|
|
|
if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.m_vfs_fs_create.inode)) == NULL)
|
2011-11-14 12:53:05 +01:00
|
|
|
return(ENOENT);
|
|
|
|
|
|
|
|
memset(&pni, 0, sizeof(pni));
|
|
|
|
pni.pni_cookie = (void** )&pn;
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
cur_time = clock_timespec();
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
memset(&va, 0, sizeof(va));
|
|
|
|
va.va_type = VREG;
|
2014-04-28 18:25:26 +02:00
|
|
|
va.va_mode = omode;
|
2011-11-14 12:53:05 +01:00
|
|
|
va.va_uid = caller_uid;
|
|
|
|
va.va_gid = caller_gid;
|
2013-04-07 10:42:26 +02:00
|
|
|
va.va_atime = va.va_mtime = va.va_ctime = cur_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
if (buildpath) {
|
|
|
|
r = puffs_path_pcnbuild(global_pu, &pcn, pn_dir);
|
|
|
|
if (r) {
|
|
|
|
lpuffs_debug("pathbuild error\n");
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = global_pu->pu_ops.puffs_node_create(global_pu, pn_dir, &pni, &pcn, &va);
|
|
|
|
if (buildpath) {
|
|
|
|
if (r) {
|
|
|
|
global_pu->pu_pathfree(global_pu, &pcn.pcn_po_full);
|
|
|
|
} else {
|
|
|
|
struct puffs_node *_pn;
|
|
|
|
|
|
|
|
_pn = PU_CMAP(global_pu, pn);
|
|
|
|
_pn->pn_po = pcn.pcn_po_full;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r != OK) {
|
|
|
|
if (r > 0) r = -r;
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open pnode */
|
|
|
|
pn->pn_count++;
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
update_timens(pn_dir, MTIME | CTIME, &cur_time);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* Reply message */
|
2014-04-28 18:25:26 +02:00
|
|
|
fs_m_out.m_fs_vfs_create.inode = pn->pn_va.va_fileid;
|
|
|
|
fs_m_out.m_fs_vfs_create.mode = pn->pn_va.va_mode;
|
|
|
|
fs_m_out.m_fs_vfs_create.file_size = pn->pn_va.va_size;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* This values are needed for the execution */
|
2014-04-28 18:25:26 +02:00
|
|
|
fs_m_out.m_fs_vfs_create.uid = pn->pn_va.va_uid;
|
|
|
|
fs_m_out.m_fs_vfs_create.gid = pn->pn_va.va_gid;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_mknod *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int fs_mknod(void)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct puffs_node *pn_dir;
|
|
|
|
struct puffs_node *pn;
|
|
|
|
struct puffs_newinfo pni;
|
|
|
|
struct puffs_kcn pkcnp;
|
|
|
|
PUFFS_MAKECRED(pcr, &global_kcred);
|
2012-02-01 12:44:26 +01:00
|
|
|
struct puffs_cn pcn = {&pkcnp, (struct puffs_cred *) __UNCONST(pcr), {0,0,0}};
|
2011-11-14 12:53:05 +01:00
|
|
|
struct vattr va;
|
2013-04-07 10:42:26 +02:00
|
|
|
struct timespec cur_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
int len;
|
|
|
|
|
|
|
|
if (global_pu->pu_ops.puffs_node_mknod == NULL) {
|
|
|
|
lpuffs_debug("No puffs_node_mknod");
|
|
|
|
return(ENFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the last component and set up caller's user and group id */
|
2014-04-30 20:00:29 +02:00
|
|
|
len = fs_m_in.m_vfs_fs_mknod.path_len;
|
2011-11-14 12:53:05 +01:00
|
|
|
pcn.pcn_namelen = len - 1;
|
|
|
|
if (pcn.pcn_namelen > NAME_MAX)
|
|
|
|
return(ENAMETOOLONG);
|
|
|
|
|
2014-04-30 20:00:29 +02:00
|
|
|
err_code = sys_safecopyfrom(VFS_PROC_NR, fs_m_in.m_vfs_fs_mknod.grant,
|
2011-11-14 12:53:05 +01:00
|
|
|
(vir_bytes) 0, (vir_bytes) pcn.pcn_name,
|
2012-06-16 03:46:15 +02:00
|
|
|
(size_t) len);
|
2011-11-14 12:53:05 +01:00
|
|
|
if (err_code != OK) return(err_code);
|
|
|
|
NUL(pcn.pcn_name, len, sizeof(pcn.pcn_name));
|
|
|
|
|
2014-04-30 20:00:29 +02:00
|
|
|
caller_uid = fs_m_in.m_vfs_fs_mknod.uid;
|
|
|
|
caller_gid = fs_m_in.m_vfs_fs_mknod.gid;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* Get last directory pnode */
|
2014-04-30 20:00:29 +02:00
|
|
|
if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.m_vfs_fs_mknod.inode)) == NULL)
|
2011-11-14 12:53:05 +01:00
|
|
|
return(ENOENT);
|
|
|
|
|
|
|
|
memset(&pni, 0, sizeof(pni));
|
|
|
|
pni.pni_cookie = (void** )&pn;
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
cur_time = clock_timespec();
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
memset(&va, 0, sizeof(va));
|
|
|
|
va.va_type = VDIR;
|
2014-04-30 20:00:29 +02:00
|
|
|
va.va_mode = fs_m_in.m_vfs_fs_mknod.mode;
|
2011-11-14 12:53:05 +01:00
|
|
|
va.va_uid = caller_uid;
|
|
|
|
va.va_gid = caller_gid;
|
2014-04-30 20:00:29 +02:00
|
|
|
va.va_rdev = fs_m_in.m_vfs_fs_mknod.device;
|
2013-04-07 10:42:26 +02:00
|
|
|
va.va_atime = va.va_mtime = va.va_ctime = cur_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
if (buildpath) {
|
|
|
|
if (puffs_path_pcnbuild(global_pu, &pcn, pn_dir) != 0) {
|
|
|
|
lpuffs_debug("pathbuild error\n");
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = global_pu->pu_ops.puffs_node_mknod(global_pu, pn_dir, &pni, &pcn, &va);
|
|
|
|
if (buildpath) {
|
|
|
|
if (r) {
|
|
|
|
global_pu->pu_pathfree(global_pu, &pcn.pcn_po_full);
|
|
|
|
} else {
|
|
|
|
struct puffs_node *_pn;
|
|
|
|
|
|
|
|
_pn = PU_CMAP(global_pu, pn);
|
|
|
|
_pn->pn_po = pcn.pcn_po_full;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r != OK) {
|
|
|
|
if (r > 0) r = -r;
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
update_timens(pn_dir, MTIME | CTIME, &cur_time);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_mkdir *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int fs_mkdir(void)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct puffs_node *pn_dir;
|
|
|
|
struct puffs_node *pn;
|
|
|
|
struct puffs_newinfo pni;
|
|
|
|
struct puffs_kcn pkcnp;
|
|
|
|
PUFFS_MAKECRED(pcr, &global_kcred);
|
2012-02-01 12:44:26 +01:00
|
|
|
struct puffs_cn pcn = {&pkcnp, (struct puffs_cred *) __UNCONST(pcr), {0,0,0}};
|
2011-11-14 12:53:05 +01:00
|
|
|
struct vattr va;
|
2013-04-07 10:42:26 +02:00
|
|
|
struct timespec cur_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
int len;
|
|
|
|
|
|
|
|
if (global_pu->pu_ops.puffs_node_mkdir == NULL) {
|
|
|
|
lpuffs_debug("No puffs_node_mkdir");
|
|
|
|
return(ENFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the last component and set up caller's user and group id */
|
2014-04-30 19:44:48 +02:00
|
|
|
len = fs_m_in.m_vfs_fs_mkdir.path_len;
|
2011-11-14 12:53:05 +01:00
|
|
|
pcn.pcn_namelen = len - 1;
|
|
|
|
if (pcn.pcn_namelen > NAME_MAX)
|
|
|
|
return(ENAMETOOLONG);
|
|
|
|
|
2014-04-30 19:44:48 +02:00
|
|
|
err_code = sys_safecopyfrom(VFS_PROC_NR, fs_m_in.m_vfs_fs_mkdir.grant,
|
2011-11-14 12:53:05 +01:00
|
|
|
(vir_bytes) 0, (vir_bytes) pcn.pcn_name,
|
2012-06-16 03:46:15 +02:00
|
|
|
(phys_bytes) len);
|
2011-11-14 12:53:05 +01:00
|
|
|
if (err_code != OK) return(err_code);
|
|
|
|
NUL(pcn.pcn_name, len, sizeof(pcn.pcn_name));
|
|
|
|
|
2014-04-30 19:44:48 +02:00
|
|
|
caller_uid = fs_m_in.m_vfs_fs_mkdir.uid;
|
|
|
|
caller_gid = fs_m_in.m_vfs_fs_mkdir.gid;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* Get last directory pnode */
|
2014-04-30 19:44:48 +02:00
|
|
|
if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.m_vfs_fs_mkdir.inode)) == NULL)
|
2011-11-14 12:53:05 +01:00
|
|
|
return(ENOENT);
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
cur_time = clock_timespec();
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
memset(&pni, 0, sizeof(pni));
|
|
|
|
pni.pni_cookie = (void** )&pn;
|
|
|
|
|
|
|
|
memset(&va, 0, sizeof(va));
|
|
|
|
va.va_type = VDIR;
|
2014-04-30 19:44:48 +02:00
|
|
|
va.va_mode = fs_m_in.m_vfs_fs_mkdir.mode;
|
2011-11-14 12:53:05 +01:00
|
|
|
va.va_uid = caller_uid;
|
|
|
|
va.va_gid = caller_gid;
|
2013-04-07 10:42:26 +02:00
|
|
|
va.va_atime = va.va_mtime = va.va_ctime = cur_time;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
if (buildpath) {
|
|
|
|
r = puffs_path_pcnbuild(global_pu, &pcn, pn_dir);
|
|
|
|
if (r) {
|
|
|
|
lpuffs_debug("pathbuild error\n");
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = global_pu->pu_ops.puffs_node_mkdir(global_pu, pn_dir, &pni, &pcn, &va);
|
|
|
|
if (buildpath) {
|
|
|
|
if (r) {
|
|
|
|
global_pu->pu_pathfree(global_pu, &pcn.pcn_po_full);
|
|
|
|
} else {
|
|
|
|
struct puffs_node *_pn;
|
|
|
|
|
|
|
|
_pn = PU_CMAP(global_pu, pn);
|
|
|
|
_pn->pn_po = pcn.pcn_po_full;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r != OK) {
|
|
|
|
if (r > 0) r = -r;
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2013-04-07 10:42:26 +02:00
|
|
|
update_timens(pn_dir, MTIME | CTIME, &cur_time);
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_slink *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int fs_slink(void)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct pnode *pn; /* pnode containing symbolic link */
|
|
|
|
struct pnode *pn_dir; /* directory containing link */
|
|
|
|
char target[PATH_MAX + 1]; /* target path */
|
|
|
|
struct puffs_newinfo pni;
|
|
|
|
struct puffs_kcn pkcnp;
|
|
|
|
PUFFS_MAKECRED(pcr, &global_kcred);
|
2012-02-01 12:44:26 +01:00
|
|
|
struct puffs_cn pcn = {&pkcnp, (struct puffs_cred *) __UNCONST(pcr), {0,0,0}};
|
2011-11-14 12:53:05 +01:00
|
|
|
struct vattr va;
|
|
|
|
int len;
|
|
|
|
|
2014-04-29 20:59:48 +02:00
|
|
|
caller_uid = fs_m_in.m_vfs_fs_slink.uid;
|
|
|
|
caller_gid = fs_m_in.m_vfs_fs_slink.gid;
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
/* Copy the link name's last component */
|
2014-04-29 20:59:48 +02:00
|
|
|
len = fs_m_in.m_vfs_fs_slink.path_len;
|
2011-11-14 12:53:05 +01:00
|
|
|
pcn.pcn_namelen = len - 1;
|
|
|
|
if (pcn.pcn_namelen > NAME_MAX)
|
|
|
|
return(ENAMETOOLONG);
|
|
|
|
|
2014-04-29 20:59:48 +02:00
|
|
|
if (fs_m_in.m_vfs_fs_slink.mem_size >= PATH_MAX)
|
2011-11-14 12:53:05 +01:00
|
|
|
return(ENAMETOOLONG);
|
|
|
|
|
2014-04-29 20:59:48 +02:00
|
|
|
r = sys_safecopyfrom(VFS_PROC_NR, fs_m_in.m_vfs_fs_slink.grant_path,
|
2011-11-14 12:53:05 +01:00
|
|
|
(vir_bytes) 0, (vir_bytes) pcn.pcn_name,
|
2012-06-16 03:46:15 +02:00
|
|
|
(size_t) len);
|
2011-11-14 12:53:05 +01:00
|
|
|
if (r != OK) return(r);
|
|
|
|
NUL(pcn.pcn_name, len, sizeof(pcn.pcn_name));
|
|
|
|
|
|
|
|
/* Copy the target path (note that it's not null terminated) */
|
2014-04-29 20:59:48 +02:00
|
|
|
r = sys_safecopyfrom(VFS_PROC_NR, fs_m_in.m_vfs_fs_slink.grant_target,
|
2011-11-14 12:53:05 +01:00
|
|
|
(vir_bytes) 0, (vir_bytes) target,
|
2014-04-29 20:59:48 +02:00
|
|
|
fs_m_in.m_vfs_fs_slink.mem_size);
|
2011-11-14 12:53:05 +01:00
|
|
|
if (r != OK) return(r);
|
2014-04-29 20:59:48 +02:00
|
|
|
target[fs_m_in.m_vfs_fs_slink.mem_size] = '\0';
|
2011-11-14 12:53:05 +01:00
|
|
|
|
2014-04-29 20:59:48 +02:00
|
|
|
if (strlen(target) != (size_t) fs_m_in.m_vfs_fs_slink.mem_size) {
|
2011-11-14 12:53:05 +01:00
|
|
|
/* This can happen if the user provides a buffer
|
|
|
|
* with a \0 in it. This can cause a lot of trouble
|
|
|
|
* when the symlink is used later. We could just use
|
|
|
|
* the strlen() value, but we want to let the user
|
|
|
|
* know he did something wrong. ENAMETOOLONG doesn't
|
|
|
|
* exactly describe the error, but there is no
|
|
|
|
* ENAMETOOWRONG.
|
|
|
|
*/
|
|
|
|
return(ENAMETOOLONG);
|
|
|
|
}
|
|
|
|
|
2014-04-29 20:59:48 +02:00
|
|
|
if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.m_vfs_fs_slink.inode)) == NULL)
|
2011-11-14 12:53:05 +01:00
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
memset(&pni, 0, sizeof(pni));
|
|
|
|
pni.pni_cookie = (void** )&pn;
|
|
|
|
|
|
|
|
memset(&va, 0, sizeof(va));
|
|
|
|
va.va_type = VLNK;
|
2014-04-29 20:59:48 +02:00
|
|
|
va.va_mode = (I_SYMBOLIC_LINK | RWX_MODES);
|
2011-11-14 12:53:05 +01:00
|
|
|
va.va_uid = caller_uid;
|
|
|
|
va.va_gid = caller_gid;
|
2013-04-07 10:42:26 +02:00
|
|
|
va.va_atime = va.va_mtime = va.va_ctime = clock_timespec();
|
2011-11-14 12:53:05 +01:00
|
|
|
|
|
|
|
if (buildpath) {
|
|
|
|
r = puffs_path_pcnbuild(global_pu, &pcn, pn_dir);
|
|
|
|
if (r) {
|
|
|
|
lpuffs_debug("pathbuild error\n");
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = global_pu->pu_ops.puffs_node_symlink(global_pu, pn_dir, &pni, &pcn, &va, target);
|
|
|
|
if (buildpath) {
|
|
|
|
if (r) {
|
|
|
|
global_pu->pu_pathfree(global_pu, &pcn.pcn_po_full);
|
|
|
|
} else {
|
|
|
|
struct puffs_node *_pn;
|
|
|
|
|
|
|
|
_pn = PU_CMAP(global_pu, pn);
|
|
|
|
_pn->pn_po = pcn.pcn_po_full;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r > 0) r = -r;
|
|
|
|
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_inhibread *
|
|
|
|
*===========================================================================*/
|
2014-02-24 14:00:17 +01:00
|
|
|
int fs_inhibread(void)
|
2011-11-14 12:53:05 +01:00
|
|
|
{
|
|
|
|
return(OK);
|
|
|
|
}
|