/**************************************************************************** find a zero bit in a bitmap starting at the specified offset, with wraparound ****************************************************************************/ int bitmap_find(struct bitmap *bm, unsigned ofs) { unsigned int i, j; if (ofs > bm->n) ofs = 0; i = ofs; while (i < bm->n) { if (~(bm->b[i/32])) { j = i; do { if (!bitmap_query(bm, j)) return j; j++; } while (j & 31 && j < bm->n); } i += 32; i &= ~31; } i = 0; while (i < ofs) { if (~(bm->b[i/32])) { j = i; do { if (!bitmap_query(bm, j)) return j; j++; } while (j & 31 && j < bm->n); } i += 32; i &= ~31; } return -1; }
/**************************************************************************** * find a zero bit in a bitmap starting at the specified offset, with * wraparound * ****************************************************************************/ int bitmap_find(bitmap_t *bitmap, unsigned ofs) { int i, j; if (ofs > bitmap->n) ofs = 0; i = ofs; while (i < bitmap->n) { if (~(bitmap->b[i/32])) { j = i; do { if (!bitmap_query(bitmap, j)) return j; j++; } while (j & 31 && j < bitmap->n); } i += 32; i &= ~31; } i = 0; while (i < ofs) { if (~(bitmap->b[i/32])) { j = i; do { if (!bitmap_query(bitmap, j)) return j; j++; } while (j & 31 && j < bitmap->n); } i += 32; i &= ~31; } return -1; }
enum pdb_value_state pdb_get_init_flags(const struct samu *sampass, enum pdb_elements element) { enum pdb_value_state ret = PDB_DEFAULT; if (!sampass->change_flags || !sampass->set_flags) return ret; if (bitmap_query(sampass->set_flags, element)) { DEBUG(11, ("element %d: SET\n", element)); ret = PDB_SET; } if (bitmap_query(sampass->change_flags, element)) { DEBUG(11, ("element %d: CHANGED\n", element)); ret = PDB_CHANGED; } if (ret == PDB_DEFAULT) { DEBUG(11, ("element %d: DEFAULT\n", element)); } return ret; }
/***************************************************** a wrapper for dup() *******************************************************/ int smbw_dup(int fd) { int fd2; struct smbw_file *file, *file2; smbw_busy++; file = smbw_file(fd); if (!file) { errno = EBADF; goto failed; } fd2 = dup(file->fd); if (fd2 == -1) { goto failed; } if (bitmap_query(smbw_file_bmap, fd2)) { DEBUG(0,("ERROR: fd already open in dup!\n")); errno = EIO; goto failed; } file2 = (struct smbw_file *)malloc(sizeof(*file2)); if (!file2) { close(fd2); errno = ENOMEM; goto failed; } ZERO_STRUCTP(file2); *file2 = *file; file2->fd = fd2; file->f->ref_count++; bitmap_set(smbw_file_bmap, fd2); DLIST_ADD(smbw_files, file2); smbw_busy--; return fd2; failed: smbw_busy--; return -1; }
/***************************************************** a wrapper for open() *******************************************************/ int smbw_open(const char *fname, int flags, mode_t mode) { fstring server, share; pstring path; struct smbw_server *srv=NULL; int eno=0, fd = -1; struct smbw_file *file=NULL; smbw_init(); if (!fname) { errno = EINVAL; return -1; } smbw_busy++; /* work out what server they are after */ smbw_parse_path(fname, server, share, path); /* get a connection to the server */ srv = smbw_server(server, share); if (!srv) { /* smbw_server sets errno */ goto failed; } if (path[strlen(path)-1] == '\\') { fd = -1; } else { fd = cli_open(&srv->cli, path, flags, DENY_NONE); } if (fd == -1) { /* it might be a directory. Maybe we should use chkpath? */ eno = smbw_errno(&srv->cli); fd = smbw_dir_open(fname); if (fd == -1) errno = eno; smbw_busy--; return fd; } file = (struct smbw_file *)malloc(sizeof(*file)); if (!file) { errno = ENOMEM; goto failed; } ZERO_STRUCTP(file); file->f = (struct smbw_filedes *)malloc(sizeof(*(file->f))); if (!file->f) { errno = ENOMEM; goto failed; } ZERO_STRUCTP(file->f); file->f->cli_fd = fd; file->f->fname = strdup(path); if (!file->f->fname) { errno = ENOMEM; goto failed; } file->srv = srv; file->fd = open(SMBW_DUMMY, O_WRONLY); if (file->fd == -1) { errno = EMFILE; goto failed; } if (bitmap_query(smbw_file_bmap, file->fd)) { DEBUG(0,("ERROR: fd used in smbw_open\n")); errno = EIO; goto failed; } file->f->ref_count=1; bitmap_set(smbw_file_bmap, file->fd); DLIST_ADD(smbw_files, file); DEBUG(4,("opened %s\n", fname)); smbw_busy--; return file->fd; failed: if (fd != -1) { cli_close(&srv->cli, fd); } if (file) { if (file->f) { SAFE_FREE(file->f->fname); SAFE_FREE(file->f); } SAFE_FREE(file); } smbw_busy--; return -1; }
/***************************************************** determine if a file descriptor is a smb one *******************************************************/ int smbw_fd(int fd) { if (smbw_busy) return 0; return smbw_file_bmap && bitmap_query(smbw_file_bmap, fd); }