/** * counts the number of sub-directories in specified directory * @param sb super block * @param clu start cluster number of specified directory to count * @return return the number of sub-directories on sucess, errno on failure */ int count_subdir(struct super_block *sb, unsigned int clu) { struct buffer_head *bh = NULL; struct rfs_dir_entry *ep = NULL; unsigned int cpos = 0; unsigned int type; int count = 0, err = 0; while (1) { ep = get_entry_with_cluster(sb, clu, cpos++, &bh); if (IS_ERR(ep)) { err = PTR_ERR(ep); if (err == -EFAULT) /* end of cluster */ break; brelse(bh); return err; } /* check type of dir entry */ type = entry_type(ep); if (type == TYPE_DIR) count++; else if (type == TYPE_UNUSED) break; } brelse(bh); return count; }
/** * processes a log file (lf) stream manipulator. * @param _lf Path identifying file to write XML to. * @returns always returns *this **/ log_client& log_client::operator<<(lf _lf) { // make sure buffers initialized check_buffer(); // decide how to handle modifier. switch(_lf) { // end entry and flush (lf::end) case (lf::end): { // add the entry to the log schedule and create next entry. auto converted_buffer = std::dynamic_pointer_cast<log_entry>(*m_buffer); // ensure that the entry type is set... if(converted_buffer->entry_type() == category::unspecified) { // ... else use the fallback type converted_buffer->entry_type(default_entry_type()); } // ensure that the entry namespace is set... if(converted_buffer->log_namespace() == "") { // ... else ue the fallback namespace converted_buffer->log_namespace(default_namespace()); } // schedule the entry for serialization and re-initialize buffer m_output_interface->add_entry(converted_buffer); initialize_buffer(); break; } // unknown operator default: { #ifdef _DEBUG // if we are debugging - notify developer that the flow is unrecognized and going unprocessed. std::cerr << translate("WARNING: unknown inglenook log flag encountered in stream (inglenook::logging::lf): ") << _lf << std::endl; #endif } } return *this; }
/** * read dir entry in specified directory * @param inode specified directory inode * @param bh buffer head to read dir entries * @param ppos entry position to read * @param[out] dir_info to save dir entry info * @return return 0 on success, errno on failure */ static int internal_readdir(struct inode *inode, struct buffer_head **bh, loff_t *ppos, struct rfs_dir_info *dir_info) { #ifdef CONFIG_RFS_VFAT unsigned short uname[UNICODE_NAME_LENGTH]; #endif struct rfs_dir_entry *ep = NULL; loff_t index = *ppos; unsigned long ino; unsigned int type; int err; while (1) { ep = get_entry(inode, (u32) index, bh); if (IS_ERR(ep)) return PTR_ERR(ep); index++; type = entry_type(ep); dir_info->type = type; if (type == TYPE_UNUSED) return -INTERNAL_EOF; /* not error case */ if ((type == TYPE_DELETED) || (type == TYPE_EXTEND) || (type == TYPE_VOLUME)) continue; #ifdef CONFIG_RFS_VFAT uname[0] = 0x0; get_uname_from_entry(inode, index - 1, uname); if (uname[0] == 0x0 || !IS_VFAT(RFS_SB(inode->i_sb))) convert_dosname_to_cstring(dir_info->name, ep->name, ep->sysid); else convert_uname_to_cstring(dir_info->name, uname, RFS_SB(inode->i_sb)->nls_disk); #else convert_dosname_to_cstring(dir_info->name, ep->name, ep->sysid); #endif err = rfs_iunique(inode, index - 1, &ino); if (err) return err; dir_info->ino = ino; *ppos = index; return 0; } return 0; }
~scheduler_type() { if (running()) { m_terminated = true; // terminates the background thread entry_type& entry = m_global_queue.allocate_entry(); delete entry.dangling(); entry = entry_type(&m_global_queue); entry.wait(); #if defined(LIBXSTREAM_STDFEATURES) m_thread.detach(); #else # if defined(__GNUC__) pthread_detach(m_thread); # else CloseHandle(m_thread); # endif #endif } }
/** * check whether directory is emtpy * @param dir inode corresponding to the directory * @return return 0 on success, errno on failure * * is_dir_empty is usually invoked before removing or renaming directry. */ int is_dir_empty(struct inode *dir) { struct buffer_head *bh = NULL; struct rfs_dir_entry *ep; unsigned int cpos = 0; int err = 0, count = 0; unsigned int type; if (dir->i_ino == ROOT_INO) return -ENOTEMPTY; while (1) { ep = get_entry(dir, cpos++, &bh); if (IS_ERR(ep)) { err = PTR_ERR(ep); if (err == -EFAULT) err = 0; goto out; } type = entry_type(ep); if ((type == TYPE_FILE) || (type == TYPE_DIR)) { /* check entry index bigger than entry index of parent directory (..) */ if (++count > 2) { err = -ENOTEMPTY; goto out; } } else if (type == TYPE_UNUSED) { /* do not need checking anymore */ goto out; } } out : brelse(bh); return err; }