Hi, Attached my c file, kindly review and let me know if any mistakes that i did in this file.
Thanks, Gnana 2011/1/25 Vladimir 'φ-coder/phcoder' Serbinenko <phco...@gmail.com>: > On 01/25/2011 07:02 AM, Gnanasekar Loganathan wrote: >> Hi Vladimir, >> >> I'm using the grub_disk_write function to write the data. >> > This should work (as long as used right, of course). >> My goal is to erase all the data in that particular partition. >> >> > GRUB isn't the right place to write so much data. I recommend having a > small kernel with ramdisk. >> Booted os will do read and write operation on that partition. >> >> -Gnana >> >> 2011/1/24 Vladimir 'φ-coder/phcoder' Serbinenko <phco...@gmail.com>: >> >>> On 01/24/2011 03:49 PM, Gnanasekar Loganathan wrote: >>> >>>> Hi All, >>>> >>>> I try to opening a file called "(hd0,2,a)+10" from GRUB. >>>> >>>> >>> This is old syntax. New one is (hd0,netbsd1) >>> >>>> For me open got success and able read some of the data. >>>> But i'm not able to write some data into the file, getting "out of >>>> partition" error. >>>> >>>> >>> GRUB has no file writing functions whatsoever, only disk writing >>> (grub_disk_write) >>> You can look into save_env in grub-core/commands/loadenv.c for reference >>> on the limited file overwrite possibilities. >>> I would be able to help better if I knew what your end goal is. >>> >>>> Kindly help me, how to open, read and write into a raw file from the GRUB. >>>> >>>> FYI: Partition type is NetBSD one. >>>> >>>> If you need any info, kindly revert back. >>>> >>>> Thanks, >>>> Gnana >>>> >>>> _______________________________________________ >>>> Grub-devel mailing list >>>> Grub-devel@gnu.org >>>> http://lists.gnu.org/mailman/listinfo/grub-devel >>>> >>>> >>>> >>> >>> -- >>> Regards >>> Vladimir 'φ-coder/phcoder' Serbinenko >>> >>> >>> >>> _______________________________________________ >>> Grub-devel mailing list >>> Grub-devel@gnu.org >>> http://lists.gnu.org/mailman/listinfo/grub-devel >>> >>> >>> >> _______________________________________________ >> Grub-devel mailing list >> Grub-devel@gnu.org >> http://lists.gnu.org/mailman/listinfo/grub-devel >> >> > > > -- > Regards > Vladimir 'φ-coder/phcoder' Serbinenko > > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > >
char rBuf[208 * 512] = {0}; static int dev_reset(void) { char *dev_file = "(hd0,2,a)+2048"; grub_file_t file; grub_disk_t disk; grub_disk_addr_t part_start = 0; grub_disk_addr_t bt_sector = 0; unsigned bt_offset = 0; unsigned bt_length = 0; auto void NESTED_FUNC_ATTR read_hook (grub_disk_addr_t sector, unsigned offset, unsigned length); void NESTED_FUNC_ATTR read_hook (grub_disk_addr_t sector, unsigned offset, unsigned length) { if( bt_sector == 0 ) { bt_sector = sector; bt_offset = offset; bt_length = length; grub_printf("bt_sector = %llu\nbt_offset = %u\nbt_length = %u\n", bt_sector, bt_offset, bt_length); } else { grub_dprintf("bsd", "%s:%s:%d Still more...!\n", __FILE__, __FUNCTION__, __LINE__); } } file = grub_file_open(dev_file); if( !file ) { grub_printf("Error: Unable to open '%s' .\n", dev_file); return grub_errno; } if( ! file->device->disk ) { grub_printf("disk device required!\n"); return grub_errno; } file->read_hook = read_hook; grub_file_read(file, rBuf, sizeof(rBuf)); file->read_hook = 0; disk = file->device->disk; grub_printf("File size: %llu\ntotal_sectors = %llu", file->size, disk->total_sectors); if( disk->partition ) part_start = grub_partition_get_start(disk->partition); else part_start = 0; grub_printf("%s[%d]: %llu\n", __FUNCTION__, __LINE__, part_start); if( bt_sector > part_start ) { part_start = bt_sector - part_start; } grub_printf("%s[%d]: %llu\n", __FUNCTION__, __LINE__, part_start); { int i=0; do { grub_printf("%x ",rBuf[i++]); } while(i<512); } grub_memset(nvbuf, 0, SECTOR_SIZE); if(grub_disk_write(disk, part_start, 0, SECTOR_SIZE, nvbuf) ) { grub_printf("%s %s:%d Disk write error!\n", __FILE__, __FUNCTION__, __LINE__); grub_printf("disk = %x\n part_start = %llu\n", (unsigned int)disk, part_start); } else grub_dprintf("bsd", "Device reset done!"); grub_file_close(file); return grub_errno; }
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel