📄 ext3-ea-in-inode-2.6-suse.patch
字号:
%patchIndex: linux-2.6.0/fs/ext3/ialloc.c===================================================================--- linux-2.6.0.orig/fs/ext3/ialloc.c 2004-01-14 18:54:11.000000000 +0300+++ linux-2.6.0/fs/ext3/ialloc.c 2004-01-14 18:54:12.000000000 +0300@@ -627,6 +627,9 @@ inode->i_generation = EXT3_SB(sb)->s_next_generation++; 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)) {Index: linux-2.6.0/fs/ext3/inode.c===================================================================--- linux-2.6.0.orig/fs/ext3/inode.c 2004-01-14 18:54:12.000000000 +0300+++ linux-2.6.0/fs/ext3/inode.c 2004-01-14 19:09:46.000000000 +0300@@ -2339,7 +2339,7 @@ * trying to determine the inode's location on-disk and no read need be * performed. */-static int ext3_get_inode_loc(struct inode *inode,+int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc, int in_mem) { unsigned long block;@@ -2547,6 +2547,11 @@ ei->i_data[block] = raw_inode->i_block[block]; INIT_LIST_HEAD(&ei->i_orphan); + if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE)+ ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);+ else+ ei->i_extra_isize = 0;+ if (S_ISREG(inode->i_mode)) { inode->i_op = &ext3_file_inode_operations; inode->i_fop = &ext3_file_operations;@@ -2682,6 +2687,9 @@ } else for (block = 0; block < EXT3_N_BLOCKS; block++) raw_inode->i_block[block] = ei->i_data[block]; + if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE)+ raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);+ BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); rc = ext3_journal_dirty_metadata(handle, bh); if (!err)@@ -2849,7 +2857,8 @@ ext3_reserve_inode_write(handle_t *handl { int err = 0; if (handle) {- err = ext3_get_inode_loc(inode, iloc, 1);+ err = ext3_get_inode_loc(inode, iloc, EXT3_I(inode)->i_state &+ EXT3_STATE_NEW); if (!err) { BUFFER_TRACE(iloc->bh, "get_write_access"); err = ext3_journal_get_write_access(handle, iloc->bh);Index: linux-2.6.0/fs/ext3/xattr.c===================================================================--- linux-2.6.0.orig/fs/ext3/xattr.c 2003-12-30 08:33:13.000000000 +0300+++ linux-2.6.0/fs/ext3/xattr.c 2004-01-14 18:54:12.000000000 +0300@@ -246,17 +246,12 @@ } /*- * ext3_xattr_get()- *- * Copy an extended attribute into the buffer- * provided, or compute the buffer size required.- * Buffer is NULL to compute the size of the buffer required.+ * ext3_xattr_block_get() *- * Returns a negative error number on failure, or the number of bytes- * used / required on success.+ * routine looks for attribute in EA block and returns it's value and size */ int-ext3_xattr_get(struct inode *inode, int name_index, const char *name,+ext3_xattr_block_get(struct inode *inode, int name_index, const char *name, void *buffer, size_t buffer_size) { struct buffer_head *bh = NULL;@@ -270,7 +265,6 @@ if (name == NULL) return -EINVAL;- down_read(&EXT3_I(inode)->xattr_sem); error = -ENODATA; if (!EXT3_I(inode)->i_file_acl) goto cleanup;@@ -343,15 +337,87 @@ cleanup: brelse(bh);- up_read(&EXT3_I(inode)->xattr_sem); return error; } /*- * ext3_xattr_list()+ * ext3_xattr_ibody_get() *- * Copy a list of attribute names into the buffer+ * routine looks for attribute in inode body and returns it's value and size+ */+int+ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name,+ void *buffer, size_t buffer_size)+{+ int size, name_len = strlen(name), storage_size;+ struct ext3_xattr_entry *last;+ struct ext3_inode *raw_inode;+ struct ext3_iloc iloc;+ char *start, *end;+ int ret = -ENOENT;+ + if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)+ return -ENOENT;++ ret = ext3_get_inode_loc(inode, &iloc, 0);+ if (ret)+ return ret;+ raw_inode = ext3_raw_inode(&iloc);++ storage_size = EXT3_SB(inode->i_sb)->s_inode_size -+ EXT3_GOOD_OLD_INODE_SIZE -+ EXT3_I(inode)->i_extra_isize -+ sizeof(__u32);+ start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE ++ EXT3_I(inode)->i_extra_isize;+ if (le32_to_cpu((*(__u32*) start)) != EXT3_XATTR_MAGIC) {+ brelse(iloc.bh);+ return -ENOENT;+ }+ start += sizeof(__u32);+ end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;++ last = (struct ext3_xattr_entry *) start;+ while (!IS_LAST_ENTRY(last)) {+ struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);+ if (le32_to_cpu(last->e_value_size) > storage_size ||+ (char *) next >= end) {+ ext3_error(inode->i_sb, "ext3_xattr_ibody_get",+ "inode %ld", inode->i_ino);+ brelse(iloc.bh);+ return -EIO;+ }+ if (name_index == last->e_name_index &&+ name_len == last->e_name_len &&+ !memcmp(name, last->e_name, name_len))+ goto found;+ last = next;+ }++ /* can't find EA */+ brelse(iloc.bh);+ return -ENOENT;+ +found:+ size = le32_to_cpu(last->e_value_size);+ if (buffer) {+ ret = -ERANGE;+ if (buffer_size >= size) {+ memcpy(buffer, start + le16_to_cpu(last->e_value_offs),+ size);+ ret = size;+ }+ } else+ ret = size;+ brelse(iloc.bh);+ return ret;+}++/*+ * ext3_xattr_get()+ *+ * Copy an extended attribute into the buffer * provided, or compute the buffer size required. * Buffer is NULL to compute the size of the buffer required. *@@ -359,7 +425,31 @@ * used / required on success. */ int-ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)+ext3_xattr_get(struct inode *inode, int name_index, const char *name,+ void *buffer, size_t buffer_size)+{+ int err;++ down_read(&EXT3_I(inode)->xattr_sem);++ /* try to find attribute in inode body */+ err = ext3_xattr_ibody_get(inode, name_index, name,+ buffer, buffer_size);+ if (err < 0)+ /* search was unsuccessful, try to find EA in dedicated block */+ err = ext3_xattr_block_get(inode, name_index, name,+ buffer, buffer_size);+ up_read(&EXT3_I(inode)->xattr_sem);++ return err;+}++/* ext3_xattr_ibody_list()+ *+ * generate list of attributes stored in EA block+ */+int+ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) { struct buffer_head *bh = NULL; struct ext3_xattr_entry *entry;@@ -370,7 +460,6 @@ ea_idebug(inode, "buffer=%p, buffer_size=%ld", buffer, (long)buffer_size); - down_read(&EXT3_I(inode)->xattr_sem); error = 0; if (!EXT3_I(inode)->i_file_acl) goto cleanup;@@ -431,11 +520,138 @@ cleanup: brelse(bh);- up_read(&EXT3_I(inode)->xattr_sem); return error; } +/* ext3_xattr_ibody_list()+ *+ * generate list of attributes stored in inode body+ */+int+ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)+{+ struct ext3_xattr_entry *last;+ struct ext3_inode *raw_inode;+ char *start, *end, *buf;+ struct ext3_iloc iloc;+ int storage_size;+ int ret;+ int size = 0;+ + if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)+ return 0;++ ret = ext3_get_inode_loc(inode, &iloc, 0);+ if (ret)+ return ret;+ raw_inode = ext3_raw_inode(&iloc);++ storage_size = EXT3_SB(inode->i_sb)->s_inode_size -+ EXT3_GOOD_OLD_INODE_SIZE -+ EXT3_I(inode)->i_extra_isize -+ sizeof(__u32);+ start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE ++ EXT3_I(inode)->i_extra_isize;+ if (le32_to_cpu((*(__u32*) start)) != EXT3_XATTR_MAGIC) {+ brelse(iloc.bh);+ return 0;+ }+ start += sizeof(__u32);+ end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;++ last = (struct ext3_xattr_entry *) start;+ while (!IS_LAST_ENTRY(last)) {+ struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);+ struct ext3_xattr_handler *handler;+ if (le32_to_cpu(last->e_value_size) > storage_size ||+ (char *) next >= end) {+ ext3_error(inode->i_sb, "ext3_xattr_ibody_list",+ "inode %ld", inode->i_ino);+ brelse(iloc.bh);+ return -EIO;+ }+ handler = ext3_xattr_handler(last->e_name_index);+ if (handler)+ size += handler->list(NULL, inode, last->e_name,+ last->e_name_len);+ last = next;+ }++ if (!buffer) {+ ret = size;+ goto cleanup;+ } else {+ ret = -ERANGE;+ if (size > buffer_size)+ goto cleanup;+ }++ last = (struct ext3_xattr_entry *) start;+ buf = buffer;+ while (!IS_LAST_ENTRY(last)) {+ struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);+ struct ext3_xattr_handler *handler;+ handler = ext3_xattr_handler(last->e_name_index);+ if (handler)+ buf += handler->list(buf, inode, last->e_name,+ last->e_name_len);+ last = next;+ }+ ret = size;+cleanup:+ brelse(iloc.bh);+ return ret;+}++/*+ * ext3_xattr_list()+ *+ * Copy a list of attribute names into the buffer+ * provided, or compute the buffer size required.+ * Buffer is NULL to compute the size of the buffer required.+ *+ * Returns a negative error number on failure, or the number of bytes+ * used / required on success.+ */+int+ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)+{+ int error;+ int size = buffer_size;++ down_read(&EXT3_I(inode)->xattr_sem);++ /* get list of attributes stored in inode body */+ error = ext3_xattr_ibody_list(inode, buffer, buffer_size);+ if (error < 0) {+ /* some error occured while collecting+ * attributes in inode body */+ size = 0;+ goto cleanup;+ }+ size = error;++ /* get list of attributes stored in dedicated block */+ if (buffer) {+ buffer_size -= error;+ if (buffer_size <= 0) {+ buffer = NULL;+ buffer_size = 0;+ } else+ buffer += error;+ }++ error = ext3_xattr_block_list(inode, buffer, buffer_size);+ if (error < 0)+ /* listing was successful, so we return len */+ size = 0;++cleanup:+ up_read(&EXT3_I(inode)->xattr_sem);+ return error + size;+}+ /* * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is * not set, set it.@@ -457,6 +673,279 @@ } /*+ * ext3_xattr_ibody_find()+ *+ * search attribute and calculate free space in inode body+ * NOTE: free space includes space our attribute hold+ */+int+ext3_xattr_ibody_find(struct inode *inode, int name_index,+ const char *name, struct ext3_xattr_entry *rentry, int *free)+{+ struct ext3_xattr_entry *last;+ struct ext3_inode *raw_inode;+ int name_len = strlen(name);+ int err, storage_size;+ struct ext3_iloc iloc;+ char *start, *end;+ int ret = -ENOENT;+ + if (EXT3_SB(inode->i_sb)->s_inode_size <= EXT3_GOOD_OLD_INODE_SIZE)+ return ret;++ err = ext3_get_inode_loc(inode, &iloc, 0);+ if (err)+ return -EIO;+ raw_inode = ext3_raw_inode(&iloc);++ storage_size = EXT3_SB(inode->i_sb)->s_inode_size -+ EXT3_GOOD_OLD_INODE_SIZE -+ EXT3_I(inode)->i_extra_isize -+ sizeof(__u32);+ *free = storage_size - sizeof(__u32);+ start = (char *) raw_inode + EXT3_GOOD_OLD_INODE_SIZE ++ EXT3_I(inode)->i_extra_isize;+ if (le32_to_cpu((*(__u32*) start)) != EXT3_XATTR_MAGIC) {+ brelse(iloc.bh);+ return -ENOENT;+ }+ start += sizeof(__u32);+ end = (char *) raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;++ last = (struct ext3_xattr_entry *) start;+ while (!IS_LAST_ENTRY(last)) {+ struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(last);+ if (le32_to_cpu(last->e_value_size) > storage_size ||+ (char *) next >= end) {+ ext3_error(inode->i_sb, "ext3_xattr_ibody_find",+ "inode %ld", inode->i_ino);+ brelse(iloc.bh);+ return -EIO;+ }++ if (name_index == last->e_name_index &&+ name_len == last->e_name_len &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -