cregit-Linux how code gets into the kernel

Release 4.11 fs/affs/namei.c

Directory: fs/affs
/*
 *  linux/fs/affs/namei.c
 *
 *  (c) 1996  Hans-Joachim Widmaier - Rewritten
 *
 *  (C) 1993  Ray Burr - Modified for Amiga FFS filesystem.
 *
 *  (C) 1991  Linus Torvalds - minix filesystem
 */

#include "affs.h"
#include <linux/exportfs.h>


typedef int (*toupper_t)(int);

/* Simple toupper() for DOS\1 */


static int affs_toupper(int ch) { return ch >= 'a' && ch <= 'z' ? ch -= ('a' - 'A') : ch; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)28100.00%2100.00%
Total28100.00%2100.00%

/* International toupper() for DOS\3 ("international") */
static int affs_intl_toupper(int ch) { return (ch >= 'a' && ch <= 'z') || (ch >= 0xE0 && ch <= 0xFE && ch != 0xF7) ? ch - ('a' - 'A') : ch; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)44100.00%2100.00%
Total44100.00%2100.00%


static inline toupper_t affs_get_toupper(struct super_block *sb) { return affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL) ? affs_intl_toupper : affs_toupper; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds1551.72%125.00%
Linus Torvalds (pre-git)620.69%125.00%
Fabian Frederick517.24%125.00%
Brian Gerst310.34%125.00%
Total29100.00%4100.00%

/* * Note: the dentry argument is the parent dentry. */
static inline int __affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr, toupper_t toupper, bool notruncate) { const u8 *name = qstr->name; unsigned long hash; int retval; u32 len; retval = affs_check_name(qstr->name, qstr->len, notruncate); if (retval) return retval; hash = init_name_hash(dentry); len = min(qstr->len, AFFSNAMEMAX); for (; len > 0; name++, len--) hash = partial_name_hash(toupper(*name), hash); qstr->hash = end_name_hash(hash); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)6654.55%222.22%
Linus Torvalds3932.23%444.44%
Fabian Frederick1613.22%333.33%
Total121100.00%9100.00%


static int affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr) { return __affs_hash_dentry(dentry, qstr, affs_toupper, affs_nofilenametruncate(dentry)); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds1546.88%240.00%
Linus Torvalds (pre-git)1134.38%120.00%
Fabian Frederick515.62%120.00%
Nicholas Piggin13.12%120.00%
Total32100.00%5100.00%


static int affs_intl_hash_dentry(const struct dentry *dentry, struct qstr *qstr) { return __affs_hash_dentry(dentry, qstr, affs_intl_toupper, affs_nofilenametruncate(dentry)); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds2062.50%240.00%
Linus Torvalds (pre-git)618.75%120.00%
Fabian Frederick515.62%120.00%
Nicholas Piggin13.12%120.00%
Total32100.00%5100.00%


static inline int __affs_compare_dentry(unsigned int len, const char *str, const struct qstr *name, toupper_t toupper, bool notruncate) { const u8 *aname = str; const u8 *bname = name->name; /* * 'str' is the name of an already existing dentry, so the name * must be valid. 'name' must be validated first. */ if (affs_check_name(name->name, name->len, notruncate)) return 1; /* * If the names are longer than the allowed 30 chars, * the excess is ignored, so their length may differ. */ if (len >= AFFSNAMEMAX) { if (name->len < AFFSNAMEMAX) return 1; len = AFFSNAMEMAX; } else if (len != name->len) return 1; for (; len > 0; len--) if (toupper(*aname++) != toupper(*bname++)) return 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)6045.80%450.00%
Linus Torvalds4735.88%112.50%
Nicholas Piggin1612.21%112.50%
Fabian Frederick86.11%225.00%
Total131100.00%8100.00%


static int affs_compare_dentry(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) { return __affs_compare_dentry(len, str, name, affs_toupper, affs_nofilenametruncate(dentry)); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds2352.27%125.00%
Nicholas Piggin1636.36%125.00%
Fabian Frederick49.09%125.00%
Al Viro12.27%125.00%
Total44100.00%4100.00%


static int affs_intl_compare_dentry(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) { return __affs_compare_dentry(len, str, name, affs_intl_toupper, affs_nofilenametruncate(dentry)); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds2250.00%125.00%
Nicholas Piggin1738.64%125.00%
Fabian Frederick49.09%125.00%
Al Viro12.27%125.00%
Total44100.00%4100.00%

/* * NOTE! unlike strncmp, affs_match returns 1 for success, 0 for failure. */
static inline int affs_match(struct dentry *dentry, const u8 *name2, toupper_t toupper) { const u8 *name = dentry->d_name.name; int len = dentry->d_name.len; if (len >= AFFSNAMEMAX) { if (*name2 < AFFSNAMEMAX) return 0; len = AFFSNAMEMAX; } else if (len != *name2) return 0; for (name2++; len > 0; len--) if (toupper(*name++) != toupper(*name2++)) return 0; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5652.34%360.00%
Linus Torvalds4844.86%120.00%
Fabian Frederick32.80%120.00%
Total107100.00%5100.00%


int affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len) { toupper_t toupper = affs_get_toupper(sb); u32 hash; hash = len = min(len, AFFSNAMEMAX); for (; len > 0; len--) hash = (hash * 13 + toupper(*name++)) & 0x7ff; return hash % AFFS_SB(sb)->s_hashsize; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3950.00%228.57%
Linus Torvalds3443.59%228.57%
Brian Gerst33.85%114.29%
Fabian Frederick22.56%228.57%
Total78100.00%7100.00%


static struct buffer_head * affs_find_entry(struct inode *dir, struct dentry *dentry) { struct super_block *sb = dir->i_sb; struct buffer_head *bh; toupper_t toupper = affs_get_toupper(sb); u32 key; pr_debug("%s(\"%pd\")\n", __func__, dentry); bh = affs_bread(sb, dir->i_ino); if (!bh) return ERR_PTR(-EIO); key = be32_to_cpu(AFFS_HEAD(bh)->table[affs_hash_name(sb, dentry->d_name.name, dentry->d_name.len)]); for (;;) { affs_brelse(bh); if (key == 0) return NULL; bh = affs_bread(sb, key); if (!bh) return ERR_PTR(-EIO); if (affs_match(dentry, AFFS_TAIL(sb, bh)->name, toupper)) return bh; key = be32_to_cpu(AFFS_TAIL(sb, bh)->hash_chain); } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11663.74%457.14%
Linus Torvalds6334.62%114.29%
Fabian Frederick21.10%114.29%
Al Viro10.55%114.29%
Total182100.00%7100.00%


struct dentry * affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) { struct super_block *sb = dir->i_sb; struct buffer_head *bh; struct inode *inode = NULL; pr_debug("%s(\"%pd\")\n", __func__, dentry); affs_lock_dir(dir); bh = affs_find_entry(dir, dentry); affs_unlock_dir(dir); if (IS_ERR(bh)) return ERR_CAST(bh); if (bh) { u32 ino = bh->b_blocknr; /* store the real header ino in d_fsdata for faster lookups */ dentry->d_fsdata = (void *)(long)ino; switch (be32_to_cpu(AFFS_TAIL(sb, bh)->stype)) { //link to dirs disabled //case ST_LINKDIR: case ST_LINKFILE: ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original); } affs_brelse(bh); inode = affs_iget(sb, ino); if (IS_ERR(inode)) return ERR_CAST(inode); } d_add(dentry, inode); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)9652.75%428.57%
Linus Torvalds7038.46%321.43%
David Howells84.40%214.29%
Al Viro42.20%214.29%
Fabian Frederick21.10%17.14%
Julia Lawall10.55%17.14%
Trond Myklebust10.55%17.14%
Total182100.00%14100.00%


int affs_unlink(struct inode *dir, struct dentry *dentry) { pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino, d_inode(dentry)->i_ino, dentry); return affs_remove_header(dentry); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2458.54%444.44%
Linus Torvalds717.07%111.11%
Roman Zippel49.76%111.11%
David Howells37.32%111.11%
Fabian Frederick24.88%111.11%
Geert Uytterhoeven12.44%111.11%
Total41100.00%9100.00%


int affs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) { struct super_block *sb = dir->i_sb; struct inode *inode; int error; pr_debug("%s(%lu,\"%pd\",0%ho)\n", __func__, dir->i_ino, dentry, mode); inode = affs_new_inode(dir); if (!inode) return -ENOSPC; inode->i_mode = mode; affs_mode_to_prot(inode); mark_inode_dirty(inode); inode->i_op = &affs_file_inode_operations; inode->i_fop = &affs_file_operations; inode->i_mapping->a_ops = affs_test_opt(AFFS_SB(sb)->s_flags, SF_OFS) ? &affs_aops_ofs : &affs_aops; error = affs_add_entry(dir, inode, dentry, ST_FILE); if (error) { clear_nlink(inode); iput(inode); return error; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10667.09%637.50%
Linus Torvalds3320.89%16.25%
Fabian Frederick85.06%318.75%
Al Viro42.53%318.75%
Miklos Szeredi31.90%16.25%
Brian Gerst31.90%16.25%
Trond Myklebust10.63%16.25%
Total158100.00%16100.00%


int affs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) { struct inode *inode; int error; pr_debug("%s(%lu,\"%pd\",0%ho)\n", __func__, dir->i_ino, dentry, mode); inode = affs_new_inode(dir); if (!inode) return -ENOSPC; inode->i_mode = S_IFDIR | mode; affs_mode_to_prot(inode); inode->i_op = &affs_dir_inode_operations; inode->i_fop = &affs_dir_operations; error = affs_add_entry(dir, inode, dentry, ST_USERDIR); if (error) { clear_nlink(inode); mark_inode_dirty(inode); iput(inode); return error; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)9173.39%440.00%
Linus Torvalds2520.16%110.00%
Miklos Szeredi32.42%110.00%
Fabian Frederick32.42%220.00%
Al Viro21.61%220.00%
Total124100.00%10100.00%


int affs_rmdir(struct inode *dir, struct dentry *dentry) { pr_debug("%s(dir=%lu, %lu \"%pd\")\n", __func__, dir->i_ino, d_inode(dentry)->i_ino, dentry); return affs_remove_header(dentry); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2970.73%228.57%
Roman Zippel49.76%114.29%
David Howells37.32%114.29%
Fabian Frederick24.88%114.29%
Linus Torvalds24.88%114.29%
Geert Uytterhoeven12.44%114.29%
Total41100.00%7100.00%


int affs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) { struct super_block *sb = dir->i_sb; struct buffer_head *bh; struct inode *inode; char *p; int i, maxlen, error; char c, lc; pr_debug("%s(%lu,\"%pd\" -> \"%s\")\n", __func__, dir->i_ino, dentry, symname); maxlen = AFFS_SB(sb)->s_hashsize * sizeof(u32) - 1; inode = affs_new_inode(dir); if (!inode) return -ENOSPC; inode->i_op = &affs_symlink_inode_operations; inode_nohighmem(inode); inode->i_data.a_ops = &affs_symlink_aops; inode->i_mode = S_IFLNK | 0777; affs_mode_to_prot(inode); error = -EIO; bh = affs_bread(sb, inode->i_ino); if (!bh) goto err; i = 0; p = (char *)AFFS_HEAD(bh)->table; lc = '/'; if (*symname == '/') { struct affs_sb_info *sbi = AFFS_SB(sb); while (*symname == '/') symname++; spin_lock(&sbi->symlink_lock); while (sbi->s_volume[i]) /* Cannot overflow */ *p++ = sbi->s_volume[i++]; spin_unlock(&sbi->symlink_lock); } while (i < maxlen && (c = *symname++)) { if (c == '.' && lc == '/' && *symname == '.' && symname[1] == '/') { *p++ = '/'; i++; symname += 2; lc = '/'; } else if (c == '.' && lc == '/' && *symname == '/') { symname++; lc = '/'; } else { *p++ = c; lc = c; i++; } if (lc == '/') while (*symname == '/') symname++; } *p = 0; mark_buffer_dirty_inode(bh, inode); affs_brelse(bh); mark_inode_dirty(inode); error = affs_add_entry(dir, inode, dentry, ST_SOFTLINK); if (error) goto err; return 0; err: clear_nlink(inode); mark_inode_dirty(inode); iput(inode); return error; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)34781.26%640.00%
Linus Torvalds358.20%213.33%
Al Viro347.96%320.00%
Brian Gerst51.17%16.67%
Miklos Szeredi30.70%16.67%
Fabian Frederick30.70%213.33%
Total427100.00%15100.00%


int affs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) { struct inode *inode = d_inode(old_dentry); pr_debug("%s(%lu, %lu, \"%pd\")\n", __func__, inode->i_ino, dir->i_ino, dentry); return affs_add_entry(dir, inode, dentry, ST_LINKFILE); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4881.36%337.50%
Linus Torvalds46.78%112.50%
David Howells35.08%112.50%
Fabian Frederick23.39%112.50%
Geert Uytterhoeven11.69%112.50%
Andrew Morton11.69%112.50%
Total59100.00%8100.00%


int affs_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { struct super_block *sb = old_dir->i_sb; struct buffer_head *bh = NULL; int retval; if (flags & ~RENAME_NOREPLACE) return -EINVAL; pr_debug("%s(old=%lu,\"%pd\" to new=%lu,\"%pd\")\n", __func__, old_dir->i_ino, old_dentry, new_dir->i_ino, new_dentry); retval = affs_check_name(new_dentry->d_name.name, new_dentry->d_name.len, affs_nofilenametruncate(old_dentry)); if (retval) return retval; /* Unlink destination if it already exists */ if (d_really_is_positive(new_dentry)) { retval = affs_remove_header(new_dentry); if (retval) return retval; } bh = affs_bread(sb, d_inode(old_dentry)->i_ino); if (!bh) return -EIO; /* Remove header from its parent directory. */ affs_lock_dir(old_dir); retval = affs_remove_hash(old_dir, bh); affs_unlock_dir(old_dir); if (retval) goto done; /* And insert it into the new directory with the new name. */ affs_copy_name(AFFS_TAIL(sb, bh)->name, new_dentry); affs_fix_checksum(sb, bh); affs_lock_dir(new_dir); retval = affs_insert_hash(new_dir, bh); affs_unlock_dir(new_dir); /* TODO: move it back to old_dir, if error? */ done: mark_buffer_dirty_inode(bh, retval ? old_dir : new_dir); affs_brelse(bh); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)13454.92%533.33%
Linus Torvalds7028.69%320.00%
Miklos Szeredi156.15%16.67%
Fabian Frederick72.87%213.33%
Andrew Morton72.87%16.67%
David Howells62.46%16.67%
Florin Malita41.64%16.67%
Geert Uytterhoeven10.41%16.67%
Total244100.00%15100.00%


static struct dentry *affs_get_parent(struct dentry *child) { struct inode *parent; struct buffer_head *bh; bh = affs_bread(child->d_sb, d_inode(child)->i_ino); if (!bh) return ERR_PTR(-EIO); parent = affs_iget(child->d_sb, be32_to_cpu(AFFS_TAIL(child->d_sb, bh)->parent)); brelse(bh); if (IS_ERR(parent)) return ERR_CAST(parent); return d_obtain_alias(parent); }

Contributors

PersonTokensPropCommitsCommitProp
Fabian Frederick98100.00%1100.00%
Total98100.00%1100.00%


static struct inode *affs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation) { struct inode *inode; if (!affs_validblock(sb, ino)) return ERR_PTR(-ESTALE); inode = affs_iget(sb, ino); if (IS_ERR(inode)) return ERR_CAST(inode); if (generation && inode->i_generation != generation) { iput(inode); return ERR_PTR(-ESTALE); } return inode; }

Contributors

PersonTokensPropCommitsCommitProp
Fabian Frederick90100.00%1100.00%
Total90100.00%1100.00%


static struct dentry *affs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { return generic_fh_to_dentry(sb, fid, fh_len, fh_type, affs_nfs_get_inode); }

Contributors

PersonTokensPropCommitsCommitProp
Fabian Frederick38100.00%1100.00%
Total38100.00%1100.00%


static struct dentry *affs_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type) { return generic_fh_to_parent(sb, fid, fh_len, fh_type, affs_nfs_get_inode); }

Contributors

PersonTokensPropCommitsCommitProp
Fabian Frederick38100.00%1100.00%
Total38100.00%1100.00%

const struct export_operations affs_export_ops = { .fh_to_dentry = affs_fh_to_dentry, .fh_to_parent = affs_fh_to_parent, .get_parent = affs_get_parent, }; const struct dentry_operations affs_dentry_operations = { .d_hash = affs_hash_dentry, .d_compare = affs_compare_dentry, }; const struct dentry_operations affs_intl_dentry_operations = { .d_hash = affs_intl_hash_dentry, .d_compare = affs_intl_compare_dentry, };

Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)131452.79%1325.00%
Linus Torvalds58223.38%611.54%
Fabian Frederick40616.31%917.31%
Nicholas Piggin512.05%23.85%
Al Viro481.93%917.31%
Miklos Szeredi240.96%23.85%
David Howells230.92%35.77%
Brian Gerst140.56%11.92%
Roman Zippel80.32%11.92%
Andrew Morton80.32%11.92%
Florin Malita40.16%11.92%
Geert Uytterhoeven40.16%11.92%
Trond Myklebust20.08%23.85%
Julia Lawall10.04%11.92%
Total2489100.00%52100.00%
Directory: fs/affs
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.