/* there are 3 steps here : 1. set related 'in_use' flag in dev_usage 2. create related data structure of the device 3. create daemon thread for the device (step 1 is done before calling register) */ int register_device(char *name, RELATED_DEV *rdev, IDEV_TYPE type) { IDEV *p_idev; int i; /* step 2 */ /* check if there is enough room */ if (dev_list.dev_total >= MAX_DEVICE_NO) return -1; i = find_empty_entry(); if (i >= 0) { /* temprarily, we only support LC6311 module */ p_idev = idev_init(name, rdev, type); if (p_idev) { /* idev_init is also ok, then update device list. */ dev_list.dev[i].active = 1; dev_list.dev[i].idev = p_idev; dev_list.dev_total++; } else { /* idev_init failed */ return -2; } } /* FIX ME */ /* temporarily, enable module as soon as possible. */ idev_set_enable(p_idev); /* step 3 */ /* create daemon thread for the device. */ if (pthread_create(&p_idev->thread_id, NULL, device_daemon, p_idev)) { /* thread creation error */ dm_log(NULL, "create thread for device [%d][%s] error.", i, name); /* free the device structure */ idev_release(p_idev); return -3; } /* all ok. */ return i; }
void data_phonebook_add(data_phonebook obj, data_entry *arg, CORBA_Environment *ev) { impl_node impl = find_impl(obj, ev); int i; /* If we failed to find the implementation, return. */ if (ev->_major != CORBA_NO_EXCEPTION) return; /* See if this entry is already in the phonebook. */ for (i = 0; i < impl->pb_size; ++i) { if (impl->pb[i] && !strcmp(impl->pb[i]->n, arg->n)) { /* * We found a duplicate! Raise a `data_duplicate' * exception. */ data_duplicate *d = (data_duplicate *) CORBA_alloc(sizeof(data_duplicate)); if (!d) { signal_no_memory(ev); return; } d->p = (CORBA_char *) CORBA_alloc(strlen(impl->pb[i]->p) + 1); if (!d->p) { CORBA_free(d); signal_no_memory(ev); return; } strcpy(d->p, impl->pb[i]->p); CORBA_BOA_set_exception(boa, ev, CORBA_USER_EXCEPTION, ex_data_duplicate, d); return; } } /* Find an empty entry in `impl'; grow the phonebook if necessary. */ i = find_empty_entry(impl, ev); if (ev->_major != CORBA_NO_EXCEPTION) return; /* * Allocate memory for the new entry. Note that we have to copy the * `arg' data because CORBA says we can't keep pointers into `in' data * after this function has returned. */ impl->pb[i] = (data_entry *) malloc(sizeof(data_entry)); if (!impl->pb[i]) { signal_no_memory(ev); return; } impl->pb[i]->n = (char *) malloc(sizeof(char) * (strlen(arg->n) + 1)); impl->pb[i]->p = (char *) malloc(sizeof(char) * (strlen(arg->p) + 1)); if (!(impl->pb[i]->n) || !(impl->pb[i]->p)) { /* Free what we have allocated and signal an exception. */ if (impl->pb[i]->n) free(impl->pb[i]->n); if (impl->pb[i]->p) free(impl->pb[i]->p); free(impl->pb[i]); impl->pb[i] = 0; signal_no_memory(ev); return; } /* Copy the `arg' information into our phonebook. */ strcpy(impl->pb[i]->n, arg->n); strcpy(impl->pb[i]->p, arg->p); /* Increment the number of entries in our phonebook. */ impl->pb_elems++; /* Success! */ return; }
static void m2i_open_write(path_t *path, cbmdirent_t *dent, uint8_t type, buffer_t *buf, uint8_t append) { uint16_t offset; uint8_t *str; uint8_t *nameptr; uint8_t i; FRESULT res; /* Check for read-only image file */ if (!(partition[path->part].imagehandle.flag & FA_WRITE)) { set_error(ERROR_WRITE_PROTECT); return; } if (append) { open_existing(path, dent, type, buf, 1); } else { if (check_invalid_name(dent->name)) { set_error(ERROR_SYNTAX_JOKER); return; } /* Find an empty entry */ offset = find_empty_entry(path->part); if (offset < M2I_ENTRY_OFFSET) return; memset(ops_scratch, ' ', sizeof(ops_scratch)); str = ops_scratch; switch (type & TYPE_MASK) { case TYPE_DEL: *str++ = 'D'; break; case TYPE_SEQ: *str++ = 'S'; break; case TYPE_PRG: *str++ = 'P'; break; case TYPE_USR: *str++ = 'U'; break; default: /* Unknown type - play it safe, don't create a file */ return; } *str++ = ':'; /* Generate a FAT name */ for (i=0;i<8;i++) { *str++ = '0'; } *str = 0; do { FILINFO finfo; finfo.lfn = NULL; /* See if it's already there */ res = f_stat(&partition[path->part].fatfs, ops_scratch + M2I_FATNAME_OFFSET, &finfo); if (res == FR_OK) { str = ops_scratch + M2I_FATNAME_OFFSET+7; /* Increment name */ while (1) { if (++(*str) > '9') { *str-- = '0'; continue; } break; } } } while (res == FR_OK); if (res != FR_NO_FILE) return; /* Copy the CBM file name */ nameptr = dent->name; str = ops_scratch + M2I_CBMNAME_OFFSET; while (*nameptr) *str++ = *nameptr++; /* Update dent with the new FAT name */ ustrcpy(dent->pvt.fat.realname, ops_scratch + M2I_FATNAME_OFFSET); /* Finish creating the M2I entry */ ops_scratch[M2I_FATNAME_OFFSET + 8] = ' '; ops_scratch[M2I_FATNAME_OFFSET + 12] = ':'; ops_scratch[M2I_CBMNAME_OFFSET + CBM_NAME_LENGTH] = 13; ops_scratch[M2I_CBMNAME_OFFSET + CBM_NAME_LENGTH + 1] = 10; /* Write it */ if (image_write(path->part, offset, ops_scratch, M2I_ENTRY_LEN, 1)) return; /* Write the actual file - always without P00 header */ fat_open_write(path, dent, TYPE_RAW, buf, append); /* Abort on error */ if (current_error) { /* No error checking here. Either it works or everything has failed. */ ops_scratch[0] = '-'; image_write(path->part, offset, ops_scratch, 1, 1); } } }
static int create_entry(struct ghostfs *gfs, const char *path, bool is_dir, struct dir_entry **entry) { struct dir_iter it; struct cluster *prev = NULL, *next = NULL; const char *name; int cluster_nr = 0; int ret; ret = dir_iter_lookup(gfs, &it, path, true); if (ret < 0) return ret; if (!dir_entry_is_directory(it.entry)) return -ENOTDIR; name = last_component(path); if (strlen(name) > FILENAME_SIZE - 1) return -ENAMETOOLONG; if (!name[0]) return -EINVAL; if (dir_contains(gfs, it.entry->cluster, name) == 0) return -EEXIST; ret = find_empty_entry(gfs, &it, it.entry->cluster); if (ret < 0) { int nr; if (ret != -ENOENT) return ret; nr = alloc_clusters(gfs, 1, &next, true); if (nr < 0) return nr; prev = it.cluster; find_empty_entry(gfs, &it, nr); prev->hdr.next = nr; cluster_set_dirty(prev, true); } if (is_dir) { cluster_nr = alloc_clusters(gfs, 1, NULL, true); if (cluster_nr < 0) { if (next) { free_clusters(gfs, next); prev->hdr.next = 0; } return cluster_nr; } } strcpy(it.entry->filename, name); dir_entry_set_size(it.entry, 0, is_dir); it.entry->cluster = cluster_nr; cluster_set_dirty(it.cluster, true); if (entry) *entry = it.entry; return 0; }