5
* @author: Anton Bondarev
14
#include <fs/dir_context.h>
15
#include <fs/fs_driver.h>
16
#include <fs/hlpr_path.h>
18
#include <fs/super_block.h>
19
#include <fs/inode_operation.h>
25
#include <security/security.h>
27
static int create_new_node(struct path *parent, const char *name, mode_t mode) {
31
if(NULL == parent->node->i_sb) {
35
if (0 != vfs_create(parent, name, mode, &node)) {
39
if ((mode & VFS_DIR_VIRTUAL) && S_ISDIR(mode)) {
40
node.node->i_sb = parent->node->i_sb;
42
struct super_block *sb = parent->node->i_sb;
44
if (!sb || !sb->sb_iops || !sb->sb_iops->ino_create) {
45
retval = -ENOSYS;/* FIXME EPERM ?*/
49
retval = sb->sb_iops->ino_create(node.node, parent->node, node.node->i_mode);
54
/* XXX it's here and not in vfs since vfs node associated with drive after
55
* creating. security may call driver dependent features, like setting
58
security_node_cred_fill(node.node);
61
vfs_del_leaf(node.node);
65
int kmkdir(const char *pathname, mode_t mode) {
67
const char *lastpath, *ch;
70
if (-ENOENT != (res = fs_perm_lookup(pathname, &lastpath, &node))) {
75
if (NULL != (ch = strchr(lastpath, '/'))
76
&& NULL != path_next(ch, NULL)) {
81
if_mounted_follow_down(&node);
83
if (0 != fs_perm_check(node.node, S_IWOTH)) {
88
if (0 != (res = security_node_create(node.node, S_IFDIR | mode))) {
93
if (0 != (res = create_new_node(&node, lastpath, S_IFDIR | mode))) {
101
int kcreat(struct path *dir_path, const char *path, mode_t mode, struct path *child) {
102
struct super_block *sb;
105
assert(dir_path->node);
107
path = path_next(path, NULL);
114
if (NULL != strchr(path, '/')) {
119
if (0 != (fs_perm_check(dir_path->node, S_IWOTH))) {
124
if (0 != (ret = security_node_create(dir_path->node, S_IFREG | mode))) {
129
if (0 != vfs_create(dir_path, path, S_IFREG | mode, child)) {
134
child->mnt_desc = dir_path->mnt_desc;
136
if(!dir_path->node || !dir_path->node->i_sb) {
138
vfs_del_leaf(child->node);
142
sb = dir_path->node->i_sb;
143
if (!sb || !sb->sb_iops || !sb->sb_iops->ino_create) {
145
vfs_del_leaf(child->node);
149
ret = sb->sb_iops->ino_create(child->node, dir_path->node, child->node->i_mode);
152
vfs_del_leaf(child->node);
156
/* XXX it's here and not in vfs since vfs node associated with drive after
157
* creating. security may call driver dependent features, like setting
160
security_node_cred_fill(child->node);