2016-11-13 7 views
-3

私のタイトルはそれをすべて言っています。私は自分のオペレーティングシステムクラス用のファイルシステムシミュレーションを作成する必要があります。私はまだCが役に立たないので、なぜ私は助けを求めているのですか?そして、私を捨てているものの1つは、256バイトの2^16ブロックの配列であるストレージを作成しなければならないということです。ブロックは、ディレクトリまたはファイルのメタデータ、インデックスノード、またはデータノードのような構造体(もちろん、結合体を使用します)でオーバーレイされるまで、単純なバイトシーケンスです。ノードのタイプもあります:サイズの配列を作成する方法2^16ブロックを256バイトで構成

私はこれは私が右のそれを設定した場合

#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 for the file 
    unsigned short owner; // owner ID 
    unsigned short size; 
    index_t block_ref; // reference to the 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のが、私は、これはどのように私だと思うヘッダである

#include "project1task3.h" 

int main() 
{ 

    createFileSystem(); 
} 
/* 
* create the file system 
* (i.e., allocate and initializing all structures and auxiliary data; 
* create the superblock) 
* 
* 
* */ 
void createFileSystem() 
{ 
    // setting up file system "superblock" 
    FS_NODE fileSystem; 
    NODE typeNode; 
    NODE* p; // pointer that will point to file or director 
    //typeNode.type = DIR; 
    int i; 
    int j; 
    size_t nodeSize; 
    // allocate space for the fixed sie and the variable part (union) 
    nodeSize = sizeof(FS_NODE) + sizeof(NODE); 
    if ((memory = malloc(nodeSize)) == NULL) 
    { 
     for(i = 0; i < MEM;i++) 
     { 
      for(j = 0; j < BLOCK_SIZE;j++) 
      { 
       //not sure if this is how it should be 
       memory->content.index[j] = 0; 

      } 
     } 
    } 




    strcpy(fileSystem.name,"\\"); 
    fileSystem.creat_t = 0; // set creation time to 0 
    fileSystem.access = 400; //the access should not allow for deletion or name change, 400 will allow only for read in 
    fileSystem.owner = 000;// no permissions yet basically 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 about a file or a directory 
    * such as size, access rights, creation time, access time, and modification time, along with a pointer to actual content of the 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 a node with the type opf directory, the size indicates the number of files in the directory, 
    * and the block reference points to the index block that holds indices to all files in the directory. 
    * Assume that a directory may hold directly up to 127 files or directories; each index of the index block points to a file or a directory descriptor. 
    * Of course, each of the subdirectries may hold another 127 files or directories, and so on. 
    * 
    * 
    * */ 

    /* 
     * * 
     * 
     * In case of a file, the size in the file descriptor indicates the actual size of the file. 
     * The block reference either ponts to a single data block 
     * if the size of the file is less than 254, or to an index block with an array of references to data blocks for file larger than 254. 
     * Assume that the maximum size of a file is 127 * 254 (i.e., maximum allowed for a one-level indexing). 
     * 
     * 
     * 
     * */ 



} 
/* 
* 
* create a file (i.e., allocate one block for meta-level information; set the size to 0, the times to the current time, and the access rights to some default) 
create of a directory (just like a file creation, but with a different type) 
delete a file (return blocks and clean up your supporting structures; e.g., reset the bits in the bit vector) 
delete a directory (delete the files from the directory, and then delete the directory; clean up) 
obtain file information (type - file or directory, size, times, access right, owner) 
* 
* 
* */ 
void createAFile() 
{ 
} 

void createDirectory() 
{ 
} 


void deleteFile() 
{ 
} 

void obtainFileInfo() 
{ 

} 

をやったことを、このブロックあたり256バイトの2^16ブロックの配列を作成するためにノードメモリを設定する必要があります。どんな助けもありがとう。

+0

ない質問はここにあるものを確認してください。どこに問題がありますか? –

答えて

1

スペースの寸法が固定されているので、あなただけのようにメモリを宣言することができるはずです。

char space[65536][256]; 
関連する問題