Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] nvram - convert PRINT_PROC to seq_file

Convert the /proc/drivers/nvram file from the old PRINT_PROC macro
to the new seq_file filesystem.

Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

+83 -79
+83 -79
drivers/char/nvram.c
··· 32 32 * added changelog 33 33 * 1.2 Erik Gilling: Cobalt Networks support 34 34 * Tim Hockin: general cleanup, Cobalt support 35 + * 1.3 Wim Van Sebroeck: convert PRINT_PROC to seq_file 35 36 */ 36 37 37 - #define NVRAM_VERSION "1.2" 38 + #define NVRAM_VERSION "1.3" 38 39 39 40 #include <linux/module.h> 40 41 #include <linux/smp_lock.h> ··· 107 106 #include <linux/mc146818rtc.h> 108 107 #include <linux/init.h> 109 108 #include <linux/proc_fs.h> 109 + #include <linux/seq_file.h> 110 110 #include <linux/spinlock.h> 111 111 #include <linux/io.h> 112 112 #include <linux/uaccess.h> ··· 124 122 static void mach_set_checksum(void); 125 123 126 124 #ifdef CONFIG_PROC_FS 127 - static int mach_proc_infos(unsigned char *contents, char *buffer, int *len, 128 - off_t *begin, off_t offset, int size); 125 + static void mach_proc_infos(unsigned char *contents, struct seq_file *seq, 126 + void *offset); 129 127 #endif 130 128 131 129 /* ··· 372 370 } 373 371 374 372 #ifndef CONFIG_PROC_FS 375 - static int nvram_read_proc(char *buffer, char **start, off_t offset, 376 - int size, int *eof, void *data) 373 + static int nvram_add_proc_fs(void) 377 374 { 378 375 return 0; 379 376 } 377 + 380 378 #else 381 379 382 - static int nvram_read_proc(char *buffer, char **start, off_t offset, 383 - int size, int *eof, void *data) 380 + static int nvram_proc_read(struct seq_file *seq, void *offset) 384 381 { 385 382 unsigned char contents[NVRAM_BYTES]; 386 - int i, len = 0; 387 - off_t begin = 0; 383 + int i = 0; 388 384 389 385 spin_lock_irq(&rtc_lock); 390 386 for (i = 0; i < NVRAM_BYTES; ++i) 391 387 contents[i] = __nvram_read_byte(i); 392 388 spin_unlock_irq(&rtc_lock); 393 389 394 - *eof = mach_proc_infos(contents, buffer, &len, &begin, offset, size); 390 + mach_proc_infos(contents, seq, offset); 395 391 396 - if (offset >= begin + len) 397 - return 0; 398 - *start = buffer + (offset - begin); 399 - return (size < begin + len - offset) ? size : begin + len - offset; 400 - 392 + return 0; 401 393 } 402 394 403 - /* This macro frees the machine specific function from bounds checking and 404 - * this like that... */ 405 - #define PRINT_PROC(fmt,args...) \ 406 - do { \ 407 - *len += sprintf(buffer + *len, fmt, ##args); \ 408 - if (*begin + *len > offset + size) \ 409 - return 0; \ 410 - if (*begin + *len < offset) { \ 411 - *begin += *len; \ 412 - *len = 0; \ 413 - } \ 414 - } while (0) 395 + static int nvram_proc_open(struct inode *inode, struct file *file) 396 + { 397 + return single_open(file, nvram_proc_read, NULL); 398 + } 399 + 400 + static const struct file_operations nvram_proc_fops = { 401 + .owner = THIS_MODULE, 402 + .open = nvram_proc_open, 403 + .read = seq_read, 404 + .llseek = seq_lseek, 405 + .release = single_release, 406 + }; 407 + 408 + static int nvram_add_proc_fs(void) 409 + { 410 + if (!proc_create("driver/nvram", 0, NULL, &nvram_proc_fops)) 411 + return -ENOMEM; 412 + return 0; 413 + } 415 414 416 415 #endif /* CONFIG_PROC_FS */ 417 416 ··· 446 443 NVRAM_MINOR); 447 444 goto out; 448 445 } 449 - if (!create_proc_read_entry("driver/nvram", 0, NULL, nvram_read_proc, 450 - NULL)) { 446 + ret = nvram_add_proc_fs(); 447 + if (ret) { 451 448 printk(KERN_ERR "nvram: can't create /proc/driver/nvram\n"); 452 - ret = -ENOMEM; 453 449 goto outmisc; 454 450 } 455 451 ret = 0; ··· 513 511 "monochrome", 514 512 }; 515 513 516 - static int pc_proc_infos(unsigned char *nvram, char *buffer, int *len, 517 - off_t *begin, off_t offset, int size) 514 + static void pc_proc_infos(unsigned char *nvram, struct seq_file *seq, 515 + void *offset) 518 516 { 519 517 int checksum; 520 518 int type; ··· 523 521 checksum = __nvram_check_checksum(); 524 522 spin_unlock_irq(&rtc_lock); 525 523 526 - PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not "); 524 + seq_printf(seq, "Checksum status: %svalid\n", checksum ? "" : "not "); 527 525 528 - PRINT_PROC("# floppies : %d\n", 526 + seq_printf(seq, "# floppies : %d\n", 529 527 (nvram[6] & 1) ? (nvram[6] >> 6) + 1 : 0); 530 - PRINT_PROC("Floppy 0 type : "); 528 + seq_printf(seq, "Floppy 0 type : "); 531 529 type = nvram[2] >> 4; 532 530 if (type < ARRAY_SIZE(floppy_types)) 533 - PRINT_PROC("%s\n", floppy_types[type]); 531 + seq_printf(seq, "%s\n", floppy_types[type]); 534 532 else 535 - PRINT_PROC("%d (unknown)\n", type); 536 - PRINT_PROC("Floppy 1 type : "); 533 + seq_printf(seq, "%d (unknown)\n", type); 534 + seq_printf(seq, "Floppy 1 type : "); 537 535 type = nvram[2] & 0x0f; 538 536 if (type < ARRAY_SIZE(floppy_types)) 539 - PRINT_PROC("%s\n", floppy_types[type]); 537 + seq_printf(seq, "%s\n", floppy_types[type]); 540 538 else 541 - PRINT_PROC("%d (unknown)\n", type); 539 + seq_printf(seq, "%d (unknown)\n", type); 542 540 543 - PRINT_PROC("HD 0 type : "); 541 + seq_printf(seq, "HD 0 type : "); 544 542 type = nvram[4] >> 4; 545 543 if (type) 546 - PRINT_PROC("%02x\n", type == 0x0f ? nvram[11] : type); 544 + seq_printf(seq, "%02x\n", type == 0x0f ? nvram[11] : type); 547 545 else 548 - PRINT_PROC("none\n"); 546 + seq_printf(seq, "none\n"); 549 547 550 - PRINT_PROC("HD 1 type : "); 548 + seq_printf(seq, "HD 1 type : "); 551 549 type = nvram[4] & 0x0f; 552 550 if (type) 553 - PRINT_PROC("%02x\n", type == 0x0f ? nvram[12] : type); 551 + seq_printf(seq, "%02x\n", type == 0x0f ? nvram[12] : type); 554 552 else 555 - PRINT_PROC("none\n"); 553 + seq_printf(seq, "none\n"); 556 554 557 - PRINT_PROC("HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 555 + seq_printf(seq, "HD type 48 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 558 556 nvram[18] | (nvram[19] << 8), 559 557 nvram[20], nvram[25], 560 558 nvram[21] | (nvram[22] << 8), nvram[23] | (nvram[24] << 8)); 561 - PRINT_PROC("HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 559 + seq_printf(seq, "HD type 49 data: %d/%d/%d C/H/S, precomp %d, lz %d\n", 562 560 nvram[39] | (nvram[40] << 8), 563 561 nvram[41], nvram[46], 564 562 nvram[42] | (nvram[43] << 8), nvram[44] | (nvram[45] << 8)); 565 563 566 - PRINT_PROC("DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 567 - PRINT_PROC("Extended memory: %d kB (configured), %d kB (tested)\n", 564 + seq_printf(seq, "DOS base memory: %d kB\n", nvram[7] | (nvram[8] << 8)); 565 + seq_printf(seq, "Extended memory: %d kB (configured), %d kB (tested)\n", 568 566 nvram[9] | (nvram[10] << 8), nvram[34] | (nvram[35] << 8)); 569 567 570 - PRINT_PROC("Gfx adapter : %s\n", gfx_types[(nvram[6] >> 4) & 3]); 568 + seq_printf(seq, "Gfx adapter : %s\n", 569 + gfx_types[(nvram[6] >> 4) & 3]); 571 570 572 - PRINT_PROC("FPU : %sinstalled\n", 571 + seq_printf(seq, "FPU : %sinstalled\n", 573 572 (nvram[6] & 2) ? "" : "not "); 574 573 575 - return 1; 574 + return; 576 575 } 577 576 #endif 578 577 ··· 643 640 "2", "4", "16", "256", "65536", "??", "??", "??" 644 641 }; 645 642 646 - static int atari_proc_infos(unsigned char *nvram, char *buffer, int *len, 647 - off_t *begin, off_t offset, int size) 643 + static void atari_proc_infos(unsigned char *nvram, struct seq_file *seq, 644 + void *offset) 648 645 { 649 646 int checksum = nvram_check_checksum(); 650 647 int i; 651 648 unsigned vmode; 652 649 653 - PRINT_PROC("Checksum status : %svalid\n", checksum ? "" : "not "); 650 + seq_printf(seq, "Checksum status : %svalid\n", checksum ? "" : "not "); 654 651 655 - PRINT_PROC("Boot preference : "); 652 + seq_printf(seq, "Boot preference : "); 656 653 for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i) { 657 654 if (nvram[1] == boot_prefs[i].val) { 658 - PRINT_PROC("%s\n", boot_prefs[i].name); 655 + seq_printf(seq, "%s\n", boot_prefs[i].name); 659 656 break; 660 657 } 661 658 } 662 659 if (i < 0) 663 - PRINT_PROC("0x%02x (undefined)\n", nvram[1]); 660 + seq_printf(seq, "0x%02x (undefined)\n", nvram[1]); 664 661 665 - PRINT_PROC("SCSI arbitration : %s\n", 662 + seq_printf(seq, "SCSI arbitration : %s\n", 666 663 (nvram[16] & 0x80) ? "on" : "off"); 667 - PRINT_PROC("SCSI host ID : "); 664 + seq_printf(seq, "SCSI host ID : "); 668 665 if (nvram[16] & 0x80) 669 - PRINT_PROC("%d\n", nvram[16] & 7); 666 + seq_printf(seq, "%d\n", nvram[16] & 7); 670 667 else 671 - PRINT_PROC("n/a\n"); 668 + seq_printf(seq, "n/a\n"); 672 669 673 670 /* the following entries are defined only for the Falcon */ 674 671 if ((atari_mch_cookie >> 16) != ATARI_MCH_FALCON) 675 - return 1; 672 + return; 676 673 677 - PRINT_PROC("OS language : "); 674 + seq_printf(seq, "OS language : "); 678 675 if (nvram[6] < ARRAY_SIZE(languages)) 679 - PRINT_PROC("%s\n", languages[nvram[6]]); 676 + seq_printf(seq, "%s\n", languages[nvram[6]]); 680 677 else 681 - PRINT_PROC("%u (undefined)\n", nvram[6]); 682 - PRINT_PROC("Keyboard language: "); 678 + seq_printf(seq, "%u (undefined)\n", nvram[6]); 679 + seq_printf(seq, "Keyboard language: "); 683 680 if (nvram[7] < ARRAY_SIZE(languages)) 684 - PRINT_PROC("%s\n", languages[nvram[7]]); 681 + seq_printf(seq, "%s\n", languages[nvram[7]]); 685 682 else 686 - PRINT_PROC("%u (undefined)\n", nvram[7]); 687 - PRINT_PROC("Date format : "); 688 - PRINT_PROC(dateformat[nvram[8] & 7], 683 + seq_printf(seq, "%u (undefined)\n", nvram[7]); 684 + seq_printf(seq, "Date format : "); 685 + seq_printf(seq, dateformat[nvram[8] & 7], 689 686 nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/'); 690 - PRINT_PROC(", %dh clock\n", nvram[8] & 16 ? 24 : 12); 691 - PRINT_PROC("Boot delay : "); 687 + seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12); 688 + seq_printf(seq, "Boot delay : "); 692 689 if (nvram[10] == 0) 693 - PRINT_PROC("default"); 690 + seq_printf(seq, "default"); 694 691 else 695 - PRINT_PROC("%ds%s\n", nvram[10], 692 + seq_printf(seq, "%ds%s\n", nvram[10], 696 693 nvram[10] < 8 ? ", no memory test" : ""); 697 694 698 695 vmode = (nvram[14] << 8) || nvram[15]; 699 - PRINT_PROC("Video mode : %s colors, %d columns, %s %s monitor\n", 696 + seq_printf(seq, 697 + "Video mode : %s colors, %d columns, %s %s monitor\n", 700 698 colors[vmode & 7], 701 699 vmode & 8 ? 80 : 40, 702 700 vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC"); 703 - PRINT_PROC(" %soverscan, compat. mode %s%s\n", 701 + seq_printf(seq, " %soverscan, compat. mode %s%s\n", 704 702 vmode & 64 ? "" : "no ", 705 703 vmode & 128 ? "on" : "off", 706 704 vmode & 256 ? 707 705 (vmode & 16 ? ", line doubling" : ", half screen") : ""); 708 706 709 - return 1; 707 + return; 710 708 } 711 709 #endif 712 710