c - How to create an array of size 2^16 blocks consisting of 256 bytes -
so title says all. have create file system simulation operating systems class. still not c why asking help. , 1 of things throwing me off have create storage array of 2^16 blocks of 256 bytes each; block plain sequence of bytes until overlaid structure (use union, of course): directory or file meta-data, index node, or data node; there type of node:
this did
#include "project1task3.h" int main() { createfilesystem(); } /* * create file system * (i.e., allocate , initializing structures , auxiliary data; * create superblock) * * * */ void createfilesystem() { // setting file system "superblock" fs_node filesystem; node typenode; node* p; // pointer point file or director //typenode.type = dir; int i; int j; size_t nodesize; // allocate space fixed sie , variable part (union) nodesize = sizeof(fs_node) + sizeof(node); if ((memory = malloc(nodesize)) == null) { for(i = 0; < mem;i++) { for(j = 0; j < block_size;j++) { //not sure if how should memory->content.index[j] = 0; } } } strcpy(filesystem.name,"\\"); filesystem.creat_t = 0; // set creation time 0 filesystem.access = 400; //the access should not allow deletion or name change, 400 allow read in filesystem.owner = 000;// no permissions yet none filesystem.size = 0; filesystem.block_ref = block_size; filesystem.access_t =0; filesystem.mod_t = 0; /* *a file-descriptor node holds meta-data information file or directory * such size, access rights, creation time, access time, , modification time, along pointer actual content of file or director * */ typenode.content.fd.creat_t =0; typenode.content.fd.access = 400; typenode.content.fd.size=0; typenode.content.fd.mod_t = 0; typenode.content.fd.access_t = 0; //if((memory= malloc(sizeof *memory + mem)) != null) /* * * in case of node type opf directory, size indicates number of files in directory, * , block reference points index block holds indices files in directory. * assume directory may hold directly 127 files or directories; each index of index block points file or directory descriptor. * of course, each of subdirectries may hold 127 files or directories, , on. * * * */ /* * * * * in case of file, size in file descriptor indicates actual size of file. * block reference either ponts single data block * if size of file less 254, or index block array of references data blocks file larger 254. * assume maximum size of file 127 * 254 (i.e., maximum allowed one-level indexing). * * * * */ } /* * * create file (i.e., allocate 1 block meta-level information; set size 0, times current time, , access rights default) create of directory (just file creation, different type) delete file (return blocks , clean supporting structures; e.g., reset bits in bit vector) delete directory (delete files directory, , delete directory; clean up) obtain file information (type - file or directory, size, times, access right, owner) * * * */ void createafile() { } void createdirectory() { } void deletefile() { } void obtainfileinfo() { }
this header
#include <time.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <string.h> #define block_size 256 #define max_name_length 128 #define data_size 254 #define index_size 127 #define mem 65536 //2^16 typedef char data_t; typedef unsigned short index_t; typedef enum { dir, filee, index, data } node_type; typedef struct fs_node { char name[max_name_length]; time_t creat_t; // creation time time_t access_t; // last access time_t mod_t; // last modification mode_t access; // access rights file unsigned short owner; // owner id unsigned short size; index_t block_ref; // reference data or index block } fs_node; typedef struct node { node_type type; union { fs_node fd; data_t data[data_size]; index_t index[index_size]; } content; } node; // storage blocks node *memory; // allocate 2^16 blocks (in init void createfilesystem(); void createafile(); void createdirectory(); void deletefile(); void obtainfileinfo();
idk if set right, think how should set node memory create array of 2^16 blocks of 256 bytes per block. appreciated.
since space dimensions fixed, should able declare memory this:
char space[65536][256];
Comments
Post a Comment