mirror of https://github.com/vitalif/e2fsprogs
libext2fs: move ext2fs_get_num_dirs to its own file
This reduces the number of C library symbols needed by boot loader systems such as yaboot. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>pu
parent
c4111cd7ea
commit
bc0b1a899a
|
@ -50,6 +50,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \
|
|||
freefs.o \
|
||||
gen_bitmap.o \
|
||||
gen_bitmap64.o \
|
||||
get_num_dirs.o \
|
||||
get_pathname.o \
|
||||
getsize.o \
|
||||
getsectsize.o \
|
||||
|
@ -122,6 +123,7 @@ SRCS= ext2_err.c \
|
|||
$(srcdir)/freefs.c \
|
||||
$(srcdir)/gen_bitmap.c \
|
||||
$(srcdir)/gen_bitmap64.c \
|
||||
$(srcdir)/get_num_dirs.c \
|
||||
$(srcdir)/get_pathname.c \
|
||||
$(srcdir)/getsize.c \
|
||||
$(srcdir)/getsectsize.c \
|
||||
|
@ -686,6 +688,13 @@ gen_bitmap64.o: $(srcdir)/gen_bitmap64.c $(top_builddir)/lib/config.h \
|
|||
$(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
|
||||
$(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \
|
||||
$(srcdir)/bitops.h $(srcdir)/bmap64.h
|
||||
get_num_dirs.o: $(srcdir)/get_num_dirs.c $(top_builddir)/lib/config.h \
|
||||
$(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \
|
||||
$(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \
|
||||
$(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \
|
||||
$(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
|
||||
$(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \
|
||||
$(srcdir)/bitops.h
|
||||
get_pathname.o: $(srcdir)/get_pathname.c $(top_builddir)/lib/config.h \
|
||||
$(top_builddir)/lib/dirpaths.h $(srcdir)/ext2_fs.h \
|
||||
$(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
|
||||
|
|
|
@ -24,34 +24,6 @@ static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b);
|
|||
static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b);
|
||||
static EXT2_QSORT_TYPE (*sortfunc32)(const void *a, const void *b);
|
||||
|
||||
/*
|
||||
* Returns the number of directories in the filesystem as reported by
|
||||
* the group descriptors. Of course, the group descriptors could be
|
||||
* wrong!
|
||||
*/
|
||||
errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs)
|
||||
{
|
||||
dgrp_t i;
|
||||
ext2_ino_t num_dirs, max_dirs;
|
||||
|
||||
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
||||
|
||||
num_dirs = 0;
|
||||
max_dirs = fs->super->s_inodes_per_group;
|
||||
for (i = 0; i < fs->group_desc_count; i++) {
|
||||
if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs)
|
||||
num_dirs += max_dirs / 8;
|
||||
else
|
||||
num_dirs += ext2fs_bg_used_dirs_count(fs, i);
|
||||
}
|
||||
if (num_dirs > fs->super->s_inodes_count)
|
||||
num_dirs = fs->super->s_inodes_count;
|
||||
|
||||
*ret_num_dirs = num_dirs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function for making a new directory block list (for
|
||||
* initialize and copy).
|
||||
|
|
|
@ -938,8 +938,6 @@ extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs);
|
|||
extern __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group);
|
||||
|
||||
/* dblist.c */
|
||||
|
||||
extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
|
||||
extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
|
||||
extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
|
||||
blk_t blk, int blockcnt);
|
||||
|
@ -1189,6 +1187,9 @@ errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap,
|
|||
errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
|
||||
ext2fs_block_bitmap *bitmap);
|
||||
|
||||
/* get_num_dirs.c */
|
||||
extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
|
||||
|
||||
/* getsize.c */
|
||||
extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
|
||||
blk_t *retblocks);
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* get_num_dirs.c -- calculate number of directories
|
||||
*
|
||||
* Copyright 1997 by Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Library
|
||||
* General Public License, version 2.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fsP.h"
|
||||
|
||||
/*
|
||||
* Returns the number of directories in the filesystem as reported by
|
||||
* the group descriptors. Of course, the group descriptors could be
|
||||
* wrong!
|
||||
*/
|
||||
errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs)
|
||||
{
|
||||
dgrp_t i;
|
||||
ext2_ino_t num_dirs, max_dirs;
|
||||
|
||||
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
||||
|
||||
num_dirs = 0;
|
||||
max_dirs = fs->super->s_inodes_per_group;
|
||||
for (i = 0; i < fs->group_desc_count; i++) {
|
||||
if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs)
|
||||
num_dirs += max_dirs / 8;
|
||||
else
|
||||
num_dirs += ext2fs_bg_used_dirs_count(fs, i);
|
||||
}
|
||||
if (num_dirs > fs->super->s_inodes_count)
|
||||
num_dirs = fs->super->s_inodes_count;
|
||||
|
||||
*ret_num_dirs = num_dirs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue