Btrfs: add inode item
Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
1d4f6404de
commit
1e1d27017c
|
@ -2,7 +2,7 @@ CC=gcc
|
|||
CFLAGS = -g -Wall
|
||||
headers = radix-tree.h ctree.h disk-io.h kerncompat.h print-tree.h list.h
|
||||
objects = ctree.o disk-io.o radix-tree.o mkfs.o extent-tree.o print-tree.o \
|
||||
root-tree.o dir-item.o hash.o
|
||||
root-tree.o dir-item.o hash.o file-item.o inode-item.o
|
||||
|
||||
# if you don't have sparse installed, use ls instead
|
||||
CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* Add simple tree locking (semaphore per tree)
|
||||
* Make allocator smarter
|
||||
* Do actual block accounting
|
||||
* Check compat and incompat flags on the inode
|
||||
* Port into the kernel
|
||||
* Add virtual filesystems, mountable snapshots
|
||||
* Get rid of struct ctree_path, limiting tree levels held at one time
|
||||
|
|
175
fs/btrfs/ctree.h
175
fs/btrfs/ctree.h
|
@ -132,6 +132,37 @@ struct btrfs_extent_item {
|
|||
__le64 owner;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_inode_timespec {
|
||||
__le32 sec;
|
||||
__le32 nsec;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/*
|
||||
* there is no padding here on purpose. If you want to extent the inode,
|
||||
* make a new item type
|
||||
*/
|
||||
struct btrfs_inode_item {
|
||||
__le64 generation;
|
||||
__le64 size;
|
||||
__le64 nblocks;
|
||||
__le32 nlink;
|
||||
__le32 uid;
|
||||
__le32 gid;
|
||||
__le32 mode;
|
||||
__le32 rdev;
|
||||
__le16 flags;
|
||||
__le16 compat_flags;
|
||||
struct btrfs_inode_timespec atime;
|
||||
struct btrfs_inode_timespec ctime;
|
||||
struct btrfs_inode_timespec mtime;
|
||||
struct btrfs_inode_timespec otime;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/* inline data is just a blob of bytes */
|
||||
struct btrfs_inline_data_item {
|
||||
u8 data;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_dir_item {
|
||||
__le64 objectid;
|
||||
__le16 flags;
|
||||
|
@ -170,15 +201,149 @@ struct btrfs_root {
|
|||
u32 blocksize;
|
||||
};
|
||||
|
||||
|
||||
/* the lower bits in the key flags defines the item type */
|
||||
#define BTRFS_KEY_TYPE_MAX 256
|
||||
#define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1)
|
||||
|
||||
/*
|
||||
* inode items have the data typically returned from stat and store other
|
||||
* info about object characteristics. There is one for every file and dir in
|
||||
* the FS
|
||||
*/
|
||||
#define BTRFS_INODE_ITEM_KEY 1
|
||||
|
||||
/*
|
||||
* dir items are the name -> inode pointers in a directory. There is one
|
||||
* for every name in a directory.
|
||||
*/
|
||||
#define BTRFS_DIR_ITEM_KEY 2
|
||||
#define BTRFS_ROOT_ITEM_KEY 3
|
||||
#define BTRFS_EXTENT_ITEM_KEY 4
|
||||
#define BTRFS_STRING_ITEM_KEY 5
|
||||
/*
|
||||
* inline data is file data that fits in the btree.
|
||||
*/
|
||||
#define BTRFS_INLINE_DATA_KEY 3
|
||||
/*
|
||||
* extent data is for data that can't fit in the btree. It points to
|
||||
* a (hopefully) huge chunk of disk
|
||||
*/
|
||||
#define BTRFS_EXTENT_DATA_KEY 4
|
||||
/*
|
||||
* root items point to tree roots. There are typically in the root
|
||||
* tree used by the super block to find all the other trees
|
||||
*/
|
||||
#define BTRFS_ROOT_ITEM_KEY 5
|
||||
/*
|
||||
* extent items are in the extent map tree. These record which blocks
|
||||
* are used, and how many references there are to each block
|
||||
*/
|
||||
#define BTRFS_EXTENT_ITEM_KEY 6
|
||||
/*
|
||||
* string items are for debugging. They just store a short string of
|
||||
* data in the FS
|
||||
*/
|
||||
#define BTRFS_STRING_ITEM_KEY 7
|
||||
|
||||
static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le64_to_cpu(i->generation);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
|
||||
u64 val)
|
||||
{
|
||||
i->generation = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le64_to_cpu(i->size);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
|
||||
{
|
||||
i->size = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le64_to_cpu(i->nblocks);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
|
||||
{
|
||||
i->nblocks = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le32_to_cpu(i->nlink);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
|
||||
{
|
||||
i->nlink = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le32_to_cpu(i->uid);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
|
||||
{
|
||||
i->uid = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le32_to_cpu(i->gid);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
|
||||
{
|
||||
i->gid = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le32_to_cpu(i->mode);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
|
||||
{
|
||||
i->mode = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le32_to_cpu(i->rdev);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
|
||||
{
|
||||
i->rdev = cpu_to_le32(val);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le16_to_cpu(i->flags);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
|
||||
{
|
||||
i->flags = cpu_to_le16(val);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
|
||||
{
|
||||
return le16_to_cpu(i->compat_flags);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
|
||||
u16 val)
|
||||
{
|
||||
i->compat_flags = cpu_to_le16(val);
|
||||
}
|
||||
|
||||
|
||||
static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
|
||||
{
|
||||
|
@ -344,8 +509,6 @@ static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type)
|
|||
btrfs_set_disk_key_flags(key, flags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
|
||||
{
|
||||
return le64_to_cpu(h->blocknr);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "kerncompat.h"
|
||||
#include "radix-tree.h"
|
||||
#include "ctree.h"
|
||||
#include "disk-io.h"
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "kerncompat.h"
|
||||
#include "radix-tree.h"
|
||||
#include "ctree.h"
|
||||
#include "disk-io.h"
|
||||
|
||||
int btrfs_insert_inode(struct btrfs_root *root, u64 objectid,
|
||||
struct btrfs_inode_item *inode_item)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
int ret;
|
||||
key.objectid = objectid;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
|
||||
key.offset = 0;
|
||||
|
||||
btrfs_init_path(&path);
|
||||
ret = btrfs_insert_item(root, &key, inode_item, sizeof(*inode_item));
|
||||
btrfs_release_path(root, &path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btrfs_lookup_inode(struct btrfs_root *root, struct btrfs_path *path,
|
||||
u64 objectid, int mod)
|
||||
{
|
||||
struct btrfs_key key;
|
||||
int ins_len = mod < 0 ? -1 : 0;
|
||||
int cow = mod != 0;
|
||||
|
||||
key.objectid = objectid;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
|
||||
key.offset = 0;
|
||||
return btrfs_search_slot(root, &key, path, ins_len, cow);
|
||||
}
|
Loading…
Reference in New Issue