From 0daa219ee1119e30059077da5be03c4506963fe2 Mon Sep 17 00:00:00 2001 From: Miao Xie Date: Wed, 3 Jul 2013 21:25:10 +0800 Subject: Btrfs-progs: don't close the file descriptor 0 when closing a device As we know, the file descriptor 0 is a special number, so we shouldn't use it to initialize the file descriptor of the devices, or we might close this special file descriptor by mistake when we close the devices. "-1" is a better choice. Signed-off-by: Miao Xie Signed-off-by: Chris Mason --- volumes.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'volumes.c') diff --git a/volumes.c b/volumes.c index d6f81f87..b88385bb 100644 --- a/volumes.c +++ b/volumes.c @@ -116,6 +116,7 @@ static int device_list_add(const char *path, /* we can safely leave the fs_devices entry around */ return -ENOMEM; } + device->fd = -1; device->devid = devid; memcpy(device->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE); @@ -161,8 +162,10 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices) again: list_for_each(cur, &fs_devices->devices) { device = list_entry(cur, struct btrfs_device, dev_list); - close(device->fd); - device->fd = -1; + if (device->fd != -1) { + close(device->fd); + device->fd = -1; + } device->writeable = 0; } -- cgit v1.2.3