mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	[PATCH] ext4: initial copy of files from ext3
Start of the ext4 patch series. See Documentation/filesystems/ext4.txt for details. This is a simple copy of the files in fs/ext3 to fs/ext4 and /usr/incude/linux/ext3* to /usr/include/ex4* Signed-off-by: Dave Kleikamp <shaggy@austin.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
		
							parent
							
								
									502717f4e1
								
							
						
					
					
						commit
						ac27a0ec11
					
				
					 26 changed files with 16978 additions and 0 deletions
				
			
		
							
								
								
									
										12
									
								
								fs/ext4/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								fs/ext4/Makefile
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Makefile for the linux ext3-filesystem routines.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					obj-$(CONFIG_EXT3_FS) += ext3.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ext3-y	:= balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
 | 
				
			||||||
 | 
						   ioctl.o namei.o super.o symlink.o hash.o resize.o
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ext3-$(CONFIG_EXT3_FS_XATTR)	 += xattr.o xattr_user.o xattr_trusted.o
 | 
				
			||||||
 | 
					ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
 | 
				
			||||||
 | 
					ext3-$(CONFIG_EXT3_FS_SECURITY)	 += xattr_security.o
 | 
				
			||||||
							
								
								
									
										551
									
								
								fs/ext4/acl.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										551
									
								
								fs/ext4/acl.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,551 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * linux/fs/ext3/acl.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/init.h>
 | 
				
			||||||
 | 
					#include <linux/sched.h>
 | 
				
			||||||
 | 
					#include <linux/slab.h>
 | 
				
			||||||
 | 
					#include <linux/capability.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					#include "acl.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Convert from filesystem to in-memory representation.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static struct posix_acl *
 | 
				
			||||||
 | 
					ext3_acl_from_disk(const void *value, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const char *end = (char *)value + size;
 | 
				
			||||||
 | 
						int n, count;
 | 
				
			||||||
 | 
						struct posix_acl *acl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!value)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						if (size < sizeof(ext3_acl_header))
 | 
				
			||||||
 | 
							 return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
						if (((ext3_acl_header *)value)->a_version !=
 | 
				
			||||||
 | 
						    cpu_to_le32(EXT3_ACL_VERSION))
 | 
				
			||||||
 | 
							return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
						value = (char *)value + sizeof(ext3_acl_header);
 | 
				
			||||||
 | 
						count = ext3_acl_count(size);
 | 
				
			||||||
 | 
						if (count < 0)
 | 
				
			||||||
 | 
							return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
						if (count == 0)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						acl = posix_acl_alloc(count, GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!acl)
 | 
				
			||||||
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
 | 
						for (n=0; n < count; n++) {
 | 
				
			||||||
 | 
							ext3_acl_entry *entry =
 | 
				
			||||||
 | 
								(ext3_acl_entry *)value;
 | 
				
			||||||
 | 
							if ((char *)value + sizeof(ext3_acl_entry_short) > end)
 | 
				
			||||||
 | 
								goto fail;
 | 
				
			||||||
 | 
							acl->a_entries[n].e_tag  = le16_to_cpu(entry->e_tag);
 | 
				
			||||||
 | 
							acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
 | 
				
			||||||
 | 
							switch(acl->a_entries[n].e_tag) {
 | 
				
			||||||
 | 
								case ACL_USER_OBJ:
 | 
				
			||||||
 | 
								case ACL_GROUP_OBJ:
 | 
				
			||||||
 | 
								case ACL_MASK:
 | 
				
			||||||
 | 
								case ACL_OTHER:
 | 
				
			||||||
 | 
									value = (char *)value +
 | 
				
			||||||
 | 
										sizeof(ext3_acl_entry_short);
 | 
				
			||||||
 | 
									acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case ACL_USER:
 | 
				
			||||||
 | 
								case ACL_GROUP:
 | 
				
			||||||
 | 
									value = (char *)value + sizeof(ext3_acl_entry);
 | 
				
			||||||
 | 
									if ((char *)value > end)
 | 
				
			||||||
 | 
										goto fail;
 | 
				
			||||||
 | 
									acl->a_entries[n].e_id =
 | 
				
			||||||
 | 
										le32_to_cpu(entry->e_id);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									goto fail;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (value != end)
 | 
				
			||||||
 | 
							goto fail;
 | 
				
			||||||
 | 
						return acl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fail:
 | 
				
			||||||
 | 
						posix_acl_release(acl);
 | 
				
			||||||
 | 
						return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Convert from in-memory to filesystem representation.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void *
 | 
				
			||||||
 | 
					ext3_acl_to_disk(const struct posix_acl *acl, size_t *size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						ext3_acl_header *ext_acl;
 | 
				
			||||||
 | 
						char *e;
 | 
				
			||||||
 | 
						size_t n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*size = ext3_acl_size(acl->a_count);
 | 
				
			||||||
 | 
						ext_acl = kmalloc(sizeof(ext3_acl_header) + acl->a_count *
 | 
				
			||||||
 | 
								sizeof(ext3_acl_entry), GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!ext_acl)
 | 
				
			||||||
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
 | 
						ext_acl->a_version = cpu_to_le32(EXT3_ACL_VERSION);
 | 
				
			||||||
 | 
						e = (char *)ext_acl + sizeof(ext3_acl_header);
 | 
				
			||||||
 | 
						for (n=0; n < acl->a_count; n++) {
 | 
				
			||||||
 | 
							ext3_acl_entry *entry = (ext3_acl_entry *)e;
 | 
				
			||||||
 | 
							entry->e_tag  = cpu_to_le16(acl->a_entries[n].e_tag);
 | 
				
			||||||
 | 
							entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
 | 
				
			||||||
 | 
							switch(acl->a_entries[n].e_tag) {
 | 
				
			||||||
 | 
								case ACL_USER:
 | 
				
			||||||
 | 
								case ACL_GROUP:
 | 
				
			||||||
 | 
									entry->e_id =
 | 
				
			||||||
 | 
										cpu_to_le32(acl->a_entries[n].e_id);
 | 
				
			||||||
 | 
									e += sizeof(ext3_acl_entry);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case ACL_USER_OBJ:
 | 
				
			||||||
 | 
								case ACL_GROUP_OBJ:
 | 
				
			||||||
 | 
								case ACL_MASK:
 | 
				
			||||||
 | 
								case ACL_OTHER:
 | 
				
			||||||
 | 
									e += sizeof(ext3_acl_entry_short);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									goto fail;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return (char *)ext_acl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fail:
 | 
				
			||||||
 | 
						kfree(ext_acl);
 | 
				
			||||||
 | 
						return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline struct posix_acl *
 | 
				
			||||||
 | 
					ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct posix_acl *acl = EXT3_ACL_NOT_CACHED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spin_lock(&inode->i_lock);
 | 
				
			||||||
 | 
						if (*i_acl != EXT3_ACL_NOT_CACHED)
 | 
				
			||||||
 | 
							acl = posix_acl_dup(*i_acl);
 | 
				
			||||||
 | 
						spin_unlock(&inode->i_lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return acl;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline void
 | 
				
			||||||
 | 
					ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl,
 | 
				
			||||||
 | 
					                  struct posix_acl *acl)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						spin_lock(&inode->i_lock);
 | 
				
			||||||
 | 
						if (*i_acl != EXT3_ACL_NOT_CACHED)
 | 
				
			||||||
 | 
							posix_acl_release(*i_acl);
 | 
				
			||||||
 | 
						*i_acl = posix_acl_dup(acl);
 | 
				
			||||||
 | 
						spin_unlock(&inode->i_lock);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Inode operation get_posix_acl().
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * inode->i_mutex: don't care
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static struct posix_acl *
 | 
				
			||||||
 | 
					ext3_get_acl(struct inode *inode, int type)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct ext3_inode_info *ei = EXT3_I(inode);
 | 
				
			||||||
 | 
						int name_index;
 | 
				
			||||||
 | 
						char *value = NULL;
 | 
				
			||||||
 | 
						struct posix_acl *acl;
 | 
				
			||||||
 | 
						int retval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, POSIX_ACL))
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch(type) {
 | 
				
			||||||
 | 
							case ACL_TYPE_ACCESS:
 | 
				
			||||||
 | 
								acl = ext3_iget_acl(inode, &ei->i_acl);
 | 
				
			||||||
 | 
								if (acl != EXT3_ACL_NOT_CACHED)
 | 
				
			||||||
 | 
									return acl;
 | 
				
			||||||
 | 
								name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							case ACL_TYPE_DEFAULT:
 | 
				
			||||||
 | 
								acl = ext3_iget_acl(inode, &ei->i_default_acl);
 | 
				
			||||||
 | 
								if (acl != EXT3_ACL_NOT_CACHED)
 | 
				
			||||||
 | 
									return acl;
 | 
				
			||||||
 | 
								name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								return ERR_PTR(-EINVAL);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						retval = ext3_xattr_get(inode, name_index, "", NULL, 0);
 | 
				
			||||||
 | 
						if (retval > 0) {
 | 
				
			||||||
 | 
							value = kmalloc(retval, GFP_KERNEL);
 | 
				
			||||||
 | 
							if (!value)
 | 
				
			||||||
 | 
								return ERR_PTR(-ENOMEM);
 | 
				
			||||||
 | 
							retval = ext3_xattr_get(inode, name_index, "", value, retval);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (retval > 0)
 | 
				
			||||||
 | 
							acl = ext3_acl_from_disk(value, retval);
 | 
				
			||||||
 | 
						else if (retval == -ENODATA || retval == -ENOSYS)
 | 
				
			||||||
 | 
							acl = NULL;
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							acl = ERR_PTR(retval);
 | 
				
			||||||
 | 
						kfree(value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!IS_ERR(acl)) {
 | 
				
			||||||
 | 
							switch(type) {
 | 
				
			||||||
 | 
								case ACL_TYPE_ACCESS:
 | 
				
			||||||
 | 
									ext3_iset_acl(inode, &ei->i_acl, acl);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case ACL_TYPE_DEFAULT:
 | 
				
			||||||
 | 
									ext3_iset_acl(inode, &ei->i_default_acl, acl);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return acl;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Set the access or default ACL of an inode.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * inode->i_mutex: down unless called from ext3_new_inode
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_set_acl(handle_t *handle, struct inode *inode, int type,
 | 
				
			||||||
 | 
						     struct posix_acl *acl)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct ext3_inode_info *ei = EXT3_I(inode);
 | 
				
			||||||
 | 
						int name_index;
 | 
				
			||||||
 | 
						void *value = NULL;
 | 
				
			||||||
 | 
						size_t size = 0;
 | 
				
			||||||
 | 
						int error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (S_ISLNK(inode->i_mode))
 | 
				
			||||||
 | 
							return -EOPNOTSUPP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch(type) {
 | 
				
			||||||
 | 
							case ACL_TYPE_ACCESS:
 | 
				
			||||||
 | 
								name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS;
 | 
				
			||||||
 | 
								if (acl) {
 | 
				
			||||||
 | 
									mode_t mode = inode->i_mode;
 | 
				
			||||||
 | 
									error = posix_acl_equiv_mode(acl, &mode);
 | 
				
			||||||
 | 
									if (error < 0)
 | 
				
			||||||
 | 
										return error;
 | 
				
			||||||
 | 
									else {
 | 
				
			||||||
 | 
										inode->i_mode = mode;
 | 
				
			||||||
 | 
										ext3_mark_inode_dirty(handle, inode);
 | 
				
			||||||
 | 
										if (error == 0)
 | 
				
			||||||
 | 
											acl = NULL;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							case ACL_TYPE_DEFAULT:
 | 
				
			||||||
 | 
								name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT;
 | 
				
			||||||
 | 
								if (!S_ISDIR(inode->i_mode))
 | 
				
			||||||
 | 
									return acl ? -EACCES : 0;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								return -EINVAL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (acl) {
 | 
				
			||||||
 | 
							value = ext3_acl_to_disk(acl, &size);
 | 
				
			||||||
 | 
							if (IS_ERR(value))
 | 
				
			||||||
 | 
								return (int)PTR_ERR(value);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						error = ext3_xattr_set_handle(handle, inode, name_index, "",
 | 
				
			||||||
 | 
									      value, size, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						kfree(value);
 | 
				
			||||||
 | 
						if (!error) {
 | 
				
			||||||
 | 
							switch(type) {
 | 
				
			||||||
 | 
								case ACL_TYPE_ACCESS:
 | 
				
			||||||
 | 
									ext3_iset_acl(inode, &ei->i_acl, acl);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case ACL_TYPE_DEFAULT:
 | 
				
			||||||
 | 
									ext3_iset_acl(inode, &ei->i_default_acl, acl);
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return error;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_check_acl(struct inode *inode, int mask)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct posix_acl *acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (IS_ERR(acl))
 | 
				
			||||||
 | 
							return PTR_ERR(acl);
 | 
				
			||||||
 | 
						if (acl) {
 | 
				
			||||||
 | 
							int error = posix_acl_permission(inode, acl, mask);
 | 
				
			||||||
 | 
							posix_acl_release(acl);
 | 
				
			||||||
 | 
							return error;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return -EAGAIN;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					ext3_permission(struct inode *inode, int mask, struct nameidata *nd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return generic_permission(inode, mask, ext3_check_acl);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Initialize the ACLs of a new inode. Called from ext3_new_inode.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * dir->i_mutex: down
 | 
				
			||||||
 | 
					 * inode->i_mutex: up (access to inode is still exclusive)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct posix_acl *acl = NULL;
 | 
				
			||||||
 | 
						int error = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!S_ISLNK(inode->i_mode)) {
 | 
				
			||||||
 | 
							if (test_opt(dir->i_sb, POSIX_ACL)) {
 | 
				
			||||||
 | 
								acl = ext3_get_acl(dir, ACL_TYPE_DEFAULT);
 | 
				
			||||||
 | 
								if (IS_ERR(acl))
 | 
				
			||||||
 | 
									return PTR_ERR(acl);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!acl)
 | 
				
			||||||
 | 
								inode->i_mode &= ~current->fs->umask;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
 | 
				
			||||||
 | 
							struct posix_acl *clone;
 | 
				
			||||||
 | 
							mode_t mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (S_ISDIR(inode->i_mode)) {
 | 
				
			||||||
 | 
								error = ext3_set_acl(handle, inode,
 | 
				
			||||||
 | 
										     ACL_TYPE_DEFAULT, acl);
 | 
				
			||||||
 | 
								if (error)
 | 
				
			||||||
 | 
									goto cleanup;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							clone = posix_acl_clone(acl, GFP_KERNEL);
 | 
				
			||||||
 | 
							error = -ENOMEM;
 | 
				
			||||||
 | 
							if (!clone)
 | 
				
			||||||
 | 
								goto cleanup;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mode = inode->i_mode;
 | 
				
			||||||
 | 
							error = posix_acl_create_masq(clone, &mode);
 | 
				
			||||||
 | 
							if (error >= 0) {
 | 
				
			||||||
 | 
								inode->i_mode = mode;
 | 
				
			||||||
 | 
								if (error > 0) {
 | 
				
			||||||
 | 
									/* This is an extended ACL */
 | 
				
			||||||
 | 
									error = ext3_set_acl(handle, inode,
 | 
				
			||||||
 | 
											     ACL_TYPE_ACCESS, clone);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							posix_acl_release(clone);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					cleanup:
 | 
				
			||||||
 | 
						posix_acl_release(acl);
 | 
				
			||||||
 | 
						return error;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Does chmod for an inode that may have an Access Control List. The
 | 
				
			||||||
 | 
					 * inode->i_mode field must be updated to the desired value by the caller
 | 
				
			||||||
 | 
					 * before calling this function.
 | 
				
			||||||
 | 
					 * Returns 0 on success, or a negative error number.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * We change the ACL rather than storing some ACL entries in the file
 | 
				
			||||||
 | 
					 * mode permission bits (which would be more efficient), because that
 | 
				
			||||||
 | 
					 * would break once additional permissions (like  ACL_APPEND, ACL_DELETE
 | 
				
			||||||
 | 
					 * for directories) are added. There are no more bits available in the
 | 
				
			||||||
 | 
					 * file mode.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * inode->i_mutex: down
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					ext3_acl_chmod(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct posix_acl *acl, *clone;
 | 
				
			||||||
 | 
					        int error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (S_ISLNK(inode->i_mode))
 | 
				
			||||||
 | 
							return -EOPNOTSUPP;
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, POSIX_ACL))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
 | 
				
			||||||
 | 
						if (IS_ERR(acl) || !acl)
 | 
				
			||||||
 | 
							return PTR_ERR(acl);
 | 
				
			||||||
 | 
						clone = posix_acl_clone(acl, GFP_KERNEL);
 | 
				
			||||||
 | 
						posix_acl_release(acl);
 | 
				
			||||||
 | 
						if (!clone)
 | 
				
			||||||
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
						error = posix_acl_chmod_masq(clone, inode->i_mode);
 | 
				
			||||||
 | 
						if (!error) {
 | 
				
			||||||
 | 
							handle_t *handle;
 | 
				
			||||||
 | 
							int retries = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						retry:
 | 
				
			||||||
 | 
							handle = ext3_journal_start(inode,
 | 
				
			||||||
 | 
									EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
 | 
				
			||||||
 | 
							if (IS_ERR(handle)) {
 | 
				
			||||||
 | 
								error = PTR_ERR(handle);
 | 
				
			||||||
 | 
								ext3_std_error(inode->i_sb, error);
 | 
				
			||||||
 | 
								goto out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
 | 
				
			||||||
 | 
							ext3_journal_stop(handle);
 | 
				
			||||||
 | 
							if (error == -ENOSPC &&
 | 
				
			||||||
 | 
							    ext3_should_retry_alloc(inode->i_sb, &retries))
 | 
				
			||||||
 | 
								goto retry;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						posix_acl_release(clone);
 | 
				
			||||||
 | 
						return error;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Extended attribute handlers
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static size_t
 | 
				
			||||||
 | 
					ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len,
 | 
				
			||||||
 | 
								   const char *name, size_t name_len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, POSIX_ACL))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (list && size <= list_len)
 | 
				
			||||||
 | 
							memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
 | 
				
			||||||
 | 
						return size;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static size_t
 | 
				
			||||||
 | 
					ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len,
 | 
				
			||||||
 | 
								    const char *name, size_t name_len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, POSIX_ACL))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (list && size <= list_len)
 | 
				
			||||||
 | 
							memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
 | 
				
			||||||
 | 
						return size;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct posix_acl *acl;
 | 
				
			||||||
 | 
						int error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, POSIX_ACL))
 | 
				
			||||||
 | 
							return -EOPNOTSUPP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						acl = ext3_get_acl(inode, type);
 | 
				
			||||||
 | 
						if (IS_ERR(acl))
 | 
				
			||||||
 | 
							return PTR_ERR(acl);
 | 
				
			||||||
 | 
						if (acl == NULL)
 | 
				
			||||||
 | 
							return -ENODATA;
 | 
				
			||||||
 | 
						error = posix_acl_to_xattr(acl, buffer, size);
 | 
				
			||||||
 | 
						posix_acl_release(acl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return error;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_get_acl_access(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
								  void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") != 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_get_acl_default(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
								   void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") != 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_set_acl(struct inode *inode, int type, const void *value,
 | 
				
			||||||
 | 
							   size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						handle_t *handle;
 | 
				
			||||||
 | 
						struct posix_acl *acl;
 | 
				
			||||||
 | 
						int error, retries = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, POSIX_ACL))
 | 
				
			||||||
 | 
							return -EOPNOTSUPP;
 | 
				
			||||||
 | 
						if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
 | 
				
			||||||
 | 
							return -EPERM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (value) {
 | 
				
			||||||
 | 
							acl = posix_acl_from_xattr(value, size);
 | 
				
			||||||
 | 
							if (IS_ERR(acl))
 | 
				
			||||||
 | 
								return PTR_ERR(acl);
 | 
				
			||||||
 | 
							else if (acl) {
 | 
				
			||||||
 | 
								error = posix_acl_valid(acl);
 | 
				
			||||||
 | 
								if (error)
 | 
				
			||||||
 | 
									goto release_and_out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else
 | 
				
			||||||
 | 
							acl = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					retry:
 | 
				
			||||||
 | 
						handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
 | 
				
			||||||
 | 
						if (IS_ERR(handle))
 | 
				
			||||||
 | 
							return PTR_ERR(handle);
 | 
				
			||||||
 | 
						error = ext3_set_acl(handle, inode, type, acl);
 | 
				
			||||||
 | 
						ext3_journal_stop(handle);
 | 
				
			||||||
 | 
						if (error == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries))
 | 
				
			||||||
 | 
							goto retry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					release_and_out:
 | 
				
			||||||
 | 
						posix_acl_release(acl);
 | 
				
			||||||
 | 
						return error;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_set_acl_access(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
								  const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") != 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_set_acl_default(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
								   const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") != 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct xattr_handler ext3_xattr_acl_access_handler = {
 | 
				
			||||||
 | 
						.prefix	= POSIX_ACL_XATTR_ACCESS,
 | 
				
			||||||
 | 
						.list	= ext3_xattr_list_acl_access,
 | 
				
			||||||
 | 
						.get	= ext3_xattr_get_acl_access,
 | 
				
			||||||
 | 
						.set	= ext3_xattr_set_acl_access,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct xattr_handler ext3_xattr_acl_default_handler = {
 | 
				
			||||||
 | 
						.prefix	= POSIX_ACL_XATTR_DEFAULT,
 | 
				
			||||||
 | 
						.list	= ext3_xattr_list_acl_default,
 | 
				
			||||||
 | 
						.get	= ext3_xattr_get_acl_default,
 | 
				
			||||||
 | 
						.set	= ext3_xattr_set_acl_default,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										81
									
								
								fs/ext4/acl.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								fs/ext4/acl.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,81 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					  File: fs/ext3/acl.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/posix_acl_xattr.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_ACL_VERSION	0x0001
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
						__le16		e_tag;
 | 
				
			||||||
 | 
						__le16		e_perm;
 | 
				
			||||||
 | 
						__le32		e_id;
 | 
				
			||||||
 | 
					} ext3_acl_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
						__le16		e_tag;
 | 
				
			||||||
 | 
						__le16		e_perm;
 | 
				
			||||||
 | 
					} ext3_acl_entry_short;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct {
 | 
				
			||||||
 | 
						__le32		a_version;
 | 
				
			||||||
 | 
					} ext3_acl_header;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline size_t ext3_acl_size(int count)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (count <= 4) {
 | 
				
			||||||
 | 
							return sizeof(ext3_acl_header) +
 | 
				
			||||||
 | 
							       count * sizeof(ext3_acl_entry_short);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return sizeof(ext3_acl_header) +
 | 
				
			||||||
 | 
							       4 * sizeof(ext3_acl_entry_short) +
 | 
				
			||||||
 | 
							       (count - 4) * sizeof(ext3_acl_entry);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_acl_count(size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						ssize_t s;
 | 
				
			||||||
 | 
						size -= sizeof(ext3_acl_header);
 | 
				
			||||||
 | 
						s = size - 4 * sizeof(ext3_acl_entry_short);
 | 
				
			||||||
 | 
						if (s < 0) {
 | 
				
			||||||
 | 
							if (size % sizeof(ext3_acl_entry_short))
 | 
				
			||||||
 | 
								return -1;
 | 
				
			||||||
 | 
							return size / sizeof(ext3_acl_entry_short);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if (s % sizeof(ext3_acl_entry))
 | 
				
			||||||
 | 
								return -1;
 | 
				
			||||||
 | 
							return s / sizeof(ext3_acl_entry) + 4;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_POSIX_ACL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Value for inode->u.ext3_i.i_acl and inode->u.ext3_i.i_default_acl
 | 
				
			||||||
 | 
					   if the ACL has not been cached */
 | 
				
			||||||
 | 
					#define EXT3_ACL_NOT_CACHED ((void *)-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* acl.c */
 | 
				
			||||||
 | 
					extern int ext3_permission (struct inode *, int, struct nameidata *);
 | 
				
			||||||
 | 
					extern int ext3_acl_chmod (struct inode *);
 | 
				
			||||||
 | 
					extern int ext3_init_acl (handle_t *, struct inode *, struct inode *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else  /* CONFIG_EXT3_FS_POSIX_ACL */
 | 
				
			||||||
 | 
					#include <linux/sched.h>
 | 
				
			||||||
 | 
					#define ext3_permission NULL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					ext3_acl_chmod(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif  /* CONFIG_EXT3_FS_POSIX_ACL */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										1818
									
								
								fs/ext4/balloc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1818
									
								
								fs/ext4/balloc.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										32
									
								
								fs/ext4/bitmap.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								fs/ext4/bitmap.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,32 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/bitmap.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/buffer_head.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef EXT3FS_DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int i;
 | 
				
			||||||
 | 
						unsigned long sum = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!map)
 | 
				
			||||||
 | 
							return (0);
 | 
				
			||||||
 | 
						for (i = 0; i < numchars; i++)
 | 
				
			||||||
 | 
							sum += nibblemap[map->b_data[i] & 0xf] +
 | 
				
			||||||
 | 
								nibblemap[(map->b_data[i] >> 4) & 0xf];
 | 
				
			||||||
 | 
						return (sum);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif  /*  EXT3FS_DEBUG  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										518
									
								
								fs/ext4/dir.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										518
									
								
								fs/ext4/dir.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,518 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/dir.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  linux/fs/minix/dir.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  ext3 directory handling functions
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Big-endian to little-endian byte-swapping/bitmaps by
 | 
				
			||||||
 | 
					 *        David S. Miller (davem@caip.rutgers.edu), 1995
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Hash Tree Directory indexing (c) 2001  Daniel Phillips
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/buffer_head.h>
 | 
				
			||||||
 | 
					#include <linux/smp_lock.h>
 | 
				
			||||||
 | 
					#include <linux/slab.h>
 | 
				
			||||||
 | 
					#include <linux/rbtree.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static unsigned char ext3_filetype_table[] = {
 | 
				
			||||||
 | 
						DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ext3_readdir(struct file *, void *, filldir_t);
 | 
				
			||||||
 | 
					static int ext3_dx_readdir(struct file * filp,
 | 
				
			||||||
 | 
								   void * dirent, filldir_t filldir);
 | 
				
			||||||
 | 
					static int ext3_release_dir (struct inode * inode,
 | 
				
			||||||
 | 
									struct file * filp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const struct file_operations ext3_dir_operations = {
 | 
				
			||||||
 | 
						.llseek		= generic_file_llseek,
 | 
				
			||||||
 | 
						.read		= generic_read_dir,
 | 
				
			||||||
 | 
						.readdir	= ext3_readdir,		/* we take BKL. needed?*/
 | 
				
			||||||
 | 
						.ioctl		= ext3_ioctl,		/* BKL held */
 | 
				
			||||||
 | 
					#ifdef CONFIG_COMPAT
 | 
				
			||||||
 | 
						.compat_ioctl	= ext3_compat_ioctl,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						.fsync		= ext3_sync_file,	/* BKL held */
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_INDEX
 | 
				
			||||||
 | 
						.release	= ext3_release_dir,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static unsigned char get_dtype(struct super_block *sb, int filetype)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE) ||
 | 
				
			||||||
 | 
						    (filetype >= EXT3_FT_MAX))
 | 
				
			||||||
 | 
							return DT_UNKNOWN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (ext3_filetype_table[filetype]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ext3_check_dir_entry (const char * function, struct inode * dir,
 | 
				
			||||||
 | 
								  struct ext3_dir_entry_2 * de,
 | 
				
			||||||
 | 
								  struct buffer_head * bh,
 | 
				
			||||||
 | 
								  unsigned long offset)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const char * error_msg = NULL;
 | 
				
			||||||
 | 
						const int rlen = le16_to_cpu(de->rec_len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (rlen < EXT3_DIR_REC_LEN(1))
 | 
				
			||||||
 | 
							error_msg = "rec_len is smaller than minimal";
 | 
				
			||||||
 | 
						else if (rlen % 4 != 0)
 | 
				
			||||||
 | 
							error_msg = "rec_len % 4 != 0";
 | 
				
			||||||
 | 
						else if (rlen < EXT3_DIR_REC_LEN(de->name_len))
 | 
				
			||||||
 | 
							error_msg = "rec_len is too small for name_len";
 | 
				
			||||||
 | 
						else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
 | 
				
			||||||
 | 
							error_msg = "directory entry across blocks";
 | 
				
			||||||
 | 
						else if (le32_to_cpu(de->inode) >
 | 
				
			||||||
 | 
								le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
 | 
				
			||||||
 | 
							error_msg = "inode out of bounds";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (error_msg != NULL)
 | 
				
			||||||
 | 
							ext3_error (dir->i_sb, function,
 | 
				
			||||||
 | 
								"bad entry in directory #%lu: %s - "
 | 
				
			||||||
 | 
								"offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
 | 
				
			||||||
 | 
								dir->i_ino, error_msg, offset,
 | 
				
			||||||
 | 
								(unsigned long) le32_to_cpu(de->inode),
 | 
				
			||||||
 | 
								rlen, de->name_len);
 | 
				
			||||||
 | 
						return error_msg == NULL ? 1 : 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ext3_readdir(struct file * filp,
 | 
				
			||||||
 | 
								 void * dirent, filldir_t filldir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int error = 0;
 | 
				
			||||||
 | 
						unsigned long offset;
 | 
				
			||||||
 | 
						int i, stored;
 | 
				
			||||||
 | 
						struct ext3_dir_entry_2 *de;
 | 
				
			||||||
 | 
						struct super_block *sb;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
						struct inode *inode = filp->f_dentry->d_inode;
 | 
				
			||||||
 | 
						int ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sb = inode->i_sb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_INDEX
 | 
				
			||||||
 | 
						if (EXT3_HAS_COMPAT_FEATURE(inode->i_sb,
 | 
				
			||||||
 | 
									    EXT3_FEATURE_COMPAT_DIR_INDEX) &&
 | 
				
			||||||
 | 
						    ((EXT3_I(inode)->i_flags & EXT3_INDEX_FL) ||
 | 
				
			||||||
 | 
						     ((inode->i_size >> sb->s_blocksize_bits) == 1))) {
 | 
				
			||||||
 | 
							err = ext3_dx_readdir(filp, dirent, filldir);
 | 
				
			||||||
 | 
							if (err != ERR_BAD_DX_DIR) {
 | 
				
			||||||
 | 
								ret = err;
 | 
				
			||||||
 | 
								goto out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * We don't set the inode dirty flag since it's not
 | 
				
			||||||
 | 
							 * critical that it get flushed back to the disk.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							EXT3_I(filp->f_dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						stored = 0;
 | 
				
			||||||
 | 
						offset = filp->f_pos & (sb->s_blocksize - 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (!error && !stored && filp->f_pos < inode->i_size) {
 | 
				
			||||||
 | 
							unsigned long blk = filp->f_pos >> EXT3_BLOCK_SIZE_BITS(sb);
 | 
				
			||||||
 | 
							struct buffer_head map_bh;
 | 
				
			||||||
 | 
							struct buffer_head *bh = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							map_bh.b_state = 0;
 | 
				
			||||||
 | 
							err = ext3_get_blocks_handle(NULL, inode, blk, 1,
 | 
				
			||||||
 | 
											&map_bh, 0, 0);
 | 
				
			||||||
 | 
							if (err > 0) {
 | 
				
			||||||
 | 
								page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
 | 
				
			||||||
 | 
									&filp->f_ra,
 | 
				
			||||||
 | 
									filp,
 | 
				
			||||||
 | 
									map_bh.b_blocknr >>
 | 
				
			||||||
 | 
										(PAGE_CACHE_SHIFT - inode->i_blkbits),
 | 
				
			||||||
 | 
									1);
 | 
				
			||||||
 | 
								bh = ext3_bread(NULL, inode, blk, 0, &err);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * We ignore I/O errors on directories so users have a chance
 | 
				
			||||||
 | 
							 * of recovering data when there's a bad sector
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if (!bh) {
 | 
				
			||||||
 | 
								ext3_error (sb, "ext3_readdir",
 | 
				
			||||||
 | 
									"directory #%lu contains a hole at offset %lu",
 | 
				
			||||||
 | 
									inode->i_ino, (unsigned long)filp->f_pos);
 | 
				
			||||||
 | 
								filp->f_pos += sb->s_blocksize - offset;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					revalidate:
 | 
				
			||||||
 | 
							/* If the dir block has changed since the last call to
 | 
				
			||||||
 | 
							 * readdir(2), then we might be pointing to an invalid
 | 
				
			||||||
 | 
							 * dirent right now.  Scan from the start of the block
 | 
				
			||||||
 | 
							 * to make sure. */
 | 
				
			||||||
 | 
							if (filp->f_version != inode->i_version) {
 | 
				
			||||||
 | 
								for (i = 0; i < sb->s_blocksize && i < offset; ) {
 | 
				
			||||||
 | 
									de = (struct ext3_dir_entry_2 *)
 | 
				
			||||||
 | 
										(bh->b_data + i);
 | 
				
			||||||
 | 
									/* It's too expensive to do a full
 | 
				
			||||||
 | 
									 * dirent test each time round this
 | 
				
			||||||
 | 
									 * loop, but we do have to test at
 | 
				
			||||||
 | 
									 * least that it is non-zero.  A
 | 
				
			||||||
 | 
									 * failure will be detected in the
 | 
				
			||||||
 | 
									 * dirent test below. */
 | 
				
			||||||
 | 
									if (le16_to_cpu(de->rec_len) <
 | 
				
			||||||
 | 
											EXT3_DIR_REC_LEN(1))
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									i += le16_to_cpu(de->rec_len);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								offset = i;
 | 
				
			||||||
 | 
								filp->f_pos = (filp->f_pos & ~(sb->s_blocksize - 1))
 | 
				
			||||||
 | 
									| offset;
 | 
				
			||||||
 | 
								filp->f_version = inode->i_version;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							while (!error && filp->f_pos < inode->i_size
 | 
				
			||||||
 | 
							       && offset < sb->s_blocksize) {
 | 
				
			||||||
 | 
								de = (struct ext3_dir_entry_2 *) (bh->b_data + offset);
 | 
				
			||||||
 | 
								if (!ext3_check_dir_entry ("ext3_readdir", inode, de,
 | 
				
			||||||
 | 
											   bh, offset)) {
 | 
				
			||||||
 | 
									/* On error, skip the f_pos to the
 | 
				
			||||||
 | 
					                                   next block. */
 | 
				
			||||||
 | 
									filp->f_pos = (filp->f_pos |
 | 
				
			||||||
 | 
											(sb->s_blocksize - 1)) + 1;
 | 
				
			||||||
 | 
									brelse (bh);
 | 
				
			||||||
 | 
									ret = stored;
 | 
				
			||||||
 | 
									goto out;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								offset += le16_to_cpu(de->rec_len);
 | 
				
			||||||
 | 
								if (le32_to_cpu(de->inode)) {
 | 
				
			||||||
 | 
									/* We might block in the next section
 | 
				
			||||||
 | 
									 * if the data destination is
 | 
				
			||||||
 | 
									 * currently swapped out.  So, use a
 | 
				
			||||||
 | 
									 * version stamp to detect whether or
 | 
				
			||||||
 | 
									 * not the directory has been modified
 | 
				
			||||||
 | 
									 * during the copy operation.
 | 
				
			||||||
 | 
									 */
 | 
				
			||||||
 | 
									unsigned long version = filp->f_version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									error = filldir(dirent, de->name,
 | 
				
			||||||
 | 
											de->name_len,
 | 
				
			||||||
 | 
											filp->f_pos,
 | 
				
			||||||
 | 
											le32_to_cpu(de->inode),
 | 
				
			||||||
 | 
											get_dtype(sb, de->file_type));
 | 
				
			||||||
 | 
									if (error)
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									if (version != filp->f_version)
 | 
				
			||||||
 | 
										goto revalidate;
 | 
				
			||||||
 | 
									stored ++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								filp->f_pos += le16_to_cpu(de->rec_len);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							offset = 0;
 | 
				
			||||||
 | 
							brelse (bh);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_INDEX
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * These functions convert from the major/minor hash to an f_pos
 | 
				
			||||||
 | 
					 * value.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Currently we only use major hash numer.  This is unfortunate, but
 | 
				
			||||||
 | 
					 * on 32-bit machines, the same VFS interface is used for lseek and
 | 
				
			||||||
 | 
					 * llseek, so if we use the 64 bit offset, then the 32-bit versions of
 | 
				
			||||||
 | 
					 * lseek/telldir/seekdir will blow out spectacularly, and from within
 | 
				
			||||||
 | 
					 * the ext2 low-level routine, we don't know if we're being called by
 | 
				
			||||||
 | 
					 * a 64-bit version of the system call or the 32-bit version of the
 | 
				
			||||||
 | 
					 * system call.  Worse yet, NFSv2 only allows for a 32-bit readdir
 | 
				
			||||||
 | 
					 * cookie.  Sigh.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define hash2pos(major, minor)	(major >> 1)
 | 
				
			||||||
 | 
					#define pos2maj_hash(pos)	((pos << 1) & 0xffffffff)
 | 
				
			||||||
 | 
					#define pos2min_hash(pos)	(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This structure holds the nodes of the red-black tree used to store
 | 
				
			||||||
 | 
					 * the directory entry in hash order.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct fname {
 | 
				
			||||||
 | 
						__u32		hash;
 | 
				
			||||||
 | 
						__u32		minor_hash;
 | 
				
			||||||
 | 
						struct rb_node	rb_hash;
 | 
				
			||||||
 | 
						struct fname	*next;
 | 
				
			||||||
 | 
						__u32		inode;
 | 
				
			||||||
 | 
						__u8		name_len;
 | 
				
			||||||
 | 
						__u8		file_type;
 | 
				
			||||||
 | 
						char		name[0];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This functoin implements a non-recursive way of freeing all of the
 | 
				
			||||||
 | 
					 * nodes in the red-black tree.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void free_rb_tree_fname(struct rb_root *root)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct rb_node	*n = root->rb_node;
 | 
				
			||||||
 | 
						struct rb_node	*parent;
 | 
				
			||||||
 | 
						struct fname	*fname;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (n) {
 | 
				
			||||||
 | 
							/* Do the node's children first */
 | 
				
			||||||
 | 
							if ((n)->rb_left) {
 | 
				
			||||||
 | 
								n = n->rb_left;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (n->rb_right) {
 | 
				
			||||||
 | 
								n = n->rb_right;
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * The node has no children; free it, and then zero
 | 
				
			||||||
 | 
							 * out parent's link to it.  Finally go to the
 | 
				
			||||||
 | 
							 * beginning of the loop and try to free the parent
 | 
				
			||||||
 | 
							 * node.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							parent = rb_parent(n);
 | 
				
			||||||
 | 
							fname = rb_entry(n, struct fname, rb_hash);
 | 
				
			||||||
 | 
							while (fname) {
 | 
				
			||||||
 | 
								struct fname * old = fname;
 | 
				
			||||||
 | 
								fname = fname->next;
 | 
				
			||||||
 | 
								kfree (old);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!parent)
 | 
				
			||||||
 | 
								root->rb_node = NULL;
 | 
				
			||||||
 | 
							else if (parent->rb_left == n)
 | 
				
			||||||
 | 
								parent->rb_left = NULL;
 | 
				
			||||||
 | 
							else if (parent->rb_right == n)
 | 
				
			||||||
 | 
								parent->rb_right = NULL;
 | 
				
			||||||
 | 
							n = parent;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						root->rb_node = NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct dir_private_info *create_dir_info(loff_t pos)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct dir_private_info *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						p = kmalloc(sizeof(struct dir_private_info), GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!p)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						p->root.rb_node = NULL;
 | 
				
			||||||
 | 
						p->curr_node = NULL;
 | 
				
			||||||
 | 
						p->extra_fname = NULL;
 | 
				
			||||||
 | 
						p->last_pos = 0;
 | 
				
			||||||
 | 
						p->curr_hash = pos2maj_hash(pos);
 | 
				
			||||||
 | 
						p->curr_minor_hash = pos2min_hash(pos);
 | 
				
			||||||
 | 
						p->next_hash = 0;
 | 
				
			||||||
 | 
						return p;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ext3_htree_free_dir_info(struct dir_private_info *p)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						free_rb_tree_fname(&p->root);
 | 
				
			||||||
 | 
						kfree(p);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Given a directory entry, enter it into the fname rb tree.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 | 
				
			||||||
 | 
								     __u32 minor_hash,
 | 
				
			||||||
 | 
								     struct ext3_dir_entry_2 *dirent)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct rb_node **p, *parent = NULL;
 | 
				
			||||||
 | 
						struct fname * fname, *new_fn;
 | 
				
			||||||
 | 
						struct dir_private_info *info;
 | 
				
			||||||
 | 
						int len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						info = (struct dir_private_info *) dir_file->private_data;
 | 
				
			||||||
 | 
						p = &info->root.rb_node;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Create and allocate the fname structure */
 | 
				
			||||||
 | 
						len = sizeof(struct fname) + dirent->name_len + 1;
 | 
				
			||||||
 | 
						new_fn = kzalloc(len, GFP_KERNEL);
 | 
				
			||||||
 | 
						if (!new_fn)
 | 
				
			||||||
 | 
							return -ENOMEM;
 | 
				
			||||||
 | 
						new_fn->hash = hash;
 | 
				
			||||||
 | 
						new_fn->minor_hash = minor_hash;
 | 
				
			||||||
 | 
						new_fn->inode = le32_to_cpu(dirent->inode);
 | 
				
			||||||
 | 
						new_fn->name_len = dirent->name_len;
 | 
				
			||||||
 | 
						new_fn->file_type = dirent->file_type;
 | 
				
			||||||
 | 
						memcpy(new_fn->name, dirent->name, dirent->name_len);
 | 
				
			||||||
 | 
						new_fn->name[dirent->name_len] = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (*p) {
 | 
				
			||||||
 | 
							parent = *p;
 | 
				
			||||||
 | 
							fname = rb_entry(parent, struct fname, rb_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * If the hash and minor hash match up, then we put
 | 
				
			||||||
 | 
							 * them on a linked list.  This rarely happens...
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if ((new_fn->hash == fname->hash) &&
 | 
				
			||||||
 | 
							    (new_fn->minor_hash == fname->minor_hash)) {
 | 
				
			||||||
 | 
								new_fn->next = fname->next;
 | 
				
			||||||
 | 
								fname->next = new_fn;
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (new_fn->hash < fname->hash)
 | 
				
			||||||
 | 
								p = &(*p)->rb_left;
 | 
				
			||||||
 | 
							else if (new_fn->hash > fname->hash)
 | 
				
			||||||
 | 
								p = &(*p)->rb_right;
 | 
				
			||||||
 | 
							else if (new_fn->minor_hash < fname->minor_hash)
 | 
				
			||||||
 | 
								p = &(*p)->rb_left;
 | 
				
			||||||
 | 
							else /* if (new_fn->minor_hash > fname->minor_hash) */
 | 
				
			||||||
 | 
								p = &(*p)->rb_right;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rb_link_node(&new_fn->rb_hash, parent, p);
 | 
				
			||||||
 | 
						rb_insert_color(&new_fn->rb_hash, &info->root);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This is a helper function for ext3_dx_readdir.  It calls filldir
 | 
				
			||||||
 | 
					 * for all entres on the fname linked list.  (Normally there is only
 | 
				
			||||||
 | 
					 * one entry on the linked list, unless there are 62 bit hash collisions.)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static int call_filldir(struct file * filp, void * dirent,
 | 
				
			||||||
 | 
								filldir_t filldir, struct fname *fname)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct dir_private_info *info = filp->private_data;
 | 
				
			||||||
 | 
						loff_t	curr_pos;
 | 
				
			||||||
 | 
						struct inode *inode = filp->f_dentry->d_inode;
 | 
				
			||||||
 | 
						struct super_block * sb;
 | 
				
			||||||
 | 
						int error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sb = inode->i_sb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!fname) {
 | 
				
			||||||
 | 
							printk("call_filldir: called with null fname?!?\n");
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						curr_pos = hash2pos(fname->hash, fname->minor_hash);
 | 
				
			||||||
 | 
						while (fname) {
 | 
				
			||||||
 | 
							error = filldir(dirent, fname->name,
 | 
				
			||||||
 | 
									fname->name_len, curr_pos,
 | 
				
			||||||
 | 
									fname->inode,
 | 
				
			||||||
 | 
									get_dtype(sb, fname->file_type));
 | 
				
			||||||
 | 
							if (error) {
 | 
				
			||||||
 | 
								filp->f_pos = curr_pos;
 | 
				
			||||||
 | 
								info->extra_fname = fname->next;
 | 
				
			||||||
 | 
								return error;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							fname = fname->next;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ext3_dx_readdir(struct file * filp,
 | 
				
			||||||
 | 
								 void * dirent, filldir_t filldir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct dir_private_info *info = filp->private_data;
 | 
				
			||||||
 | 
						struct inode *inode = filp->f_dentry->d_inode;
 | 
				
			||||||
 | 
						struct fname *fname;
 | 
				
			||||||
 | 
						int	ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!info) {
 | 
				
			||||||
 | 
							info = create_dir_info(filp->f_pos);
 | 
				
			||||||
 | 
							if (!info)
 | 
				
			||||||
 | 
								return -ENOMEM;
 | 
				
			||||||
 | 
							filp->private_data = info;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (filp->f_pos == EXT3_HTREE_EOF)
 | 
				
			||||||
 | 
							return 0;	/* EOF */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Some one has messed with f_pos; reset the world */
 | 
				
			||||||
 | 
						if (info->last_pos != filp->f_pos) {
 | 
				
			||||||
 | 
							free_rb_tree_fname(&info->root);
 | 
				
			||||||
 | 
							info->curr_node = NULL;
 | 
				
			||||||
 | 
							info->extra_fname = NULL;
 | 
				
			||||||
 | 
							info->curr_hash = pos2maj_hash(filp->f_pos);
 | 
				
			||||||
 | 
							info->curr_minor_hash = pos2min_hash(filp->f_pos);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * If there are any leftover names on the hash collision
 | 
				
			||||||
 | 
						 * chain, return them first.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (info->extra_fname &&
 | 
				
			||||||
 | 
						    call_filldir(filp, dirent, filldir, info->extra_fname))
 | 
				
			||||||
 | 
							goto finished;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!info->curr_node)
 | 
				
			||||||
 | 
							info->curr_node = rb_first(&info->root);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (1) {
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * Fill the rbtree if we have no more entries,
 | 
				
			||||||
 | 
							 * or the inode has changed since we last read in the
 | 
				
			||||||
 | 
							 * cached entries.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if ((!info->curr_node) ||
 | 
				
			||||||
 | 
							    (filp->f_version != inode->i_version)) {
 | 
				
			||||||
 | 
								info->curr_node = NULL;
 | 
				
			||||||
 | 
								free_rb_tree_fname(&info->root);
 | 
				
			||||||
 | 
								filp->f_version = inode->i_version;
 | 
				
			||||||
 | 
								ret = ext3_htree_fill_tree(filp, info->curr_hash,
 | 
				
			||||||
 | 
											   info->curr_minor_hash,
 | 
				
			||||||
 | 
											   &info->next_hash);
 | 
				
			||||||
 | 
								if (ret < 0)
 | 
				
			||||||
 | 
									return ret;
 | 
				
			||||||
 | 
								if (ret == 0) {
 | 
				
			||||||
 | 
									filp->f_pos = EXT3_HTREE_EOF;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								info->curr_node = rb_first(&info->root);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							fname = rb_entry(info->curr_node, struct fname, rb_hash);
 | 
				
			||||||
 | 
							info->curr_hash = fname->hash;
 | 
				
			||||||
 | 
							info->curr_minor_hash = fname->minor_hash;
 | 
				
			||||||
 | 
							if (call_filldir(filp, dirent, filldir, fname))
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							info->curr_node = rb_next(info->curr_node);
 | 
				
			||||||
 | 
							if (!info->curr_node) {
 | 
				
			||||||
 | 
								if (info->next_hash == ~0) {
 | 
				
			||||||
 | 
									filp->f_pos = EXT3_HTREE_EOF;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								info->curr_hash = info->next_hash;
 | 
				
			||||||
 | 
								info->curr_minor_hash = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					finished:
 | 
				
			||||||
 | 
						info->last_pos = filp->f_pos;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ext3_release_dir (struct inode * inode, struct file * filp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					       if (filp->private_data)
 | 
				
			||||||
 | 
							ext3_htree_free_dir_info(filp->private_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										139
									
								
								fs/ext4/file.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								fs/ext4/file.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,139 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/file.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  linux/fs/minix/file.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  ext3 fs regular file handling primitives
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  64-bit file support on 64-bit platforms by Jakub Jelinek
 | 
				
			||||||
 | 
					 *	(jj@sunsite.ms.mff.cuni.cz)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/time.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					#include "acl.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Called when an inode is released. Note that this is different
 | 
				
			||||||
 | 
					 * from ext3_file_open: open gets called at every open, but release
 | 
				
			||||||
 | 
					 * gets called only when /all/ the files are closed.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static int ext3_release_file (struct inode * inode, struct file * filp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* if we are the last writer on the inode, drop the block reservation */
 | 
				
			||||||
 | 
						if ((filp->f_mode & FMODE_WRITE) &&
 | 
				
			||||||
 | 
								(atomic_read(&inode->i_writecount) == 1))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							mutex_lock(&EXT3_I(inode)->truncate_mutex);
 | 
				
			||||||
 | 
							ext3_discard_reservation(inode);
 | 
				
			||||||
 | 
							mutex_unlock(&EXT3_I(inode)->truncate_mutex);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (is_dx(inode) && filp->private_data)
 | 
				
			||||||
 | 
							ext3_htree_free_dir_info(filp->private_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static ssize_t
 | 
				
			||||||
 | 
					ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
 | 
				
			||||||
 | 
							unsigned long nr_segs, loff_t pos)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct file *file = iocb->ki_filp;
 | 
				
			||||||
 | 
						struct inode *inode = file->f_dentry->d_inode;
 | 
				
			||||||
 | 
						ssize_t ret;
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = generic_file_aio_write(iocb, iov, nr_segs, pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Skip flushing if there was an error, or if nothing was written.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (ret <= 0)
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * If the inode is IS_SYNC, or is O_SYNC and we are doing data
 | 
				
			||||||
 | 
						 * journalling then we need to make sure that we force the transaction
 | 
				
			||||||
 | 
						 * to disk to keep all metadata uptodate synchronously.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (file->f_flags & O_SYNC) {
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * If we are non-data-journaled, then the dirty data has
 | 
				
			||||||
 | 
							 * already been flushed to backing store by generic_osync_inode,
 | 
				
			||||||
 | 
							 * and the inode has been flushed too if there have been any
 | 
				
			||||||
 | 
							 * modifications other than mere timestamp updates.
 | 
				
			||||||
 | 
							 *
 | 
				
			||||||
 | 
							 * Open question --- do we care about flushing timestamps too
 | 
				
			||||||
 | 
							 * if the inode is IS_SYNC?
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if (!ext3_should_journal_data(inode))
 | 
				
			||||||
 | 
								return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							goto force_commit;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * So we know that there has been no forced data flush.  If the inode
 | 
				
			||||||
 | 
						 * is marked IS_SYNC, we need to force one ourselves.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (!IS_SYNC(inode))
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Open question #2 --- should we force data to disk here too?  If we
 | 
				
			||||||
 | 
						 * don't, the only impact is that data=writeback filesystems won't
 | 
				
			||||||
 | 
						 * flush data to disk automatically on IS_SYNC, only metadata (but
 | 
				
			||||||
 | 
						 * historically, that is what ext2 has done.)
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					force_commit:
 | 
				
			||||||
 | 
						err = ext3_force_commit(inode->i_sb);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const struct file_operations ext3_file_operations = {
 | 
				
			||||||
 | 
						.llseek		= generic_file_llseek,
 | 
				
			||||||
 | 
						.read		= do_sync_read,
 | 
				
			||||||
 | 
						.write		= do_sync_write,
 | 
				
			||||||
 | 
						.aio_read	= generic_file_aio_read,
 | 
				
			||||||
 | 
						.aio_write	= ext3_file_write,
 | 
				
			||||||
 | 
						.ioctl		= ext3_ioctl,
 | 
				
			||||||
 | 
					#ifdef CONFIG_COMPAT
 | 
				
			||||||
 | 
						.compat_ioctl	= ext3_compat_ioctl,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						.mmap		= generic_file_mmap,
 | 
				
			||||||
 | 
						.open		= generic_file_open,
 | 
				
			||||||
 | 
						.release	= ext3_release_file,
 | 
				
			||||||
 | 
						.fsync		= ext3_sync_file,
 | 
				
			||||||
 | 
						.sendfile	= generic_file_sendfile,
 | 
				
			||||||
 | 
						.splice_read	= generic_file_splice_read,
 | 
				
			||||||
 | 
						.splice_write	= generic_file_splice_write,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inode_operations ext3_file_inode_operations = {
 | 
				
			||||||
 | 
						.truncate	= ext3_truncate,
 | 
				
			||||||
 | 
						.setattr	= ext3_setattr,
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_XATTR
 | 
				
			||||||
 | 
						.setxattr	= generic_setxattr,
 | 
				
			||||||
 | 
						.getxattr	= generic_getxattr,
 | 
				
			||||||
 | 
						.listxattr	= ext3_listxattr,
 | 
				
			||||||
 | 
						.removexattr	= generic_removexattr,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						.permission	= ext3_permission,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										88
									
								
								fs/ext4/fsync.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								fs/ext4/fsync.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,88 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/fsync.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1993  Stephen Tweedie (sct@redhat.com)
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *  Copyright (C) 1992  Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 *                      Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 *                      Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *  linux/fs/minix/truncate.c   Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  ext3fs fsync primitive
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Big-endian to little-endian byte-swapping/bitmaps by
 | 
				
			||||||
 | 
					 *        David S. Miller (davem@caip.rutgers.edu), 1995
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Removed unnecessary code duplication for little endian machines
 | 
				
			||||||
 | 
					 *  and excessive __inline__s.
 | 
				
			||||||
 | 
					 *        Andi Kleen, 1997
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Major simplications and cleanup - we only need to do the metadata, because
 | 
				
			||||||
 | 
					 * we can depend on generic_block_fdatasync() to sync the data blocks.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/time.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/sched.h>
 | 
				
			||||||
 | 
					#include <linux/writeback.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * akpm: A new design for ext3_sync_file().
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This is only called from sys_fsync(), sys_fdatasync() and sys_msync().
 | 
				
			||||||
 | 
					 * There cannot be a transaction open by this task.
 | 
				
			||||||
 | 
					 * Another task could have dirtied this inode.  Its data can be in any
 | 
				
			||||||
 | 
					 * state in the journalling system.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * What we do is just kick off a commit and wait on it.  This will snapshot the
 | 
				
			||||||
 | 
					 * inode to disk.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct inode *inode = dentry->d_inode;
 | 
				
			||||||
 | 
						int ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						J_ASSERT(ext3_journal_current_handle() == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * data=writeback:
 | 
				
			||||||
 | 
						 *  The caller's filemap_fdatawrite()/wait will sync the data.
 | 
				
			||||||
 | 
						 *  sync_inode() will sync the metadata
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * data=ordered:
 | 
				
			||||||
 | 
						 *  The caller's filemap_fdatawrite() will write the data and
 | 
				
			||||||
 | 
						 *  sync_inode() will write the inode if it is dirty.  Then the caller's
 | 
				
			||||||
 | 
						 *  filemap_fdatawait() will wait on the pages.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * data=journal:
 | 
				
			||||||
 | 
						 *  filemap_fdatawrite won't do anything (the buffers are clean).
 | 
				
			||||||
 | 
						 *  ext3_force_commit will write the file data into the journal and
 | 
				
			||||||
 | 
						 *  will wait on that.
 | 
				
			||||||
 | 
						 *  filemap_fdatawait() will encounter a ton of newly-dirtied pages
 | 
				
			||||||
 | 
						 *  (they were dirtied by commit).  But that's OK - the blocks are
 | 
				
			||||||
 | 
						 *  safe in-journal, which is all fsync() needs to ensure.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (ext3_should_journal_data(inode)) {
 | 
				
			||||||
 | 
							ret = ext3_force_commit(inode->i_sb);
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * The VFS has written the file data.  If the inode is unaltered
 | 
				
			||||||
 | 
						 * then we need not start a commit.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC)) {
 | 
				
			||||||
 | 
							struct writeback_control wbc = {
 | 
				
			||||||
 | 
								.sync_mode = WB_SYNC_ALL,
 | 
				
			||||||
 | 
								.nr_to_write = 0, /* sys_fsync did this */
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
							ret = sync_inode(inode, &wbc);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										152
									
								
								fs/ext4/hash.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								fs/ext4/hash.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,152 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/hash.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 2002 by Theodore Ts'o
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is released under the GPL v2.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file may be redistributed under the terms of the GNU Public
 | 
				
			||||||
 | 
					 * License.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/sched.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/cryptohash.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DELTA 0x9E3779B9
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void TEA_transform(__u32 buf[4], __u32 const in[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						__u32	sum = 0;
 | 
				
			||||||
 | 
						__u32	b0 = buf[0], b1 = buf[1];
 | 
				
			||||||
 | 
						__u32	a = in[0], b = in[1], c = in[2], d = in[3];
 | 
				
			||||||
 | 
						int	n = 16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						do {
 | 
				
			||||||
 | 
							sum += DELTA;
 | 
				
			||||||
 | 
							b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b);
 | 
				
			||||||
 | 
							b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d);
 | 
				
			||||||
 | 
						} while(--n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						buf[0] += b0;
 | 
				
			||||||
 | 
						buf[1] += b1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The old legacy hash */
 | 
				
			||||||
 | 
					static __u32 dx_hack_hash (const char *name, int len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						__u32 hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
 | 
				
			||||||
 | 
						while (len--) {
 | 
				
			||||||
 | 
							__u32 hash = hash1 + (hash0 ^ (*name++ * 7152373));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (hash & 0x80000000) hash -= 0x7fffffff;
 | 
				
			||||||
 | 
							hash1 = hash0;
 | 
				
			||||||
 | 
							hash0 = hash;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return (hash0 << 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						__u32	pad, val;
 | 
				
			||||||
 | 
						int	i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pad = (__u32)len | ((__u32)len << 8);
 | 
				
			||||||
 | 
						pad |= pad << 16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						val = pad;
 | 
				
			||||||
 | 
						if (len > num*4)
 | 
				
			||||||
 | 
							len = num * 4;
 | 
				
			||||||
 | 
						for (i=0; i < len; i++) {
 | 
				
			||||||
 | 
							if ((i % 4) == 0)
 | 
				
			||||||
 | 
								val = pad;
 | 
				
			||||||
 | 
							val = msg[i] + (val << 8);
 | 
				
			||||||
 | 
							if ((i % 4) == 3) {
 | 
				
			||||||
 | 
								*buf++ = val;
 | 
				
			||||||
 | 
								val = pad;
 | 
				
			||||||
 | 
								num--;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (--num >= 0)
 | 
				
			||||||
 | 
							*buf++ = val;
 | 
				
			||||||
 | 
						while (--num >= 0)
 | 
				
			||||||
 | 
							*buf++ = pad;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Returns the hash of a filename.  If len is 0 and name is NULL, then
 | 
				
			||||||
 | 
					 * this function can be used to test whether or not a hash version is
 | 
				
			||||||
 | 
					 * supported.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The seed is an 4 longword (32 bits) "secret" which can be used to
 | 
				
			||||||
 | 
					 * uniquify a hash.  If the seed is all zero's, then some default seed
 | 
				
			||||||
 | 
					 * may be used.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * A particular hash version specifies whether or not the seed is
 | 
				
			||||||
 | 
					 * represented, and whether or not the returned hash is 32 bits or 64
 | 
				
			||||||
 | 
					 * bits.  32 bit hashes will return 0 for the minor hash.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						__u32	hash;
 | 
				
			||||||
 | 
						__u32	minor_hash = 0;
 | 
				
			||||||
 | 
						const char	*p;
 | 
				
			||||||
 | 
						int		i;
 | 
				
			||||||
 | 
						__u32		in[8], buf[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Initialize the default seed for the hash checksum functions */
 | 
				
			||||||
 | 
						buf[0] = 0x67452301;
 | 
				
			||||||
 | 
						buf[1] = 0xefcdab89;
 | 
				
			||||||
 | 
						buf[2] = 0x98badcfe;
 | 
				
			||||||
 | 
						buf[3] = 0x10325476;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Check to see if the seed is all zero's */
 | 
				
			||||||
 | 
						if (hinfo->seed) {
 | 
				
			||||||
 | 
							for (i=0; i < 4; i++) {
 | 
				
			||||||
 | 
								if (hinfo->seed[i])
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (i < 4)
 | 
				
			||||||
 | 
								memcpy(buf, hinfo->seed, sizeof(buf));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (hinfo->hash_version) {
 | 
				
			||||||
 | 
						case DX_HASH_LEGACY:
 | 
				
			||||||
 | 
							hash = dx_hack_hash(name, len);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case DX_HASH_HALF_MD4:
 | 
				
			||||||
 | 
							p = name;
 | 
				
			||||||
 | 
							while (len > 0) {
 | 
				
			||||||
 | 
								str2hashbuf(p, len, in, 8);
 | 
				
			||||||
 | 
								half_md4_transform(buf, in);
 | 
				
			||||||
 | 
								len -= 32;
 | 
				
			||||||
 | 
								p += 32;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							minor_hash = buf[2];
 | 
				
			||||||
 | 
							hash = buf[1];
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case DX_HASH_TEA:
 | 
				
			||||||
 | 
							p = name;
 | 
				
			||||||
 | 
							while (len > 0) {
 | 
				
			||||||
 | 
								str2hashbuf(p, len, in, 4);
 | 
				
			||||||
 | 
								TEA_transform(buf, in);
 | 
				
			||||||
 | 
								len -= 16;
 | 
				
			||||||
 | 
								p += 16;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							hash = buf[0];
 | 
				
			||||||
 | 
							minor_hash = buf[1];
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							hinfo->hash = 0;
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						hash = hash & ~1;
 | 
				
			||||||
 | 
						if (hash == (EXT3_HTREE_EOF << 1))
 | 
				
			||||||
 | 
							hash = (EXT3_HTREE_EOF-1) << 1;
 | 
				
			||||||
 | 
						hinfo->hash = hash;
 | 
				
			||||||
 | 
						hinfo->minor_hash = minor_hash;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										758
									
								
								fs/ext4/ialloc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										758
									
								
								fs/ext4/ialloc.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,758 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/ialloc.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  BSD ufs-inspired inode and directory allocation by
 | 
				
			||||||
 | 
					 *  Stephen Tweedie (sct@redhat.com), 1993
 | 
				
			||||||
 | 
					 *  Big-endian to little-endian byte-swapping/bitmaps by
 | 
				
			||||||
 | 
					 *        David S. Miller (davem@caip.rutgers.edu), 1995
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/time.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include <linux/stat.h>
 | 
				
			||||||
 | 
					#include <linux/string.h>
 | 
				
			||||||
 | 
					#include <linux/quotaops.h>
 | 
				
			||||||
 | 
					#include <linux/buffer_head.h>
 | 
				
			||||||
 | 
					#include <linux/random.h>
 | 
				
			||||||
 | 
					#include <linux/bitops.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <asm/byteorder.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					#include "acl.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * ialloc.c contains the inodes allocation and deallocation routines
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * The free inodes are managed by bitmaps.  A file system contains several
 | 
				
			||||||
 | 
					 * blocks groups.  Each group contains 1 bitmap block for blocks, 1 bitmap
 | 
				
			||||||
 | 
					 * block for inodes, N blocks for the inode table and data blocks.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The file system contains group descriptors which are located after the
 | 
				
			||||||
 | 
					 * super block.  Each descriptor contains the number of the bitmap block and
 | 
				
			||||||
 | 
					 * the free blocks count in the block.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Read the inode allocation bitmap for a given block_group, reading
 | 
				
			||||||
 | 
					 * into the specified slot in the superblock's bitmap cache.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Return buffer_head of bitmap on success or NULL.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static struct buffer_head *
 | 
				
			||||||
 | 
					read_inode_bitmap(struct super_block * sb, unsigned long block_group)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct ext3_group_desc *desc;
 | 
				
			||||||
 | 
						struct buffer_head *bh = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						desc = ext3_get_group_desc(sb, block_group, NULL);
 | 
				
			||||||
 | 
						if (!desc)
 | 
				
			||||||
 | 
							goto error_out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
 | 
				
			||||||
 | 
						if (!bh)
 | 
				
			||||||
 | 
							ext3_error(sb, "read_inode_bitmap",
 | 
				
			||||||
 | 
								    "Cannot read inode bitmap - "
 | 
				
			||||||
 | 
								    "block_group = %lu, inode_bitmap = %u",
 | 
				
			||||||
 | 
								    block_group, le32_to_cpu(desc->bg_inode_bitmap));
 | 
				
			||||||
 | 
					error_out:
 | 
				
			||||||
 | 
						return bh;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * NOTE! When we get the inode, we're the only people
 | 
				
			||||||
 | 
					 * that have access to it, and as such there are no
 | 
				
			||||||
 | 
					 * race conditions we have to worry about. The inode
 | 
				
			||||||
 | 
					 * is not on the hash-lists, and it cannot be reached
 | 
				
			||||||
 | 
					 * through the filesystem because the directory entry
 | 
				
			||||||
 | 
					 * has been deleted earlier.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * HOWEVER: we must make sure that we get no aliases,
 | 
				
			||||||
 | 
					 * which means that we have to call "clear_inode()"
 | 
				
			||||||
 | 
					 * _before_ we mark the inode not in use in the inode
 | 
				
			||||||
 | 
					 * bitmaps. Otherwise a newly created file might use
 | 
				
			||||||
 | 
					 * the same inode number (not actually the same pointer
 | 
				
			||||||
 | 
					 * though), and then we'd have two inodes sharing the
 | 
				
			||||||
 | 
					 * same inode number and space on the harddisk.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void ext3_free_inode (handle_t *handle, struct inode * inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct super_block * sb = inode->i_sb;
 | 
				
			||||||
 | 
						int is_directory;
 | 
				
			||||||
 | 
						unsigned long ino;
 | 
				
			||||||
 | 
						struct buffer_head *bitmap_bh = NULL;
 | 
				
			||||||
 | 
						struct buffer_head *bh2;
 | 
				
			||||||
 | 
						unsigned long block_group;
 | 
				
			||||||
 | 
						unsigned long bit;
 | 
				
			||||||
 | 
						struct ext3_group_desc * gdp;
 | 
				
			||||||
 | 
						struct ext3_super_block * es;
 | 
				
			||||||
 | 
						struct ext3_sb_info *sbi;
 | 
				
			||||||
 | 
						int fatal = 0, err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (atomic_read(&inode->i_count) > 1) {
 | 
				
			||||||
 | 
							printk ("ext3_free_inode: inode has count=%d\n",
 | 
				
			||||||
 | 
										atomic_read(&inode->i_count));
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (inode->i_nlink) {
 | 
				
			||||||
 | 
							printk ("ext3_free_inode: inode has nlink=%d\n",
 | 
				
			||||||
 | 
								inode->i_nlink);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (!sb) {
 | 
				
			||||||
 | 
							printk("ext3_free_inode: inode on nonexistent device\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						sbi = EXT3_SB(sb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ino = inode->i_ino;
 | 
				
			||||||
 | 
						ext3_debug ("freeing inode %lu\n", ino);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Note: we must free any quota before locking the superblock,
 | 
				
			||||||
 | 
						 * as writing the quota to disk may need the lock as well.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						DQUOT_INIT(inode);
 | 
				
			||||||
 | 
						ext3_xattr_delete_inode(handle, inode);
 | 
				
			||||||
 | 
						DQUOT_FREE_INODE(inode);
 | 
				
			||||||
 | 
						DQUOT_DROP(inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						is_directory = S_ISDIR(inode->i_mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Do this BEFORE marking the inode not in use or returning an error */
 | 
				
			||||||
 | 
						clear_inode (inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						es = EXT3_SB(sb)->s_es;
 | 
				
			||||||
 | 
						if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
 | 
				
			||||||
 | 
							ext3_error (sb, "ext3_free_inode",
 | 
				
			||||||
 | 
								    "reserved or nonexistent inode %lu", ino);
 | 
				
			||||||
 | 
							goto error_return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb);
 | 
				
			||||||
 | 
						bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb);
 | 
				
			||||||
 | 
						bitmap_bh = read_inode_bitmap(sb, block_group);
 | 
				
			||||||
 | 
						if (!bitmap_bh)
 | 
				
			||||||
 | 
							goto error_return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						BUFFER_TRACE(bitmap_bh, "get_write_access");
 | 
				
			||||||
 | 
						fatal = ext3_journal_get_write_access(handle, bitmap_bh);
 | 
				
			||||||
 | 
						if (fatal)
 | 
				
			||||||
 | 
							goto error_return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Ok, now we can actually update the inode bitmaps.. */
 | 
				
			||||||
 | 
						if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
 | 
				
			||||||
 | 
										bit, bitmap_bh->b_data))
 | 
				
			||||||
 | 
							ext3_error (sb, "ext3_free_inode",
 | 
				
			||||||
 | 
								      "bit already cleared for inode %lu", ino);
 | 
				
			||||||
 | 
						else {
 | 
				
			||||||
 | 
							gdp = ext3_get_group_desc (sb, block_group, &bh2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							BUFFER_TRACE(bh2, "get_write_access");
 | 
				
			||||||
 | 
							fatal = ext3_journal_get_write_access(handle, bh2);
 | 
				
			||||||
 | 
							if (fatal) goto error_return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (gdp) {
 | 
				
			||||||
 | 
								spin_lock(sb_bgl_lock(sbi, block_group));
 | 
				
			||||||
 | 
								gdp->bg_free_inodes_count = cpu_to_le16(
 | 
				
			||||||
 | 
									le16_to_cpu(gdp->bg_free_inodes_count) + 1);
 | 
				
			||||||
 | 
								if (is_directory)
 | 
				
			||||||
 | 
									gdp->bg_used_dirs_count = cpu_to_le16(
 | 
				
			||||||
 | 
									  le16_to_cpu(gdp->bg_used_dirs_count) - 1);
 | 
				
			||||||
 | 
								spin_unlock(sb_bgl_lock(sbi, block_group));
 | 
				
			||||||
 | 
								percpu_counter_inc(&sbi->s_freeinodes_counter);
 | 
				
			||||||
 | 
								if (is_directory)
 | 
				
			||||||
 | 
									percpu_counter_dec(&sbi->s_dirs_counter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
 | 
				
			||||||
 | 
							err = ext3_journal_dirty_metadata(handle, bh2);
 | 
				
			||||||
 | 
							if (!fatal) fatal = err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						BUFFER_TRACE(bitmap_bh, "call ext3_journal_dirty_metadata");
 | 
				
			||||||
 | 
						err = ext3_journal_dirty_metadata(handle, bitmap_bh);
 | 
				
			||||||
 | 
						if (!fatal)
 | 
				
			||||||
 | 
							fatal = err;
 | 
				
			||||||
 | 
						sb->s_dirt = 1;
 | 
				
			||||||
 | 
					error_return:
 | 
				
			||||||
 | 
						brelse(bitmap_bh);
 | 
				
			||||||
 | 
						ext3_std_error(sb, fatal);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * There are two policies for allocating an inode.  If the new inode is
 | 
				
			||||||
 | 
					 * a directory, then a forward search is made for a block group with both
 | 
				
			||||||
 | 
					 * free space and a low directory-to-inode ratio; if that fails, then of
 | 
				
			||||||
 | 
					 * the groups with above-average free space, that group with the fewest
 | 
				
			||||||
 | 
					 * directories already is chosen.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For other inodes, search forward from the parent directory\'s block
 | 
				
			||||||
 | 
					 * group to find a free inode.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static int find_group_dir(struct super_block *sb, struct inode *parent)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int ngroups = EXT3_SB(sb)->s_groups_count;
 | 
				
			||||||
 | 
						unsigned int freei, avefreei;
 | 
				
			||||||
 | 
						struct ext3_group_desc *desc, *best_desc = NULL;
 | 
				
			||||||
 | 
						struct buffer_head *bh;
 | 
				
			||||||
 | 
						int group, best_group = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						freei = percpu_counter_read_positive(&EXT3_SB(sb)->s_freeinodes_counter);
 | 
				
			||||||
 | 
						avefreei = freei / ngroups;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (group = 0; group < ngroups; group++) {
 | 
				
			||||||
 | 
							desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
							if (!desc || !desc->bg_free_inodes_count)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (!best_desc ||
 | 
				
			||||||
 | 
							    (le16_to_cpu(desc->bg_free_blocks_count) >
 | 
				
			||||||
 | 
							     le16_to_cpu(best_desc->bg_free_blocks_count))) {
 | 
				
			||||||
 | 
								best_group = group;
 | 
				
			||||||
 | 
								best_desc = desc;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return best_group;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Orlov's allocator for directories.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * We always try to spread first-level directories.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * If there are blockgroups with both free inodes and free blocks counts
 | 
				
			||||||
 | 
					 * not worse than average we return one with smallest directory count.
 | 
				
			||||||
 | 
					 * Otherwise we simply return a random group.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the rest rules look so:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * It's OK to put directory into a group unless
 | 
				
			||||||
 | 
					 * it has too many directories already (max_dirs) or
 | 
				
			||||||
 | 
					 * it has too few free inodes left (min_inodes) or
 | 
				
			||||||
 | 
					 * it has too few free blocks left (min_blocks) or
 | 
				
			||||||
 | 
					 * it's already running too large debt (max_debt).
 | 
				
			||||||
 | 
					 * Parent's group is prefered, if it doesn't satisfy these
 | 
				
			||||||
 | 
					 * conditions we search cyclically through the rest. If none
 | 
				
			||||||
 | 
					 * of the groups look good we just look for a group with more
 | 
				
			||||||
 | 
					 * free inodes than average (starting at parent's group).
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Debt is incremented each time we allocate a directory and decremented
 | 
				
			||||||
 | 
					 * when we allocate an inode, within 0--255.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define INODE_COST 64
 | 
				
			||||||
 | 
					#define BLOCK_COST 256
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int find_group_orlov(struct super_block *sb, struct inode *parent)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int parent_group = EXT3_I(parent)->i_block_group;
 | 
				
			||||||
 | 
						struct ext3_sb_info *sbi = EXT3_SB(sb);
 | 
				
			||||||
 | 
						struct ext3_super_block *es = sbi->s_es;
 | 
				
			||||||
 | 
						int ngroups = sbi->s_groups_count;
 | 
				
			||||||
 | 
						int inodes_per_group = EXT3_INODES_PER_GROUP(sb);
 | 
				
			||||||
 | 
						unsigned int freei, avefreei;
 | 
				
			||||||
 | 
						ext3_fsblk_t freeb, avefreeb;
 | 
				
			||||||
 | 
						ext3_fsblk_t blocks_per_dir;
 | 
				
			||||||
 | 
						unsigned int ndirs;
 | 
				
			||||||
 | 
						int max_debt, max_dirs, min_inodes;
 | 
				
			||||||
 | 
						ext3_grpblk_t min_blocks;
 | 
				
			||||||
 | 
						int group = -1, i;
 | 
				
			||||||
 | 
						struct ext3_group_desc *desc;
 | 
				
			||||||
 | 
						struct buffer_head *bh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter);
 | 
				
			||||||
 | 
						avefreei = freei / ngroups;
 | 
				
			||||||
 | 
						freeb = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
 | 
				
			||||||
 | 
						avefreeb = freeb / ngroups;
 | 
				
			||||||
 | 
						ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ((parent == sb->s_root->d_inode) ||
 | 
				
			||||||
 | 
						    (EXT3_I(parent)->i_flags & EXT3_TOPDIR_FL)) {
 | 
				
			||||||
 | 
							int best_ndir = inodes_per_group;
 | 
				
			||||||
 | 
							int best_group = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							get_random_bytes(&group, sizeof(group));
 | 
				
			||||||
 | 
							parent_group = (unsigned)group % ngroups;
 | 
				
			||||||
 | 
							for (i = 0; i < ngroups; i++) {
 | 
				
			||||||
 | 
								group = (parent_group + i) % ngroups;
 | 
				
			||||||
 | 
								desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
								if (!desc || !desc->bg_free_inodes_count)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								if (le16_to_cpu(desc->bg_free_blocks_count) < avefreeb)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								best_group = group;
 | 
				
			||||||
 | 
								best_ndir = le16_to_cpu(desc->bg_used_dirs_count);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (best_group >= 0)
 | 
				
			||||||
 | 
								return best_group;
 | 
				
			||||||
 | 
							goto fallback;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						blocks_per_dir = (le32_to_cpu(es->s_blocks_count) - freeb) / ndirs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						max_dirs = ndirs / ngroups + inodes_per_group / 16;
 | 
				
			||||||
 | 
						min_inodes = avefreei - inodes_per_group / 4;
 | 
				
			||||||
 | 
						min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext3_fsblk_t)BLOCK_COST);
 | 
				
			||||||
 | 
						if (max_debt * INODE_COST > inodes_per_group)
 | 
				
			||||||
 | 
							max_debt = inodes_per_group / INODE_COST;
 | 
				
			||||||
 | 
						if (max_debt > 255)
 | 
				
			||||||
 | 
							max_debt = 255;
 | 
				
			||||||
 | 
						if (max_debt == 0)
 | 
				
			||||||
 | 
							max_debt = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < ngroups; i++) {
 | 
				
			||||||
 | 
							group = (parent_group + i) % ngroups;
 | 
				
			||||||
 | 
							desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
							if (!desc || !desc->bg_free_inodes_count)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (le16_to_cpu(desc->bg_free_inodes_count) < min_inodes)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (le16_to_cpu(desc->bg_free_blocks_count) < min_blocks)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							return group;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fallback:
 | 
				
			||||||
 | 
						for (i = 0; i < ngroups; i++) {
 | 
				
			||||||
 | 
							group = (parent_group + i) % ngroups;
 | 
				
			||||||
 | 
							desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
							if (!desc || !desc->bg_free_inodes_count)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei)
 | 
				
			||||||
 | 
								return group;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (avefreei) {
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * The free-inodes counter is approximate, and for really small
 | 
				
			||||||
 | 
							 * filesystems the above test can fail to find any blockgroups
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							avefreei = 0;
 | 
				
			||||||
 | 
							goto fallback;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int find_group_other(struct super_block *sb, struct inode *parent)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int parent_group = EXT3_I(parent)->i_block_group;
 | 
				
			||||||
 | 
						int ngroups = EXT3_SB(sb)->s_groups_count;
 | 
				
			||||||
 | 
						struct ext3_group_desc *desc;
 | 
				
			||||||
 | 
						struct buffer_head *bh;
 | 
				
			||||||
 | 
						int group, i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Try to place the inode in its parent directory
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						group = parent_group;
 | 
				
			||||||
 | 
						desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
						if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
 | 
				
			||||||
 | 
								le16_to_cpu(desc->bg_free_blocks_count))
 | 
				
			||||||
 | 
							return group;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * We're going to place this inode in a different blockgroup from its
 | 
				
			||||||
 | 
						 * parent.  We want to cause files in a common directory to all land in
 | 
				
			||||||
 | 
						 * the same blockgroup.  But we want files which are in a different
 | 
				
			||||||
 | 
						 * directory which shares a blockgroup with our parent to land in a
 | 
				
			||||||
 | 
						 * different blockgroup.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * So add our directory's i_ino into the starting point for the hash.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						group = (group + parent->i_ino) % ngroups;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Use a quadratic hash to find a group with a free inode and some free
 | 
				
			||||||
 | 
						 * blocks.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						for (i = 1; i < ngroups; i <<= 1) {
 | 
				
			||||||
 | 
							group += i;
 | 
				
			||||||
 | 
							if (group >= ngroups)
 | 
				
			||||||
 | 
								group -= ngroups;
 | 
				
			||||||
 | 
							desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
							if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
 | 
				
			||||||
 | 
									le16_to_cpu(desc->bg_free_blocks_count))
 | 
				
			||||||
 | 
								return group;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * That failed: try linear search for a free inode, even if that group
 | 
				
			||||||
 | 
						 * has no free blocks.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						group = parent_group;
 | 
				
			||||||
 | 
						for (i = 0; i < ngroups; i++) {
 | 
				
			||||||
 | 
							if (++group >= ngroups)
 | 
				
			||||||
 | 
								group = 0;
 | 
				
			||||||
 | 
							desc = ext3_get_group_desc (sb, group, &bh);
 | 
				
			||||||
 | 
							if (desc && le16_to_cpu(desc->bg_free_inodes_count))
 | 
				
			||||||
 | 
								return group;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * There are two policies for allocating an inode.  If the new inode is
 | 
				
			||||||
 | 
					 * a directory, then a forward search is made for a block group with both
 | 
				
			||||||
 | 
					 * free space and a low directory-to-inode ratio; if that fails, then of
 | 
				
			||||||
 | 
					 * the groups with above-average free space, that group with the fewest
 | 
				
			||||||
 | 
					 * directories already is chosen.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For other inodes, search forward from the parent directory's block
 | 
				
			||||||
 | 
					 * group to find a free inode.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct super_block *sb;
 | 
				
			||||||
 | 
						struct buffer_head *bitmap_bh = NULL;
 | 
				
			||||||
 | 
						struct buffer_head *bh2;
 | 
				
			||||||
 | 
						int group;
 | 
				
			||||||
 | 
						unsigned long ino = 0;
 | 
				
			||||||
 | 
						struct inode * inode;
 | 
				
			||||||
 | 
						struct ext3_group_desc * gdp = NULL;
 | 
				
			||||||
 | 
						struct ext3_super_block * es;
 | 
				
			||||||
 | 
						struct ext3_inode_info *ei;
 | 
				
			||||||
 | 
						struct ext3_sb_info *sbi;
 | 
				
			||||||
 | 
						int err = 0;
 | 
				
			||||||
 | 
						struct inode *ret;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Cannot create files in a deleted directory */
 | 
				
			||||||
 | 
						if (!dir || !dir->i_nlink)
 | 
				
			||||||
 | 
							return ERR_PTR(-EPERM);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sb = dir->i_sb;
 | 
				
			||||||
 | 
						inode = new_inode(sb);
 | 
				
			||||||
 | 
						if (!inode)
 | 
				
			||||||
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
 | 
						ei = EXT3_I(inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sbi = EXT3_SB(sb);
 | 
				
			||||||
 | 
						es = sbi->s_es;
 | 
				
			||||||
 | 
						if (S_ISDIR(mode)) {
 | 
				
			||||||
 | 
							if (test_opt (sb, OLDALLOC))
 | 
				
			||||||
 | 
								group = find_group_dir(sb, dir);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								group = find_group_orlov(sb, dir);
 | 
				
			||||||
 | 
						} else
 | 
				
			||||||
 | 
							group = find_group_other(sb, dir);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = -ENOSPC;
 | 
				
			||||||
 | 
						if (group == -1)
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < sbi->s_groups_count; i++) {
 | 
				
			||||||
 | 
							err = -EIO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							gdp = ext3_get_group_desc(sb, group, &bh2);
 | 
				
			||||||
 | 
							if (!gdp)
 | 
				
			||||||
 | 
								goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							brelse(bitmap_bh);
 | 
				
			||||||
 | 
							bitmap_bh = read_inode_bitmap(sb, group);
 | 
				
			||||||
 | 
							if (!bitmap_bh)
 | 
				
			||||||
 | 
								goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ino = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					repeat_in_this_group:
 | 
				
			||||||
 | 
							ino = ext3_find_next_zero_bit((unsigned long *)
 | 
				
			||||||
 | 
									bitmap_bh->b_data, EXT3_INODES_PER_GROUP(sb), ino);
 | 
				
			||||||
 | 
							if (ino < EXT3_INODES_PER_GROUP(sb)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								BUFFER_TRACE(bitmap_bh, "get_write_access");
 | 
				
			||||||
 | 
								err = ext3_journal_get_write_access(handle, bitmap_bh);
 | 
				
			||||||
 | 
								if (err)
 | 
				
			||||||
 | 
									goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (!ext3_set_bit_atomic(sb_bgl_lock(sbi, group),
 | 
				
			||||||
 | 
											ino, bitmap_bh->b_data)) {
 | 
				
			||||||
 | 
									/* we won it */
 | 
				
			||||||
 | 
									BUFFER_TRACE(bitmap_bh,
 | 
				
			||||||
 | 
										"call ext3_journal_dirty_metadata");
 | 
				
			||||||
 | 
									err = ext3_journal_dirty_metadata(handle,
 | 
				
			||||||
 | 
													bitmap_bh);
 | 
				
			||||||
 | 
									if (err)
 | 
				
			||||||
 | 
										goto fail;
 | 
				
			||||||
 | 
									goto got;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								/* we lost it */
 | 
				
			||||||
 | 
								journal_release_buffer(handle, bitmap_bh);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (++ino < EXT3_INODES_PER_GROUP(sb))
 | 
				
			||||||
 | 
									goto repeat_in_this_group;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * This case is possible in concurrent environment.  It is very
 | 
				
			||||||
 | 
							 * rare.  We cannot repeat the find_group_xxx() call because
 | 
				
			||||||
 | 
							 * that will simply return the same blockgroup, because the
 | 
				
			||||||
 | 
							 * group descriptor metadata has not yet been updated.
 | 
				
			||||||
 | 
							 * So we just go onto the next blockgroup.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if (++group == sbi->s_groups_count)
 | 
				
			||||||
 | 
								group = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = -ENOSPC;
 | 
				
			||||||
 | 
						goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					got:
 | 
				
			||||||
 | 
						ino += group * EXT3_INODES_PER_GROUP(sb) + 1;
 | 
				
			||||||
 | 
						if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
 | 
				
			||||||
 | 
							ext3_error (sb, "ext3_new_inode",
 | 
				
			||||||
 | 
								    "reserved inode or inode > inodes count - "
 | 
				
			||||||
 | 
								    "block_group = %d, inode=%lu", group, ino);
 | 
				
			||||||
 | 
							err = -EIO;
 | 
				
			||||||
 | 
							goto fail;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						BUFFER_TRACE(bh2, "get_write_access");
 | 
				
			||||||
 | 
						err = ext3_journal_get_write_access(handle, bh2);
 | 
				
			||||||
 | 
						if (err) goto fail;
 | 
				
			||||||
 | 
						spin_lock(sb_bgl_lock(sbi, group));
 | 
				
			||||||
 | 
						gdp->bg_free_inodes_count =
 | 
				
			||||||
 | 
							cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1);
 | 
				
			||||||
 | 
						if (S_ISDIR(mode)) {
 | 
				
			||||||
 | 
							gdp->bg_used_dirs_count =
 | 
				
			||||||
 | 
								cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						spin_unlock(sb_bgl_lock(sbi, group));
 | 
				
			||||||
 | 
						BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
 | 
				
			||||||
 | 
						err = ext3_journal_dirty_metadata(handle, bh2);
 | 
				
			||||||
 | 
						if (err) goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						percpu_counter_dec(&sbi->s_freeinodes_counter);
 | 
				
			||||||
 | 
						if (S_ISDIR(mode))
 | 
				
			||||||
 | 
							percpu_counter_inc(&sbi->s_dirs_counter);
 | 
				
			||||||
 | 
						sb->s_dirt = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						inode->i_uid = current->fsuid;
 | 
				
			||||||
 | 
						if (test_opt (sb, GRPID))
 | 
				
			||||||
 | 
							inode->i_gid = dir->i_gid;
 | 
				
			||||||
 | 
						else if (dir->i_mode & S_ISGID) {
 | 
				
			||||||
 | 
							inode->i_gid = dir->i_gid;
 | 
				
			||||||
 | 
							if (S_ISDIR(mode))
 | 
				
			||||||
 | 
								mode |= S_ISGID;
 | 
				
			||||||
 | 
						} else
 | 
				
			||||||
 | 
							inode->i_gid = current->fsgid;
 | 
				
			||||||
 | 
						inode->i_mode = mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						inode->i_ino = ino;
 | 
				
			||||||
 | 
						/* This is the optimal IO size (for stat), not the fs block size */
 | 
				
			||||||
 | 
						inode->i_blocks = 0;
 | 
				
			||||||
 | 
						inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(ei->i_data, 0, sizeof(ei->i_data));
 | 
				
			||||||
 | 
						ei->i_dir_start_lookup = 0;
 | 
				
			||||||
 | 
						ei->i_disksize = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
 | 
				
			||||||
 | 
						if (S_ISLNK(mode))
 | 
				
			||||||
 | 
							ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
 | 
				
			||||||
 | 
						/* dirsync only applies to directories */
 | 
				
			||||||
 | 
						if (!S_ISDIR(mode))
 | 
				
			||||||
 | 
							ei->i_flags &= ~EXT3_DIRSYNC_FL;
 | 
				
			||||||
 | 
					#ifdef EXT3_FRAGMENTS
 | 
				
			||||||
 | 
						ei->i_faddr = 0;
 | 
				
			||||||
 | 
						ei->i_frag_no = 0;
 | 
				
			||||||
 | 
						ei->i_frag_size = 0;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						ei->i_file_acl = 0;
 | 
				
			||||||
 | 
						ei->i_dir_acl = 0;
 | 
				
			||||||
 | 
						ei->i_dtime = 0;
 | 
				
			||||||
 | 
						ei->i_block_alloc_info = NULL;
 | 
				
			||||||
 | 
						ei->i_block_group = group;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ext3_set_inode_flags(inode);
 | 
				
			||||||
 | 
						if (IS_DIRSYNC(inode))
 | 
				
			||||||
 | 
							handle->h_sync = 1;
 | 
				
			||||||
 | 
						insert_inode_hash(inode);
 | 
				
			||||||
 | 
						spin_lock(&sbi->s_next_gen_lock);
 | 
				
			||||||
 | 
						inode->i_generation = sbi->s_next_generation++;
 | 
				
			||||||
 | 
						spin_unlock(&sbi->s_next_gen_lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ei->i_state = EXT3_STATE_NEW;
 | 
				
			||||||
 | 
						ei->i_extra_isize =
 | 
				
			||||||
 | 
							(EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) ?
 | 
				
			||||||
 | 
							sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = inode;
 | 
				
			||||||
 | 
						if(DQUOT_ALLOC_INODE(inode)) {
 | 
				
			||||||
 | 
							err = -EDQUOT;
 | 
				
			||||||
 | 
							goto fail_drop;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ext3_init_acl(handle, inode, dir);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							goto fail_free_drop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ext3_init_security(handle,inode, dir);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							goto fail_free_drop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = ext3_mark_inode_dirty(handle, inode);
 | 
				
			||||||
 | 
						if (err) {
 | 
				
			||||||
 | 
							ext3_std_error(sb, err);
 | 
				
			||||||
 | 
							goto fail_free_drop;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ext3_debug("allocating inode %lu\n", inode->i_ino);
 | 
				
			||||||
 | 
						goto really_out;
 | 
				
			||||||
 | 
					fail:
 | 
				
			||||||
 | 
						ext3_std_error(sb, err);
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						iput(inode);
 | 
				
			||||||
 | 
						ret = ERR_PTR(err);
 | 
				
			||||||
 | 
					really_out:
 | 
				
			||||||
 | 
						brelse(bitmap_bh);
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fail_free_drop:
 | 
				
			||||||
 | 
						DQUOT_FREE_INODE(inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fail_drop:
 | 
				
			||||||
 | 
						DQUOT_DROP(inode);
 | 
				
			||||||
 | 
						inode->i_flags |= S_NOQUOTA;
 | 
				
			||||||
 | 
						inode->i_nlink = 0;
 | 
				
			||||||
 | 
						iput(inode);
 | 
				
			||||||
 | 
						brelse(bitmap_bh);
 | 
				
			||||||
 | 
						return ERR_PTR(err);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Verify that we are loading a valid orphan from disk */
 | 
				
			||||||
 | 
					struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count);
 | 
				
			||||||
 | 
						unsigned long block_group;
 | 
				
			||||||
 | 
						int bit;
 | 
				
			||||||
 | 
						struct buffer_head *bitmap_bh = NULL;
 | 
				
			||||||
 | 
						struct inode *inode = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Error cases - e2fsck has already cleaned up for us */
 | 
				
			||||||
 | 
						if (ino > max_ino) {
 | 
				
			||||||
 | 
							ext3_warning(sb, __FUNCTION__,
 | 
				
			||||||
 | 
								     "bad orphan ino %lu!  e2fsck was run?", ino);
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb);
 | 
				
			||||||
 | 
						bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb);
 | 
				
			||||||
 | 
						bitmap_bh = read_inode_bitmap(sb, block_group);
 | 
				
			||||||
 | 
						if (!bitmap_bh) {
 | 
				
			||||||
 | 
							ext3_warning(sb, __FUNCTION__,
 | 
				
			||||||
 | 
								     "inode bitmap error for orphan %lu", ino);
 | 
				
			||||||
 | 
							goto out;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Having the inode bit set should be a 100% indicator that this
 | 
				
			||||||
 | 
						 * is a valid orphan (no e2fsck run on fs).  Orphans also include
 | 
				
			||||||
 | 
						 * inodes that were being truncated, so we can't check i_nlink==0.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (!ext3_test_bit(bit, bitmap_bh->b_data) ||
 | 
				
			||||||
 | 
								!(inode = iget(sb, ino)) || is_bad_inode(inode) ||
 | 
				
			||||||
 | 
								NEXT_ORPHAN(inode) > max_ino) {
 | 
				
			||||||
 | 
							ext3_warning(sb, __FUNCTION__,
 | 
				
			||||||
 | 
								     "bad orphan inode %lu!  e2fsck was run?", ino);
 | 
				
			||||||
 | 
							printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n",
 | 
				
			||||||
 | 
							       bit, (unsigned long long)bitmap_bh->b_blocknr,
 | 
				
			||||||
 | 
							       ext3_test_bit(bit, bitmap_bh->b_data));
 | 
				
			||||||
 | 
							printk(KERN_NOTICE "inode=%p\n", inode);
 | 
				
			||||||
 | 
							if (inode) {
 | 
				
			||||||
 | 
								printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
 | 
				
			||||||
 | 
								       is_bad_inode(inode));
 | 
				
			||||||
 | 
								printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
 | 
				
			||||||
 | 
								       NEXT_ORPHAN(inode));
 | 
				
			||||||
 | 
								printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							/* Avoid freeing blocks if we got a bad deleted inode */
 | 
				
			||||||
 | 
							if (inode && inode->i_nlink == 0)
 | 
				
			||||||
 | 
								inode->i_blocks = 0;
 | 
				
			||||||
 | 
							iput(inode);
 | 
				
			||||||
 | 
							inode = NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
 | 
						brelse(bitmap_bh);
 | 
				
			||||||
 | 
						return inode;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned long ext3_count_free_inodes (struct super_block * sb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned long desc_count;
 | 
				
			||||||
 | 
						struct ext3_group_desc *gdp;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					#ifdef EXT3FS_DEBUG
 | 
				
			||||||
 | 
						struct ext3_super_block *es;
 | 
				
			||||||
 | 
						unsigned long bitmap_count, x;
 | 
				
			||||||
 | 
						struct buffer_head *bitmap_bh = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						es = EXT3_SB(sb)->s_es;
 | 
				
			||||||
 | 
						desc_count = 0;
 | 
				
			||||||
 | 
						bitmap_count = 0;
 | 
				
			||||||
 | 
						gdp = NULL;
 | 
				
			||||||
 | 
						for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) {
 | 
				
			||||||
 | 
							gdp = ext3_get_group_desc (sb, i, NULL);
 | 
				
			||||||
 | 
							if (!gdp)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
 | 
				
			||||||
 | 
							brelse(bitmap_bh);
 | 
				
			||||||
 | 
							bitmap_bh = read_inode_bitmap(sb, i);
 | 
				
			||||||
 | 
							if (!bitmap_bh)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							x = ext3_count_free(bitmap_bh, EXT3_INODES_PER_GROUP(sb) / 8);
 | 
				
			||||||
 | 
							printk("group %d: stored = %d, counted = %lu\n",
 | 
				
			||||||
 | 
								i, le16_to_cpu(gdp->bg_free_inodes_count), x);
 | 
				
			||||||
 | 
							bitmap_count += x;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						brelse(bitmap_bh);
 | 
				
			||||||
 | 
						printk("ext3_count_free_inodes: stored = %u, computed = %lu, %lu\n",
 | 
				
			||||||
 | 
							le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count);
 | 
				
			||||||
 | 
						return desc_count;
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
						desc_count = 0;
 | 
				
			||||||
 | 
						for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) {
 | 
				
			||||||
 | 
							gdp = ext3_get_group_desc (sb, i, NULL);
 | 
				
			||||||
 | 
							if (!gdp)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
 | 
				
			||||||
 | 
							cond_resched();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return desc_count;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Called at mount-time, super-block is locked */
 | 
				
			||||||
 | 
					unsigned long ext3_count_dirs (struct super_block * sb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned long count = 0;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) {
 | 
				
			||||||
 | 
							struct ext3_group_desc *gdp = ext3_get_group_desc (sb, i, NULL);
 | 
				
			||||||
 | 
							if (!gdp)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							count += le16_to_cpu(gdp->bg_used_dirs_count);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return count;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										3219
									
								
								fs/ext4/inode.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3219
									
								
								fs/ext4/inode.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										307
									
								
								fs/ext4/ioctl.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										307
									
								
								fs/ext4/ioctl.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,307 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * linux/fs/ext3/ioctl.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/capability.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include <linux/time.h>
 | 
				
			||||||
 | 
					#include <linux/compat.h>
 | 
				
			||||||
 | 
					#include <linux/smp_lock.h>
 | 
				
			||||||
 | 
					#include <asm/uaccess.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
 | 
				
			||||||
 | 
							unsigned long arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct ext3_inode_info *ei = EXT3_I(inode);
 | 
				
			||||||
 | 
						unsigned int flags;
 | 
				
			||||||
 | 
						unsigned short rsv_window_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (cmd) {
 | 
				
			||||||
 | 
						case EXT3_IOC_GETFLAGS:
 | 
				
			||||||
 | 
							flags = ei->i_flags & EXT3_FL_USER_VISIBLE;
 | 
				
			||||||
 | 
							return put_user(flags, (int __user *) arg);
 | 
				
			||||||
 | 
						case EXT3_IOC_SETFLAGS: {
 | 
				
			||||||
 | 
							handle_t *handle = NULL;
 | 
				
			||||||
 | 
							int err;
 | 
				
			||||||
 | 
							struct ext3_iloc iloc;
 | 
				
			||||||
 | 
							unsigned int oldflags;
 | 
				
			||||||
 | 
							unsigned int jflag;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (IS_RDONLY(inode))
 | 
				
			||||||
 | 
								return -EROFS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
 | 
				
			||||||
 | 
								return -EACCES;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (get_user(flags, (int __user *) arg))
 | 
				
			||||||
 | 
								return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!S_ISDIR(inode->i_mode))
 | 
				
			||||||
 | 
								flags &= ~EXT3_DIRSYNC_FL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mutex_lock(&inode->i_mutex);
 | 
				
			||||||
 | 
							oldflags = ei->i_flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* The JOURNAL_DATA flag is modifiable only by root */
 | 
				
			||||||
 | 
							jflag = flags & EXT3_JOURNAL_DATA_FL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
 | 
				
			||||||
 | 
							 * the relevant capability.
 | 
				
			||||||
 | 
							 *
 | 
				
			||||||
 | 
							 * This test looks nicer. Thanks to Pauline Middelink
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
 | 
				
			||||||
 | 
								if (!capable(CAP_LINUX_IMMUTABLE)) {
 | 
				
			||||||
 | 
									mutex_unlock(&inode->i_mutex);
 | 
				
			||||||
 | 
									return -EPERM;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * The JOURNAL_DATA flag can only be changed by
 | 
				
			||||||
 | 
							 * the relevant capability.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) {
 | 
				
			||||||
 | 
								if (!capable(CAP_SYS_RESOURCE)) {
 | 
				
			||||||
 | 
									mutex_unlock(&inode->i_mutex);
 | 
				
			||||||
 | 
									return -EPERM;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							handle = ext3_journal_start(inode, 1);
 | 
				
			||||||
 | 
							if (IS_ERR(handle)) {
 | 
				
			||||||
 | 
								mutex_unlock(&inode->i_mutex);
 | 
				
			||||||
 | 
								return PTR_ERR(handle);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (IS_SYNC(inode))
 | 
				
			||||||
 | 
								handle->h_sync = 1;
 | 
				
			||||||
 | 
							err = ext3_reserve_inode_write(handle, inode, &iloc);
 | 
				
			||||||
 | 
							if (err)
 | 
				
			||||||
 | 
								goto flags_err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							flags = flags & EXT3_FL_USER_MODIFIABLE;
 | 
				
			||||||
 | 
							flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
 | 
				
			||||||
 | 
							ei->i_flags = flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ext3_set_inode_flags(inode);
 | 
				
			||||||
 | 
							inode->i_ctime = CURRENT_TIME_SEC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = ext3_mark_iloc_dirty(handle, inode, &iloc);
 | 
				
			||||||
 | 
					flags_err:
 | 
				
			||||||
 | 
							ext3_journal_stop(handle);
 | 
				
			||||||
 | 
							if (err) {
 | 
				
			||||||
 | 
								mutex_unlock(&inode->i_mutex);
 | 
				
			||||||
 | 
								return err;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL))
 | 
				
			||||||
 | 
								err = ext3_change_inode_journal_flag(inode, jflag);
 | 
				
			||||||
 | 
							mutex_unlock(&inode->i_mutex);
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						case EXT3_IOC_GETVERSION:
 | 
				
			||||||
 | 
						case EXT3_IOC_GETVERSION_OLD:
 | 
				
			||||||
 | 
							return put_user(inode->i_generation, (int __user *) arg);
 | 
				
			||||||
 | 
						case EXT3_IOC_SETVERSION:
 | 
				
			||||||
 | 
						case EXT3_IOC_SETVERSION_OLD: {
 | 
				
			||||||
 | 
							handle_t *handle;
 | 
				
			||||||
 | 
							struct ext3_iloc iloc;
 | 
				
			||||||
 | 
							__u32 generation;
 | 
				
			||||||
 | 
							int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
 | 
				
			||||||
 | 
								return -EPERM;
 | 
				
			||||||
 | 
							if (IS_RDONLY(inode))
 | 
				
			||||||
 | 
								return -EROFS;
 | 
				
			||||||
 | 
							if (get_user(generation, (int __user *) arg))
 | 
				
			||||||
 | 
								return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							handle = ext3_journal_start(inode, 1);
 | 
				
			||||||
 | 
							if (IS_ERR(handle))
 | 
				
			||||||
 | 
								return PTR_ERR(handle);
 | 
				
			||||||
 | 
							err = ext3_reserve_inode_write(handle, inode, &iloc);
 | 
				
			||||||
 | 
							if (err == 0) {
 | 
				
			||||||
 | 
								inode->i_ctime = CURRENT_TIME_SEC;
 | 
				
			||||||
 | 
								inode->i_generation = generation;
 | 
				
			||||||
 | 
								err = ext3_mark_iloc_dirty(handle, inode, &iloc);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							ext3_journal_stop(handle);
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#ifdef CONFIG_JBD_DEBUG
 | 
				
			||||||
 | 
						case EXT3_IOC_WAIT_FOR_READONLY:
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * This is racy - by the time we're woken up and running,
 | 
				
			||||||
 | 
							 * the superblock could be released.  And the module could
 | 
				
			||||||
 | 
							 * have been unloaded.  So sue me.
 | 
				
			||||||
 | 
							 *
 | 
				
			||||||
 | 
							 * Returns 1 if it slept, else zero.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								struct super_block *sb = inode->i_sb;
 | 
				
			||||||
 | 
								DECLARE_WAITQUEUE(wait, current);
 | 
				
			||||||
 | 
								int ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								set_current_state(TASK_INTERRUPTIBLE);
 | 
				
			||||||
 | 
								add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
 | 
				
			||||||
 | 
								if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) {
 | 
				
			||||||
 | 
									schedule();
 | 
				
			||||||
 | 
									ret = 1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait);
 | 
				
			||||||
 | 
								return ret;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						case EXT3_IOC_GETRSVSZ:
 | 
				
			||||||
 | 
							if (test_opt(inode->i_sb, RESERVATION)
 | 
				
			||||||
 | 
								&& S_ISREG(inode->i_mode)
 | 
				
			||||||
 | 
								&& ei->i_block_alloc_info) {
 | 
				
			||||||
 | 
								rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size;
 | 
				
			||||||
 | 
								return put_user(rsv_window_size, (int __user *)arg);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return -ENOTTY;
 | 
				
			||||||
 | 
						case EXT3_IOC_SETRSVSZ: {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
 | 
				
			||||||
 | 
								return -ENOTTY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (IS_RDONLY(inode))
 | 
				
			||||||
 | 
								return -EROFS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
 | 
				
			||||||
 | 
								return -EACCES;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (get_user(rsv_window_size, (int __user *)arg))
 | 
				
			||||||
 | 
								return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (rsv_window_size > EXT3_MAX_RESERVE_BLOCKS)
 | 
				
			||||||
 | 
								rsv_window_size = EXT3_MAX_RESERVE_BLOCKS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * need to allocate reservation structure for this inode
 | 
				
			||||||
 | 
							 * before set the window size
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							mutex_lock(&ei->truncate_mutex);
 | 
				
			||||||
 | 
							if (!ei->i_block_alloc_info)
 | 
				
			||||||
 | 
								ext3_init_block_alloc_info(inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (ei->i_block_alloc_info){
 | 
				
			||||||
 | 
								struct ext3_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
 | 
				
			||||||
 | 
								rsv->rsv_goal_size = rsv_window_size;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							mutex_unlock(&ei->truncate_mutex);
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						case EXT3_IOC_GROUP_EXTEND: {
 | 
				
			||||||
 | 
							ext3_fsblk_t n_blocks_count;
 | 
				
			||||||
 | 
							struct super_block *sb = inode->i_sb;
 | 
				
			||||||
 | 
							int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!capable(CAP_SYS_RESOURCE))
 | 
				
			||||||
 | 
								return -EPERM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (IS_RDONLY(inode))
 | 
				
			||||||
 | 
								return -EROFS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (get_user(n_blocks_count, (__u32 __user *)arg))
 | 
				
			||||||
 | 
								return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = ext3_group_extend(sb, EXT3_SB(sb)->s_es, n_blocks_count);
 | 
				
			||||||
 | 
							journal_lock_updates(EXT3_SB(sb)->s_journal);
 | 
				
			||||||
 | 
							journal_flush(EXT3_SB(sb)->s_journal);
 | 
				
			||||||
 | 
							journal_unlock_updates(EXT3_SB(sb)->s_journal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						case EXT3_IOC_GROUP_ADD: {
 | 
				
			||||||
 | 
							struct ext3_new_group_data input;
 | 
				
			||||||
 | 
							struct super_block *sb = inode->i_sb;
 | 
				
			||||||
 | 
							int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!capable(CAP_SYS_RESOURCE))
 | 
				
			||||||
 | 
								return -EPERM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (IS_RDONLY(inode))
 | 
				
			||||||
 | 
								return -EROFS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
 | 
				
			||||||
 | 
									sizeof(input)))
 | 
				
			||||||
 | 
								return -EFAULT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = ext3_group_add(sb, &input);
 | 
				
			||||||
 | 
							journal_lock_updates(EXT3_SB(sb)->s_journal);
 | 
				
			||||||
 | 
							journal_flush(EXT3_SB(sb)->s_journal);
 | 
				
			||||||
 | 
							journal_unlock_updates(EXT3_SB(sb)->s_journal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return -ENOTTY;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_COMPAT
 | 
				
			||||||
 | 
					long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct inode *inode = file->f_dentry->d_inode;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* These are just misnamed, they actually get/put from/to user an int */
 | 
				
			||||||
 | 
						switch (cmd) {
 | 
				
			||||||
 | 
						case EXT3_IOC32_GETFLAGS:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_GETFLAGS;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_SETFLAGS:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_SETFLAGS;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_GETVERSION:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_GETVERSION;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_SETVERSION:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_SETVERSION;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_GROUP_EXTEND:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_GROUP_EXTEND;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_GETVERSION_OLD:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_GETVERSION_OLD;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_SETVERSION_OLD:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_SETVERSION_OLD;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
					#ifdef CONFIG_JBD_DEBUG
 | 
				
			||||||
 | 
						case EXT3_IOC32_WAIT_FOR_READONLY:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_WAIT_FOR_READONLY;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						case EXT3_IOC32_GETRSVSZ:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_GETRSVSZ;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC32_SETRSVSZ:
 | 
				
			||||||
 | 
							cmd = EXT3_IOC_SETRSVSZ;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case EXT3_IOC_GROUP_ADD:
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return -ENOIOCTLCMD;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						lock_kernel();
 | 
				
			||||||
 | 
						ret = ext3_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
 | 
				
			||||||
 | 
						unlock_kernel();
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										2397
									
								
								fs/ext4/namei.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2397
									
								
								fs/ext4/namei.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										8
									
								
								fs/ext4/namei.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								fs/ext4/namei.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					/*  linux/fs/ext3/namei.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 2005 Simtec Electronics
 | 
				
			||||||
 | 
					 *	Ben Dooks <ben@simtec.co.uk>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern struct dentry *ext3_get_parent(struct dentry *child);
 | 
				
			||||||
							
								
								
									
										1042
									
								
								fs/ext4/resize.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1042
									
								
								fs/ext4/resize.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										2754
									
								
								fs/ext4/super.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2754
									
								
								fs/ext4/super.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										54
									
								
								fs/ext4/symlink.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								fs/ext4/symlink.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,54 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/fs/ext3/symlink.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  linux/fs/minix/symlink.c
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  ext3 symlink handling code
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/namei.h>
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void * ext3_follow_link(struct dentry *dentry, struct nameidata *nd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct ext3_inode_info *ei = EXT3_I(dentry->d_inode);
 | 
				
			||||||
 | 
						nd_set_link(nd, (char*)ei->i_data);
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inode_operations ext3_symlink_inode_operations = {
 | 
				
			||||||
 | 
						.readlink	= generic_readlink,
 | 
				
			||||||
 | 
						.follow_link	= page_follow_link_light,
 | 
				
			||||||
 | 
						.put_link	= page_put_link,
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_XATTR
 | 
				
			||||||
 | 
						.setxattr	= generic_setxattr,
 | 
				
			||||||
 | 
						.getxattr	= generic_getxattr,
 | 
				
			||||||
 | 
						.listxattr	= ext3_listxattr,
 | 
				
			||||||
 | 
						.removexattr	= generic_removexattr,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct inode_operations ext3_fast_symlink_inode_operations = {
 | 
				
			||||||
 | 
						.readlink	= generic_readlink,
 | 
				
			||||||
 | 
						.follow_link	= ext3_follow_link,
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_XATTR
 | 
				
			||||||
 | 
						.setxattr	= generic_setxattr,
 | 
				
			||||||
 | 
						.getxattr	= generic_getxattr,
 | 
				
			||||||
 | 
						.listxattr	= ext3_listxattr,
 | 
				
			||||||
 | 
						.removexattr	= generic_removexattr,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										1317
									
								
								fs/ext4/xattr.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1317
									
								
								fs/ext4/xattr.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										145
									
								
								fs/ext4/xattr.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								fs/ext4/xattr.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,145 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					  File: fs/ext3/xattr.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  On-disk format of extended attributes for the ext3 filesystem.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/xattr.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Magic value in attribute blocks */
 | 
				
			||||||
 | 
					#define EXT3_XATTR_MAGIC		0xEA020000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Maximum number of references to one attribute block */
 | 
				
			||||||
 | 
					#define EXT3_XATTR_REFCOUNT_MAX		1024
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Name indexes */
 | 
				
			||||||
 | 
					#define EXT3_XATTR_INDEX_USER			1
 | 
				
			||||||
 | 
					#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS	2
 | 
				
			||||||
 | 
					#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT	3
 | 
				
			||||||
 | 
					#define EXT3_XATTR_INDEX_TRUSTED		4
 | 
				
			||||||
 | 
					#define	EXT3_XATTR_INDEX_LUSTRE			5
 | 
				
			||||||
 | 
					#define EXT3_XATTR_INDEX_SECURITY	        6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_xattr_header {
 | 
				
			||||||
 | 
						__le32	h_magic;	/* magic number for identification */
 | 
				
			||||||
 | 
						__le32	h_refcount;	/* reference count */
 | 
				
			||||||
 | 
						__le32	h_blocks;	/* number of disk blocks used */
 | 
				
			||||||
 | 
						__le32	h_hash;		/* hash value of all attributes */
 | 
				
			||||||
 | 
						__u32	h_reserved[4];	/* zero right now */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_xattr_ibody_header {
 | 
				
			||||||
 | 
						__le32	h_magic;	/* magic number for identification */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_xattr_entry {
 | 
				
			||||||
 | 
						__u8	e_name_len;	/* length of name */
 | 
				
			||||||
 | 
						__u8	e_name_index;	/* attribute name index */
 | 
				
			||||||
 | 
						__le16	e_value_offs;	/* offset in disk block of value */
 | 
				
			||||||
 | 
						__le32	e_value_block;	/* disk block attribute is stored on (n/i) */
 | 
				
			||||||
 | 
						__le32	e_value_size;	/* size of attribute value */
 | 
				
			||||||
 | 
						__le32	e_hash;		/* hash value of name and value */
 | 
				
			||||||
 | 
						char	e_name[0];	/* attribute name */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_XATTR_PAD_BITS		2
 | 
				
			||||||
 | 
					#define EXT3_XATTR_PAD		(1<<EXT3_XATTR_PAD_BITS)
 | 
				
			||||||
 | 
					#define EXT3_XATTR_ROUND		(EXT3_XATTR_PAD-1)
 | 
				
			||||||
 | 
					#define EXT3_XATTR_LEN(name_len) \
 | 
				
			||||||
 | 
						(((name_len) + EXT3_XATTR_ROUND + \
 | 
				
			||||||
 | 
						sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND)
 | 
				
			||||||
 | 
					#define EXT3_XATTR_NEXT(entry) \
 | 
				
			||||||
 | 
						( (struct ext3_xattr_entry *)( \
 | 
				
			||||||
 | 
						  (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) )
 | 
				
			||||||
 | 
					#define EXT3_XATTR_SIZE(size) \
 | 
				
			||||||
 | 
						(((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ifdef CONFIG_EXT3_FS_XATTR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern struct xattr_handler ext3_xattr_user_handler;
 | 
				
			||||||
 | 
					extern struct xattr_handler ext3_xattr_trusted_handler;
 | 
				
			||||||
 | 
					extern struct xattr_handler ext3_xattr_acl_access_handler;
 | 
				
			||||||
 | 
					extern struct xattr_handler ext3_xattr_acl_default_handler;
 | 
				
			||||||
 | 
					extern struct xattr_handler ext3_xattr_security_handler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern ssize_t ext3_listxattr(struct dentry *, char *, size_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t);
 | 
				
			||||||
 | 
					extern int ext3_xattr_list(struct inode *, char *, size_t);
 | 
				
			||||||
 | 
					extern int ext3_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
 | 
				
			||||||
 | 
					extern int ext3_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
 | 
				
			||||||
 | 
					extern void ext3_xattr_put_super(struct super_block *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern int init_ext3_xattr(void);
 | 
				
			||||||
 | 
					extern void exit_ext3_xattr(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern struct xattr_handler *ext3_xattr_handlers[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# else  /* CONFIG_EXT3_FS_XATTR */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					ext3_xattr_get(struct inode *inode, int name_index, const char *name,
 | 
				
			||||||
 | 
						       void *buffer, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -EOPNOTSUPP;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					ext3_xattr_list(struct inode *inode, void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -EOPNOTSUPP;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					ext3_xattr_set(struct inode *inode, int name_index, const char *name,
 | 
				
			||||||
 | 
						       const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -EOPNOTSUPP;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
 | 
				
			||||||
 | 
						       const char *name, const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -EOPNOTSUPP;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline void
 | 
				
			||||||
 | 
					ext3_xattr_delete_inode(handle_t *handle, struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline void
 | 
				
			||||||
 | 
					ext3_xattr_put_super(struct super_block *sb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					init_ext3_xattr(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline void
 | 
				
			||||||
 | 
					exit_ext3_xattr(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ext3_xattr_handlers	NULL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# endif  /* CONFIG_EXT3_FS_XATTR */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_SECURITY
 | 
				
			||||||
 | 
					extern int ext3_init_security(handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
									struct inode *dir);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					static inline int ext3_init_security(handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
									struct inode *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										77
									
								
								fs/ext4/xattr_security.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								fs/ext4/xattr_security.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,77 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * linux/fs/ext3/xattr_security.c
 | 
				
			||||||
 | 
					 * Handler for storing security labels as extended attributes.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/module.h>
 | 
				
			||||||
 | 
					#include <linux/string.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/smp_lock.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include <linux/security.h>
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static size_t
 | 
				
			||||||
 | 
					ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size,
 | 
				
			||||||
 | 
								 const char *name, size_t name_len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1;
 | 
				
			||||||
 | 
						const size_t total_len = prefix_len + name_len + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (list && total_len <= list_size) {
 | 
				
			||||||
 | 
							memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
 | 
				
			||||||
 | 
							memcpy(list+prefix_len, name, name_len);
 | 
				
			||||||
 | 
							list[prefix_len + name_len] = '\0';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return total_len;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_security_get(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
							       void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") == 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_get(inode, EXT3_XATTR_INDEX_SECURITY, name,
 | 
				
			||||||
 | 
								      buffer, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_security_set(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
							       const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") == 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_set(inode, EXT3_XATTR_INDEX_SECURITY, name,
 | 
				
			||||||
 | 
								      value, size, flags);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err;
 | 
				
			||||||
 | 
						size_t len;
 | 
				
			||||||
 | 
						void *value;
 | 
				
			||||||
 | 
						char *name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = security_inode_init_security(inode, dir, &name, &value, &len);
 | 
				
			||||||
 | 
						if (err) {
 | 
				
			||||||
 | 
							if (err == -EOPNOTSUPP)
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							return err;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_SECURITY,
 | 
				
			||||||
 | 
									    name, value, len, 0);
 | 
				
			||||||
 | 
						kfree(name);
 | 
				
			||||||
 | 
						kfree(value);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct xattr_handler ext3_xattr_security_handler = {
 | 
				
			||||||
 | 
						.prefix	= XATTR_SECURITY_PREFIX,
 | 
				
			||||||
 | 
						.list	= ext3_xattr_security_list,
 | 
				
			||||||
 | 
						.get	= ext3_xattr_security_get,
 | 
				
			||||||
 | 
						.set	= ext3_xattr_security_set,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										62
									
								
								fs/ext4/xattr_trusted.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								fs/ext4/xattr_trusted.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,62 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * linux/fs/ext3/xattr_trusted.c
 | 
				
			||||||
 | 
					 * Handler for trusted extended attributes.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/module.h>
 | 
				
			||||||
 | 
					#include <linux/string.h>
 | 
				
			||||||
 | 
					#include <linux/capability.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/smp_lock.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define XATTR_TRUSTED_PREFIX "trusted."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static size_t
 | 
				
			||||||
 | 
					ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
 | 
				
			||||||
 | 
								const char *name, size_t name_len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
 | 
				
			||||||
 | 
						const size_t total_len = prefix_len + name_len + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!capable(CAP_SYS_ADMIN))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (list && total_len <= list_size) {
 | 
				
			||||||
 | 
							memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
 | 
				
			||||||
 | 
							memcpy(list+prefix_len, name, name_len);
 | 
				
			||||||
 | 
							list[prefix_len + name_len] = '\0';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return total_len;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_trusted_get(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
							       void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") == 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name,
 | 
				
			||||||
 | 
								      buffer, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_trusted_set(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
							       const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") == 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						return ext3_xattr_set(inode, EXT3_XATTR_INDEX_TRUSTED, name,
 | 
				
			||||||
 | 
								      value, size, flags);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct xattr_handler ext3_xattr_trusted_handler = {
 | 
				
			||||||
 | 
						.prefix	= XATTR_TRUSTED_PREFIX,
 | 
				
			||||||
 | 
						.list	= ext3_xattr_trusted_list,
 | 
				
			||||||
 | 
						.get	= ext3_xattr_trusted_get,
 | 
				
			||||||
 | 
						.set	= ext3_xattr_trusted_set,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										64
									
								
								fs/ext4/xattr_user.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								fs/ext4/xattr_user.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,64 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * linux/fs/ext3/xattr_user.c
 | 
				
			||||||
 | 
					 * Handler for extended user attributes.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/module.h>
 | 
				
			||||||
 | 
					#include <linux/string.h>
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/smp_lock.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					#include "xattr.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define XATTR_USER_PREFIX "user."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static size_t
 | 
				
			||||||
 | 
					ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size,
 | 
				
			||||||
 | 
							     const char *name, size_t name_len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
 | 
				
			||||||
 | 
						const size_t total_len = prefix_len + name_len + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, XATTR_USER))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (list && total_len <= list_size) {
 | 
				
			||||||
 | 
							memcpy(list, XATTR_USER_PREFIX, prefix_len);
 | 
				
			||||||
 | 
							memcpy(list+prefix_len, name, name_len);
 | 
				
			||||||
 | 
							list[prefix_len + name_len] = '\0';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return total_len;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_user_get(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
							    void *buffer, size_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") == 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, XATTR_USER))
 | 
				
			||||||
 | 
							return -EOPNOTSUPP;
 | 
				
			||||||
 | 
						return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					ext3_xattr_user_set(struct inode *inode, const char *name,
 | 
				
			||||||
 | 
							    const void *value, size_t size, int flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (strcmp(name, "") == 0)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						if (!test_opt(inode->i_sb, XATTR_USER))
 | 
				
			||||||
 | 
							return -EOPNOTSUPP;
 | 
				
			||||||
 | 
						return ext3_xattr_set(inode, EXT3_XATTR_INDEX_USER, name,
 | 
				
			||||||
 | 
								      value, size, flags);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct xattr_handler ext3_xattr_user_handler = {
 | 
				
			||||||
 | 
						.prefix	= XATTR_USER_PREFIX,
 | 
				
			||||||
 | 
						.list	= ext3_xattr_user_list,
 | 
				
			||||||
 | 
						.get	= ext3_xattr_user_get,
 | 
				
			||||||
 | 
						.set	= ext3_xattr_user_set,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										885
									
								
								include/linux/ext4_fs.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										885
									
								
								include/linux/ext4_fs.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,885 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/include/linux/ext3_fs.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  linux/include/linux/minix_fs.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _LINUX_EXT3_FS_H
 | 
				
			||||||
 | 
					#define _LINUX_EXT3_FS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/types.h>
 | 
				
			||||||
 | 
					#include <linux/magic.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * The second extended filesystem constants/structures
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Define EXT3FS_DEBUG to produce debug messages
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#undef EXT3FS_DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Define EXT3_RESERVATION to reserve data blocks for expanding files
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_DEFAULT_RESERVE_BLOCKS     8
 | 
				
			||||||
 | 
					/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
 | 
				
			||||||
 | 
					#define EXT3_MAX_RESERVE_BLOCKS         1027
 | 
				
			||||||
 | 
					#define EXT3_RESERVE_WINDOW_NOT_ALLOCATED 0
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Always enable hashed directories
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define CONFIG_EXT3_INDEX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Debug code
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifdef EXT3FS_DEBUG
 | 
				
			||||||
 | 
					#define ext3_debug(f, a...)						\
 | 
				
			||||||
 | 
						do {								\
 | 
				
			||||||
 | 
							printk (KERN_DEBUG "EXT3-fs DEBUG (%s, %d): %s:",	\
 | 
				
			||||||
 | 
								__FILE__, __LINE__, __FUNCTION__);		\
 | 
				
			||||||
 | 
							printk (KERN_DEBUG f, ## a);				\
 | 
				
			||||||
 | 
						} while (0)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define ext3_debug(f, a...)	do {} while (0)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Special inodes numbers
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define	EXT3_BAD_INO		 1	/* Bad blocks inode */
 | 
				
			||||||
 | 
					#define EXT3_ROOT_INO		 2	/* Root inode */
 | 
				
			||||||
 | 
					#define EXT3_BOOT_LOADER_INO	 5	/* Boot loader inode */
 | 
				
			||||||
 | 
					#define EXT3_UNDEL_DIR_INO	 6	/* Undelete directory inode */
 | 
				
			||||||
 | 
					#define EXT3_RESIZE_INO		 7	/* Reserved group descriptors inode */
 | 
				
			||||||
 | 
					#define EXT3_JOURNAL_INO	 8	/* Journal inode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* First non-reserved inode for old ext3 filesystems */
 | 
				
			||||||
 | 
					#define EXT3_GOOD_OLD_FIRST_INO	11
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Maximal count of links to a file
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_LINK_MAX		32000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Macro-instructions used to manage several block sizes
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_MIN_BLOCK_SIZE		1024
 | 
				
			||||||
 | 
					#define	EXT3_MAX_BLOCK_SIZE		4096
 | 
				
			||||||
 | 
					#define EXT3_MIN_BLOCK_LOG_SIZE		  10
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					# define EXT3_BLOCK_SIZE(s)		((s)->s_blocksize)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					# define EXT3_BLOCK_SIZE(s)		(EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#define	EXT3_ADDR_PER_BLOCK(s)		(EXT3_BLOCK_SIZE(s) / sizeof (__u32))
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					# define EXT3_BLOCK_SIZE_BITS(s)	((s)->s_blocksize_bits)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					# define EXT3_BLOCK_SIZE_BITS(s)	((s)->s_log_block_size + 10)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					#define	EXT3_ADDR_PER_BLOCK_BITS(s)	(EXT3_SB(s)->s_addr_per_block_bits)
 | 
				
			||||||
 | 
					#define EXT3_INODE_SIZE(s)		(EXT3_SB(s)->s_inode_size)
 | 
				
			||||||
 | 
					#define EXT3_FIRST_INO(s)		(EXT3_SB(s)->s_first_ino)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define EXT3_INODE_SIZE(s)	(((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \
 | 
				
			||||||
 | 
									 EXT3_GOOD_OLD_INODE_SIZE : \
 | 
				
			||||||
 | 
									 (s)->s_inode_size)
 | 
				
			||||||
 | 
					#define EXT3_FIRST_INO(s)	(((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \
 | 
				
			||||||
 | 
									 EXT3_GOOD_OLD_FIRST_INO : \
 | 
				
			||||||
 | 
									 (s)->s_first_ino)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Macro-instructions used to manage fragments
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_MIN_FRAG_SIZE		1024
 | 
				
			||||||
 | 
					#define	EXT3_MAX_FRAG_SIZE		4096
 | 
				
			||||||
 | 
					#define EXT3_MIN_FRAG_LOG_SIZE		  10
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					# define EXT3_FRAG_SIZE(s)		(EXT3_SB(s)->s_frag_size)
 | 
				
			||||||
 | 
					# define EXT3_FRAGS_PER_BLOCK(s)	(EXT3_SB(s)->s_frags_per_block)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					# define EXT3_FRAG_SIZE(s)		(EXT3_MIN_FRAG_SIZE << (s)->s_log_frag_size)
 | 
				
			||||||
 | 
					# define EXT3_FRAGS_PER_BLOCK(s)	(EXT3_BLOCK_SIZE(s) / EXT3_FRAG_SIZE(s))
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Structure of a blocks group descriptor
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_group_desc
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						__le32	bg_block_bitmap;		/* Blocks bitmap block */
 | 
				
			||||||
 | 
						__le32	bg_inode_bitmap;		/* Inodes bitmap block */
 | 
				
			||||||
 | 
						__le32	bg_inode_table;		/* Inodes table block */
 | 
				
			||||||
 | 
						__le16	bg_free_blocks_count;	/* Free blocks count */
 | 
				
			||||||
 | 
						__le16	bg_free_inodes_count;	/* Free inodes count */
 | 
				
			||||||
 | 
						__le16	bg_used_dirs_count;	/* Directories count */
 | 
				
			||||||
 | 
						__u16	bg_pad;
 | 
				
			||||||
 | 
						__le32	bg_reserved[3];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Macro-instructions used to manage group descriptors
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					# define EXT3_BLOCKS_PER_GROUP(s)	(EXT3_SB(s)->s_blocks_per_group)
 | 
				
			||||||
 | 
					# define EXT3_DESC_PER_BLOCK(s)		(EXT3_SB(s)->s_desc_per_block)
 | 
				
			||||||
 | 
					# define EXT3_INODES_PER_GROUP(s)	(EXT3_SB(s)->s_inodes_per_group)
 | 
				
			||||||
 | 
					# define EXT3_DESC_PER_BLOCK_BITS(s)	(EXT3_SB(s)->s_desc_per_block_bits)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					# define EXT3_BLOCKS_PER_GROUP(s)	((s)->s_blocks_per_group)
 | 
				
			||||||
 | 
					# define EXT3_DESC_PER_BLOCK(s)		(EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_group_desc))
 | 
				
			||||||
 | 
					# define EXT3_INODES_PER_GROUP(s)	((s)->s_inodes_per_group)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Constants relative to the data blocks
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define	EXT3_NDIR_BLOCKS		12
 | 
				
			||||||
 | 
					#define	EXT3_IND_BLOCK			EXT3_NDIR_BLOCKS
 | 
				
			||||||
 | 
					#define	EXT3_DIND_BLOCK			(EXT3_IND_BLOCK + 1)
 | 
				
			||||||
 | 
					#define	EXT3_TIND_BLOCK			(EXT3_DIND_BLOCK + 1)
 | 
				
			||||||
 | 
					#define	EXT3_N_BLOCKS			(EXT3_TIND_BLOCK + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Inode flags
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define	EXT3_SECRM_FL			0x00000001 /* Secure deletion */
 | 
				
			||||||
 | 
					#define	EXT3_UNRM_FL			0x00000002 /* Undelete */
 | 
				
			||||||
 | 
					#define	EXT3_COMPR_FL			0x00000004 /* Compress file */
 | 
				
			||||||
 | 
					#define EXT3_SYNC_FL			0x00000008 /* Synchronous updates */
 | 
				
			||||||
 | 
					#define EXT3_IMMUTABLE_FL		0x00000010 /* Immutable file */
 | 
				
			||||||
 | 
					#define EXT3_APPEND_FL			0x00000020 /* writes to file may only append */
 | 
				
			||||||
 | 
					#define EXT3_NODUMP_FL			0x00000040 /* do not dump file */
 | 
				
			||||||
 | 
					#define EXT3_NOATIME_FL			0x00000080 /* do not update atime */
 | 
				
			||||||
 | 
					/* Reserved for compression usage... */
 | 
				
			||||||
 | 
					#define EXT3_DIRTY_FL			0x00000100
 | 
				
			||||||
 | 
					#define EXT3_COMPRBLK_FL		0x00000200 /* One or more compressed clusters */
 | 
				
			||||||
 | 
					#define EXT3_NOCOMPR_FL			0x00000400 /* Don't compress */
 | 
				
			||||||
 | 
					#define EXT3_ECOMPR_FL			0x00000800 /* Compression error */
 | 
				
			||||||
 | 
					/* End compression flags --- maybe not all used */
 | 
				
			||||||
 | 
					#define EXT3_INDEX_FL			0x00001000 /* hash-indexed directory */
 | 
				
			||||||
 | 
					#define EXT3_IMAGIC_FL			0x00002000 /* AFS directory */
 | 
				
			||||||
 | 
					#define EXT3_JOURNAL_DATA_FL		0x00004000 /* file data should be journaled */
 | 
				
			||||||
 | 
					#define EXT3_NOTAIL_FL			0x00008000 /* file tail should not be merged */
 | 
				
			||||||
 | 
					#define EXT3_DIRSYNC_FL			0x00010000 /* dirsync behaviour (directories only) */
 | 
				
			||||||
 | 
					#define EXT3_TOPDIR_FL			0x00020000 /* Top of directory hierarchies*/
 | 
				
			||||||
 | 
					#define EXT3_RESERVED_FL		0x80000000 /* reserved for ext3 lib */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_FL_USER_VISIBLE		0x0003DFFF /* User visible flags */
 | 
				
			||||||
 | 
					#define EXT3_FL_USER_MODIFIABLE		0x000380FF /* User modifiable flags */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Inode dynamic state flags
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_STATE_JDATA		0x00000001 /* journaled data exists */
 | 
				
			||||||
 | 
					#define EXT3_STATE_NEW			0x00000002 /* inode is newly created */
 | 
				
			||||||
 | 
					#define EXT3_STATE_XATTR		0x00000004 /* has in-inode xattrs */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Used to pass group descriptor data when online resize is done */
 | 
				
			||||||
 | 
					struct ext3_new_group_input {
 | 
				
			||||||
 | 
						__u32 group;            /* Group number for this data */
 | 
				
			||||||
 | 
						__u32 block_bitmap;     /* Absolute block number of block bitmap */
 | 
				
			||||||
 | 
						__u32 inode_bitmap;     /* Absolute block number of inode bitmap */
 | 
				
			||||||
 | 
						__u32 inode_table;      /* Absolute block number of inode table start */
 | 
				
			||||||
 | 
						__u32 blocks_count;     /* Total number of blocks in this group */
 | 
				
			||||||
 | 
						__u16 reserved_blocks;  /* Number of reserved blocks in this group */
 | 
				
			||||||
 | 
						__u16 unused;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* The struct ext3_new_group_input in kernel space, with free_blocks_count */
 | 
				
			||||||
 | 
					struct ext3_new_group_data {
 | 
				
			||||||
 | 
						__u32 group;
 | 
				
			||||||
 | 
						__u32 block_bitmap;
 | 
				
			||||||
 | 
						__u32 inode_bitmap;
 | 
				
			||||||
 | 
						__u32 inode_table;
 | 
				
			||||||
 | 
						__u32 blocks_count;
 | 
				
			||||||
 | 
						__u16 reserved_blocks;
 | 
				
			||||||
 | 
						__u16 unused;
 | 
				
			||||||
 | 
						__u32 free_blocks_count;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * ioctl commands
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define	EXT3_IOC_GETFLAGS		FS_IOC_GETFLAGS
 | 
				
			||||||
 | 
					#define	EXT3_IOC_SETFLAGS		FS_IOC_SETFLAGS
 | 
				
			||||||
 | 
					#define	EXT3_IOC_GETVERSION		_IOR('f', 3, long)
 | 
				
			||||||
 | 
					#define	EXT3_IOC_SETVERSION		_IOW('f', 4, long)
 | 
				
			||||||
 | 
					#define EXT3_IOC_GROUP_EXTEND		_IOW('f', 7, unsigned long)
 | 
				
			||||||
 | 
					#define EXT3_IOC_GROUP_ADD		_IOW('f', 8,struct ext3_new_group_input)
 | 
				
			||||||
 | 
					#define	EXT3_IOC_GETVERSION_OLD		FS_IOC_GETVERSION
 | 
				
			||||||
 | 
					#define	EXT3_IOC_SETVERSION_OLD		FS_IOC_SETVERSION
 | 
				
			||||||
 | 
					#ifdef CONFIG_JBD_DEBUG
 | 
				
			||||||
 | 
					#define EXT3_IOC_WAIT_FOR_READONLY	_IOR('f', 99, long)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#define EXT3_IOC_GETRSVSZ		_IOR('f', 5, long)
 | 
				
			||||||
 | 
					#define EXT3_IOC_SETRSVSZ		_IOW('f', 6, long)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * ioctl commands in 32 bit emulation
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_IOC32_GETFLAGS		FS_IOC32_GETFLAGS
 | 
				
			||||||
 | 
					#define EXT3_IOC32_SETFLAGS		FS_IOC32_SETFLAGS
 | 
				
			||||||
 | 
					#define EXT3_IOC32_GETVERSION		_IOR('f', 3, int)
 | 
				
			||||||
 | 
					#define EXT3_IOC32_SETVERSION		_IOW('f', 4, int)
 | 
				
			||||||
 | 
					#define EXT3_IOC32_GETRSVSZ		_IOR('f', 5, int)
 | 
				
			||||||
 | 
					#define EXT3_IOC32_SETRSVSZ		_IOW('f', 6, int)
 | 
				
			||||||
 | 
					#define EXT3_IOC32_GROUP_EXTEND		_IOW('f', 7, unsigned int)
 | 
				
			||||||
 | 
					#ifdef CONFIG_JBD_DEBUG
 | 
				
			||||||
 | 
					#define EXT3_IOC32_WAIT_FOR_READONLY	_IOR('f', 99, int)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#define EXT3_IOC32_GETVERSION_OLD	FS_IOC32_GETVERSION
 | 
				
			||||||
 | 
					#define EXT3_IOC32_SETVERSION_OLD	FS_IOC32_SETVERSION
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  Mount options
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_mount_options {
 | 
				
			||||||
 | 
						unsigned long s_mount_opt;
 | 
				
			||||||
 | 
						uid_t s_resuid;
 | 
				
			||||||
 | 
						gid_t s_resgid;
 | 
				
			||||||
 | 
						unsigned long s_commit_interval;
 | 
				
			||||||
 | 
					#ifdef CONFIG_QUOTA
 | 
				
			||||||
 | 
						int s_jquota_fmt;
 | 
				
			||||||
 | 
						char *s_qf_names[MAXQUOTAS];
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Structure of an inode on the disk
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_inode {
 | 
				
			||||||
 | 
						__le16	i_mode;		/* File mode */
 | 
				
			||||||
 | 
						__le16	i_uid;		/* Low 16 bits of Owner Uid */
 | 
				
			||||||
 | 
						__le32	i_size;		/* Size in bytes */
 | 
				
			||||||
 | 
						__le32	i_atime;	/* Access time */
 | 
				
			||||||
 | 
						__le32	i_ctime;	/* Creation time */
 | 
				
			||||||
 | 
						__le32	i_mtime;	/* Modification time */
 | 
				
			||||||
 | 
						__le32	i_dtime;	/* Deletion Time */
 | 
				
			||||||
 | 
						__le16	i_gid;		/* Low 16 bits of Group Id */
 | 
				
			||||||
 | 
						__le16	i_links_count;	/* Links count */
 | 
				
			||||||
 | 
						__le32	i_blocks;	/* Blocks count */
 | 
				
			||||||
 | 
						__le32	i_flags;	/* File flags */
 | 
				
			||||||
 | 
						union {
 | 
				
			||||||
 | 
							struct {
 | 
				
			||||||
 | 
								__u32  l_i_reserved1;
 | 
				
			||||||
 | 
							} linux1;
 | 
				
			||||||
 | 
							struct {
 | 
				
			||||||
 | 
								__u32  h_i_translator;
 | 
				
			||||||
 | 
							} hurd1;
 | 
				
			||||||
 | 
							struct {
 | 
				
			||||||
 | 
								__u32  m_i_reserved1;
 | 
				
			||||||
 | 
							} masix1;
 | 
				
			||||||
 | 
						} osd1;				/* OS dependent 1 */
 | 
				
			||||||
 | 
						__le32	i_block[EXT3_N_BLOCKS];/* Pointers to blocks */
 | 
				
			||||||
 | 
						__le32	i_generation;	/* File version (for NFS) */
 | 
				
			||||||
 | 
						__le32	i_file_acl;	/* File ACL */
 | 
				
			||||||
 | 
						__le32	i_dir_acl;	/* Directory ACL */
 | 
				
			||||||
 | 
						__le32	i_faddr;	/* Fragment address */
 | 
				
			||||||
 | 
						union {
 | 
				
			||||||
 | 
							struct {
 | 
				
			||||||
 | 
								__u8	l_i_frag;	/* Fragment number */
 | 
				
			||||||
 | 
								__u8	l_i_fsize;	/* Fragment size */
 | 
				
			||||||
 | 
								__u16	i_pad1;
 | 
				
			||||||
 | 
								__le16	l_i_uid_high;	/* these 2 fields    */
 | 
				
			||||||
 | 
								__le16	l_i_gid_high;	/* were reserved2[0] */
 | 
				
			||||||
 | 
								__u32	l_i_reserved2;
 | 
				
			||||||
 | 
							} linux2;
 | 
				
			||||||
 | 
							struct {
 | 
				
			||||||
 | 
								__u8	h_i_frag;	/* Fragment number */
 | 
				
			||||||
 | 
								__u8	h_i_fsize;	/* Fragment size */
 | 
				
			||||||
 | 
								__u16	h_i_mode_high;
 | 
				
			||||||
 | 
								__u16	h_i_uid_high;
 | 
				
			||||||
 | 
								__u16	h_i_gid_high;
 | 
				
			||||||
 | 
								__u32	h_i_author;
 | 
				
			||||||
 | 
							} hurd2;
 | 
				
			||||||
 | 
							struct {
 | 
				
			||||||
 | 
								__u8	m_i_frag;	/* Fragment number */
 | 
				
			||||||
 | 
								__u8	m_i_fsize;	/* Fragment size */
 | 
				
			||||||
 | 
								__u16	m_pad1;
 | 
				
			||||||
 | 
								__u32	m_i_reserved2[2];
 | 
				
			||||||
 | 
							} masix2;
 | 
				
			||||||
 | 
						} osd2;				/* OS dependent 2 */
 | 
				
			||||||
 | 
						__le16	i_extra_isize;
 | 
				
			||||||
 | 
						__le16	i_pad1;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define i_size_high	i_dir_acl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(__KERNEL__) || defined(__linux__)
 | 
				
			||||||
 | 
					#define i_reserved1	osd1.linux1.l_i_reserved1
 | 
				
			||||||
 | 
					#define i_frag		osd2.linux2.l_i_frag
 | 
				
			||||||
 | 
					#define i_fsize		osd2.linux2.l_i_fsize
 | 
				
			||||||
 | 
					#define i_uid_low	i_uid
 | 
				
			||||||
 | 
					#define i_gid_low	i_gid
 | 
				
			||||||
 | 
					#define i_uid_high	osd2.linux2.l_i_uid_high
 | 
				
			||||||
 | 
					#define i_gid_high	osd2.linux2.l_i_gid_high
 | 
				
			||||||
 | 
					#define i_reserved2	osd2.linux2.l_i_reserved2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#elif defined(__GNU__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define i_translator	osd1.hurd1.h_i_translator
 | 
				
			||||||
 | 
					#define i_frag		osd2.hurd2.h_i_frag;
 | 
				
			||||||
 | 
					#define i_fsize		osd2.hurd2.h_i_fsize;
 | 
				
			||||||
 | 
					#define i_uid_high	osd2.hurd2.h_i_uid_high
 | 
				
			||||||
 | 
					#define i_gid_high	osd2.hurd2.h_i_gid_high
 | 
				
			||||||
 | 
					#define i_author	osd2.hurd2.h_i_author
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#elif defined(__masix__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define i_reserved1	osd1.masix1.m_i_reserved1
 | 
				
			||||||
 | 
					#define i_frag		osd2.masix2.m_i_frag
 | 
				
			||||||
 | 
					#define i_fsize		osd2.masix2.m_i_fsize
 | 
				
			||||||
 | 
					#define i_reserved2	osd2.masix2.m_i_reserved2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* defined(__KERNEL__) || defined(__linux__) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * File system states
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define	EXT3_VALID_FS			0x0001	/* Unmounted cleanly */
 | 
				
			||||||
 | 
					#define	EXT3_ERROR_FS			0x0002	/* Errors detected */
 | 
				
			||||||
 | 
					#define	EXT3_ORPHAN_FS			0x0004	/* Orphans being recovered */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Mount flags
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_CHECK		0x00001	/* Do mount-time checks */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_OLDALLOC		0x00002  /* Don't use the new Orlov allocator */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_GRPID		0x00004	/* Create files with directory's group */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_DEBUG		0x00008	/* Some debugging messages */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_ERRORS_CONT		0x00010	/* Continue on errors */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_ERRORS_RO		0x00020	/* Remount fs ro on errors */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_ERRORS_PANIC		0x00040	/* Panic on errors */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_MINIX_DF		0x00080	/* Mimics the Minix statfs */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_NOLOAD		0x00100	/* Don't use existing journal*/
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_ABORT		0x00200	/* Fatal error detected */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_DATA_FLAGS		0x00C00	/* Mode for data writes: */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_JOURNAL_DATA		0x00400	/* Write data to journal */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_ORDERED_DATA		0x00800	/* Flush data before commit */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_WRITEBACK_DATA	0x00C00	/* No data ordering */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_UPDATE_JOURNAL	0x01000	/* Update the journal format */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_NO_UID32		0x02000  /* Disable 32-bit UIDs */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_XATTR_USER		0x04000	/* Extended user attributes */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_POSIX_ACL		0x08000	/* POSIX Access Control Lists */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_RESERVATION		0x10000	/* Preallocation */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_BARRIER		0x20000 /* Use block barriers */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_NOBH			0x40000 /* No bufferheads */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_QUOTA		0x80000 /* Some quota option set */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_USRQUOTA		0x100000 /* "old" user quota */
 | 
				
			||||||
 | 
					#define EXT3_MOUNT_GRPQUOTA		0x200000 /* "old" group quota */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
 | 
				
			||||||
 | 
					#ifndef _LINUX_EXT2_FS_H
 | 
				
			||||||
 | 
					#define clear_opt(o, opt)		o &= ~EXT3_MOUNT_##opt
 | 
				
			||||||
 | 
					#define set_opt(o, opt)			o |= EXT3_MOUNT_##opt
 | 
				
			||||||
 | 
					#define test_opt(sb, opt)		(EXT3_SB(sb)->s_mount_opt & \
 | 
				
			||||||
 | 
										 EXT3_MOUNT_##opt)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define EXT2_MOUNT_NOLOAD		EXT3_MOUNT_NOLOAD
 | 
				
			||||||
 | 
					#define EXT2_MOUNT_ABORT		EXT3_MOUNT_ABORT
 | 
				
			||||||
 | 
					#define EXT2_MOUNT_DATA_FLAGS		EXT3_MOUNT_DATA_FLAGS
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ext3_set_bit			ext2_set_bit
 | 
				
			||||||
 | 
					#define ext3_set_bit_atomic		ext2_set_bit_atomic
 | 
				
			||||||
 | 
					#define ext3_clear_bit			ext2_clear_bit
 | 
				
			||||||
 | 
					#define ext3_clear_bit_atomic		ext2_clear_bit_atomic
 | 
				
			||||||
 | 
					#define ext3_test_bit			ext2_test_bit
 | 
				
			||||||
 | 
					#define ext3_find_first_zero_bit	ext2_find_first_zero_bit
 | 
				
			||||||
 | 
					#define ext3_find_next_zero_bit		ext2_find_next_zero_bit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Maximal mount counts between two filesystem checks
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_DFL_MAX_MNT_COUNT		20	/* Allow 20 mounts */
 | 
				
			||||||
 | 
					#define EXT3_DFL_CHECKINTERVAL		0	/* Don't use interval check */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Behaviour when detecting errors
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_ERRORS_CONTINUE		1	/* Continue execution */
 | 
				
			||||||
 | 
					#define EXT3_ERRORS_RO			2	/* Remount fs read-only */
 | 
				
			||||||
 | 
					#define EXT3_ERRORS_PANIC		3	/* Panic */
 | 
				
			||||||
 | 
					#define EXT3_ERRORS_DEFAULT		EXT3_ERRORS_CONTINUE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Structure of the super block
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_super_block {
 | 
				
			||||||
 | 
					/*00*/	__le32	s_inodes_count;		/* Inodes count */
 | 
				
			||||||
 | 
						__le32	s_blocks_count;		/* Blocks count */
 | 
				
			||||||
 | 
						__le32	s_r_blocks_count;	/* Reserved blocks count */
 | 
				
			||||||
 | 
						__le32	s_free_blocks_count;	/* Free blocks count */
 | 
				
			||||||
 | 
					/*10*/	__le32	s_free_inodes_count;	/* Free inodes count */
 | 
				
			||||||
 | 
						__le32	s_first_data_block;	/* First Data Block */
 | 
				
			||||||
 | 
						__le32	s_log_block_size;	/* Block size */
 | 
				
			||||||
 | 
						__le32	s_log_frag_size;	/* Fragment size */
 | 
				
			||||||
 | 
					/*20*/	__le32	s_blocks_per_group;	/* # Blocks per group */
 | 
				
			||||||
 | 
						__le32	s_frags_per_group;	/* # Fragments per group */
 | 
				
			||||||
 | 
						__le32	s_inodes_per_group;	/* # Inodes per group */
 | 
				
			||||||
 | 
						__le32	s_mtime;		/* Mount time */
 | 
				
			||||||
 | 
					/*30*/	__le32	s_wtime;		/* Write time */
 | 
				
			||||||
 | 
						__le16	s_mnt_count;		/* Mount count */
 | 
				
			||||||
 | 
						__le16	s_max_mnt_count;	/* Maximal mount count */
 | 
				
			||||||
 | 
						__le16	s_magic;		/* Magic signature */
 | 
				
			||||||
 | 
						__le16	s_state;		/* File system state */
 | 
				
			||||||
 | 
						__le16	s_errors;		/* Behaviour when detecting errors */
 | 
				
			||||||
 | 
						__le16	s_minor_rev_level;	/* minor revision level */
 | 
				
			||||||
 | 
					/*40*/	__le32	s_lastcheck;		/* time of last check */
 | 
				
			||||||
 | 
						__le32	s_checkinterval;	/* max. time between checks */
 | 
				
			||||||
 | 
						__le32	s_creator_os;		/* OS */
 | 
				
			||||||
 | 
						__le32	s_rev_level;		/* Revision level */
 | 
				
			||||||
 | 
					/*50*/	__le16	s_def_resuid;		/* Default uid for reserved blocks */
 | 
				
			||||||
 | 
						__le16	s_def_resgid;		/* Default gid for reserved blocks */
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * These fields are for EXT3_DYNAMIC_REV superblocks only.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * Note: the difference between the compatible feature set and
 | 
				
			||||||
 | 
						 * the incompatible feature set is that if there is a bit set
 | 
				
			||||||
 | 
						 * in the incompatible feature set that the kernel doesn't
 | 
				
			||||||
 | 
						 * know about, it should refuse to mount the filesystem.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * e2fsck's requirements are more strict; if it doesn't know
 | 
				
			||||||
 | 
						 * about a feature in either the compatible or incompatible
 | 
				
			||||||
 | 
						 * feature set, it must abort and not try to meddle with
 | 
				
			||||||
 | 
						 * things it doesn't understand...
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						__le32	s_first_ino;		/* First non-reserved inode */
 | 
				
			||||||
 | 
						__le16   s_inode_size;		/* size of inode structure */
 | 
				
			||||||
 | 
						__le16	s_block_group_nr;	/* block group # of this superblock */
 | 
				
			||||||
 | 
						__le32	s_feature_compat;	/* compatible feature set */
 | 
				
			||||||
 | 
					/*60*/	__le32	s_feature_incompat;	/* incompatible feature set */
 | 
				
			||||||
 | 
						__le32	s_feature_ro_compat;	/* readonly-compatible feature set */
 | 
				
			||||||
 | 
					/*68*/	__u8	s_uuid[16];		/* 128-bit uuid for volume */
 | 
				
			||||||
 | 
					/*78*/	char	s_volume_name[16];	/* volume name */
 | 
				
			||||||
 | 
					/*88*/	char	s_last_mounted[64];	/* directory where last mounted */
 | 
				
			||||||
 | 
					/*C8*/	__le32	s_algorithm_usage_bitmap; /* For compression */
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Performance hints.  Directory preallocation should only
 | 
				
			||||||
 | 
						 * happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						__u8	s_prealloc_blocks;	/* Nr of blocks to try to preallocate*/
 | 
				
			||||||
 | 
						__u8	s_prealloc_dir_blocks;	/* Nr to preallocate for dirs */
 | 
				
			||||||
 | 
						__le16	s_reserved_gdt_blocks;	/* Per group desc for online growth */
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
					/*D0*/	__u8	s_journal_uuid[16];	/* uuid of journal superblock */
 | 
				
			||||||
 | 
					/*E0*/	__le32	s_journal_inum;		/* inode number of journal file */
 | 
				
			||||||
 | 
						__le32	s_journal_dev;		/* device number of journal file */
 | 
				
			||||||
 | 
						__le32	s_last_orphan;		/* start of list of inodes to delete */
 | 
				
			||||||
 | 
						__le32	s_hash_seed[4];		/* HTREE hash seed */
 | 
				
			||||||
 | 
						__u8	s_def_hash_version;	/* Default hash version to use */
 | 
				
			||||||
 | 
						__u8	s_reserved_char_pad;
 | 
				
			||||||
 | 
						__u16	s_reserved_word_pad;
 | 
				
			||||||
 | 
						__le32	s_default_mount_opts;
 | 
				
			||||||
 | 
						__le32	s_first_meta_bg;	/* First metablock block group */
 | 
				
			||||||
 | 
						__u32	s_reserved[190];	/* Padding to the end of the block */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					#include <linux/ext3_fs_i.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs_sb.h>
 | 
				
			||||||
 | 
					static inline struct ext3_sb_info * EXT3_SB(struct super_block *sb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return sb->s_fs_info;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline struct ext3_inode_info *EXT3_I(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return container_of(inode, struct ext3_inode_info, vfs_inode);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_valid_inum(struct super_block *sb, unsigned long ino)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return ino == EXT3_ROOT_INO ||
 | 
				
			||||||
 | 
							ino == EXT3_JOURNAL_INO ||
 | 
				
			||||||
 | 
							ino == EXT3_RESIZE_INO ||
 | 
				
			||||||
 | 
							(ino >= EXT3_FIRST_INO(sb) &&
 | 
				
			||||||
 | 
							 ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					/* Assume that user mode programs are passing in an ext3fs superblock, not
 | 
				
			||||||
 | 
					 * a kernel struct super_block.  This will allow us to call the feature-test
 | 
				
			||||||
 | 
					 * macros from user land. */
 | 
				
			||||||
 | 
					#define EXT3_SB(sb)	(sb)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Codes for operating systems
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_OS_LINUX		0
 | 
				
			||||||
 | 
					#define EXT3_OS_HURD		1
 | 
				
			||||||
 | 
					#define EXT3_OS_MASIX		2
 | 
				
			||||||
 | 
					#define EXT3_OS_FREEBSD		3
 | 
				
			||||||
 | 
					#define EXT3_OS_LITES		4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Revision levels
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_GOOD_OLD_REV	0	/* The good old (original) format */
 | 
				
			||||||
 | 
					#define EXT3_DYNAMIC_REV	1	/* V2 format w/ dynamic inode sizes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_CURRENT_REV	EXT3_GOOD_OLD_REV
 | 
				
			||||||
 | 
					#define EXT3_MAX_SUPP_REV	EXT3_DYNAMIC_REV
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_GOOD_OLD_INODE_SIZE 128
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Feature set definitions
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_HAS_COMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						( EXT3_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
 | 
				
			||||||
 | 
					#define EXT3_HAS_RO_COMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						( EXT3_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
 | 
				
			||||||
 | 
					#define EXT3_HAS_INCOMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						( EXT3_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
 | 
				
			||||||
 | 
					#define EXT3_SET_COMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						EXT3_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
 | 
				
			||||||
 | 
					#define EXT3_SET_RO_COMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						EXT3_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
 | 
				
			||||||
 | 
					#define EXT3_SET_INCOMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						EXT3_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
 | 
				
			||||||
 | 
					#define EXT3_CLEAR_COMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						EXT3_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
 | 
				
			||||||
 | 
					#define EXT3_CLEAR_RO_COMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						EXT3_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
 | 
				
			||||||
 | 
					#define EXT3_CLEAR_INCOMPAT_FEATURE(sb,mask)			\
 | 
				
			||||||
 | 
						EXT3_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_DIR_PREALLOC	0x0001
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_IMAGIC_INODES	0x0002
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_HAS_JOURNAL		0x0004
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_EXT_ATTR		0x0008
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_RESIZE_INODE	0x0010
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_DIR_INDEX		0x0020
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER	0x0001
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_RO_COMPAT_LARGE_FILE	0x0002
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_RO_COMPAT_BTREE_DIR	0x0004
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_INCOMPAT_COMPRESSION	0x0001
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_INCOMPAT_FILETYPE		0x0002
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004 /* Needs recovery */
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008 /* Journal device */
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_INCOMPAT_META_BG		0x0010
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_COMPAT_SUPP	EXT2_FEATURE_COMPAT_EXT_ATTR
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_INCOMPAT_SUPP	(EXT3_FEATURE_INCOMPAT_FILETYPE| \
 | 
				
			||||||
 | 
										 EXT3_FEATURE_INCOMPAT_RECOVER| \
 | 
				
			||||||
 | 
										 EXT3_FEATURE_INCOMPAT_META_BG)
 | 
				
			||||||
 | 
					#define EXT3_FEATURE_RO_COMPAT_SUPP	(EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
 | 
				
			||||||
 | 
										 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
 | 
				
			||||||
 | 
										 EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Default values for user and/or group using reserved blocks
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define	EXT3_DEF_RESUID		0
 | 
				
			||||||
 | 
					#define	EXT3_DEF_RESGID		0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Default mount options
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_DEFM_DEBUG		0x0001
 | 
				
			||||||
 | 
					#define EXT3_DEFM_BSDGROUPS	0x0002
 | 
				
			||||||
 | 
					#define EXT3_DEFM_XATTR_USER	0x0004
 | 
				
			||||||
 | 
					#define EXT3_DEFM_ACL		0x0008
 | 
				
			||||||
 | 
					#define EXT3_DEFM_UID16		0x0010
 | 
				
			||||||
 | 
					#define EXT3_DEFM_JMODE		0x0060
 | 
				
			||||||
 | 
					#define EXT3_DEFM_JMODE_DATA	0x0020
 | 
				
			||||||
 | 
					#define EXT3_DEFM_JMODE_ORDERED	0x0040
 | 
				
			||||||
 | 
					#define EXT3_DEFM_JMODE_WBACK	0x0060
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Structure of a directory entry
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_NAME_LEN 255
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_dir_entry {
 | 
				
			||||||
 | 
						__le32	inode;			/* Inode number */
 | 
				
			||||||
 | 
						__le16	rec_len;		/* Directory entry length */
 | 
				
			||||||
 | 
						__le16	name_len;		/* Name length */
 | 
				
			||||||
 | 
						char	name[EXT3_NAME_LEN];	/* File name */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * The new version of the directory entry.  Since EXT3 structures are
 | 
				
			||||||
 | 
					 * stored in intel byte order, and the name_len field could never be
 | 
				
			||||||
 | 
					 * bigger than 255 chars, it's safe to reclaim the extra byte for the
 | 
				
			||||||
 | 
					 * file_type field.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_dir_entry_2 {
 | 
				
			||||||
 | 
						__le32	inode;			/* Inode number */
 | 
				
			||||||
 | 
						__le16	rec_len;		/* Directory entry length */
 | 
				
			||||||
 | 
						__u8	name_len;		/* Name length */
 | 
				
			||||||
 | 
						__u8	file_type;
 | 
				
			||||||
 | 
						char	name[EXT3_NAME_LEN];	/* File name */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Ext3 directory file types.  Only the low 3 bits are used.  The
 | 
				
			||||||
 | 
					 * other bits are reserved for now.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_FT_UNKNOWN		0
 | 
				
			||||||
 | 
					#define EXT3_FT_REG_FILE	1
 | 
				
			||||||
 | 
					#define EXT3_FT_DIR		2
 | 
				
			||||||
 | 
					#define EXT3_FT_CHRDEV		3
 | 
				
			||||||
 | 
					#define EXT3_FT_BLKDEV		4
 | 
				
			||||||
 | 
					#define EXT3_FT_FIFO		5
 | 
				
			||||||
 | 
					#define EXT3_FT_SOCK		6
 | 
				
			||||||
 | 
					#define EXT3_FT_SYMLINK		7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_FT_MAX		8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * EXT3_DIR_PAD defines the directory entries boundaries
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * NOTE: It must be a multiple of 4
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define EXT3_DIR_PAD			4
 | 
				
			||||||
 | 
					#define EXT3_DIR_ROUND			(EXT3_DIR_PAD - 1)
 | 
				
			||||||
 | 
					#define EXT3_DIR_REC_LEN(name_len)	(((name_len) + 8 + EXT3_DIR_ROUND) & \
 | 
				
			||||||
 | 
										 ~EXT3_DIR_ROUND)
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Hash Tree Directory indexing
 | 
				
			||||||
 | 
					 * (c) Daniel Phillips, 2001
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_INDEX
 | 
				
			||||||
 | 
					  #define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
 | 
				
			||||||
 | 
										      EXT3_FEATURE_COMPAT_DIR_INDEX) && \
 | 
				
			||||||
 | 
							      (EXT3_I(dir)->i_flags & EXT3_INDEX_FL))
 | 
				
			||||||
 | 
					#define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX)
 | 
				
			||||||
 | 
					#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  #define is_dx(dir) 0
 | 
				
			||||||
 | 
					#define EXT3_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT3_LINK_MAX)
 | 
				
			||||||
 | 
					#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Legal values for the dx_root hash_version field: */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DX_HASH_LEGACY		0
 | 
				
			||||||
 | 
					#define DX_HASH_HALF_MD4	1
 | 
				
			||||||
 | 
					#define DX_HASH_TEA		2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* hash info structure used by the directory hash */
 | 
				
			||||||
 | 
					struct dx_hash_info
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u32		hash;
 | 
				
			||||||
 | 
						u32		minor_hash;
 | 
				
			||||||
 | 
						int		hash_version;
 | 
				
			||||||
 | 
						u32		*seed;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_HTREE_EOF	0x7fffffff
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Control parameters used by ext3_htree_next_block
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define HASH_NB_ALWAYS		1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Describe an inode's exact location on disk and in memory
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_iloc
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct buffer_head *bh;
 | 
				
			||||||
 | 
						unsigned long offset;
 | 
				
			||||||
 | 
						unsigned long block_group;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline struct ext3_inode *ext3_raw_inode(struct ext3_iloc *iloc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return (struct ext3_inode *) (iloc->bh->b_data + iloc->offset);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This structure is stuffed into the struct file's private_data field
 | 
				
			||||||
 | 
					 * for directories.  It is where we put information so that we can do
 | 
				
			||||||
 | 
					 * readdir operations in hash tree order.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct dir_private_info {
 | 
				
			||||||
 | 
						struct rb_root	root;
 | 
				
			||||||
 | 
						struct rb_node	*curr_node;
 | 
				
			||||||
 | 
						struct fname	*extra_fname;
 | 
				
			||||||
 | 
						loff_t		last_pos;
 | 
				
			||||||
 | 
						__u32		curr_hash;
 | 
				
			||||||
 | 
						__u32		curr_minor_hash;
 | 
				
			||||||
 | 
						__u32		next_hash;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* calculate the first block number of the group */
 | 
				
			||||||
 | 
					static inline ext3_fsblk_t
 | 
				
			||||||
 | 
					ext3_group_first_block_no(struct super_block *sb, unsigned long group_no)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return group_no * (ext3_fsblk_t)EXT3_BLOCKS_PER_GROUP(sb) +
 | 
				
			||||||
 | 
							le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Special error return code only used by dx_probe() and its callers.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define ERR_BAD_DX_DIR	-75000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Function prototypes
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Ok, these declarations are also in <linux/kernel.h> but none of the
 | 
				
			||||||
 | 
					 * ext3 source programs needs to include it so they are duplicated here.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					# define NORET_TYPE    /**/
 | 
				
			||||||
 | 
					# define ATTRIB_NORET  __attribute__((noreturn))
 | 
				
			||||||
 | 
					# define NORET_AND     noreturn,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* balloc.c */
 | 
				
			||||||
 | 
					extern int ext3_bg_has_super(struct super_block *sb, int group);
 | 
				
			||||||
 | 
					extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
 | 
				
			||||||
 | 
					extern ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
								ext3_fsblk_t goal, int *errp);
 | 
				
			||||||
 | 
					extern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
								ext3_fsblk_t goal, unsigned long *count, int *errp);
 | 
				
			||||||
 | 
					extern void ext3_free_blocks (handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
								ext3_fsblk_t block, unsigned long count);
 | 
				
			||||||
 | 
					extern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb,
 | 
				
			||||||
 | 
									 ext3_fsblk_t block, unsigned long count,
 | 
				
			||||||
 | 
									unsigned long *pdquot_freed_blocks);
 | 
				
			||||||
 | 
					extern ext3_fsblk_t ext3_count_free_blocks (struct super_block *);
 | 
				
			||||||
 | 
					extern void ext3_check_blocks_bitmap (struct super_block *);
 | 
				
			||||||
 | 
					extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
 | 
				
			||||||
 | 
											    unsigned int block_group,
 | 
				
			||||||
 | 
											    struct buffer_head ** bh);
 | 
				
			||||||
 | 
					extern int ext3_should_retry_alloc(struct super_block *sb, int *retries);
 | 
				
			||||||
 | 
					extern void ext3_init_block_alloc_info(struct inode *);
 | 
				
			||||||
 | 
					extern void ext3_rsv_window_add(struct super_block *sb, struct ext3_reserve_window_node *rsv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* dir.c */
 | 
				
			||||||
 | 
					extern int ext3_check_dir_entry(const char *, struct inode *,
 | 
				
			||||||
 | 
									struct ext3_dir_entry_2 *,
 | 
				
			||||||
 | 
									struct buffer_head *, unsigned long);
 | 
				
			||||||
 | 
					extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 | 
				
			||||||
 | 
									    __u32 minor_hash,
 | 
				
			||||||
 | 
									    struct ext3_dir_entry_2 *dirent);
 | 
				
			||||||
 | 
					extern void ext3_htree_free_dir_info(struct dir_private_info *p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* fsync.c */
 | 
				
			||||||
 | 
					extern int ext3_sync_file (struct file *, struct dentry *, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* hash.c */
 | 
				
			||||||
 | 
					extern int ext3fs_dirhash(const char *name, int len, struct
 | 
				
			||||||
 | 
								  dx_hash_info *hinfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ialloc.c */
 | 
				
			||||||
 | 
					extern struct inode * ext3_new_inode (handle_t *, struct inode *, int);
 | 
				
			||||||
 | 
					extern void ext3_free_inode (handle_t *, struct inode *);
 | 
				
			||||||
 | 
					extern struct inode * ext3_orphan_get (struct super_block *, unsigned long);
 | 
				
			||||||
 | 
					extern unsigned long ext3_count_free_inodes (struct super_block *);
 | 
				
			||||||
 | 
					extern unsigned long ext3_count_dirs (struct super_block *);
 | 
				
			||||||
 | 
					extern void ext3_check_inodes_bitmap (struct super_block *);
 | 
				
			||||||
 | 
					extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* inode.c */
 | 
				
			||||||
 | 
					int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
 | 
				
			||||||
 | 
							struct buffer_head *bh, ext3_fsblk_t blocknr);
 | 
				
			||||||
 | 
					struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
 | 
				
			||||||
 | 
					struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
 | 
				
			||||||
 | 
					int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
						sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
 | 
				
			||||||
 | 
						int create, int extend_disksize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void ext3_read_inode (struct inode *);
 | 
				
			||||||
 | 
					extern int  ext3_write_inode (struct inode *, int);
 | 
				
			||||||
 | 
					extern int  ext3_setattr (struct dentry *, struct iattr *);
 | 
				
			||||||
 | 
					extern void ext3_delete_inode (struct inode *);
 | 
				
			||||||
 | 
					extern int  ext3_sync_inode (handle_t *, struct inode *);
 | 
				
			||||||
 | 
					extern void ext3_discard_reservation (struct inode *);
 | 
				
			||||||
 | 
					extern void ext3_dirty_inode(struct inode *);
 | 
				
			||||||
 | 
					extern int ext3_change_inode_journal_flag(struct inode *, int);
 | 
				
			||||||
 | 
					extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *);
 | 
				
			||||||
 | 
					extern void ext3_truncate (struct inode *);
 | 
				
			||||||
 | 
					extern void ext3_set_inode_flags(struct inode *);
 | 
				
			||||||
 | 
					extern void ext3_set_aops(struct inode *inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* ioctl.c */
 | 
				
			||||||
 | 
					extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
 | 
				
			||||||
 | 
							       unsigned long);
 | 
				
			||||||
 | 
					extern long ext3_compat_ioctl (struct file *, unsigned int, unsigned long);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* namei.c */
 | 
				
			||||||
 | 
					extern int ext3_orphan_add(handle_t *, struct inode *);
 | 
				
			||||||
 | 
					extern int ext3_orphan_del(handle_t *, struct inode *);
 | 
				
			||||||
 | 
					extern int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
 | 
				
			||||||
 | 
									__u32 start_minor_hash, __u32 *next_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* resize.c */
 | 
				
			||||||
 | 
					extern int ext3_group_add(struct super_block *sb,
 | 
				
			||||||
 | 
									struct ext3_new_group_data *input);
 | 
				
			||||||
 | 
					extern int ext3_group_extend(struct super_block *sb,
 | 
				
			||||||
 | 
									struct ext3_super_block *es,
 | 
				
			||||||
 | 
									ext3_fsblk_t n_blocks_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* super.c */
 | 
				
			||||||
 | 
					extern void ext3_error (struct super_block *, const char *, const char *, ...)
 | 
				
			||||||
 | 
						__attribute__ ((format (printf, 3, 4)));
 | 
				
			||||||
 | 
					extern void __ext3_std_error (struct super_block *, const char *, int);
 | 
				
			||||||
 | 
					extern void ext3_abort (struct super_block *, const char *, const char *, ...)
 | 
				
			||||||
 | 
						__attribute__ ((format (printf, 3, 4)));
 | 
				
			||||||
 | 
					extern void ext3_warning (struct super_block *, const char *, const char *, ...)
 | 
				
			||||||
 | 
						__attribute__ ((format (printf, 3, 4)));
 | 
				
			||||||
 | 
					extern void ext3_update_dynamic_rev (struct super_block *sb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ext3_std_error(sb, errno)				\
 | 
				
			||||||
 | 
					do {								\
 | 
				
			||||||
 | 
						if ((errno))						\
 | 
				
			||||||
 | 
							__ext3_std_error((sb), __FUNCTION__, (errno));	\
 | 
				
			||||||
 | 
					} while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Inodes and files operations
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* dir.c */
 | 
				
			||||||
 | 
					extern const struct file_operations ext3_dir_operations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* file.c */
 | 
				
			||||||
 | 
					extern struct inode_operations ext3_file_inode_operations;
 | 
				
			||||||
 | 
					extern const struct file_operations ext3_file_operations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* namei.c */
 | 
				
			||||||
 | 
					extern struct inode_operations ext3_dir_inode_operations;
 | 
				
			||||||
 | 
					extern struct inode_operations ext3_special_inode_operations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* symlink.c */
 | 
				
			||||||
 | 
					extern struct inode_operations ext3_symlink_inode_operations;
 | 
				
			||||||
 | 
					extern struct inode_operations ext3_fast_symlink_inode_operations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif	/* __KERNEL__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif	/* _LINUX_EXT3_FS_H */
 | 
				
			||||||
							
								
								
									
										147
									
								
								include/linux/ext4_fs_i.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								include/linux/ext4_fs_i.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,147 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/include/linux/ext3_fs_i.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  linux/include/linux/minix_fs_i.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _LINUX_EXT3_FS_I
 | 
				
			||||||
 | 
					#define _LINUX_EXT3_FS_I
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/rwsem.h>
 | 
				
			||||||
 | 
					#include <linux/rbtree.h>
 | 
				
			||||||
 | 
					#include <linux/seqlock.h>
 | 
				
			||||||
 | 
					#include <linux/mutex.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* data type for block offset of block group */
 | 
				
			||||||
 | 
					typedef int ext3_grpblk_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* data type for filesystem-wide blocks number */
 | 
				
			||||||
 | 
					typedef unsigned long ext3_fsblk_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define E3FSBLK "%lu"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_reserve_window {
 | 
				
			||||||
 | 
						ext3_fsblk_t	_rsv_start;	/* First byte reserved */
 | 
				
			||||||
 | 
						ext3_fsblk_t	_rsv_end;	/* Last byte reserved or 0 */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_reserve_window_node {
 | 
				
			||||||
 | 
						struct rb_node		rsv_node;
 | 
				
			||||||
 | 
						__u32			rsv_goal_size;
 | 
				
			||||||
 | 
						__u32			rsv_alloc_hit;
 | 
				
			||||||
 | 
						struct ext3_reserve_window	rsv_window;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ext3_block_alloc_info {
 | 
				
			||||||
 | 
						/* information about reservation window */
 | 
				
			||||||
 | 
						struct ext3_reserve_window_node	rsv_window_node;
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * was i_next_alloc_block in ext3_inode_info
 | 
				
			||||||
 | 
						 * is the logical (file-relative) number of the
 | 
				
			||||||
 | 
						 * most-recently-allocated block in this file.
 | 
				
			||||||
 | 
						 * We use this for detecting linearly ascending allocation requests.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						__u32                   last_alloc_logical_block;
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Was i_next_alloc_goal in ext3_inode_info
 | 
				
			||||||
 | 
						 * is the *physical* companion to i_next_alloc_block.
 | 
				
			||||||
 | 
						 * it the the physical block number of the block which was most-recentl
 | 
				
			||||||
 | 
						 * allocated to this file.  This give us the goal (target) for the next
 | 
				
			||||||
 | 
						 * allocation when we detect linearly ascending requests.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						ext3_fsblk_t		last_alloc_physical_block;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define rsv_start rsv_window._rsv_start
 | 
				
			||||||
 | 
					#define rsv_end rsv_window._rsv_end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * third extended file system inode data in memory
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_inode_info {
 | 
				
			||||||
 | 
						__le32	i_data[15];	/* unconverted */
 | 
				
			||||||
 | 
						__u32	i_flags;
 | 
				
			||||||
 | 
					#ifdef EXT3_FRAGMENTS
 | 
				
			||||||
 | 
						__u32	i_faddr;
 | 
				
			||||||
 | 
						__u8	i_frag_no;
 | 
				
			||||||
 | 
						__u8	i_frag_size;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
						ext3_fsblk_t	i_file_acl;
 | 
				
			||||||
 | 
						__u32	i_dir_acl;
 | 
				
			||||||
 | 
						__u32	i_dtime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * i_block_group is the number of the block group which contains
 | 
				
			||||||
 | 
						 * this file's inode.  Constant across the lifetime of the inode,
 | 
				
			||||||
 | 
						 * it is ued for making block allocation decisions - we try to
 | 
				
			||||||
 | 
						 * place a file's data blocks near its inode block, and new inodes
 | 
				
			||||||
 | 
						 * near to their parent directory's inode.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						__u32	i_block_group;
 | 
				
			||||||
 | 
						__u32	i_state;		/* Dynamic state flags for ext3 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* block reservation info */
 | 
				
			||||||
 | 
						struct ext3_block_alloc_info *i_block_alloc_info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						__u32	i_dir_start_lookup;
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_XATTR
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Extended attributes can be read independently of the main file
 | 
				
			||||||
 | 
						 * data. Taking i_mutex even when reading would cause contention
 | 
				
			||||||
 | 
						 * between readers of EAs and writers of regular file data, so
 | 
				
			||||||
 | 
						 * instead we synchronize on xattr_sem when reading or changing
 | 
				
			||||||
 | 
						 * EAs.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						struct rw_semaphore xattr_sem;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef CONFIG_EXT3_FS_POSIX_ACL
 | 
				
			||||||
 | 
						struct posix_acl	*i_acl;
 | 
				
			||||||
 | 
						struct posix_acl	*i_default_acl;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct list_head i_orphan;	/* unlinked but open inodes */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * i_disksize keeps track of what the inode size is ON DISK, not
 | 
				
			||||||
 | 
						 * in memory.  During truncate, i_size is set to the new size by
 | 
				
			||||||
 | 
						 * the VFS prior to calling ext3_truncate(), but the filesystem won't
 | 
				
			||||||
 | 
						 * set i_disksize to 0 until the truncate is actually under way.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * The intent is that i_disksize always represents the blocks which
 | 
				
			||||||
 | 
						 * are used by this file.  This allows recovery to restart truncate
 | 
				
			||||||
 | 
						 * on orphans if we crash during truncate.  We actually write i_disksize
 | 
				
			||||||
 | 
						 * into the on-disk inode when writing inodes out, instead of i_size.
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * The only time when i_disksize and i_size may be different is when
 | 
				
			||||||
 | 
						 * a truncate is in progress.  The only things which change i_disksize
 | 
				
			||||||
 | 
						 * are ext3_get_block (growth) and ext3_truncate (shrinkth).
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						loff_t	i_disksize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* on-disk additional length */
 | 
				
			||||||
 | 
						__u16 i_extra_isize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * truncate_mutex is for serialising ext3_truncate() against
 | 
				
			||||||
 | 
						 * ext3_getblock().  In the 2.4 ext2 design, great chunks of inode's
 | 
				
			||||||
 | 
						 * data tree are chopped off during truncate. We can't do that in
 | 
				
			||||||
 | 
						 * ext3 because whenever we perform intermediate commits during
 | 
				
			||||||
 | 
						 * truncate, the inode and all the metadata blocks *must* be in a
 | 
				
			||||||
 | 
						 * consistent state which allows truncation of the orphans to restart
 | 
				
			||||||
 | 
						 * during recovery.  Hence we must fix the get_block-vs-truncate race
 | 
				
			||||||
 | 
						 * by other means, so we have truncate_mutex.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						struct mutex truncate_mutex;
 | 
				
			||||||
 | 
						struct inode vfs_inode;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif	/* _LINUX_EXT3_FS_I */
 | 
				
			||||||
							
								
								
									
										83
									
								
								include/linux/ext4_fs_sb.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								include/linux/ext4_fs_sb.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,83 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 *  linux/include/linux/ext3_fs_sb.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright (C) 1992, 1993, 1994, 1995
 | 
				
			||||||
 | 
					 * Remy Card (card@masi.ibp.fr)
 | 
				
			||||||
 | 
					 * Laboratoire MASI - Institut Blaise Pascal
 | 
				
			||||||
 | 
					 * Universite Pierre et Marie Curie (Paris VI)
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  from
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  linux/include/linux/minix_fs_sb.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 *  Copyright (C) 1991, 1992  Linus Torvalds
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _LINUX_EXT3_FS_SB
 | 
				
			||||||
 | 
					#define _LINUX_EXT3_FS_SB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __KERNEL__
 | 
				
			||||||
 | 
					#include <linux/timer.h>
 | 
				
			||||||
 | 
					#include <linux/wait.h>
 | 
				
			||||||
 | 
					#include <linux/blockgroup_lock.h>
 | 
				
			||||||
 | 
					#include <linux/percpu_counter.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#include <linux/rbtree.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * third extended-fs super-block data in memory
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct ext3_sb_info {
 | 
				
			||||||
 | 
						unsigned long s_frag_size;	/* Size of a fragment in bytes */
 | 
				
			||||||
 | 
						unsigned long s_frags_per_block;/* Number of fragments per block */
 | 
				
			||||||
 | 
						unsigned long s_inodes_per_block;/* Number of inodes per block */
 | 
				
			||||||
 | 
						unsigned long s_frags_per_group;/* Number of fragments in a group */
 | 
				
			||||||
 | 
						unsigned long s_blocks_per_group;/* Number of blocks in a group */
 | 
				
			||||||
 | 
						unsigned long s_inodes_per_group;/* Number of inodes in a group */
 | 
				
			||||||
 | 
						unsigned long s_itb_per_group;	/* Number of inode table blocks per group */
 | 
				
			||||||
 | 
						unsigned long s_gdb_count;	/* Number of group descriptor blocks */
 | 
				
			||||||
 | 
						unsigned long s_desc_per_block;	/* Number of group descriptors per block */
 | 
				
			||||||
 | 
						unsigned long s_groups_count;	/* Number of groups in the fs */
 | 
				
			||||||
 | 
						struct buffer_head * s_sbh;	/* Buffer containing the super block */
 | 
				
			||||||
 | 
						struct ext3_super_block * s_es;	/* Pointer to the super block in the buffer */
 | 
				
			||||||
 | 
						struct buffer_head ** s_group_desc;
 | 
				
			||||||
 | 
						unsigned long  s_mount_opt;
 | 
				
			||||||
 | 
						uid_t s_resuid;
 | 
				
			||||||
 | 
						gid_t s_resgid;
 | 
				
			||||||
 | 
						unsigned short s_mount_state;
 | 
				
			||||||
 | 
						unsigned short s_pad;
 | 
				
			||||||
 | 
						int s_addr_per_block_bits;
 | 
				
			||||||
 | 
						int s_desc_per_block_bits;
 | 
				
			||||||
 | 
						int s_inode_size;
 | 
				
			||||||
 | 
						int s_first_ino;
 | 
				
			||||||
 | 
						spinlock_t s_next_gen_lock;
 | 
				
			||||||
 | 
						u32 s_next_generation;
 | 
				
			||||||
 | 
						u32 s_hash_seed[4];
 | 
				
			||||||
 | 
						int s_def_hash_version;
 | 
				
			||||||
 | 
						struct percpu_counter s_freeblocks_counter;
 | 
				
			||||||
 | 
						struct percpu_counter s_freeinodes_counter;
 | 
				
			||||||
 | 
						struct percpu_counter s_dirs_counter;
 | 
				
			||||||
 | 
						struct blockgroup_lock s_blockgroup_lock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* root of the per fs reservation window tree */
 | 
				
			||||||
 | 
						spinlock_t s_rsv_window_lock;
 | 
				
			||||||
 | 
						struct rb_root s_rsv_window_root;
 | 
				
			||||||
 | 
						struct ext3_reserve_window_node s_rsv_window_head;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Journaling */
 | 
				
			||||||
 | 
						struct inode * s_journal_inode;
 | 
				
			||||||
 | 
						struct journal_s * s_journal;
 | 
				
			||||||
 | 
						struct list_head s_orphan;
 | 
				
			||||||
 | 
						unsigned long s_commit_interval;
 | 
				
			||||||
 | 
						struct block_device *journal_bdev;
 | 
				
			||||||
 | 
					#ifdef CONFIG_JBD_DEBUG
 | 
				
			||||||
 | 
						struct timer_list turn_ro_timer;	/* For turning read-only (crash simulation) */
 | 
				
			||||||
 | 
						wait_queue_head_t ro_wait_queue;	/* For people waiting for the fs to go read-only */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef CONFIG_QUOTA
 | 
				
			||||||
 | 
						char *s_qf_names[MAXQUOTAS];		/* Names of quota files with journalled quota */
 | 
				
			||||||
 | 
						int s_jquota_fmt;			/* Format of quota to use */
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif	/* _LINUX_EXT3_FS_SB */
 | 
				
			||||||
							
								
								
									
										268
									
								
								include/linux/ext4_jbd.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										268
									
								
								include/linux/ext4_jbd.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,268 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * linux/include/linux/ext3_jbd.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Copyright 1998--1999 Red Hat corp --- All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is part of the Linux kernel and is made available under
 | 
				
			||||||
 | 
					 * the terms of the GNU General Public License, version 2, or at your
 | 
				
			||||||
 | 
					 * option, any later version, incorporated herein by reference.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Ext3-specific journaling extensions.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef _LINUX_EXT3_JBD_H
 | 
				
			||||||
 | 
					#define _LINUX_EXT3_JBD_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/fs.h>
 | 
				
			||||||
 | 
					#include <linux/jbd.h>
 | 
				
			||||||
 | 
					#include <linux/ext3_fs.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_JOURNAL(inode)	(EXT3_SB((inode)->i_sb)->s_journal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Define the number of blocks we need to account to a transaction to
 | 
				
			||||||
 | 
					 * modify one block of data.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * We may have to touch one inode, one bitmap buffer, up to three
 | 
				
			||||||
 | 
					 * indirection blocks, the group and superblock summaries, and the data
 | 
				
			||||||
 | 
					 * block to complete the transaction.  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_SINGLEDATA_TRANS_BLOCKS	8U
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Extended attribute operations touch at most two data buffers,
 | 
				
			||||||
 | 
					 * two bitmap buffers, and two group summaries, in addition to the inode
 | 
				
			||||||
 | 
					 * and the superblock, which are already accounted for. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_XATTR_TRANS_BLOCKS		6U
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Define the minimum size for a transaction which modifies data.  This
 | 
				
			||||||
 | 
					 * needs to take into account the fact that we may end up modifying two
 | 
				
			||||||
 | 
					 * quota files too (one for the group, one for the user quota).  The
 | 
				
			||||||
 | 
					 * superblock only gets updated once, of course, so don't bother
 | 
				
			||||||
 | 
					 * counting that again for the quota updates. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_DATA_TRANS_BLOCKS(sb)	(EXT3_SINGLEDATA_TRANS_BLOCKS + \
 | 
				
			||||||
 | 
										 EXT3_XATTR_TRANS_BLOCKS - 2 + \
 | 
				
			||||||
 | 
										 2*EXT3_QUOTA_TRANS_BLOCKS(sb))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Delete operations potentially hit one directory's namespace plus an
 | 
				
			||||||
 | 
					 * entire inode, plus arbitrary amounts of bitmap/indirection data.  Be
 | 
				
			||||||
 | 
					 * generous.  We can grow the delete transaction later if necessary. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_DELETE_TRANS_BLOCKS(sb)	(2 * EXT3_DATA_TRANS_BLOCKS(sb) + 64)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Define an arbitrary limit for the amount of data we will anticipate
 | 
				
			||||||
 | 
					 * writing to any given transaction.  For unbounded transactions such as
 | 
				
			||||||
 | 
					 * write(2) and truncate(2) we can write more than this, but we always
 | 
				
			||||||
 | 
					 * start off at the maximum transaction size and grow the transaction
 | 
				
			||||||
 | 
					 * optimistically as we go. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_MAX_TRANS_DATA		64U
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* We break up a large truncate or write transaction once the handle's
 | 
				
			||||||
 | 
					 * buffer credits gets this low, we need either to extend the
 | 
				
			||||||
 | 
					 * transaction or to start a new one.  Reserve enough space here for
 | 
				
			||||||
 | 
					 * inode, bitmap, superblock, group and indirection updates for at least
 | 
				
			||||||
 | 
					 * one block, plus two quota updates.  Quota allocations are not
 | 
				
			||||||
 | 
					 * needed. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_RESERVE_TRANS_BLOCKS	12U
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define EXT3_INDEX_EXTRA_TRANS_BLOCKS	8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_QUOTA
 | 
				
			||||||
 | 
					/* Amount of blocks needed for quota update - we know that the structure was
 | 
				
			||||||
 | 
					 * allocated so we need to update only inode+data */
 | 
				
			||||||
 | 
					#define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)
 | 
				
			||||||
 | 
					/* Amount of blocks needed for quota insert/delete - we do some block writes
 | 
				
			||||||
 | 
					 * but inode, sb and group updates are done only once */
 | 
				
			||||||
 | 
					#define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
 | 
				
			||||||
 | 
							(EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)
 | 
				
			||||||
 | 
					#define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
 | 
				
			||||||
 | 
							(EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define EXT3_QUOTA_TRANS_BLOCKS(sb) 0
 | 
				
			||||||
 | 
					#define EXT3_QUOTA_INIT_BLOCKS(sb) 0
 | 
				
			||||||
 | 
					#define EXT3_QUOTA_DEL_BLOCKS(sb) 0
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int
 | 
				
			||||||
 | 
					ext3_mark_iloc_dirty(handle_t *handle,
 | 
				
			||||||
 | 
							     struct inode *inode,
 | 
				
			||||||
 | 
							     struct ext3_iloc *iloc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * On success, We end up with an outstanding reference count against
 | 
				
			||||||
 | 
					 * iloc->bh.  This _must_ be cleaned up later.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
 | 
				
			||||||
 | 
								struct ext3_iloc *iloc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Wrapper functions with which ext3 calls into JBD.  The intent here is
 | 
				
			||||||
 | 
					 * to allow these to be turned into appropriate stubs so ext3 can control
 | 
				
			||||||
 | 
					 * ext2 filesystems, so ext2+ext3 systems only nee one fs.  This work hasn't
 | 
				
			||||||
 | 
					 * been done yet.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ext3_journal_abort_handle(const char *caller, const char *err_fn,
 | 
				
			||||||
 | 
							struct buffer_head *bh, handle_t *handle, int err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					__ext3_journal_get_undo_access(const char *where, handle_t *handle,
 | 
				
			||||||
 | 
									struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = journal_get_undo_access(handle, bh);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					__ext3_journal_get_write_access(const char *where, handle_t *handle,
 | 
				
			||||||
 | 
									struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = journal_get_write_access(handle, bh);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline void
 | 
				
			||||||
 | 
					ext3_journal_release_buffer(handle_t *handle, struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						journal_release_buffer(handle, bh);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					__ext3_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = journal_forget(handle, bh);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					__ext3_journal_revoke(const char *where, handle_t *handle,
 | 
				
			||||||
 | 
							      unsigned long blocknr, struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = journal_revoke(handle, blocknr, bh);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					__ext3_journal_get_create_access(const char *where,
 | 
				
			||||||
 | 
									 handle_t *handle, struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = journal_get_create_access(handle, bh);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int
 | 
				
			||||||
 | 
					__ext3_journal_dirty_metadata(const char *where,
 | 
				
			||||||
 | 
								      handle_t *handle, struct buffer_head *bh)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int err = journal_dirty_metadata(handle, bh);
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
							ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
 | 
				
			||||||
 | 
						return err;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ext3_journal_get_undo_access(handle, bh) \
 | 
				
			||||||
 | 
						__ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh))
 | 
				
			||||||
 | 
					#define ext3_journal_get_write_access(handle, bh) \
 | 
				
			||||||
 | 
						__ext3_journal_get_write_access(__FUNCTION__, (handle), (bh))
 | 
				
			||||||
 | 
					#define ext3_journal_revoke(handle, blocknr, bh) \
 | 
				
			||||||
 | 
						__ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
 | 
				
			||||||
 | 
					#define ext3_journal_get_create_access(handle, bh) \
 | 
				
			||||||
 | 
						__ext3_journal_get_create_access(__FUNCTION__, (handle), (bh))
 | 
				
			||||||
 | 
					#define ext3_journal_dirty_metadata(handle, bh) \
 | 
				
			||||||
 | 
						__ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
 | 
				
			||||||
 | 
					#define ext3_journal_forget(handle, bh) \
 | 
				
			||||||
 | 
						__ext3_journal_forget(__FUNCTION__, (handle), (bh))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);
 | 
				
			||||||
 | 
					int __ext3_journal_stop(const char *where, handle_t *handle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return ext3_journal_start_sb(inode->i_sb, nblocks);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ext3_journal_stop(handle) \
 | 
				
			||||||
 | 
						__ext3_journal_stop(__FUNCTION__, (handle))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline handle_t *ext3_journal_current_handle(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return journal_current_handle();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_journal_extend(handle_t *handle, int nblocks)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return journal_extend(handle, nblocks);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_journal_restart(handle_t *handle, int nblocks)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return journal_restart(handle, nblocks);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_journal_blocks_per_page(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return journal_blocks_per_page(inode);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_journal_force_commit(journal_t *journal)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return journal_force_commit(journal);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* super.c */
 | 
				
			||||||
 | 
					int ext3_force_commit(struct super_block *sb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_should_journal_data(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!S_ISREG(inode->i_mode))
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_should_order_data(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!S_ISREG(inode->i_mode))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int ext3_should_writeback_data(struct inode *inode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!S_ISREG(inode->i_mode))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif	/* _LINUX_EXT3_JBD_H */
 | 
				
			||||||
		Loading…
	
		Reference in a new issue