aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-02-04 19:14:58 -0500
committerRob Landley <rob@landley.net>2007-02-04 19:14:58 -0500
commit720fc26d33352407715cb286a4edc23d15906d5f (patch)
treef0f621317e0e2ffc895b7b814488d0bc12fd11ed /toys
parent97c63ecb359138a04073e043b85bf928a14d7e8a (diff)
downloadtoybox-720fc26d33352407715cb286a4edc23d15906d5f.tar.gz
Add parent pointer to dirtree, more work on mke2fs (populate dirtree, count
index blocks).
Diffstat (limited to 'toys')
-rw-r--r--toys/e2fs.h4
-rw-r--r--toys/mke2fs.c34
-rw-r--r--toys/toylist.h2
3 files changed, 36 insertions, 4 deletions
diff --git a/toys/e2fs.h b/toys/e2fs.h
index bcffa3c6..5a2cb64d 100644
--- a/toys/e2fs.h
+++ b/toys/e2fs.h
@@ -80,7 +80,7 @@ struct ext2_dentry {
uint16_t rec_len; // Directory entry length
uint8_t name_len; // Name length
uint8_t file_type;
- char name[255]; // File name
+ char name[0]; // File name
};
struct ext2_inode {
@@ -109,8 +109,6 @@ struct ext2_inode {
uint32_t reserved2;
};
-
-
#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
diff --git a/toys/mke2fs.c b/toys/mke2fs.c
index bf019567..bade3d22 100644
--- a/toys/mke2fs.c
+++ b/toys/mke2fs.c
@@ -30,6 +30,26 @@
#define INODES_RESERVED 10
+// Calculate data blocks plus index blocks needed to hold a file.
+uint32_t blocks_used(uint64_t size)
+{
+ uint32_t dblocks = (uint32_t)((size+(TT.blocksize-1))/TT.blocksize);
+ uint32_t idx=TT.blocksize/4, iblocks=0, diblocks=0, tiblocks=0;
+
+ // Account for direct, singly, doubly, and triply indiret index blocks
+
+ if (dblocks > 12) {
+ iblocks = ((dblocks-13)/idx)+1;
+ if (iblocks > 1) {
+ diblocks = ((iblocks-2)/idx)+1;
+ if (diblocks > 1)
+ tiblocks = ((diblocks-2)/idx)+1;
+ }
+ }
+
+ return dblocks + iblocks + diblocks + tiblocks;
+}
+
// According to http://www.opengroup.org/onlinepubs/9629399/apdxa.htm
// we should generate a uuid structure by reading a clock with 100 nanosecond
// precision, normalizing it to the start of the gregorian calendar in 1582,
@@ -187,7 +207,19 @@ int mke2fs_main(void)
temp = O_RDWR|O_CREAT;
} else temp = O_RDWR;
- // TODO: collect gene2fs list/lost+found, calculate requirements.
+ // Collect gene2fs list or lost+found, calculate requirements.
+
+ if (TT.gendir) {
+ strncpy(toybuf, TT.gendir, sizeof(toybuf));
+ TT.dt = read_dirtree(toybuf, NULL);
+ } else {
+ TT.dt = xzalloc(sizeof(struct dirtree)+11);
+ strcpy(TT.dt->name, "lost+found");
+ TT.dt->st.st_mode = S_IFDIR|0755;
+ TT.dt->st.st_ctime = TT.dt->st.st_mtime = time(NULL);
+ }
+
+ // Calculate st_nlink for each node in tree.
// TODO: Check if filesystem is mounted here
diff --git a/toys/toylist.h b/toys/toylist.h
index 715b5613..87aaba84 100644
--- a/toys/toylist.h
+++ b/toys/toylist.h
@@ -23,10 +23,12 @@ struct mke2fs_data {
long bytes_per_inode;
long inodes;
long reserved_percent;
+ char *gendir;
unsigned blocks, groups;
int fsfd, noseek;
struct ext2_superblock sb;
+ struct dirtree *dt;
};
// "E:jJ:L:m:O:"