cregit-Linux how code gets into the kernel

Release 4.10 fs/hostfs/hostfs_kern.c

Directory: fs/hostfs
/*
 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 * Licensed under the GPL
 *
 * Ported the filesystem routines to 2.5.
 * 2003-02-10 Petr Baudis <pasky@ucw.cz>
 */

#include <linux/fs.h>
#include <linux/magic.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/pagemap.h>
#include <linux/statfs.h>
#include <linux/slab.h>
#include <linux/seq_file.h>
#include <linux/mount.h>
#include <linux/namei.h>
#include "hostfs.h"
#include <init.h>
#include <kern.h>


struct hostfs_inode_info {
	
int fd;
	
fmode_t mode;
	
struct inode vfs_inode;
	
struct mutex open_mutex;
};


static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode) { return list_entry(inode, struct hostfs_inode_info, vfs_inode); }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso25100.00%1100.00%
Total25100.00%1100.00%

#define FILE_HOSTFS_I(file) HOSTFS_I(file_inode(file)) /* Changed in hostfs_args before the kernel starts running */ static char *root_ino = ""; static int append = 0; static const struct inode_operations hostfs_iops; static const struct inode_operations hostfs_dir_iops; static const struct inode_operations hostfs_link_iops; #ifndef MODULE
static int __init hostfs_args(char *options, int *add) { char *ptr; ptr = strchr(options, ','); if (ptr != NULL) *ptr++ = '\0'; if (*options != '\0') root_ino = options; options = ptr; while (options) { ptr = strchr(options, ','); if (ptr != NULL) *ptr++ = '\0'; if (*options != '\0') { if (!strcmp(options, "append")) append = 1; else printf("hostfs_args - unsupported option - %s\n", options); } options = ptr; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso120100.00%1100.00%
Total120100.00%1100.00%

__uml_setup("hostfs=", hostfs_args, "hostfs=<root dir>,<flags>,...\n" " This is used to set hostfs parameters. The root directory argument\n" " is used to confine all hostfs mounts to within the specified directory\n" " tree on the host. If this isn't specified, then a user inside UML can\n" " mount anything on the host that's accessible to the user that's running\n" " it.\n" " The only flag currently supported is 'append', which specifies that all\n" " files opened by hostfs will be opened in append mode.\n\n" ); #endif
static char *__dentry_name(struct dentry *dentry, char *name) { char *p = dentry_path_raw(dentry, name, PATH_MAX); char *root; size_t len; root = dentry->d_sb->s_fs_info; len = strlen(root); if (IS_ERR(p)) { __putname(name); return NULL; } /* * This function relies on the fact that dentry_path_raw() will place * the path name at the end of the provided buffer. */ BUG_ON(p + strlen(p) + 1 != name + PATH_MAX); strlcpy(name, root, PATH_MAX); if (len > p - name) { __putname(name); return NULL; } if (p > name + len) strcpy(name + len, p); return name; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro6146.21%342.86%
paolo giarrussopaolo giarrusso4836.36%114.29%
richard weinbergerrichard weinberger2216.67%228.57%
nick pigginnick piggin10.76%114.29%
Total132100.00%7100.00%


static char *dentry_name(struct dentry *dentry) { char *name = __getname(); if (!name) return NULL; return __dentry_name(dentry, name); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro3188.57%150.00%
paolo giarrussopaolo giarrusso411.43%150.00%
Total35100.00%2100.00%


static char *inode_name(struct inode *ino) { struct dentry *dentry; char *name; dentry = d_find_alias(ino); if (!dentry) return NULL; name = dentry_name(dentry); dput(dentry); return name; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso2650.98%133.33%
al viroal viro1325.49%133.33%
nick pigginnick piggin1223.53%133.33%
Total51100.00%3100.00%


static char *follow_link(char *link) { int len, n; char *name, *resolved, *end; name = __getname(); if (!name) { n = -ENOMEM; goto out_free; } n = hostfs_do_readlink(link, name, PATH_MAX); if (n < 0) goto out_free; else if (n == PATH_MAX) { n = -E2BIG; goto out_free; } if (*name == '/') return name; end = strrchr(link, '/'); if (end == NULL) return name; *(end + 1) = '\0'; len = strlen(link) + strlen(name) + 1; resolved = kmalloc(len, GFP_KERNEL); if (resolved == NULL) { n = -ENOMEM; goto out_free; } sprintf(resolved, "%s%s", link, name); __putname(name); kfree(link); return resolved; out_free: __putname(name); return ERR_PTR(n); }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso17086.73%133.33%
richard weinbergerrichard weinberger2512.76%133.33%
wang congwang cong10.51%133.33%
Total196100.00%3100.00%


static struct inode *hostfs_iget(struct super_block *sb) { struct inode *inode = new_inode(sb); if (!inode) return ERR_PTR(-ENOMEM); return inode; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells3592.11%133.33%
al viroal viro37.89%266.67%
Total38100.00%3100.00%


static int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) { /* * do_statfs uses struct statfs64 internally, but the linux kernel * struct statfs still has 32-bit versions for most of these fields, * so we convert them here */ int err; long long f_blocks; long long f_bfree; long long f_bavail; long long f_files; long long f_ffree; err = do_statfs(dentry->d_sb->s_fs_info, &sf->f_bsize, &f_blocks, &f_bfree, &f_bavail, &f_files, &f_ffree, &sf->f_fsid, sizeof(sf->f_fsid), &sf->f_namelen); if (err) return err; sf->f_blocks = f_blocks; sf->f_bfree = f_bfree; sf->f_bavail = f_bavail; sf->f_files = f_files; sf->f_ffree = f_ffree; sf->f_type = HOSTFS_SUPER_MAGIC; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso12694.03%120.00%
david howellsdavid howells53.73%120.00%
james hoganjames hogan10.75%120.00%
jeff dikejeff dike10.75%120.00%
al viroal viro10.75%120.00%
Total134100.00%5100.00%


static struct inode *hostfs_alloc_inode(struct super_block *sb) { struct hostfs_inode_info *hi; hi = kmalloc(sizeof(*hi), GFP_KERNEL_ACCOUNT); if (hi == NULL) return NULL; hi->fd = -1; hi->mode = 0; inode_init_once(&hi->vfs_inode); mutex_init(&hi->open_mutex); return &hi->vfs_inode; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso5877.33%120.00%
richard weinbergerrichard weinberger810.67%120.00%
james hoganjames hogan79.33%120.00%
al viroal viro11.33%120.00%
vladimir davydovvladimir davydov11.33%120.00%
Total75100.00%5100.00%


static void hostfs_evict_inode(struct inode *inode) { truncate_inode_pages_final(&inode->i_data); clear_inode(inode); if (HOSTFS_I(inode)->fd != -1) { close_file(&HOSTFS_I(inode)->fd); HOSTFS_I(inode)->fd = -1; } }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso4576.27%120.00%
mark fashehmark fasheh711.86%120.00%
al viroal viro58.47%120.00%
johannes weinerjohannes weiner11.69%120.00%
jan karajan kara11.69%120.00%
Total59100.00%5100.00%


static void hostfs_i_callback(struct rcu_head *head) { struct inode *inode = container_of(head, struct inode, i_rcu); kfree(HOSTFS_I(inode)); }

Contributors

PersonTokensPropCommitsCommitProp
nick pigginnick piggin1852.94%150.00%
paolo giarrussopaolo giarrusso1647.06%150.00%
Total34100.00%2100.00%


static void hostfs_destroy_inode(struct inode *inode) { call_rcu(&inode->i_rcu, hostfs_i_callback); }

Contributors

PersonTokensPropCommitsCommitProp
nick pigginnick piggin21100.00%1100.00%
Total21100.00%1100.00%


static int hostfs_show_options(struct seq_file *seq, struct dentry *root) { const char *root_path = root->d_sb->s_fs_info; size_t offset = strlen(root_ino) + 1; if (strlen(root_path) > offset) seq_show_option(seq, root_path + offset, NULL); if (append) seq_puts(seq, ",append"); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
miklos szeredimiklos szeredi5171.83%120.00%
richard weinbergerrichard weinberger1115.49%120.00%
al viroal viro68.45%240.00%
kees cookkees cook34.23%120.00%
Total71100.00%5100.00%

static const struct super_operations hostfs_sbops = { .alloc_inode = hostfs_alloc_inode, .destroy_inode = hostfs_destroy_inode, .evict_inode = hostfs_evict_inode, .statfs = hostfs_statfs, .show_options = hostfs_show_options, };
static int hostfs_readdir(struct file *file, struct dir_context *ctx) { void *dir; char *name; unsigned long long next, ino; int error, len; unsigned int type; name = dentry_name(file->f_path.dentry); if (name == NULL) return -ENOMEM; dir = open_dir(name, &error); __putname(name); if (dir == NULL) return -error; next = ctx->pos; seek_dir(dir, next); while ((name = read_dir(dir, &next, &ino, &len, &type)) != NULL) { if (!dir_emit(ctx, name, len, ino, type)) break; ctx->pos = next; } close_dir(dir); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso12579.62%114.29%
al viroal viro138.28%228.57%
geert uytterhoevengeert uytterhoeven85.10%114.29%
richard weinbergerrichard weinberger74.46%114.29%
josef sipekjosef sipek31.91%114.29%
james hoganjames hogan10.64%114.29%
Total157100.00%7100.00%


static int hostfs_open(struct inode *ino, struct file *file) { char *name; fmode_t mode; int err; int r, w, fd; mode = file->f_mode & (FMODE_READ | FMODE_WRITE); if ((mode & HOSTFS_I(ino)->mode) == mode) return 0; mode |= HOSTFS_I(ino)->mode; retry: r = w = 0; if (mode & FMODE_READ) r = 1; if (mode & FMODE_WRITE) r = w = 1; name = dentry_name(file->f_path.dentry); if (name == NULL) return -ENOMEM; fd = open_file(name, r, w, append); __putname(name); if (fd < 0) return fd; mutex_lock(&HOSTFS_I(ino)->open_mutex); /* somebody else had handled it first? */ if ((mode & HOSTFS_I(ino)->mode) == mode) { mutex_unlock(&HOSTFS_I(ino)->open_mutex); close_file(&fd); return 0; } if ((mode | HOSTFS_I(ino)->mode) != mode) { mode |= HOSTFS_I(ino)->mode; mutex_unlock(&HOSTFS_I(ino)->open_mutex); close_file(&fd); goto retry; } if (HOSTFS_I(ino)->fd == -1) { HOSTFS_I(ino)->fd = fd; } else { err = replace_file(fd, HOSTFS_I(ino)->fd); close_file(&fd); if (err < 0) { mutex_unlock(&HOSTFS_I(ino)->open_mutex); return err; } } HOSTFS_I(ino)->mode = mode; mutex_unlock(&HOSTFS_I(ino)->open_mutex); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro15646.43%327.27%
paolo giarrussopaolo giarrusso13740.77%19.09%
richard weinbergerrichard weinberger3911.61%545.45%
josef sipekjosef sipek30.89%19.09%
james hoganjames hogan10.30%19.09%
Total336100.00%11100.00%


static int hostfs_file_release(struct inode *inode, struct file *file) { filemap_write_and_wait(inode->i_mapping); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
richard weinbergerrichard weinberger26100.00%1100.00%
Total26100.00%1100.00%


static int hostfs_fsync(struct file *file, loff_t start, loff_t end, int datasync) { struct inode *inode = file->f_mapping->host; int ret; ret = filemap_write_and_wait_range(inode->i_mapping, start, end); if (ret) return ret; inode_lock(inode); ret = fsync_file(HOSTFS_I(inode)->fd, datasync); inode_unlock(inode); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
josef bacikjosef bacik5365.43%116.67%
paolo giarrussopaolo giarrusso2125.93%233.33%
christoph hellwigchristoph hellwig44.94%116.67%
al viroal viro22.47%116.67%
james hoganjames hogan11.23%116.67%
Total81100.00%6100.00%

static const struct file_operations hostfs_file_fops = { .llseek = generic_file_llseek, .splice_read = generic_file_splice_read, .read_iter = generic_file_read_iter, .write_iter = generic_file_write_iter, .mmap = generic_file_mmap, .open = hostfs_open, .release = hostfs_file_release, .fsync = hostfs_fsync, }; static const struct file_operations hostfs_dir_fops = { .llseek = generic_file_llseek, .iterate_shared = hostfs_readdir, .read = generic_read_dir, .open = hostfs_open, .fsync = hostfs_fsync, };
static int hostfs_writepage(struct page *page, struct writeback_control *wbc) { struct address_space *mapping = page->mapping; struct inode *inode = mapping->host; char *buffer; loff_t base = page_offset(page); int count = PAGE_SIZE; int end_index = inode->i_size >> PAGE_SHIFT; int err; if (page->index >= end_index) count = inode->i_size & (PAGE_SIZE-1); buffer = kmap(page); err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count); if (err != count) { ClearPageUptodate(page); goto out; } if (base > inode->i_size) inode->i_size = base; if (PageError(page)) ClearPageError(page); err = 0; out: kunmap(page); unlock_page(page); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso16094.12%125.00%
richard weinbergerrichard weinberger63.53%125.00%
kirill a. shutemovkirill a. shutemov31.76%125.00%
james hoganjames hogan10.59%125.00%
Total170100.00%4100.00%


static int hostfs_readpage(struct file *file, struct page *page) { char *buffer; loff_t start = page_offset(page); int bytes_read, ret = 0; buffer = kmap(page); bytes_read = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer, PAGE_SIZE); if (bytes_read < 0) { ClearPageUptodate(page); SetPageError(page); ret = bytes_read; goto out; } memset(buffer + bytes_read, 0, PAGE_SIZE - bytes_read); ClearPageError(page); SetPageUptodate(page); out: flush_dcache_page(page); kunmap(page); unlock_page(page); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso9170.54%116.67%
richard weinbergerrichard weinberger3527.13%350.00%
kirill a. shutemovkirill a. shutemov21.55%116.67%
james hoganjames hogan10.78%116.67%
Total129100.00%6100.00%


static int hostfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata) { pgoff_t index = pos >> PAGE_SHIFT; *pagep = grab_cache_page_write_begin(mapping, index, flags); if (!*pagep) return -ENOMEM; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
nick pigginnick piggin3855.88%240.00%
paolo giarrussopaolo giarrusso2841.18%120.00%
kirill a. shutemovkirill a. shutemov11.47%120.00%
james hoganjames hogan11.47%120.00%
Total68100.00%5100.00%


static int hostfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata) { struct inode *inode = mapping->host; void *buffer; unsigned from = pos & (PAGE_SIZE - 1); int err; buffer = kmap(page); err = write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer + from, copied); kunmap(page); if (!PageUptodate(page) && err == PAGE_SIZE) SetPageUptodate(page); /* * If err > 0, write_file has added err to pos, so we are comparing * i_size against the last byte written. */ if (err > 0 && (pos > inode->i_size)) inode->i_size = pos; unlock_page(page); put_page(page); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso8760.00%120.00%
nick pigginnick piggin5336.55%120.00%
kirill a. shutemovkirill a. shutemov32.07%120.00%
jeff dikejeff dike10.69%120.00%
james hoganjames hogan10.69%120.00%
Total145100.00%5100.00%

static const struct address_space_operations hostfs_aops = { .writepage = hostfs_writepage, .readpage = hostfs_readpage, .set_page_dirty = __set_page_dirty_nobuffers, .write_begin = hostfs_write_begin, .write_end = hostfs_write_end, };
static int read_name(struct inode *ino, char *name) { dev_t rdev; struct hostfs_stat st; int err = stat_file(name, &st, -1); if (err) return err; /* Reencode maj and min with the kernel encoding.*/ rdev = MKDEV(st.maj, st.min); switch (st.mode & S_IFMT) { case S_IFLNK: ino->i_op = &hostfs_link_iops; break; case S_IFDIR: ino->i_op = &hostfs_dir_iops; ino->i_fop = &hostfs_dir_fops; break; case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK: init_special_inode(ino, st.mode & S_IFMT, rdev); ino->i_op = &hostfs_iops; break; case S_IFREG: ino->i_op = &hostfs_iops; ino->i_fop = &hostfs_file_fops; ino->i_mapping->a_ops = &hostfs_aops; break; default: return -EIO; } ino->i_ino = st.ino; ino->i_mode = st.mode; set_nlink(ino, st.nlink); i_uid_write(ino, st.uid); i_gid_write(ino, st.gid); ino->i_atime = st.atime; ino->i_mtime = st.mtime; ino->i_ctime = st.ctime; ino->i_size = st.size; ino->i_blocks = st.blocks; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro15562.75%333.33%
paolo giarrussopaolo giarrusso7028.34%222.22%
richard weinbergerrichard weinberger93.64%111.11%
eric w. biedermaneric w. biederman83.24%111.11%
miklos szeredimiklos szeredi41.62%111.11%
jeff dikejeff dike10.40%111.11%
Total247100.00%9100.00%


static int hostfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) { struct inode *inode; char *name; int error, fd; inode = hostfs_iget(dir->i_sb); if (IS_ERR(inode)) { error = PTR_ERR(inode); goto out; } error = -ENOMEM; name = dentry_name(dentry); if (name == NULL) goto out_put; fd = file_create(name, mode & 0777); if (fd < 0) error = fd; else error = read_name(inode, name); __putname(name); if (error) goto out_put; HOSTFS_I(inode)->fd = fd; HOSTFS_I(inode)->mode = FMODE_READ | FMODE_WRITE; d_instantiate(dentry, inode); return 0; out_put: iput(inode); out: return error; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso15188.82%114.29%
david howellsdavid howells137.65%114.29%
al viroal viro42.35%342.86%
richard weinbergerrichard weinberger10.59%114.29%
james hoganjames hogan10.59%114.29%
Total170100.00%7100.00%


static struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry, unsigned int flags) { struct inode *inode; char *name; int err; inode = hostfs_iget(ino->i_sb); if (IS_ERR(inode)) { err = PTR_ERR(inode); goto out; } err = -ENOMEM; name = dentry_name(dentry); if (name == NULL) goto out_put; err = read_name(inode, name); __putname(name); if (err == -ENOENT) { iput(inode); inode = NULL; } else if (err) goto out_put; d_add(dentry, inode); return NULL; out_put: iput(inode); out: return ERR_PTR(err); }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso13087.84%120.00%
david howellsdavid howells138.78%120.00%
al viroal viro42.70%240.00%
james hoganjames hogan10.68%120.00%
Total148100.00%5100.00%


static int hostfs_link(struct dentry *to, struct inode *ino, struct dentry *from) { char *from_name, *to_name; int err; if ((from_name = dentry_name(from)) == NULL) return -ENOMEM; to_name = dentry_name(to); if (to_name == NULL) { __putname(from_name); return -ENOMEM; } err = link_file(to_name, from_name); __putname(from_name); __putname(to_name); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso8994.68%125.00%
al viroal viro44.26%250.00%
james hoganjames hogan11.06%125.00%
Total94100.00%4100.00%


static int hostfs_unlink(struct inode *ino, struct dentry *dentry) { char *file; int err; if (append) return -EPERM; if ((file = dentry_name(dentry)) == NULL) return -ENOMEM; err = unlink_file(file); __putname(file); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso5282.54%120.00%
al viroal viro1015.87%360.00%
james hoganjames hogan11.59%120.00%
Total63100.00%5100.00%


static int hostfs_symlink(struct inode *ino, struct dentry *dentry, const char *to) { char *file; int err; if ((file = dentry_name(dentry)) == NULL) return -ENOMEM; err = make_symlink(file, to); __putname(file); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso5995.16%125.00%
al viroal viro23.23%250.00%
james hoganjames hogan11.61%125.00%
Total62100.00%4100.00%


static int hostfs_mkdir(struct inode *ino, struct dentry *dentry, umode_t mode) { char *file; int err; if ((file = dentry_name(dentry)) == NULL) return -ENOMEM; err = do_mkdir(file, mode); __putname(file); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso5693.33%120.00%
al viroal viro35.00%360.00%
james hoganjames hogan11.67%120.00%
Total60100.00%5100.00%


static int hostfs_rmdir(struct inode *ino, struct dentry *dentry) { char *file; int err; if ((file = dentry_name(dentry)) == NULL) return -ENOMEM; err = do_rmdir(file); __putname(file); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso5294.55%125.00%
al viroal viro23.64%250.00%
james hoganjames hogan11.82%125.00%
Total55100.00%4100.00%


static int hostfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) { struct inode *inode; char *name; int err; inode = hostfs_iget(dir->i_sb); if (IS_ERR(inode)) { err = PTR_ERR(inode); goto out; } err = -ENOMEM; name = dentry_name(dentry); if (name == NULL) goto out_put; init_special_inode(inode, mode, dev); err = do_mknod(name, mode, MAJOR(dev), MINOR(dev)); if (err) goto out_free; err = read_name(inode, name); __putname(name); if (err) goto out_put; d_instantiate(dentry, inode); return 0; out_free: __putname(name); out_put: iput(inode); out: return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso13278.57%116.67%
al viroal viro158.93%350.00%
david howellsdavid howells137.74%116.67%
johannes stezenbachjohannes stezenbach84.76%116.67%
Total168100.00%6100.00%


static int hostfs_rename2(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { char *old_name, *new_name; int err; if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) return -EINVAL; old_name = dentry_name(old_dentry); if (old_name == NULL) return -ENOMEM; new_name = dentry_name(new_dentry); if (new_name == NULL) { __putname(old_name); return -ENOMEM; } if (!flags) err = rename_file(old_name, new_name); else err = rename2_file(old_name, new_name, flags); __putname(old_name); __putname(new_name); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso7253.33%120.00%
miklos szeredimiklos szeredi5742.22%120.00%
al viroal viro53.70%240.00%
james hoganjames hogan10.74%120.00%
Total135100.00%5100.00%


static int hostfs_permission(struct inode *ino, int desired) { char *name; int r = 0, w = 0, x = 0, err; if (desired & MAY_NOT_BLOCK) return -ECHILD; if (desired & MAY_READ) r = 1; if (desired & MAY_WRITE) w = 1; if (desired & MAY_EXEC) x = 1; name = inode_name(ino); if (name == NULL) return -ENOMEM; if (S_ISCHR(ino->i_mode) || S_ISBLK(ino->i_mode) || S_ISFIFO(ino->i_mode) || S_ISSOCK(ino->i_mode)) err = 0; else err = access_file(name, r, w, x); __putname(name); if (!err) err = generic_permission(ino, desired); return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso14791.88%228.57%
nick pigginnick piggin85.00%114.29%
al viroal viro31.88%228.57%
christoph hellwigchristoph hellwig10.62%114.29%
james hoganjames hogan10.62%114.29%
Total160100.00%7100.00%


static int hostfs_setattr(struct dentry *dentry, struct iattr *attr) { struct inode *inode = d_inode(dentry); struct hostfs_iattr attrs; char *name; int err; int fd = HOSTFS_I(inode)->fd; err = setattr_prepare(dentry, attr); if (err) return err; if (append) attr->ia_valid &= ~ATTR_SIZE; attrs.ia_valid = 0; if (attr->ia_valid & ATTR_MODE) { attrs.ia_valid |= HOSTFS_ATTR_MODE; attrs.ia_mode = attr->ia_mode; } if (attr->ia_valid & ATTR_UID) { attrs.ia_valid |= HOSTFS_ATTR_UID; attrs.ia_uid = from_kuid(&init_user_ns, attr->ia_uid); } if (attr->ia_valid & ATTR_GID) { attrs.ia_valid |= HOSTFS_ATTR_GID; attrs.ia_gid = from_kgid(&init_user_ns, attr->ia_gid); } if (attr->ia_valid & ATTR_SIZE) { attrs.ia_valid |= HOSTFS_ATTR_SIZE; attrs.ia_size = attr->ia_size; } if (attr->ia_valid & ATTR_ATIME) { attrs.ia_valid |= HOSTFS_ATTR_ATIME; attrs.ia_atime = attr->ia_atime; } if (attr->ia_valid & ATTR_MTIME) { attrs.ia_valid |= HOSTFS_ATTR_MTIME; attrs.ia_mtime = attr->ia_mtime; } if (attr->ia_valid & ATTR_CTIME) { attrs.ia_valid |= HOSTFS_ATTR_CTIME; attrs.ia_ctime = attr->ia_ctime; } if (attr->ia_valid & ATTR_ATIME_SET) { attrs.ia_valid |= HOSTFS_ATTR_ATIME_SET; } if (attr->ia_valid & ATTR_MTIME_SET) { attrs.ia_valid |= HOSTFS_ATTR_MTIME_SET; } name = dentry_name(dentry); if (name == NULL) return -ENOMEM; err = set_attr(name, &attrs, fd); __putname(name); if (err) return err; if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size != i_size_read(inode)) truncate_setsize(inode, attr->ia_size); setattr_copy(inode, attr); mark_inode_dirty(inode); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso30079.79%220.00%
christoph hellwigchristoph hellwig379.84%110.00%
eric w. biedermaneric w. biederman123.19%110.00%
alberto bertoglialberto bertogli112.93%110.00%
marco stornellimarco stornelli92.39%110.00%
david howellsdavid howells30.80%110.00%
jan karajan kara20.53%110.00%
james hoganjames hogan10.27%110.00%
al viroal viro10.27%110.00%
Total376100.00%10100.00%

static const struct inode_operations hostfs_iops = { .permission = hostfs_permission, .setattr = hostfs_setattr, }; static const struct inode_operations hostfs_dir_iops = { .create = hostfs_create, .lookup = hostfs_lookup, .link = hostfs_link, .unlink = hostfs_unlink, .symlink = hostfs_symlink, .mkdir = hostfs_mkdir, .rmdir = hostfs_rmdir, .mknod = hostfs_mknod, .rename = hostfs_rename2, .permission = hostfs_permission, .setattr = hostfs_setattr, };
static const char *hostfs_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) { char *link; if (!dentry) return ERR_PTR(-ECHILD); link = kmalloc(PATH_MAX, GFP_KERNEL); if (link) { char *path = dentry_name(dentry); int err = -ENOMEM; if (path) { err = hostfs_do_readlink(path, link, PATH_MAX); if (err == PATH_MAX) err = -E2BIG; __putname(path); } if (err < 0) { kfree(link); return ERR_PTR(err); } } else { return ERR_PTR(-ENOMEM); } set_delayed_call(done, kfree_link, link); return link; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro9465.73%675.00%
paolo giarrussopaolo giarrusso4833.57%112.50%
wang congwang cong10.70%112.50%
Total143100.00%8100.00%

static const struct inode_operations hostfs_link_iops = { .get_link = hostfs_get_link, };
static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent) { struct inode *root_inode; char *host_root_path, *req_root = d; int err; sb->s_blocksize = 1024; sb->s_blocksize_bits = 10; sb->s_magic = HOSTFS_SUPER_MAGIC; sb->s_op = &hostfs_sbops; sb->s_d_op = &simple_dentry_operations; sb->s_maxbytes = MAX_LFS_FILESIZE; /* NULL is printed as <NULL> by sprintf: avoid that. */ if (req_root == NULL) req_root = ""; err = -ENOMEM; sb->s_fs_info = host_root_path = kmalloc(strlen(root_ino) + strlen(req_root) + 2, GFP_KERNEL); if (host_root_path == NULL) goto out; sprintf(host_root_path, "%s/%s", root_ino, req_root); root_inode = new_inode(sb); if (!root_inode) goto out; err = read_name(root_inode, host_root_path); if (err) goto out_put; if (S_ISLNK(root_inode->i_mode)) { char *name = follow_link(host_root_path); if (IS_ERR(name)) { err = PTR_ERR(name); goto out_put; } err = read_name(root_inode, name); kfree(name); if (err) goto out_put; } err = -ENOMEM; sb->s_root = d_make_root(root_inode); if (sb->s_root == NULL) goto out; return 0; out_put: iput(root_inode); out: return err; }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso16964.26%325.00%
al viroal viro7428.14%650.00%
david howellsdavid howells93.42%18.33%
wolfgang illmeyerwolfgang illmeyer62.28%18.33%
dan carpenterdan carpenter51.90%18.33%
Total263100.00%12100.00%


static struct dentry *hostfs_read_sb(struct file_system_type *type, int flags, const char *dev_name, void *data) { return mount_nodev(type, flags, data, hostfs_fill_sb_common); }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso3389.19%150.00%
al viroal viro410.81%150.00%
Total37100.00%2100.00%


static void hostfs_kill_sb(struct super_block *s) { kill_anon_super(s); kfree(s->s_fs_info); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro23100.00%1100.00%
Total23100.00%1100.00%

static struct file_system_type hostfs_type = { .owner = THIS_MODULE, .name = "hostfs", .mount = hostfs_read_sb, .kill_sb = hostfs_kill_sb, .fs_flags = 0, }; MODULE_ALIAS_FS("hostfs");
static int __init init_hostfs(void) { return register_filesystem(&hostfs_type); }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso16100.00%1100.00%
Total16100.00%1100.00%


static void __exit exit_hostfs(void) { unregister_filesystem(&hostfs_type); }

Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso15100.00%1100.00%
Total15100.00%1100.00%

module_init(init_hostfs) module_exit(exit_hostfs) MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
paolo giarrussopaolo giarrusso320467.48%1211.21%
al viroal viro72015.16%3431.78%
richard weinbergerrichard weinberger2054.32%1614.95%
nick pigginnick piggin1563.29%54.67%
miklos szeredimiklos szeredi1222.57%43.74%
david howellsdavid howells911.92%32.80%
josef bacikjosef bacik531.12%10.93%
christoph hellwigchristoph hellwig450.95%43.74%
james hoganjames hogan280.59%32.80%
eric w. biedermaneric w. biederman250.53%21.87%
alberto bertoglialberto bertogli110.23%10.93%
kirill a. shutemovkirill a. shutemov90.19%10.93%
marco stornellimarco stornelli90.19%10.93%
geert uytterhoevengeert uytterhoeven80.17%10.93%
johannes stezenbachjohannes stezenbach80.17%10.93%
mark fashehmark fasheh70.15%10.93%
wolfgang illmeyerwolfgang illmeyer60.13%10.93%
josef sipekjosef sipek60.13%10.93%
arjan van de venarjan van de ven60.13%21.87%
jeff dikejeff dike50.11%21.87%
dan carpenterdan carpenter50.11%10.93%
jiri kosinajiri kosina30.06%10.93%
tejun heotejun heo30.06%10.93%
kees cookkees cook30.06%10.93%
jan karajan kara30.06%21.87%
jens axboejens axboe20.04%10.93%
wang congwang cong20.04%10.93%
josef 'jeff' sipekjosef 'jeff' sipek10.02%10.93%
vladimir davydovvladimir davydov10.02%10.93%
johannes weinerjohannes weiner10.02%10.93%
Total4748100.00%107100.00%
Directory: fs/hostfs
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.