include/smb_share_modes.h

ソースコードを見る。

データ構造

struct  smb_share_mode_entry

関数

smbdb_ctxsmb_share_mode_db_open (const char *db_path)
int smb_share_mode_db_close (struct smbdb_ctx *db_ctx)
int smb_lock_share_mode_entry (struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino)
int smb_unlock_share_mode_entry (struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino)
int smb_get_share_mode_entries (struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, struct smb_share_mode_entry **pp_list, unsigned char *p_delete_on_close)
int smb_create_share_mode_entry (struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *set_entry, const char *path)
int smb_delete_share_mode_entry (struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *set_entry)
int smb_change_share_mode_entry (struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *set_entry, const struct smb_share_mode_entry *new_entry)


関数

struct smbdb_ctx* smb_share_mode_db_open ( const char *  db_path  ) 

smb_share_modes.c59 行で定義されています。

参照先 smbdb_ctx::smb_tdbtdb_open().

00060 {
00061         struct smbdb_ctx *smb_db = (struct smbdb_ctx *)malloc(sizeof(struct smbdb_ctx));
00062 
00063         if (!smb_db) {
00064                 return NULL;
00065         }
00066 
00067         memset(smb_db, '\0', sizeof(struct smbdb_ctx));
00068 
00069         smb_db->smb_tdb = tdb_open(db_path,
00070                                 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST,
00071                                 O_RDWR|O_CREAT,
00072                                 0644);
00073 
00074         if (!smb_db->smb_tdb) {
00075                 free(smb_db);
00076                 return NULL;
00077         }
00078 
00079         /* Should check that this is the correct version.... */
00080         return smb_db;
00081 }

int smb_share_mode_db_close ( struct smbdb_ctx db_ctx  ) 

smb_share_modes.c89 行で定義されています。

参照先 smbdb_ctx::smb_tdbtdb_close().

00090 {
00091         int ret = tdb_close(db_ctx->smb_tdb);
00092         free(db_ctx);
00093         return ret;
00094 }

int smb_lock_share_mode_entry ( struct smbdb_ctx db_ctx,
uint64_t  dev,
uint64_t  ino 
)

smb_share_modes.c113 行で定義されています。

参照先 get_locking_key()smbdb_ctx::smb_tdbtdb_chainlock().

00116 {
00117         return tdb_chainlock(db_ctx->smb_tdb, get_locking_key(dev, ino));
00118 }

int smb_unlock_share_mode_entry ( struct smbdb_ctx db_ctx,
uint64_t  dev,
uint64_t  ino 
)

smb_share_modes.c120 行で定義されています。

参照先 get_locking_key()smbdb_ctx::smb_tdbtdb_chainunlock().

00123 {
00124         return tdb_chainunlock(db_ctx->smb_tdb, get_locking_key(dev, ino));
00125 }

int smb_get_share_mode_entries ( struct smbdb_ctx db_ctx,
uint64_t  dev,
uint64_t  ino,
struct smb_share_mode_entry **  pp_list,
unsigned char *  p_delete_on_close 
)

smb_share_modes.c170 行で定義されています。

参照先 TDB_DATA::dptrerrnoget_locking_key()list()process_id::pidlocking_data::ssharesharemodes_procid_to_pid()sharessmbdb_ctx::smb_tdbtdb_fetch()locking_data::u.

00175 {
00176         TDB_DATA db_data;
00177         struct smb_share_mode_entry *list = NULL;
00178         int num_share_modes = 0;
00179         struct locking_data *ld = NULL; /* internal samba db state. */
00180         struct share_mode_entry *shares = NULL;
00181         size_t i;
00182         int list_num;
00183 
00184         *pp_list = NULL;
00185         *p_delete_on_close = 0;
00186 
00187         db_data = tdb_fetch(db_ctx->smb_tdb, get_locking_key(dev, ino));
00188         if (!db_data.dptr) {
00189                 return 0;
00190         }
00191 
00192         ld = (struct locking_data *)db_data.dptr;
00193         num_share_modes = ld->u.s.num_share_mode_entries;
00194 
00195         if (!num_share_modes) {
00196                 free(db_data.dptr);
00197                 return 0;
00198         }
00199 
00200         list = (struct smb_share_mode_entry *)malloc(sizeof(struct smb_share_mode_entry)*num_share_modes);
00201         if (!list) {
00202                 free(db_data.dptr);
00203                 return -1;
00204         }
00205 
00206         memset(list, '\0', num_share_modes * sizeof(struct smb_share_mode_entry));
00207 
00208         shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
00209 
00210         list_num = 0;
00211         for (i = 0; i < num_share_modes; i++) {
00212                 struct share_mode_entry *share = &shares[i];
00213                 struct smb_share_mode_entry *sme = &list[list_num];
00214                 struct process_id pid = share->pid;
00215 
00216                 /* Check this process really exists. */
00217                 if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) {
00218                         continue; /* No longer exists. */
00219                 }
00220 
00221                 /* Ignore deferred open entries. */
00222                 if (share->op_type == DEFERRED_OPEN_ENTRY) {
00223                         continue;
00224                 }
00225 
00226                 /* Copy into the external list. */
00227                 sme->dev = (uint64_t)share->dev;
00228                 sme->ino = (uint64_t)share->inode;
00229                 sme->share_access = (uint32_t)share->share_access;
00230                 sme->access_mask = (uint32_t)share->access_mask;
00231                 sme->open_time.tv_sec = share->time.tv_sec;
00232                 sme->open_time.tv_usec = share->time.tv_usec;
00233                 sme->file_id = (uint32_t)share->share_file_id;
00234                 sme->pid = share->pid;
00235                 list_num++;
00236         }
00237 
00238         if (list_num == 0) {
00239                 free(db_data.dptr);
00240                 free(list);
00241                 return 0;
00242         }
00243 
00244         *p_delete_on_close = ld->u.s.delete_on_close;
00245         *pp_list = list;
00246         free(db_data.dptr);
00247         return list_num;
00248 }

int smb_create_share_mode_entry ( struct smbdb_ctx db_ctx,
uint64_t  dev,
uint64_t  ino,
const struct smb_share_mode_entry set_entry,
const char *  path 
)

smb_share_modes.c356 行で定義されています。

参照先 smb_create_share_mode_entry_ex().

00361 {
00362         if (*filename != '/') {
00363                 abort();
00364         }
00365         return smb_create_share_mode_entry_ex(db_ctx, dev, ino, new_entry,
00366                                                 "/", &filename[1]);
00367 }

int smb_delete_share_mode_entry ( struct smbdb_ctx db_ctx,
uint64_t  dev,
uint64_t  ino,
const struct smb_share_mode_entry set_entry 
)

smb_share_modes.c369 行で定義されています。

参照先 TDB_DATA::dptrTDB_DATA::dsizeerrnoget_locking_key()locking_key()process_id::pidlocking_data::sshareshare_mode_entry_equal()sharemodes_procid_to_pid()sharessmbdb_ctx::smb_tdbtdb_delete()tdb_fetch()tdb_store()locking_data::u.

00373 {
00374         TDB_DATA db_data;
00375         TDB_DATA locking_key =  get_locking_key(dev, ino);
00376         int orig_num_share_modes = 0;
00377         struct locking_data *ld = NULL; /* internal samba db state. */
00378         struct share_mode_entry *shares = NULL;
00379         char *new_data_p = NULL;
00380         size_t remaining_size = 0;
00381         size_t i, num_share_modes;
00382         const char *remaining_ptr = NULL;
00383 
00384         db_data = tdb_fetch(db_ctx->smb_tdb, locking_key);
00385         if (!db_data.dptr) {
00386                 return -1; /* Error - missing entry ! */
00387         }
00388 
00389         ld = (struct locking_data *)db_data.dptr;
00390         orig_num_share_modes = ld->u.s.num_share_mode_entries;
00391         shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
00392 
00393         if (orig_num_share_modes == 1) {
00394                 /* Only one entry - better be ours... */
00395                 if (!share_mode_entry_equal(del_entry, shares)) {
00396                         /* Error ! We can't delete someone else's entry ! */
00397                         free(db_data.dptr);
00398                         return -1;
00399                 }
00400                 /* It's ours - just remove the entire record. */
00401                 free(db_data.dptr);
00402                 return tdb_delete(db_ctx->smb_tdb, locking_key);
00403         }
00404 
00405         /* More than one - allocate a new record minus the one we'll delete. */
00406         new_data_p = (char *)malloc(
00407                 db_data.dsize - sizeof(struct share_mode_entry));
00408         if (!new_data_p) {
00409                 free(db_data.dptr);
00410                 return -1;
00411         }
00412 
00413         /* Copy the header. */
00414         memcpy(new_data_p, db_data.dptr, sizeof(struct locking_data));
00415 
00416         num_share_modes = 0;
00417         for (i = 0; i < orig_num_share_modes; i++) {
00418                 struct share_mode_entry *share = &shares[i];
00419                 struct process_id pid = share->pid;
00420 
00421                 /* Check this process really exists. */
00422                 if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) {
00423                         continue; /* No longer exists. */
00424                 }
00425 
00426                 if (share_mode_entry_equal(del_entry, share)) {
00427                         continue; /* This is our delete taget. */
00428                 }
00429 
00430                 memcpy(new_data_p + sizeof(struct locking_data) +
00431                                 (num_share_modes * sizeof(struct share_mode_entry)),
00432                         share, sizeof(struct share_mode_entry) );
00433 
00434                 num_share_modes++;
00435         }
00436 
00437         if (num_share_modes == 0) {
00438                 /* None left after pruning. Delete record. */
00439                 free(db_data.dptr);
00440                 free(new_data_p);
00441                 return tdb_delete(db_ctx->smb_tdb, locking_key);
00442         }
00443 
00444         /* Copy any delete token plus the terminating filenames. */
00445         remaining_ptr = db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(struct share_mode_entry));
00446         remaining_size = db_data.dsize - (remaining_ptr - db_data.dptr);
00447 
00448         memcpy(new_data_p + sizeof(struct locking_data) + (num_share_modes * sizeof(struct share_mode_entry)),
00449                 remaining_ptr,
00450                 remaining_size);
00451 
00452         free(db_data.dptr);
00453 
00454         db_data.dptr = new_data_p;
00455 
00456         /* Re-save smaller record. */
00457         ld = (struct locking_data *)db_data.dptr;
00458         ld->u.s.num_share_mode_entries = num_share_modes;
00459 
00460         db_data.dsize = sizeof(struct locking_data) + (num_share_modes * sizeof(struct share_mode_entry)) + remaining_size;
00461 
00462         if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {
00463                 free(db_data.dptr);
00464                 return -1;
00465         }
00466         free(db_data.dptr);
00467         return 0;
00468 }

int smb_change_share_mode_entry ( struct smbdb_ctx db_ctx,
uint64_t  dev,
uint64_t  ino,
const struct smb_share_mode_entry set_entry,
const struct smb_share_mode_entry new_entry 
)

smb_share_modes.c470 行で定義されています。

参照先 create_share_mode_entry()TDB_DATA::dptrerrnoget_locking_key()locking_key()process_id::pidlocking_data::sshareshare_mode_entry_equal()sharemodes_procid_to_pid()sharessmbdb_ctx::smb_tdbtdb_fetch()tdb_store()locking_data::u.

00475 {
00476         TDB_DATA db_data;
00477         TDB_DATA locking_key =  get_locking_key(dev, ino);
00478         int num_share_modes = 0;
00479         struct locking_data *ld = NULL; /* internal samba db state. */
00480         struct share_mode_entry *shares = NULL;
00481         size_t i;
00482         int found_entry = 0;
00483 
00484         db_data = tdb_fetch(db_ctx->smb_tdb, locking_key);
00485         if (!db_data.dptr) {
00486                 return -1; /* Error - missing entry ! */
00487         }
00488 
00489         ld = (struct locking_data *)db_data.dptr;
00490         num_share_modes = ld->u.s.num_share_mode_entries;
00491         shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
00492 
00493         for (i = 0; i < num_share_modes; i++) {
00494                 struct share_mode_entry *share = &shares[i];
00495                 struct process_id pid = share->pid;
00496 
00497                 /* Check this process really exists. */
00498                 if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) {
00499                         continue; /* No longer exists. */
00500                 }
00501 
00502                 if (share_mode_entry_equal(set_entry, share)) {
00503                         create_share_mode_entry(share, new_entry);
00504                         found_entry = 1;
00505                         break;
00506                 }
00507         }
00508 
00509         if (!found_entry) {
00510                 free(db_data.dptr);
00511                 return -1;
00512         }
00513 
00514         /* Save modified data. */
00515         if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {
00516                 free(db_data.dptr);
00517                 return -1;
00518         }
00519         free(db_data.dptr);
00520         return 0;
00521 }


Sambaに対してSat Aug 29 21:23:34 2009に生成されました。  doxygen 1.4.7