/* * Construct one file in a PID directory, if a file with the given name should * exist at all. */ static void make_one_pid_entry(struct inode * parent, char * name, int slot) { struct inode *node; struct inode_stat stat; int i; /* Don't readd if it is already there. */ node = get_inode_by_name(parent, name); if (node != NULL) return; /* Only add the file if it is a known, registered name. */ for (i = 0; pid_files[i].name != NULL; i++) { if (!strcmp(name, pid_files[i].name)) { make_stat(&stat, slot, i); node = add_inode(parent, name, i, &stat, (index_t)0, (cbdata_t)0); if (node == NULL) out_of_inodes(); break; } } }
/* Returns the inode of the directory based on the date of RSS entry (pubDate). If it does not have a pubDate atribute, it will return the inode of the directory with name "no_pubDate". */ struct inode *get_inode_by_date (char *pubDate) { struct inode *result; struct inode *temp; struct inode_stat dir_stat; char month[4]; char year[5]; // Setting the variables of the struct in order to create a new directory. dir_stat.mode = S_IFDIR; dir_stat.uid = 0; dir_stat.gid = 0; dir_stat.size = 0; dir_stat.dev = NO_DEV; if (strcmp (pubDate, "") == 0){ // The RSS entry does not have an attribute called pubDate. result = get_inode_by_name(get_root_inode(), "no_pubDate"); if (result == 0){ result = add_inode(get_root_inode(), "no_pubDate", NO_INDEX, &dir_stat, 0, 0); } } else { // Extract the month from pubDate. strncpy(month, pubDate+8, 3); // Setting the end of the string. month[3] = 0; // Extract the year from pubDate. strncpy(year, pubDate+12, 4); year[4] = 0; temp = get_inode_by_name(get_root_inode(), year); if (temp == 0){ // Make a new directory. temp = add_inode(get_root_inode(), year, NO_INDEX, &dir_stat, 0, 0); result = add_inode(temp, month, NO_INDEX, &dir_stat, 0, 0); } else { // The directory already exists. result = get_inode_by_name(temp, month); if (result == 0){ // Make a new subdirectory. result = add_inode(temp, month, NO_INDEX, &dir_stat, 0, 0); } } } return result; }
static int search_file(const char *dir_name,const char *file_name,int file_type){ /* struct s_inode parent_dir_inode; */ /* if(!get_dir_inode(dir_name,&parent_dir_inode)){ */ /* return FALSE; */ /* } */ /* if(!get_file_inode(&parent_dir_inode,filename,p_inode)){ */ /* return FALSE; */ /* } */ INODE inode; return get_inode_by_name(dir_name,file_name,file_type,&inode); }
/* * Resolve a path string to an inode. */ int fs_lookup(ino_t dir_nr, char * name, struct fsdriver_node * node_details, int * is_mountpt) { struct inode *node, *child; int r; if ((node = find_inode(dir_nr)) == NULL) return EINVAL; if (!S_ISDIR(node->i_stat.mode)) return ENOTDIR; if (strlen(name) > PNAME_MAX) return ENAMETOOLONG; if (!strcmp(name, ".")) { /* Stay in the given directory. */ child = node; } else if (!strcmp(name, "..")) { /* Progress into the parent directory. */ if ((child = get_parent_inode(node)) == NULL) return ENOENT; /* deleted? should not be possible */ } else { /* Progress into a directory entry. Call the lookup hook, if * present, before doing the actual lookup. */ if (!is_inode_deleted(node) && vtreefs_hooks->lookup_hook != NULL) { r = vtreefs_hooks->lookup_hook(node, name, get_inode_cbdata(node)); if (r != OK) return r; } if ((child = get_inode_by_name(node, name)) == NULL) return ENOENT; } /* On success, open the resulting file and return its details. */ ref_inode(child); node_details->fn_ino_nr = get_inode_number(child); node_details->fn_mode = child->i_stat.mode; node_details->fn_size = child->i_stat.size; node_details->fn_uid = child->i_stat.uid; node_details->fn_gid = child->i_stat.gid; node_details->fn_dev = child->i_stat.dev; *is_mountpt = FALSE; return OK; }
int write_data(const char *src, const char *dest) { uint8_t cnt = 0; int8_t err = 0; uint32_t inode = 0; uint64_t chunkid = 0; uint32_t indx = 0; uint64_t size = 0; int8_t status = 0; char combo_path[MAX_NAME_LEN] = {0}; sprintf(combo_path, "%s/%s", dest, strrchr(src, '/')+1); inode = get_inode_by_name(combo_path); // 显示用inode代替 if (inode == 0) { fprintf(stderr, "dest(%s) creat failed\n", dest); } // 小于64M while (cnt<RETRIES) { cnt++; err = write_data_refresh_connection(inode, indx, &chunkid); if (err == 0) { break; }else if (err == -1) { fprintf(stderr, "connect is error\n"); }else if (err == -2) { fprintf(stderr, "status from fs server is error\n"); } fprintf(stderr, "file:%u,- can't connect to data (try counter: %u)\n",inode, cnt); sleep(2); } if (cnt>=RETRIES) { return err; } // 直写 status = direct_writeblock(src, chunkid, &size); if (status == 0) { // 修改ser中文件的大小 fs_writechunk_end(inode, indx, size); } // 关闭套接字 if (rw_sock >= 0) { tcpclose(rw_sock); rw_sock = -1; } return 0; }