losetup on boot-floppies
In last days, I tried to find the reason for the ugly behaviour of the
loop driver, see #135504. I tried to reuser the code from losetup.c,
nothing did work. A loop device created by losetup can be attached and
detached as usual, but if done from debootstrap, it works once, leaves a
[loop0] zombie and on the next set_loop, the device is busy but not
showed as active (or sometimes showed though) and cannot be removed.
My solution: we put losetup on the BFs and use system calls for setting
loop devices. Any other ideas?
Gruss/Regards,
Eduard.
--
<Zomb>.oO(Die 3 F's fon Debian: Find the bug, Fix the bug, Forward to
maintainer)
-- Zomb in #debian.de
Index: debian/changelog
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/debian/changelog,v
retrieving revision 1.1102
diff -u -r1.1102 changelog
--- debian/changelog 2002/03/12 12:00:46 1.1102
+++ debian/changelog 2002/03/12 14:27:18
@@ -40,6 +40,9 @@
- user-friendly LILO menu setup, including a warning about LILO security;
IMHO enough to say, closes: #27007
- made old ext2-compatibility options appear in verbose mode only
+ - moved from del_loop/set_loop to external losetup program. Still no idea
+ why the kernel breaks on our functions, but having losetup on BFs is
+ better though. Closes: #135504 and partially #110717
* Petter Reinholdtsen
- canonicalize messages, closes: #136904, #137076
- define LANGUAGE_INST in dbootstrap_settings
Index: scripts/rootdisk/EXTRACT_LIST_all
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/scripts/rootdisk/EXTRACT_LIST_all,v
retrieving revision 1.49
diff -u -r1.49 EXTRACT_LIST_all
--- scripts/rootdisk/EXTRACT_LIST_all 2002/03/03 14:24:18 1.49
+++ scripts/rootdisk/EXTRACT_LIST_all 2002/03/12 14:27:24
@@ -9,3 +9,4 @@
makedev
modutils
netbase
+mount
Index: scripts/rootdisk/SMALL_BASE_LIST_all
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/scripts/rootdisk/SMALL_BASE_LIST_all,v
retrieving revision 1.35
diff -u -r1.35 SMALL_BASE_LIST_all
--- scripts/rootdisk/SMALL_BASE_LIST_all 2001/12/25 00:45:39 1.35
+++ scripts/rootdisk/SMALL_BASE_LIST_all 2002/03/12 14:27:24
@@ -25,3 +25,4 @@
usr/lib/debootstrap/pkgdetails
usr/lib/debootstrap/scripts/woody
usr/lib/debootstrap/scripts/sid
+sbin/losetup
Index: utilities/dbootstrap/losetup.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/losetup.c,v
retrieving revision 1.9
diff -u -r1.9 losetup.c
--- utilities/dbootstrap/losetup.c 2002/03/10 19:27:17 1.9
+++ utilities/dbootstrap/losetup.c 2002/03/12 14:27:25
@@ -34,72 +34,17 @@
int del_loop(const char *device)
{
- int fd;
- DEBUGMSG("Called del_loop for %s", device);
-
- sync();
- if ((fd = open(device, O_RDONLY)) < 0) {
- ERRMSG("del_loop failed opening device %s", device);
- return( FALSE);
- }
- /* reap any zombies that were created */
- waitpid(-1, NULL, WNOHANG);
- if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
- /* sometimes, the kernel turns crazy. Sync some times and hope that filehandles will be released */
- sync();
- sync();
- if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
- ERRMSG("del_loop ioctl got negative result doing LOOP_CLR_FD on device %s; this is probably not a big deal", device);
- return( FALSE);
- }
- }
- close(fd);
- return( TRUE);
+ char buf[26]; /* /sbin/losetup /dev/loopXY */
+ sprintf(buf, "/sbin/losetup %s", device);
+ return system(buf);
}
int set_loop(const char *device, const char *file, int offset, int *loopro)
{
- struct loop_info loopinfo;
- int fd, ffd, mode;
- DEBUGMSG("Called set_loop for %s", device);
-
- mode = *loopro ? O_RDONLY : O_RDWR;
- if ((ffd = open (file, mode)) < 0 && !*loopro
- && (errno != EROFS || (ffd = open (file, mode = O_RDONLY)) < 0)) {
- ERRMSG("set_loop got error opening file %s", file);
- return 1;
- }
- if ((fd = open (device, mode)) < 0) {
- close(ffd);
- ERRMSG("set_loop get error opening device %s", device);
- return 1;
- }
- *loopro = (mode == O_RDONLY);
-
- memset(&loopinfo, 0, sizeof(loopinfo));
- strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
- loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
-
- loopinfo.lo_offset = offset;
+ char *buf = (char *) malloc(strlen(device) + strlen(file) + 20);
+ sprintf(buf, "/sbin/losetup %s %s", device, file);
- loopinfo.lo_encrypt_key_size = 0;
- if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
- ERRMSG("set_loop ioctl got error doing LOOP_SET_FD on file %s", file);
- close(fd);
- close(ffd);
- return 1;
- }
- if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
- (void) ioctl(fd, LOOP_CLR_FD, 0);
- ERRMSG("set_loop ioctl got error doing LOOP_SET_STATUS on device %s",
- device);
- close(fd);
- close(ffd);
- return 1;
- }
- close(fd);
- close(ffd);
- return 0;
+ return system(buf);
}
char *find_unused_loop_device (void)
Reply to: