- int i;
-
- /* table max length is null*/
- for( i = 0; i < TABLE_ITEM_COUNT; i++){
- /*compare name Max name Length 15*/
- if (snap_meta->array[i].name[0]){
- if(!strncmp(snap_meta->array[i].name, name, strlen(name)))
- return i;
- }
- }
- return -1; /* can not find */
-}
-
-int set_snap_meta_index(
- struct table_snap_meta_data *snap_meta,
- char *name,
- int size)
-{
- int i;
-
- for( i = 0; i < TABLE_ITEM_COUNT; i++){
- /*compare name Max name Length 15*/
- if (! snap_meta->array[i].name[0]){
- strcpy(snap_meta->array[i].name, name);
- snap_meta->count ++;
- snap_meta->array[i].start = i * TABLE_ITEM_SIZE + 1;
- snap_meta->array[i].len = size;
- return i;
- }
- }
- return -1; /* can not find */
-}
-
-static int fsfilt_ext3_get_meta_attr(struct super_block *sb, char* name,
- char* buf, int *size)
-{
- struct inode *inode;
- struct buffer_head *bh = NULL;
- struct table_snap_meta_data *s_attr;
- unsigned long map_len = 0, left_size;
- int i, error = 0, index = 0;
- ino_t ino;
- ENTRY;
-
- ino = SB_SNAPTABLE_INO(sb);
- if (ino == 0){
- CERROR("No table file \n");
- RETURN(-ENODATA);
- }
-
- inode = iget(sb, ino);
- if(!inode || is_bad_inode(inode)){
- CERROR("unable to get table ino %lu\n", ino);
- GOTO(out_iput, error = -ENOENT);
- }
- /*read the table from the table inode*/
- bh = ext3_bread(NULL, inode, 0, 0, &error);
- if (!bh) {
- CERROR("read table ino %lu, error %d\n", ino, error);
- GOTO(out_iput, error = -ENODATA);
- }
- s_attr = (struct table_snap_meta_data *)(bh->b_data);
- index = find_snap_meta_index(s_attr, name);
- if (index < 0) {
- CDEBUG(D_INFO, "not exit %s meta attr of table ino %lu \n",
- name, inode->i_ino);
- GOTO(out_iput, error = 0);
- }
- if (!buf || *size < s_attr->array[index].len) {
- /*return the size of this meta attr */
- error = s_attr->array[index].len;
- GOTO(out_iput, error);
- }
- map_len = (s_attr->array[index].len + sb->s_blocksize - 1)
- >> sb->s_blocksize_bits;
- left_size = *size;
- for(i = 0; i < map_len; i++) {
- struct buffer_head *array_bh = NULL;
-
- array_bh = ext3_bread(NULL, inode,
- s_attr->array[index].start + i,
- 0, &error);
- if (!array_bh) {
- CERROR("ino %lu read snap attr offset %d error %d \n",
- inode->i_ino, (s_attr->array[index].start + i),
- error);
- GOTO(out_iput, error);
- }
- if (left_size >= sb->s_blocksize)
- memcpy(buf, array_bh->b_data, sb->s_blocksize);
- else
- memcpy(buf, array_bh->b_data, left_size);
- left_size -= sb->s_blocksize;
- brelse(array_bh);
- }
- *size = s_attr->array[index].len;
-out_iput:
- brelse(bh);
- iput(inode);