* Regarding writing into raw file @ 2011-01-24 14:49 Gnanasekar Loganathan 2011-01-24 14:57 ` Vladimir 'φ-coder/phcoder' Serbinenko 0 siblings, 1 reply; 8+ messages in thread From: Gnanasekar Loganathan @ 2011-01-24 14:49 UTC (permalink / raw) To: The development of GNU GRUB Hi All, I try to opening a file called "(hd0,2,a)+10" from GRUB. 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. 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-24 14:49 Regarding writing into raw file Gnanasekar Loganathan @ 2011-01-24 14:57 ` Vladimir 'φ-coder/phcoder' Serbinenko 2011-01-25 6:02 ` Gnanasekar Loganathan 0 siblings, 1 reply; 8+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-24 14:57 UTC (permalink / raw) To: grub-devel [-- Attachment #1: Type: text/plain, Size: 1022 bytes --] 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 [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 294 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-24 14:57 ` Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-25 6:02 ` Gnanasekar Loganathan 2011-01-25 7:06 ` Vladimir 'φ-coder/phcoder' Serbinenko 0 siblings, 1 reply; 8+ messages in thread From: Gnanasekar Loganathan @ 2011-01-25 6:02 UTC (permalink / raw) To: The development of GNU GRUB Hi Vladimir, I'm using the grub_disk_write function to write the data. My goal is to erase all the data in that particular partition. Booted os will do read and write operation on that partition. -Gnana 2011/1/24 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@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 > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-25 6:02 ` Gnanasekar Loganathan @ 2011-01-25 7:06 ` Vladimir 'φ-coder/phcoder' Serbinenko 2011-01-25 10:34 ` Gnanasekar Loganathan 0 siblings, 1 reply; 8+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-25 7:06 UTC (permalink / raw) To: The development of GNU GRUB [-- Attachment #1: Type: text/plain, Size: 2084 bytes --] 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 <phcoder@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 [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 294 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-25 7:06 ` Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-25 10:34 ` Gnanasekar Loganathan 2011-01-25 11:42 ` Vladimir 'φ-coder/phcoder' Serbinenko 0 siblings, 1 reply; 8+ messages in thread From: Gnanasekar Loganathan @ 2011-01-25 10:34 UTC (permalink / raw) To: The development of GNU GRUB [-- Attachment #1: Type: text/plain, Size: 2469 bytes --] 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 <phcoder@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 <phcoder@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 > > [-- Attachment #2: dev_reset.c --] [-- Type: text/x-csrc, Size: 2418 bytes --] 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; } ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-25 10:34 ` Gnanasekar Loganathan @ 2011-01-25 11:42 ` Vladimir 'φ-coder/phcoder' Serbinenko 2011-01-25 13:01 ` Gnanasekar Loganathan 0 siblings, 1 reply; 8+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-25 11:42 UTC (permalink / raw) To: grub-devel [-- Attachment #1: Type: text/plain, Size: 286 bytes --] On 01/25/2011 11:34 AM, Gnanasekar Loganathan wrote: > if(grub_disk_write(disk, part_start, 0, SECTOR_SIZE, nvbuf) ) { > Writes as well as reads are to partition, not to entire disk erand so are the sector numbers -- Regards Vladimir 'φ-coder/phcoder' Serbinenko [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 294 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-25 11:42 ` Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-25 13:01 ` Gnanasekar Loganathan 2011-01-25 13:15 ` Vladimir 'φ-coder/phcoder' Serbinenko 0 siblings, 1 reply; 8+ messages in thread From: Gnanasekar Loganathan @ 2011-01-25 13:01 UTC (permalink / raw) To: The development of GNU GRUB Actually i'm writing to the first 512 bytes only. The value of SECTOR_SIZE is 512. Also i noticed that in loadenv.c, while reading the from grubenv file, read_hook is called. Why the read_hook is not called in this scenario? 2011/1/25 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>: > On 01/25/2011 11:34 AM, Gnanasekar Loganathan wrote: >> if(grub_disk_write(disk, part_start, 0, SECTOR_SIZE, nvbuf) ) { >> > Writes as well as reads are to partition, not to entire disk erand so > are the sector numbers > > -- > Regards > Vladimir 'φ-coder/phcoder' Serbinenko > > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding writing into raw file 2011-01-25 13:01 ` Gnanasekar Loganathan @ 2011-01-25 13:15 ` Vladimir 'φ-coder/phcoder' Serbinenko 0 siblings, 0 replies; 8+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2011-01-25 13:15 UTC (permalink / raw) To: grub-devel [-- Attachment #1: Type: text/plain, Size: 1327 bytes --] On 01/25/2011 02:01 PM, Gnanasekar Loganathan wrote: > Actually i'm writing to the first 512 bytes only. > You're not. You're writing to a sector well within the partition (the one at part_start and not the one at 0) > The value of SECTOR_SIZE is 512. > > Also i noticed that in loadenv.c, while reading the from grubenv file, > read_hook is called. Why the read_hook is not called in this scenario? > read_hook doesn't work with blocklists. You overengineer the stuff. Have a look at e.g. gptsync. > 2011/1/25 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>: > >> On 01/25/2011 11:34 AM, Gnanasekar Loganathan wrote: >> >>> if(grub_disk_write(disk, part_start, 0, SECTOR_SIZE, nvbuf) ) { >>> >>> >> Writes as well as reads are to partition, not to entire disk erand so >> are the sector numbers >> >> -- >> 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 [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 294 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-01-25 13:16 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-01-24 14:49 Regarding writing into raw file Gnanasekar Loganathan 2011-01-24 14:57 ` Vladimir 'φ-coder/phcoder' Serbinenko 2011-01-25 6:02 ` Gnanasekar Loganathan 2011-01-25 7:06 ` Vladimir 'φ-coder/phcoder' Serbinenko 2011-01-25 10:34 ` Gnanasekar Loganathan 2011-01-25 11:42 ` Vladimir 'φ-coder/phcoder' Serbinenko 2011-01-25 13:01 ` Gnanasekar Loganathan 2011-01-25 13:15 ` Vladimir 'φ-coder/phcoder' Serbinenko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).