/* * hfs_remove() * * This serves as both unlink() and rmdir() in the inode_operations * structure for regular HFS directories. The purpose is to delete * an existing child, given the inode for the parent directory and * the name (and its length) of the existing directory. * * HFS does not have hardlinks, so both rmdir and unlink set the * link count to 0. The only difference is the emptiness check. */ static int hfs_remove(struct inode *dir, struct dentry *dentry) { struct inode *inode = dentry->d_inode; int res; if (S_ISDIR(inode->i_mode) && inode->i_size != 2) return -ENOTEMPTY; res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name); if (res) return res; clear_nlink(inode); inode->i_ctime = CURRENT_TIME_SEC; hfs_delete_inode(inode); mark_inode_dirty(inode); return 0; }
/* * hfs_rmdir() * * This is the rmdir() entry in the inode_operations structure for * regular HFS directories. The purpose is to delete an existing * directory, given the inode for the parent directory and the name * (and its length) of the existing directory. */ int hfs_rmdir(struct inode *dir, struct dentry *dentry) { struct inode *inode; int res; inode = dentry->d_inode; if (inode->i_size != 2) return -ENOTEMPTY; res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name); if (res) return res; inode->i_nlink = 0; inode->i_ctime = CURRENT_TIME; hfs_delete_inode(inode); mark_inode_dirty(inode); return 0; }
/* * hfs_unlink() * * This is the unlink() entry in the inode_operations structure for * regular HFS directories. The purpose is to delete an existing * file, given the inode for the parent directory and the name * (and its length) of the existing file. */ int hfs_unlink(struct inode *dir, struct dentry *dentry) { struct inode *inode; int res; inode = dentry->d_inode; res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name); if (res) return res; inode->i_nlink--; hfs_delete_inode(inode); inode->i_ctime = CURRENT_TIME; mark_inode_dirty(inode); return res; }
/* * hfs_mkdir() * * This is the mkdir() entry in the inode_operations structure for * regular HFS directories. The purpose is to create a new directory * in a directory, given the inode for the parent directory and the * name (and its length) of the new directory. */ static int hfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) { struct inode *inode; int res; inode = hfs_new_inode(dir, &dentry->d_name, S_IFDIR | mode); if (!inode) return -ENOSPC; res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); if (res) { inode->i_nlink = 0; hfs_delete_inode(inode); iput(inode); return res; } d_instantiate(dentry, inode); mark_inode_dirty(inode); return 0; }
static int hfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, struct nameidata *nd) { struct inode *inode; int res; inode = hfs_new_inode(dir, &dentry->d_name, mode); if (!inode) return -ENOSPC; res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); if (res) { clear_nlink(inode); hfs_delete_inode(inode); iput(inode); return res; } d_instantiate(dentry, inode); mark_inode_dirty(inode); return 0; }