fsw_status_t fsw_dnode_create_root_with_tree(struct fsw_volume *vol, fsw_u64 tree_id, fsw_u64 dnode_id, struct fsw_dnode **dno_out) { fsw_status_t status; struct fsw_dnode *dno; // allocate memory for the structure status = fsw_alloc_zero(vol->fstype_table->dnode_struct_size, (void **)&dno); if (status) return status; // fill the structure dno->vol = vol; dno->parent = NULL; dno->tree_id = tree_id; dno->dnode_id = dnode_id; dno->type = FSW_DNODE_TYPE_DIR; dno->refcount = 1; dno->name.type = FSW_STRING_TYPE_EMPTY; // TODO: instead, call a function to create an empty string in the native string type fsw_dnode_register(vol, dno); *dno_out = dno; return FSW_SUCCESS; }
struct fsw_posix_volume * fsw_posix_mount(const char *path, struct fsw_fstype_table *fstype_table) { fsw_status_t status; struct fsw_posix_volume *pvol; // allocate volume structure status = fsw_alloc_zero(sizeof(struct fsw_posix_volume), (void **)&pvol); if (status) return NULL; pvol->fd = -1; // open underlying file/device pvol->fd = open(path, O_RDONLY, 0); if (pvol->fd < 0) { fprintf(stderr, "fsw_posix_mount: %s: %s\n", path, strerror(errno)); fsw_free(pvol); return NULL; } // mount the filesystem if (fstype_table == NULL) fstype_table = &FSW_FSTYPE_TABLE_NAME(FSTYPE); status = fsw_mount(pvol, &fsw_posix_host_table, fstype_table, &pvol->vol); if (status) { fprintf(stderr, "fsw_posix_mount: fsw_mount returned %d\n", status); fsw_free(pvol); return NULL; } return pvol; }
static struct fsw_volume *create_dummy_volume(EFI_DISK_IO *diskio, UINT32 mediaid) { fsw_status_t err; struct fsw_volume *vol; FSW_VOLUME_DATA *Volume; err = fsw_alloc_zero(sizeof(struct fsw_volume), (void **)&vol); if(err) return NULL; err = fsw_alloc_zero(sizeof(FSW_VOLUME_DATA), (void **)&Volume); if(err) { fsw_free(vol); return NULL; } /* fstype_table->volume_free for fsw_unmount */ vol->fstype_table = &dummy_fstype; /* host_data needded to fsw_block_get()/fsw_efi_read_block() */ Volume->DiskIo = diskio; Volume->MediaId = mediaid; vol->host_data = Volume; vol->host_table = &fsw_efi_host_table; return vol; }
fsw_status_t fsw_dnode_create_with_tree(struct fsw_dnode *parent_dno, fsw_u64 tree_id, fsw_u64 dnode_id, int type, struct fsw_string *name, struct fsw_dnode **dno_out) { fsw_status_t status; struct fsw_volume *vol = parent_dno->vol; struct fsw_dnode *dno; // check if we already have a dnode with the same id for (dno = vol->dnode_head; dno; dno = dno->next) { if (dno->dnode_id == dnode_id && dno->tree_id == tree_id) { fsw_dnode_retain(dno); *dno_out = dno; return FSW_SUCCESS; } } // allocate memory for the structure status = fsw_alloc_zero(vol->fstype_table->dnode_struct_size, (void **)&dno); if (status) return status; // fill the structure dno->vol = vol; dno->parent = parent_dno; fsw_dnode_retain(dno->parent); dno->tree_id = tree_id; dno->dnode_id = dnode_id; dno->type = type; dno->refcount = 1; status = fsw_strdup_coerce(&dno->name, vol->host_table->native_string_type, name); if (status) { fsw_free(dno); return status; } fsw_dnode_register(vol, dno); *dno_out = dno; return FSW_SUCCESS; }
fsw_status_t fsw_mount(void *host_data, struct fsw_host_table *host_table, struct fsw_fstype_table *fstype_table, struct fsw_volume **vol_out) { fsw_status_t status; struct fsw_volume *vol; // allocate memory for the structure status = fsw_alloc_zero(fstype_table->volume_struct_size, (void **)&vol); if (status) return status; // initialize fields vol->phys_blocksize = 512; vol->log_blocksize = 512; vol->label.type = FSW_STRING_TYPE_EMPTY; vol->host_data = host_data; vol->host_table = host_table; vol->fstype_table = fstype_table; vol->host_string_type = host_table->native_string_type; // let the fs driver mount the file system status = vol->fstype_table->volume_mount(vol); if (status) goto errorexit; /// @todo anything else? *vol_out = vol; return FSW_SUCCESS; errorexit: fsw_unmount(vol); return status; }
static fsw_status_t rr_find_nm(struct fsw_iso9660_volume *vol, struct iso9660_dirrec *dirrec, int off, struct fsw_string *str) { fsw_u8 *r, *begin; int fCe = 0; struct fsw_rock_ridge_susp_nm *nm; int limit = dirrec->dirrec_length; begin = (fsw_u8 *)dirrec; r = (fsw_u8 *)dirrec + off; str->data = NULL; str->len = 0; str->size = 0; str->type = 0; while(off < limit) { if (r[0] == 'C' && r[1] == 'E' && r[2] == 28) { int rc; int ce_off; union fsw_rock_ridge_susp_ce *ce; if (fCe == 0) fsw_alloc_zero(ISO9660_BLOCKSIZE, (void *)&begin); fCe = 1; DEBUG((DEBUG_WARN, "%a:%d we found CE before NM or its continuation\n", __FILE__, __LINE__)); ce = (union fsw_rock_ridge_susp_ce *)r; limit = ISOINT(ce->X.len); ce_off = ISOINT(ce->X.offset); rc = rr_read_ce(vol, ce, begin); if (rc != FSW_SUCCESS) { fsw_free(begin); return rc; } begin += ce_off; r = begin; } if (r[0] == 'N' && r[1] == 'M') { nm = (struct fsw_rock_ridge_susp_nm *)r; if( nm->e.sig[0] == 'N' && nm->e.sig[1] == 'M') { int len = 0; fsw_u8 *tmp = NULL; if (nm->flags & RR_NM_CURR) { fsw_memdup(str->data, ".", 1); str->len = 1; goto done; } if (nm->flags & RR_NM_PARE) { fsw_memdup(str->data, "..", 2); str->len = 2; goto done; } len = nm->e.len - sizeof(struct fsw_rock_ridge_susp_nm) + 1; fsw_alloc_zero(str->len + len, (void **)&tmp); if (str->data != NULL) { fsw_memcpy(tmp, str->data, str->len); fsw_free(str->data); } DEBUG((DEBUG_INFO, "dst:%p src:%p len:%d\n", tmp + str->len, &nm->name[0], len)); fsw_memcpy(tmp + str->len, &nm->name[0], len); str->data = tmp; str->len += len; if ((nm->flags & RR_NM_CONT) == 0) goto done; } } r++; off = (int)(r - (fsw_u8 *)begin); } if(fCe == 1) fsw_free(begin); return FSW_NOT_FOUND; done: str->type = FSW_STRING_TYPE_ISO88591; str->size = str->len; if(fCe == 1) fsw_free(begin); return FSW_SUCCESS; }