Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CSJoe

macrumors newbie
Original poster
Jan 10, 2007
5
0
Hello,
I have been given a question that is causing me some trouble. I have to output something along the lines of
' Block summary : 237 unused, 18 reserved, 1 used, 0 invalid' using System.out.println. This is done by questioning a superblock as provided below. I am not sure how to iterate over the collection to check what the contents of the 2bit bitmap values denoting the 4 possible states are and then to return them. I know the superblock code is long and tedious but very little of the code is needed for this method. Any light you can shed on the subject will be most helpfull.

******************************************************

#ifndef __SFSTYPES_H
#define __SFSTYPES_H


/* this defines the file-system block size -- do not change! */
#define SFS_BLOCKSIZE (4096)

/* these define the specific version of the file-system supported by this code */
#define SFS_VER_MAJ 0
#define SFS_VER_MIN 1

/* these define some file-system constants for a particular version */
#define SFS_MAGIC "\xde\xad\xbe\xef"
#define SFS_NTABLES 16

/* some typedefs */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
#ifndef __uint32_t_defined
typedef unsigned int uint32_t;
#endif


/*
* The superblock can be found on block 0 (primary copy of it), and
* gives details about the file-system, layout and size.
*/

typedef struct __sfs_superblock {
uint8_t magic[4]; /* magic identifier */
uint16_t major_ver; /* major FS version */
uint16_t minor_ver; /* minor FS version */
uint32_t sb_age; /* superblock age */
uint32_t nblocks; /* total number of blocks */
uint32_t bitmap_offset; /* block offset of bitmap */
uint32_t itable_offset[SFS_NTABLES]; /* block offsets of inode tables */
uint32_t itable_length[SFS_NTABLES]; /* lengths (in blocks) of inode tables */
uint32_t itotal; /* total number of inodes */
uint32_t iused; /* number of used inodes */
uint32_t root_inode; /* inode number of the root directory
* (see below for encoding) */
} sfs_superblock_t;

/*
* block bitmap: this is arranged as 2-bits for each block; a single block of bitmap data
* will cater for 16384 actual file-system blocks (64 MB file-system). Bits defined as:
*
* 00 - unused
* 01 - reserved (superblock, inodes, block bitmaps, indirect blocks)
* 10 - used (file or directory data)
* 11 - damaged/nonexistent (unusable block -- e.g. physically damaged, or invalid in bitmap)
*/

typedef enum {
SFSB_UNUSED = 0x00,
SFSB_RESERVED = 0x01,
SFSB_USED = 0x02,
SFSB_DAMAGED = 0x03
} sfs_bitmap_e;


/*
* The inodes (index-nodes) are found in various blocks, indicated by
* "itable_offset" and "itable_length" in the superblock. A single inode
* defines a file-system entry, typically either a file or a directory.
*
* each inode is 64 bytes, giving 64 inodes per block (assuming 4096 byte blocks)
*/

typedef enum {
SFSI_INVALID = 0x0000,
SFSI_PERMASK = 0x01ff, /* permissions mask */
SFSI_TYPEMASK = 0x0e00, /* type mask */
SFSI_MODEMASK = 0xf000, /* mode mask (for inode layout) */

SFSI_PER_UR = 0x0001, /* user read */
SFSI_PER_UW = 0x0002, /* user write */
SFSI_PER_UX = 0x0004, /* user execute */
SFSI_PER_GR = 0x0008, /* group read */
SFSI_PER_GW = 0x0010, /* group write */
SFSI_PER_GX = 0x0020, /* group execute */
SFSI_PER_OR = 0x0040, /* other read */
SFSI_PER_OW = 0x0080, /* other write */
SFSI_PER_OX = 0x0100, /* other execute */

SFSI_TYPE_FILE = 0x0200, /* regular file */
SFSI_TYPE_DIR = 0x0400, /* regular directory */

SFSI_MODE_DIRECT = 0x1000, /* block-list contains actual data block offsets */
SFSI_MODE_INDIRECT = 0x2000, /* block-list contains a list of block numbers which are
* simple arrays of uint32_t's giving actual data block
* offsets. a block number of 0 means invalid/unused.
*/
} sfs_iflags_e;

typedef struct __sfs_inode {
uint32_t size; /* size in bytes */
sfs_iflags_e flags; /* flags defining type/layout/permissions */
uint32_t uid; /* owner user-ID */
uint32_t gid; /* owner group-ID */
uint32_t blocks[12]; /* block list */
} sfs_inode_t;

/*
* inode numbers are referred to in the following way:
* 0xttoooooo ((itable << 24) | (ioffset & 0x00ffffff))
* where 'itable' is the relevant inode table (given in the superblocks)
* and 'ioffset' is the inode number within that table.
*/


/*
* directories are organised as blocks containing directory entries,
* defined below. Unused entries have a name starting with a zero-byte
* and an inode number of 0 (which is actually a valid inode).
*
* each directory entry is 64 bytes long, giving 64 entries per block
* (assuming 4096-byte blocks).
*/

typedef struct __sfs_dirent {
uint8_t name[60]; /* file/directory name */
uint32_t inode; /* associated inode */
} sfs_dirent_t;



#endif /* !__SFSTYPES_H */
*********************************************************
 

rickb

macrumors newbie
Dec 5, 2006
12
0
I would need more info to help you, whats the assignment?

You'll probably have to go through JNI if thats the header you have to use
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.