/* STEP 1 * Initialize the file system. This is called once upon * file system startup. */ void *fs_init(struct fuse_conn_info *conn) { ssize_t ret_val = 0; time_t current_time = time(NULL); fprintf(stderr, "fs_init --- initializing file system.\n"); s3context_t *ctx = GET_PRIVATE_DATA; s3fs_clear_bucket(ctx->s3bucket); s3dirent_t * root_dir = (s3dirent_t *)malloc(sizeof(s3dirent_t)); root_dir->type = S3FS_TYPE_DIR; memset(root_dir->name, 0, 256); strncpy(root_dir->name, ".", 1); root_dir->mode = ROOT_DIR_MODE; root_dir->nlink = 0; root_dir->uid = fuse_get_context()->uid; root_dir->gid = fuse_get_context()->gid; root_dir->size = 0; root_dir->blocks = 0; root_dir->atime = current_time; root_dir->mtime = current_time; root_dir->ctime = current_time; ret_val = s3fs_put_object(ctx->s3bucket, "/", (uint8_t *)root_dir, sizeof(s3dirent_t)); if (-1 == ret_val) { free(root_dir); return NULL; } free(root_dir); return ctx; }
/* * You shouldn't need to change anything here. If you need to * add more items to the filesystem context object (which currently * only has the S3 bucket name), you might want to initialize that * here (but you could also reasonably do that in fs_init). */ int main(int argc, char *argv[]) { // don't allow anything to continue if we're running as root. bad stuff. if ((getuid() == 0) || (geteuid() == 0)) { fprintf(stderr, "Don't run this as root.\n"); return -1; } s3context_t *stateinfo = malloc(sizeof(s3context_t)); memset(stateinfo, 0, sizeof(s3context_t)); char *s3key = getenv(S3ACCESSKEY); if (!s3key) { fprintf(stderr, "%s environment variable must be defined\n", S3ACCESSKEY); } char *s3secret = getenv(S3SECRETKEY); if (!s3secret) { fprintf(stderr, "%s environment variable must be defined\n", S3SECRETKEY); } char *s3bucket = getenv(S3BUCKET); if (!s3bucket) { fprintf(stderr, "%s environment variable must be defined\n", S3BUCKET); } strncpy((*stateinfo).s3bucket, s3bucket, BUFFERSIZE); fprintf(stderr, "Initializing s3 credentials\n"); s3fs_init_credentials(s3key, s3secret); fprintf(stderr, "Totally clearing s3 bucket\n"); s3fs_clear_bucket(s3bucket); fprintf(stderr, "Starting up FUSE file system.\n"); int fuse_stat = fuse_main(argc, argv, &s3fs_ops, stateinfo); fprintf(stderr, "Startup function (fuse_main) returned %d\n", fuse_stat); return fuse_stat; }
/* * Initialize the file system. This is called once upon * file system startup. */ void *fs_init(struct fuse_conn_info *conn) { fprintf(stderr, "fs_init --- initializing file system.\n"); s3context_t *ctx = GET_PRIVATE_DATA; if(s3fs_clear_bucket(ctx->s3bucket)!=0) { fprintf(stderr, "Failed to initialize file system: Error clearing bucket"); return -EIO; } s3dirent_t root; struct stat meta;//= malloc(sizeof(struct stat)); meta.st_mode = (S_IFDIR | S_IRWXU); meta.st_nlink = 1; meta.st_uid = getuid(); meta.st_gid = getgid(); struct timeval tv; time_t the_time; gettimeofday(&tv, NULL); the_time = tv.tv_sec; meta.st_atime = the_time; meta.st_mtime = the_time; meta.st_ctime = the_time; strcpy(root.name, "."); root.num_entries = 1; root.type = 'D'; root.metadata = meta; root.metadata.st_size = sizeof(s3dirent_t); printf("ROOT PERMISSIONS: %o\n",root.metadata.st_mode); if(s3fs_put_object(ctx->s3bucket, "/", (uint8_t *)&root, sizeof(root)) != sizeof(root)) { fprintf(stderr, "PUT OBJECT FAILED IN FS_INIT"); return ctx; } printf("init worked? \n"); return ctx; }
/* * Initialize the file system. This is called once upon * file system startup. */ void *fs_init(struct fuse_conn_info *conn) { fprintf(stderr, "fs_init --- initializing file system.\n"); s3context_t *ctx = GET_PRIVATE_DATA; char* s3bucket = (char*)ctx; s3fs_clear_bucket(s3bucket); s3dirent_t root_dir; root_dir.type = 'D'; root_dir.name = "."; char* key = "/"; root_dir.protection = S_IFDIR; root_dir.type = 'D'; root_dir.user_id = getuid(); root_dir.group_id = getgid(); root_dir.hard_links = 0; root_dir.size = 0; root_dir.last_access = time(NULL); root_dir.mod_time = time(NULL); root_dir.status_change = time(NULL); s3fs_put_object(s3bucket, key, (uint8_t*)&root_dir, sizeof(s3dirent_t)); return ctx; }
/* * Initialize the file system. This is called once upon * file system startup. */ void *fs_init(struct fuse_conn_info *conn) //ALMOST DONE { //sommers code fprintf(stderr, "fs_init --- initializing file system.\n"); s3context_t *ctx = GET_PRIVATE_DATA; //our code //need to completely destroy everything in this bucket s3fs_clear_bucket(ctx->s3bucket); //not sure about parameter //do we need to check that the clear did not fail? //create a directory object to represent your root directory and store that on S3 s3dirent_t dir[2]; //create directory structur time_t temp; //create temporory timestamp time(&temp); //get current time strcpy(dir[0].name, "."); //set name of directory to ".". dir[0].size = sizeof(s3dirent_t); //set directory size to size of s3dirent struct strcpy(dir[0].type,"D"); //set diretory type to directory dir[0].timeAccess = temp; //set directory last access time to temp dir[0].timeMod = temp; //set directory last modified time to temp dir[0].userID = getuid(); //get user ID dir[0].groupID = getgid(); //get group ID dir[0].protection = (S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR); strcpy(dir[1].type, "U"); //set type to unused, indicating end //initialize object (put object in s3), unless fail. then return error if ((s3fs_put_object(ctx->s3bucket, "/", (const uint8_t *)&dir, sizeof(dir)))!=sizeof(dir)) { fprintf(stderr, "failed to intialize"); return -EIO; } //everything worked as planned. continue printf("%s\n","-------FINISHED INIT-------"); return ctx; }