seq_file.c (7483d45f0aee3afc0646d185cabd4af9f6cab58c) | seq_file.c (1ac101a5d675aca2426c5cd460c73fb95acb8391) |
---|---|
1/* 2 * linux/fs/seq_file.c 3 * 4 * helper functions for making synthetic files from sequences of records. 5 * initial implementation -- AV, Oct 2001. 6 */ 7 8#include <linux/fs.h> --- 126 unchanged lines hidden (view full) --- 135 size_t copied = 0; 136 loff_t pos; 137 size_t n; 138 void *p; 139 int err = 0; 140 141 mutex_lock(&m->lock); 142 | 1/* 2 * linux/fs/seq_file.c 3 * 4 * helper functions for making synthetic files from sequences of records. 5 * initial implementation -- AV, Oct 2001. 6 */ 7 8#include <linux/fs.h> --- 126 unchanged lines hidden (view full) --- 135 size_t copied = 0; 136 loff_t pos; 137 size_t n; 138 void *p; 139 int err = 0; 140 141 mutex_lock(&m->lock); 142 |
143 /* 144 * seq_file->op->..m_start/m_stop/m_next may do special actions 145 * or optimisations based on the file->f_version, so we want to 146 * pass the file->f_version to those methods. 147 * 148 * seq_file->version is just copy of f_version, and seq_file 149 * methods can treat it simply as file version. 150 * It is copied in first and copied out after all operations. 151 * It is convenient to have it as part of structure to avoid the 152 * need of passing another argument to all the seq_file methods. 153 */ 154 m->version = file->f_version; 155 |
|
143 /* Don't assume *ppos is where we left it */ 144 if (unlikely(*ppos != m->read_pos)) { | 156 /* Don't assume *ppos is where we left it */ 157 if (unlikely(*ppos != m->read_pos)) { |
145 m->read_pos = *ppos; | |
146 while ((err = traverse(m, *ppos)) == -EAGAIN) 147 ; 148 if (err) { 149 /* With prejudice... */ 150 m->read_pos = 0; 151 m->version = 0; 152 m->index = 0; 153 m->count = 0; 154 goto Done; | 158 while ((err = traverse(m, *ppos)) == -EAGAIN) 159 ; 160 if (err) { 161 /* With prejudice... */ 162 m->read_pos = 0; 163 m->version = 0; 164 m->index = 0; 165 m->count = 0; 166 goto Done; |
167 } else { 168 m->read_pos = *ppos; |
|
155 } 156 } 157 | 169 } 170 } 171 |
158 /* 159 * seq_file->op->..m_start/m_stop/m_next may do special actions 160 * or optimisations based on the file->f_version, so we want to 161 * pass the file->f_version to those methods. 162 * 163 * seq_file->version is just copy of f_version, and seq_file 164 * methods can treat it simply as file version. 165 * It is copied in first and copied out after all operations. 166 * It is convenient to have it as part of structure to avoid the 167 * need of passing another argument to all the seq_file methods. 168 */ 169 m->version = file->f_version; | |
170 /* grab buffer if we didn't have one */ 171 if (!m->buf) { 172 m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); 173 if (!m->buf) 174 goto Enomem; 175 } 176 /* if not empty - flush it first */ 177 if (m->count) { --- 459 unchanged lines hidden (view full) --- 637 m->count += len; 638 return 0; 639 } 640 m->count = m->size; 641 return -1; 642} 643EXPORT_SYMBOL(seq_puts); 644 | 172 /* grab buffer if we didn't have one */ 173 if (!m->buf) { 174 m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); 175 if (!m->buf) 176 goto Enomem; 177 } 178 /* if not empty - flush it first */ 179 if (m->count) { --- 459 unchanged lines hidden (view full) --- 639 m->count += len; 640 return 0; 641 } 642 m->count = m->size; 643 return -1; 644} 645EXPORT_SYMBOL(seq_puts); 646 |
647/* 648 * A helper routine for putting decimal numbers without rich format of printf(). 649 * only 'unsigned long long' is supported. 650 * This routine will put one byte delimiter + number into seq_file. 651 * This routine is very quick when you show lots of numbers. 652 * In usual cases, it will be better to use seq_printf(). It's easier to read. 653 */ 654int seq_put_decimal_ull(struct seq_file *m, char delimiter, 655 unsigned long long num) 656{ 657 int len; 658 659 if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ 660 goto overflow; 661 662 m->buf[m->count++] = delimiter; 663 664 if (num < 10) { 665 m->buf[m->count++] = num + '0'; 666 return 0; 667 } 668 669 len = num_to_str(m->buf + m->count, m->size - m->count, num); 670 if (!len) 671 goto overflow; 672 m->count += len; 673 return 0; 674overflow: 675 m->count = m->size; 676 return -1; 677} 678EXPORT_SYMBOL(seq_put_decimal_ull); 679 |
|
645/** 646 * seq_write - write arbitrary data to buffer 647 * @seq: seq_file identifying the buffer to which data should be written 648 * @data: data address 649 * @len: number of bytes 650 * 651 * Return 0 on success, non-zero otherwise. 652 */ --- 169 unchanged lines hidden --- | 680/** 681 * seq_write - write arbitrary data to buffer 682 * @seq: seq_file identifying the buffer to which data should be written 683 * @data: data address 684 * @len: number of bytes 685 * 686 * Return 0 on success, non-zero otherwise. 687 */ --- 169 unchanged lines hidden --- |