Ядро ОС Linux



         

Пpогpамиpование файловой системы /proc. - часть 4


if (count < 0) return -EINVAL; page = (char *) get_free_page(GFP-KERNEL); if (!page) return -ENOMEM; ino = inode->i_ino; switch (ino) { case 200: length = get_bar(page); break; case 201: length = get_suds(page); break; case 202: length = get_xyzzy(page); break; case 203: length = get_baz(page); break; case 206: length = get_rootfile(page); break; default: free_page((unsigned long) page); return -EBADF; } if (file->f_pos >= length) { free_page ((unsigned long) page); return 0; } if (count + file->t_pos > length) count = length - file->f_pos; end = count + file->f_pos; memcpy_tofs(buf, page + file->f_pos, count); free_page((unsigned long) page); file->f_pos = end; return count;

}

static int proc_ lookupfoo(struct inode * dir, const char * name, int len, struct inode ** result) { unsigned int pid, ino; int i;

*result = NULL; if (!dir) return -ENOENT; if (!S_ISDIR(dir->i_mode)) { iput(dir); return -ENOENT; } ino = dir->i_ino; i = NR_FOO_DIRENTRY; while (i-- > 0 && !proc_match(len,name,foo_dir+i)) /* nothing */; if (i < 0) { iput(dir); return -ENOENT; } if (!(*result = iget(dir->i_sb,ino))) { iput(dir); return -ENOENT; } iput(dir); return 0; }

static int proc_readfoo(struct inode * inode, struct file * flie, struct dirent * dirent, int count)

{ struct proc_dir_entry * de; unsigned int pid, ino; lnt i,j;

if (!inode !S_ISDIR(inode->i_mode)) return -EBADF; ino = inode->i_ino; if (((unsigned) filp->f_pos) < NR_FOO_DIRENTRY) { de = foo_dir + filp->f_pos; filp->f_pos++; i = de->namelen; ino = de->low_ino; put_fs _long(ino, &dirent->d_ino); put_fs_word(i, &dirent->d_reclen); put_fs_byte(0, i+dirent->d_name); j = i; while (i--) put_fs_byte(de->name[i], i+dirent->d_name); return j; } return 0; }

unsigned int get_foo(char * buffer)

{ /* code to find everything goes here */

return sprintf(buffer, "format string ", variables); }

unsigned int get_suds(char * buffer) { /* code to find everything goes here */




Содержание  Назад  Вперед