30 char *buff = (
char *)
malloc(128);
43 if (!strftime(buff, 128,
"%F %T", tm))
54 printf(
"usage: %s FILE [OPTIONS...]\r\n"
55 "Displays information of a Linnenbank Filesystem\r\n"
57 "-h Show this help message.\r\n",
61int main(
int argc,
char **argv)
65 float percentFreeBlocks = 0, percentFreeInodes = 0, megabytes = 0;
75 for (
int i = 0; i < argc - 2; i++)
78 if (!
strcmp(argv[i + 2],
"-h"))
85 printf(
"%s: unknown option `%s'\r\n",
86 argv[0], argv[i + 2]);
91 printf(
"%s: failed to fopen() `%s': %s\n",
98 printf(
"%s: failed to fseek() to %x in `%s': %s\n",
103 if (
fread(&super,
sizeof(super), 1,
fp) != 1)
105 printf(
"%s: failed to fread() superblock from `%s': %s\n",
113 printf(
"%s: `%s' is not a LinnFS filesystem (magic mismatch)\n",
132 printf(
"LinnSuperBlock\n"
136 " majorRevision = %u\n"
137 " minorRevision = %u\n"
140 " blocksPerGroup = %u\n"
141 " inodesPerGroup = %u\n"
142 " inodesCount = %u\n"
143 " blocksCount = %u (%.2fMB)\n"
144 " freeBlocksCount = %u (%.2f%%)\n"
145 " freeInodesCount = %u (%.2f%%)\n"
146 " creationTime = %s\n"
150 " groupsTable = %u\n"
166 printf(
"%s: failed to seek to LinnGroup table in `%s': %s\n",
174 if (
fread(&group,
sizeof(group), 1,
fp) != 1)
176 printf(
"%s: failed to fread() group from `%s': %s\n",
181 printf(
"LinnGroup #%u (blocks %u - %u)\n"
183 " freeBlocksCount = %u\n"
184 " freeInodesCount = %u\n"
185 " blockMap = %u - %lu\n"
186 " inodeMap = %u - %lu\n"
187 " inodeTable = %u - %lu\n"
char * timeString(u32 timestamp)
#define timestamp()
Reads the CPU's timestamp counter.
C char * strdup(const char *str)
Duplicate a string.
#define SEEK_SET
Seek relative to start-of-file.
C char * strerror(int errnum)
The strerror function maps the number in errnum to a message string.
C int errno
The lvalue errno is used by many functions to return error values.
#define EXIT_SUCCESS
Successful termination.
C int strcmp(const char *dest, const char *src)
Compare two strings.
#define EXIT_FAILURE
Unsuccessful termination.
C int printf(const char *format,...)
Output a formatted string to standard output.
u64 time_t
Used for time in seconds.
C int fclose(FILE *stream)
Close a stream.
C void * malloc(size_t size)
A memory allocator.
C size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream)
Binary input.
C FILE * fopen(const char *filename, const char *mode)
Open a stream.
int main(int argc, char **argv)
Program entry point.
#define NULL
NULL means zero.
unsigned int u32
Unsigned 32-bit number.
unsigned long ulong
Unsigned long number.
unsigned int Size
Any sane size indicator cannot go negative.
#define LINN_SUPER_MAGIC1
Second magic number (randomly chosen bytes).
#define LINN_SUPER_MAGIC0
First magic number ('Linn').
#define LINN_GROUP_NUM_BLOCKMAP(sb)
Calculate the number of blocks needed for the blocks bitmap.
#define LINN_GROUP_COUNT(sb)
Calculate the number of LinnGroups in a filesystem.
#define LINN_GROUP_NUM_INODEMAP(sb)
Calculate the number of blocks needed for the inodes bitmap.
#define LINN_SUPER_OFFSET
Fixed offset in storage of the superblock.
#define LINN_GROUP_NUM_INODETAB(sb)
Calculate the number of blocks needed for the inodes table.
A structure containing information about a file.
Structure of a group descriptor.
le32 inodeMap
Inode bitmap.
le32 freeBlocksCount
The number of free blocks in this group.
le32 inodeTable
Inode table contains pre-allocated inodes.
le32 freeInodesCount
Number of free inodes in this group.
le32 blockMap
Block bitmap.
Linnenbank Filesystem (LinnFS) super block.
le16 mountCount
Number of times we where mounted.
le32 creationTime
Time when the filesystem was created.
le32 groupsTable
Block address of the LinnGroup table.
le32 inodesCount
Total number of inodes.
le32 magic0
Allows detection of valid superblocks.
le32 freeInodesCount
Free inodes remaining.
le32 blockSize
Size of each data block.
le32 mountTime
Last time we where mounted (seconds since 1970).
le32 magic1
Allows detection of valid superblocks.
le16 minorRevision
Filesystem minor revision level.
le16 majorRevision
Filesystem major revision level.
le32 inodesPerGroup
Number of inodes per group.
le32 lastCheck
Timestamp of the last check.
le32 blocksCount
Total number of data blocks.
le32 freeBlocksCount
Number of free data blocks.
le32 blocksPerGroup
Number of blocks per group.
le16 state
Describes the current status.