static struct share_mode_entry *find_share_mode_entry(struct share_mode_data *d, struct share_mode_entry *entry) { int i; for (i=0; i<d->num_share_modes; i++) { struct share_mode_entry *e = &d->share_modes[i]; if (is_valid_share_mode_entry(entry) && is_valid_share_mode_entry(e) && share_modes_identical(e, entry)) { return e; } } return NULL; }
ssize_t del_share_entry( SMB_DEV_T dev, SMB_INO_T inode, share_mode_entry *entry, share_mode_entry **ppse) { TDB_DATA dbuf; struct locking_data *data; int i, del_count=0; share_mode_entry *shares; ssize_t count = 0; if (ppse) *ppse = NULL; /* read in the existing share modes */ dbuf = tdb_fetch(tdb, locking_key(dev, inode)); if (!dbuf.dptr) return -1; data = (struct locking_data *)dbuf.dptr; shares = (share_mode_entry *)(dbuf.dptr + sizeof(*data)); /* * Find any with this pid and delete it * by overwriting with the rest of the data * from the record. */ DEBUG(10,("del_share_entry: num_share_modes = %d\n", data->u.num_share_mode_entries )); for (i=0;i<data->u.num_share_mode_entries;) { if (share_modes_identical(&shares[i], entry)) { DEBUG(10,("del_share_entry: deleted %s\n", share_mode_str(i, &shares[i]) )); if (ppse) *ppse = memdup(&shares[i], sizeof(*shares)); data->u.num_share_mode_entries--; memmove(&shares[i], &shares[i+1], dbuf.dsize - (sizeof(*data) + (i+1)*sizeof(*shares))); del_count++; DEBUG(10,("del_share_entry: deleting entry %d\n", i )); } else { i++; } } if (del_count) { /* the record may have shrunk a bit */ dbuf.dsize -= del_count * sizeof(*shares); count = (ssize_t)data->u.num_share_mode_entries; /* store it back in the database */ if (data->u.num_share_mode_entries == 0) { if (tdb_delete(tdb, locking_key(dev, inode)) == -1) count = -1; } else { if (tdb_store(tdb, locking_key(dev, inode), dbuf, TDB_REPLACE) == -1) count = -1; } } DEBUG(10,("del_share_entry: Remaining table.\n")); print_share_mode_table((struct locking_data *)dbuf.dptr); SAFE_FREE(dbuf.dptr); return count; }